import RT-Thread RTOS 0.3.x to Google SVN

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
bernard.xiong
2009-07-02 22:48:23 +00:00
parent 80c72e66de
commit bda4730a94
321 changed files with 116698 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
#ifndef __DFS_CACHE_H__
#define __DFS_CACHE_H__
#include <rtthread.h>
#define IOMAN_STATUS_ATTR_VALIDDATA 0
#define IOMAN_STATUS_ATTR_USERBUFFER 1
#define IOMAN_STATUS_ATTR_WRITE 2
#define IOM_MODE_READONLY 1
#define IOM_MODE_READWRITE 2
#define IOM_MODE_EXP_REQ 4
#define DFS_SECTOR_SIZE 512
struct _IOManager
{
rt_device_t device;
rt_uint8_t numbuf;
rt_uint32_t sector[DFS_CACHE_MAX_NUM];
rt_uint8_t status[DFS_CACHE_MAX_NUM];
rt_uint8_t usage [DFS_CACHE_MAX_NUM];
/* cache FIFO */
rt_uint8_t ring_fifo[DFS_CACHE_MAX_NUM];
/* cache buffer */
rt_uint8_t cache[DFS_CACHE_MAX_NUM][DFS_SECTOR_SIZE];
};
typedef struct _IOManager IOManager;
rt_err_t ioman_init(IOManager* ioman);
rt_uint8_t* ioman_getSector(IOManager *ioman, rt_uint32_t address, rt_uint8_t mode);
rt_err_t ioman_releaseSector(IOManager *ioman, rt_uint8_t* buf);
rt_err_t ioman_flushRange(IOManager *ioman, rt_uint32_t address_low, rt_uint32_t address_high);
rt_err_t ioman_directSectorRead(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector);
rt_err_t ioman_directSectorWrite(IOManager *ioman, rt_uint32_t address, rt_uint8_t* buf, rt_uint32_t numsector);
#endif
+173
View File
@@ -0,0 +1,173 @@
/*
+------------------------------------------------------------------------------
| Device FileSystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_def.h, the definitions of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author notes
| 2004-10-01 ffxz The first version.
| 2004-10-14 ffxz Clean up the code.
| 2005-01-22 ffxz Clean up the code, port to MinGW
+------------------------------------------------------------------------------
*/
#ifndef __DFS_DEF_H__
#define __DFS_DEF_H__
#include <rtthread.h>
#include <dfs_config.h>
#if defined(RT_USING_NEWLIB) || defined (RT_USING_MINILIBC)
#include <string.h>
#endif
#ifndef __D_FS__
#define __D_FS__
#endif
/* Device error codes */
#define DFS_STATUS_ENOENT 2 /* No such file or directory */
#define DFS_STATUS_EIO 5 /* I/O error */
#define DFS_STATUS_ENXIO 6 /* No such device or address */
#define DFS_STATUS_EBADF 9 /* Bad file number */
#define DFS_STATUS_EAGIAN 11 /* Try again */
#define DFS_STATUS_ENOMEM 12 /* no memory */
#define DFS_STATUS_EBUSY 16 /* Device or resource busy */
#define DFS_STATUS_EEXIST 17 /* File exists */
#define DFS_STATUS_EXDEV 18 /* Cross-device link */
#define DFS_STATUS_ENODEV 19 /* No such device */
#define DFS_STATUS_ENOTDIR 20 /* Not a directory */
#define DFS_STATUS_EISDIR 21 /* Is a directory */
#define DFS_STATUS_EINVAL 22 /* Invalid argument */
#define DFS_STATUS_ENOSPC 28 /* No space left on device */
#define DFS_STATUS_EROFS 30 /* Read-only file system */
#define DFS_STATUS_ENOSYS 38 /* Function not implemented */
#define DFS_STATUS_ENOTEMPTY 39 /* Directory not empty */
#define DFS_STATUS_EMMOUNT 128 /* Filesystem table full */
/* Operation flags */
#define DFS_O_RDONLY 0000000
#define DFS_O_WRONLY 0000001
#define DFS_O_RDWR 0000002
#define DFS_O_ACCMODE 0000003
#define DFS_O_CREAT 0000100
#define DFS_O_EXCL 0000200
#define DFS_O_TRUNC 0001000
#define DFS_O_APPEND 0002000
#define DFS_O_DIRECTORY 0200000
/* File flags */
#define DFS_F_OPEN 0x01000000
#define DFS_F_DIRECTORY 0x02000000
#define DFS_F_EOF 0x04000000
#define DFS_F_ERR 0x08000000
/* Seek flags */
#define DFS_SEEK_SET 0
#define DFS_SEEK_CUR 1
#define DFS_SEEK_END 2
/* Stat codes */
#define DFS_S_IFMT 00170000
#define DFS_S_IFSOCK 0140000
#define DFS_S_IFLNK 0120000
#define DFS_S_IFREG 0100000
#define DFS_S_IFBLK 0060000
#define DFS_S_IFDIR 0040000
#define DFS_S_IFCHR 0020000
#define DFS_S_IFIFO 0010000
#define DFS_S_ISUID 0004000
#define DFS_S_ISGID 0002000
#define DFS_S_ISVTX 0001000
#define DFS_S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
#define DFS_S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
#define DFS_S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
#define DFS_S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
#define DFS_S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
#define DFS_S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
#define DFS_S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
#define DFS_S_IRWXU 00700
#define DFS_S_IRUSR 00400
#define DFS_S_IWUSR 00200
#define DFS_S_IXUSR 00100
#define DFS_S_IRWXG 00070
#define DFS_S_IRGRP 00040
#define DFS_S_IWGRP 00020
#define DFS_S_IXGRP 00010
#define DFS_S_IRWXO 00007
#define DFS_S_IROTH 00004
#define DFS_S_IWOTH 00002
#define DFS_S_IXOTH 00001
#define DEVICE_GETGEOME 0
#define DEVICE_GETINFO 1
#define DEVICE_FORMAT 2
#define DEVICE_CLEAN_SECTOR 3
struct device_geometry
{
rt_uint32_t sector_count; /* count of sectors */
rt_uint32_t cylinder_count; /* count of cylinder */
rt_uint32_t sectors_per_track; /* number of sectors per track */
rt_uint32_t head_count; /* count of head */
rt_uint32_t bytes_per_sector; /* number of bytes per sector */
};
struct dfs_stat
{
rt_device_t st_dev;
rt_uint16_t st_mode;
rt_uint32_t st_size;
rt_time_t st_mtime;
rt_uint32_t st_blksize;
};
#define stat dfs_stat
/* File types */
#define FT_REGULAR 0
#define FT_SOCKET 1
#define FT_DIRECTORY 2
/* file descriptor */
struct dfs_fd
{
char path[DFS_PATH_MAX + 1];/* Name (below mount point) */
int type; /* Type (regular or socket) */
int ref_count; /* Descriptor reference count */
struct dfs_filesystem* fs; /* Resident file system */
rt_uint32_t flags; /* Descriptor flags */
rt_size_t size; /* Size in bytes */
rt_off_t pos; /* Current file position */
void *data; /* Specific file system data */
};
#define DFS_DT_UNKNOWN 0x00
#define DFS_DT_REG 0x01
#define DFS_DT_DIR 0x02
struct dfs_dirent
{
rt_uint8_t d_type; /* The type of the file */
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
rt_uint16_t d_reclen; /* length of this record */
char d_name[256]; /* The null-terminated file name */
};
#define dirent dfs_dirent
struct dfs_session
{
rt_mailbox_t mbox;
};
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_efs.h
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2008-08-30 Yi.Qiu
+------------------------------------------------------------------------------
*/
#ifndef __DFS_EFS_H__
#define __DFS_EFS_H__
#ifdef __cplusplus
extern "C" {
#endif
int efsl_init(void);
#ifdef __cplusplus
}
#endif
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_fat.h, FAT 12/16/32 file system definitions
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2003-03-30 ffxz
+------------------------------------------------------------------------------
*/
#ifndef __DFS_FAT_H__
#define __DFS_FAT_H__
#ifdef __cplusplus
extern "C" {
#endif
int fatfs_init(void);
#ifdef __cplusplus
}
#endif
#endif
+87
View File
@@ -0,0 +1,87 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_fs.h, the filesystem related defines of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2005-02-22 ffxz The first version.
+------------------------------------------------------------------------------
*/
#ifndef __DFS_FS_H__
#define __DFS_FS_H__
#include <dfs_def.h>
#include <dfs_config.h>
/* Pre-declaration */
struct dfs_filesystem;
struct dfs_fd;
struct dfs_dirent;
/* File system operations struct */
struct dfs_filesystem_operation
{
char name[DFS_FS_NAME_MAX + 1];
int (*mount) (struct dfs_filesystem* fs);
int (*unmount) (struct dfs_filesystem* fs);
int (*open) (struct dfs_fd* fd);
int (*close) (struct dfs_fd* fd);
int (*ioctl) (struct dfs_fd* fd, int cmd, void *args);
int (*read) (struct dfs_fd* fd, void* buf, rt_size_t count);
int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count);
int (*lseek) (struct dfs_fd* fd, rt_off_t offset);
int (*getdents) (struct dfs_fd* fd, struct dfs_dirent* dirp, rt_uint32_t count);
int (*unlink) (struct dfs_filesystem* fs, const char* pathname);
int (*stat) (struct dfs_filesystem* fs, const char* filename, struct dfs_stat* buf);
int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath);
};
/* Mounted file system */
struct dfs_filesystem
{
rt_device_t dev_id; /* Attached device */
char path[DFS_PATH_MAX + 1]; /* File system mount point */
struct dfs_filesystem_operation* ops; /* Operations for file system type */
rt_uint32_t block_id; /* Current block_id on attached device */
void *data; /* Specific file system data */
};
/* file system partition table */
struct dfs_partition
{
rt_uint8_t type; /* file system type */
rt_off_t offset; /* partition start offset */
rt_size_t size; /* partition size */
rt_sem_t lock;
};
int dfs_register(struct dfs_filesystem_operation* ops);
struct dfs_filesystem* dfs_filesystem_lookup(const char *path);
rt_err_t dfs_filesystem_get_partition(struct dfs_partition* part, rt_uint8_t* buf, rt_uint32_t pindex);
int dfs_mount(const char* device_name, const char* path,
const char* filesystemtype, rt_uint32_t rwflag, const
void* data);
int dfs_unmount(const char *specialfile);
/* extern variable */
extern struct dfs_filesystem_operation* filesystem_operation_table[];
extern struct dfs_filesystem filesystem_table[];
extern rt_sem_t filesystem_table_lock;
extern rt_sem_t filesystem_operation_table_lock;
extern char working_directory[];
extern rt_sem_t working_directory_lock;
#endif
+42
View File
@@ -0,0 +1,42 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_init.h, the initilization definitions of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2005-02-21 ffxz The first version.
+------------------------------------------------------------------------------
*/
#ifndef __DFS_INIT_H__
#define __DFS_INIT_H__
#ifdef __cplusplus
extern "C" {
#endif
/* initilization of dfs */
void dfs_init(void);
/* initilization of dfs with filesystem server */
void dfs_server_init(void);
#ifdef __cplusplus
}
#endif
#endif
+100
View File
@@ -0,0 +1,100 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_posix.h, the filesystem related defines of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2009-05-27 Yi.qiu The first version.
+------------------------------------------------------------------------------
*/
#ifndef __DFS_POSIX_H__
#define __DFS_POSIX_H__
#include <dfs_raw.h>
#define O_RDONLY DFS_O_RDONLY
#define O_WRONLY DFS_O_WRONLY
#define O_RDWR DFS_O_RDWR
#define O_ACCMODE DFS_O_ACCMODE
#define O_CREAT DFS_O_CREAT
#define O_EXCL DFS_O_EXCL
#define O_TRUNC DFS_O_TRUNC
#define O_APPEND DFS_O_APPEND
#define O_DIRECTORY DFS_O_DIRECTORY
#define S_IFMT DFS_S_IFMT
#define S_IFSOCK DFS_S_IFSOCK
#define S_IFLNK DFS_S_IFLNK
#define S_IFREG DFS_S_IFREG
#define S_IFBLK DFS_S_IFBLK
#define S_IFDIR DFS_S_IFDIR
#define S_IFCHR DFS_S_IFCHR
#define S_IFIFO DFS_S_IFIFO
#define S_ISUID DFS_S_ISUID
#define S_ISGID DFS_S_ISGID
#define S_ISVTX DFS_S_ISVTX
#define S_ISLNK(m) (((m) & DFS_S_IFMT) == DFS_S_IFLNK)
#define S_ISREG(m) (((m) & DFS_S_IFMT) == DFS_S_IFREG)
#define S_ISDIR(m) (((m) & DFS_S_IFMT) == DFS_S_IFDIR)
#define S_ISCHR(m) (((m) & DFS_S_IFMT) == DFS_S_IFCHR)
#define S_ISBLK(m) (((m) & DFS_S_IFMT) == DFS_S_IFBLK)
#define S_ISFIFO(m) (((m) & DFS_S_IFMT) == DFS_S_IFIFO)
#define S_ISSOCK(m) (((m) & DFS_S_IFMT) == DFS_S_IFSOCK)
#define S_IRWXU DFS_S_IRWXU
#define S_IRUSR DFS_S_IRUSR
#define S_IWUSR DFS_S_IWUSR
#define S_IXUSR DFS_S_IXUSR
#define S_IRWXG DFS_S_IRWXG
#define S_IRGRP DFS_S_IRGRP
#define S_IWGRP DFS_S_IWGRP
#define S_IXGRP DFS_S_IXGRP
#define S_IRWXO DFS_S_IRWXO
#define S_IROTH DFS_S_IROTH
#define S_IWOTH DFS_S_IWOTH
#define S_IXOTH DFS_S_IXOTH
#define SEEK_SET DFS_SEEK_SET
#define SEEK_CUR DFS_SEEK_CUR
#define SEEK_END DFS_SEEK_END
typedef struct
{
int fd; /* directory file */
char buf[512];
int num;
int cur;
rt_sem_t *sem;
} DIR;
/* file api*/
int open(const char *file, int flags, int mode);
int close(int d);
int read(int fd, char *buf, int len);
int write(int fd, char *buf, int len);
int lseek(int fd, int offset, int dir);
int rename(const char* old, const char* new );
int unlink(const char *pathname);
int stat(const char *file, struct dfs_stat *buf);
/* directory api*/
int mkdir (const char *path, rt_uint16_t mode);
int rmdir(const char *path);
DIR* opendir(const char* name);
struct dfs_dirent* readdir(DIR *d);
rt_off_t telldir(DIR *d);
void seekdir(DIR *d, rt_off_t offset);
void rewinddir(DIR *d);
int closedir(DIR* d);
int chdir(const char *path);
char* getcwd(char *buf, rt_size_t size);
#endif
+38
View File
@@ -0,0 +1,38 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_raw.h, the raw APIs of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2005-01-26 ffxz The first version
+------------------------------------------------------------------------------
*/
#ifndef __DFS_RAW_H__
#define __DFS_RAW_H__
#include <dfs_def.h>
#include <dfs_fs.h>
int dfile_raw_open(struct dfs_fd* fd, const char *path, int flags);
int dfile_raw_close(struct dfs_fd* fd);
int dfile_raw_ioctl(struct dfs_fd* fd, int cmd, void *args);
int dfile_raw_read(struct dfs_fd* fd, void *buf, rt_size_t len);
int dfile_raw_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nbytes);
int dfile_raw_unlink(const char *path);
int dfile_raw_write(struct dfs_fd* fd, const void *buf, rt_size_t len);
int dfile_raw_lseek(struct dfs_fd* fd, rt_off_t offset);
int dfile_raw_stat(const char *path, struct dfs_stat *buf);
int dfile_raw_rename(const char* oldpath, const char* newpath);
/* FD APIs */
int fd_new(void);
struct dfs_fd* fd_get(int fd);
void fd_put(struct dfs_fd* fd);
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
+------------------------------------------------------------------------------
| Project : Device Filesystem
+------------------------------------------------------------------------------
| Copyright 2004, 2005 www.fayfayspace.org.
| All rights reserved.
|------------------------------------------------------------------------------
| File : dfs_util.h, some misc definitions of Device FileSystem
|------------------------------------------------------------------------------
| Chang Logs:
| Date Author Notes
| 2005-01-26 ffxz The first version
+------------------------------------------------------------------------------
*/
#ifndef __DFS_UTIL_H__
#define __DFS_UTIL_H__
#include <dfs_def.h>
int dir_name(const char* path, char* dirname, int len);
int file_name(const char* path, char* filename, int len);
int next_dir_name(const char* path, int pos, char* next);
void build_fullpath(const char *directory, const char *filename, char *fullpath);
int str_is_prefix(const char* prefix, const char* str);
#if !defined(RT_USING_MINILIBC) && !defined(RT_USING_NEWLIB)
char *strrchr(const char *t, int c);
#if defined (__ARMCC_VERSION) && (__ARMCC_VERSION / 10000 < 35)
int strncasecmp(const char* s1, const char* s2, rt_size_t len);
#endif /* end of __ARMCC_VERSION */
#endif
#endif