diff --git a/components/dfs/SConscript b/components/dfs/SConscript index fdb1127f00..c22f9d0a7e 100644 --- a/components/dfs/SConscript +++ b/components/dfs/SConscript @@ -10,17 +10,6 @@ src/dfs_file.c src/dfs_posix.c """) -# DFS-FatFs options -fatfs = Split(""" -filesystems/fatfs/fatfs_cache.c -filesystems/fatfs/fatfs_direntry.c -filesystems/fatfs/fatfs_fat.c -filesystems/fatfs/fatfs_file.c -filesystems/fatfs/fatfs_filename.c -filesystems/fatfs/fatfs_init.c -filesystems/fatfs_misc.c -filesystems/fatfs/fatfs_mount.c""") - # DFS-ELMFAT options elmfat = Split(""" filesystems/elmfat/dfs_elm.c diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index a93aa3b58c..c2143d51a1 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -134,7 +134,7 @@ int dfs_elm_mkfs(const char* device_name) return -DFS_STATUS_EIO; } -int dfs_elm_statfs(struct dfs_filesystem* fs, struct dfs_statfs *buf) +int dfs_elm_statfs(struct dfs_filesystem* fs, struct _statfs *buf) { FATFS *f; FRESULT res; @@ -373,19 +373,19 @@ int dfs_elm_lseek(struct dfs_fd* file, rt_off_t offset) return elm_result_to_dfs(result); } -int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count) +int dfs_elm_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count) { DIR* dir; FILINFO fno; FRESULT result; rt_uint32_t index; - struct dfs_dirent* d; + struct _dirent* d; dir = (DIR*)(file->data); RT_ASSERT(dir != RT_NULL); /* make integer count */ - count = (count / sizeof(struct dfs_dirent)) * sizeof(struct dfs_dirent); + count = (count / sizeof(struct _dirent)) * sizeof(struct _dirent); if ( count == 0 ) return -DFS_STATUS_EINVAL; #if _USE_LFN @@ -415,11 +415,11 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t c else d->d_type &= DFS_DT_REG; d->d_namlen = rt_strlen(fn); - d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent); + d->d_reclen = (rt_uint16_t)sizeof(struct _dirent); rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1); index ++; - if ( index * sizeof(struct dfs_dirent) >= count ) + if ( index * sizeof(struct _dirent) >= count ) break; } @@ -430,7 +430,7 @@ int dfs_elm_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t c if (index == 0) return elm_result_to_dfs(result); - return index * sizeof(struct dfs_dirent); + return index * sizeof(struct _dirent); } int dfs_elm_unlink(struct dfs_filesystem* fs, const char* path) @@ -500,7 +500,7 @@ int dfs_elm_rename(struct dfs_filesystem* fs, const char* oldpath, const char* n return elm_result_to_dfs(result); } -int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *st) +int dfs_elm_stat(struct dfs_filesystem* fs, const char *path, struct _stat *st) { FILINFO file_info; FRESULT result; diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index c5cf2820ab..a68f5f3c71 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -717,7 +717,7 @@ int nfs_open(struct dfs_fd* file) return 0; } -int nfs_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *st) +int nfs_stat(struct dfs_filesystem* fs, const char *path, struct _stat *st) { GETATTR3args args; GETATTR3res res; @@ -729,6 +729,8 @@ int nfs_stat(struct dfs_filesystem* fs, const char *path, struct dfs_stat *st) RT_ASSERT(fs->data != RT_NULL); nfs = (struct nfs_filesystem *)fs->data; + rt_kprintf("get path:%s stat\n", path); + handle = get_handle(nfs, path); if(handle == RT_NULL) return -1; @@ -975,11 +977,11 @@ int nfs_rename(struct dfs_filesystem* fs, const char *src, const char *dest) return ret; } -int nfs_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count) +int nfs_getdents(struct dfs_fd* file, struct _dirent* dirp, rt_uint32_t count) { nfs_dir *dir; rt_uint32_t index; - struct dfs_dirent* d; + struct _dirent* d; struct nfs_filesystem* nfs; char *name; @@ -990,7 +992,7 @@ int nfs_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count nfs = (struct nfs_filesystem *)file->fs->data; /* make integer count */ - count = (count / sizeof(struct dfs_dirent)) * sizeof(struct dfs_dirent); + count = (count / sizeof(struct _dirent)) * sizeof(struct _dirent); if ( count == 0 ) return -DFS_STATUS_EINVAL; index = 0; @@ -1006,15 +1008,15 @@ int nfs_getdents(struct dfs_fd* file, struct dfs_dirent* dirp, rt_uint32_t count d->d_type &= DFS_DT_REG; d->d_namlen = rt_strlen(name); - d->d_reclen = (rt_uint16_t)sizeof(struct dfs_dirent); + d->d_reclen = (rt_uint16_t)sizeof(struct _dirent); rt_strncpy(d->d_name, name, rt_strlen(name) + 1); index ++; - if ( index * sizeof(struct dfs_dirent) >= count ) + if ( index * sizeof(struct _dirent) >= count ) break; } - return index * sizeof(struct dfs_dirent); + return index * sizeof(struct _dirent); } static const struct dfs_filesystem_operation _nfs = diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h index e3c52dd957..e220487043 100644 --- a/components/dfs/include/dfs_def.h +++ b/components/dfs/include/dfs_def.h @@ -111,7 +111,7 @@ #define DEVICE_FORMAT 2 #define DEVICE_CLEAN_SECTOR 3 -struct dfs_stat +struct _stat { rt_device_t st_dev; rt_uint16_t st_mode; @@ -120,7 +120,7 @@ struct dfs_stat rt_uint32_t st_blksize; }; -struct dfs_statfs +struct _statfs { rt_size_t f_bsize; /* block size */ rt_size_t f_blocks; /* total data blocks in file system */ @@ -153,13 +153,12 @@ struct dfs_fd #define DFS_DT_REG 0x01 #define DFS_DT_DIR 0x02 -struct dfs_dirent +struct _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[DFS_PATH_MAX]; /* The null-terminated file name */ }; -#define dirent dfs_dirent #endif diff --git a/components/dfs/include/dfs_file.h b/components/dfs/include/dfs_file.h index 4987201aa4..e0455e00c9 100644 --- a/components/dfs/include/dfs_file.h +++ b/components/dfs/include/dfs_file.h @@ -24,11 +24,11 @@ int dfs_file_open(struct dfs_fd* fd, const char *path, int flags); int dfs_file_close(struct dfs_fd* fd); int dfs_file_ioctl(struct dfs_fd* fd, int cmd, void *args); int dfs_file_read(struct dfs_fd* fd, void *buf, rt_size_t len); -int dfs_file_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nbytes); +int dfs_file_getdents(struct dfs_fd* fd, struct _dirent* dirp, rt_size_t nbytes); int dfs_file_unlink(const char *path); int dfs_file_write(struct dfs_fd* fd, const void *buf, rt_size_t len); int dfs_file_lseek(struct dfs_fd* fd, rt_off_t offset); -int dfs_file_stat(const char *path, struct dfs_stat *buf); +int dfs_file_stat(const char *path, struct _stat *buf); int dfs_file_rename(const char* oldpath, const char* newpath); #endif diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h index 8c0a2b04d9..d47e5c93cf 100644 --- a/components/dfs/include/dfs_fs.h +++ b/components/dfs/include/dfs_fs.h @@ -33,7 +33,7 @@ struct dfs_filesystem_operation /* make a file system */ int (*mkfs) (const char* device_name); - int (*statfs) (struct dfs_filesystem* fs, struct dfs_statfs *buf); + int (*statfs) (struct dfs_filesystem* fs, struct _statfs *buf); int (*open) (struct dfs_fd* fd); int (*close) (struct dfs_fd* fd); @@ -42,10 +42,10 @@ struct dfs_filesystem_operation int (*write) (struct dfs_fd* fd, const void* buf, rt_size_t count); int (*flush) (struct dfs_fd* fd); 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 (*getdents) (struct dfs_fd* fd, struct _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 (*stat) (struct dfs_filesystem* fs, const char* filename, struct _stat* buf); int (*rename) (struct dfs_filesystem* fs, const char* oldpath, const char* newpath); }; @@ -86,6 +86,6 @@ extern char working_directory[]; void dfs_lock(void); void dfs_unlock(void); -int dfs_statfs(const char* path, struct dfs_statfs* buffer); +int dfs_statfs(const char* path, struct _statfs* buffer); #endif diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index ce1e94028b..502fc87c9d 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -16,6 +16,7 @@ #define __DFS_POSIX_H__ #include +#include #define O_RDONLY DFS_O_RDONLY #define O_WRONLY DFS_O_WRONLY @@ -74,14 +75,9 @@ typedef struct int cur; } DIR; -struct stat -{ - struct dfs_stat parent; -}; -struct statfs -{ - struct dfs_statfs parent; -}; +#define stat _stat +#define statfs _statfs +#define dirent _dirent /* file api*/ int open(const char *file, int flags, int mode); @@ -91,14 +87,14 @@ 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); -int statfs(const char *path, struct dfs_statfs *buf); +int stat(const char *file, struct _stat *buf); +int statfs(const char *path, struct _statfs *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); +struct _dirent* readdir(DIR *d); rt_off_t telldir(DIR *d); void seekdir(DIR *d, rt_off_t offset); void rewinddir(DIR *d); diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index f5562dc4a8..8450fee03c 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -173,7 +173,7 @@ int dfs_file_read(struct dfs_fd* fd, void *buf, rt_size_t len) * * @return the read dirent, others on failed. */ -int dfs_file_getdents(struct dfs_fd* fd, struct dfs_dirent* dirp, rt_size_t nbytes) +int dfs_file_getdents(struct dfs_fd* fd, struct _dirent* dirp, rt_size_t nbytes) { struct dfs_filesystem* fs; @@ -298,7 +298,7 @@ int dfs_file_lseek(struct dfs_fd* fd, rt_off_t offset) * * @return 0 on successful, -1 on failed. */ -int dfs_file_stat(const char *path, struct dfs_stat *buf) +int dfs_file_stat(const char *path, struct _stat *buf) { int result; char* fullpath; @@ -422,10 +422,10 @@ __exit: #include static struct dfs_fd fd; -static struct dfs_dirent dirent; +static struct _dirent dirent; void ls(const char* pathname) { - struct dfs_stat stat; + struct _stat stat; int length; char* fullpath; @@ -437,11 +437,11 @@ void ls(const char* pathname) rt_kprintf("Directory %s:\n", pathname); do { - rt_memset(&dirent, 0, sizeof(struct dfs_dirent)); - length = dfs_file_getdents(&fd, &dirent, sizeof(struct dfs_dirent)); + rt_memset(&dirent, 0, sizeof(struct _dirent)); + length = dfs_file_getdents(&fd, &dirent, sizeof(struct _dirent)); if ( length > 0 ) { - rt_memset(&stat, 0, sizeof(struct dfs_stat)); + rt_memset(&stat, 0, sizeof(struct _stat)); /* build full path for each file */ if (pathname[strlen(pathname) - 1] != '/') diff --git a/components/dfs/src/dfs_fs.c b/components/dfs/src/dfs_fs.c index 98e61abd83..71ddb479ec 100644 --- a/components/dfs/src/dfs_fs.c +++ b/components/dfs/src/dfs_fs.c @@ -408,7 +408,7 @@ int dfs_mkfs(const char* fs_name, const char* device_name) * * @return 0 on successful, others on failed. */ -int dfs_statfs(const char* path, struct dfs_statfs* buffer) +int dfs_statfs(const char* path, struct _statfs* buffer) { struct dfs_filesystem* fs; @@ -432,7 +432,7 @@ FINSH_FUNCTION_EXPORT(mkfs, make a file system); void df(const char* path) { - struct dfs_statfs buffer; + struct _statfs buffer; if (dfs_statfs(path, &buffer) == 0) { diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 8b5918cb58..415ae455b1 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -261,7 +261,7 @@ int unlink(const char *pathname) * * @return 0 on successful, -1 on failed. */ -int stat(const char *file, struct dfs_stat *buf) +int stat(const char *file, struct _stat *buf) { int result; @@ -283,7 +283,7 @@ int stat(const char *file, struct dfs_stat *buf) * * @return 0 on successful, others on failed. */ -int statfs(const char *path, struct dfs_statfs *buf) +int statfs(const char *path, struct _statfs *buf) { int result; @@ -404,7 +404,7 @@ DIR* opendir(const char* name) * * @return the next directory entry, NULL on the end of directory or failed. */ -struct dfs_dirent* readdir(DIR *d) +struct _dirent* readdir(DIR *d) { int result; struct dfs_fd* fd; @@ -416,9 +416,9 @@ struct dfs_dirent* readdir(DIR *d) return RT_NULL; } - if (!d->num || (d->cur += ((struct dfs_dirent*)(d->buf + d->cur))->d_reclen) >= d->num) + if (!d->num || (d->cur += ((struct _dirent*)(d->buf + d->cur))->d_reclen) >= d->num) { - result = dfs_file_getdents(fd, (struct dfs_dirent*)d->buf, sizeof(d->buf) - 1); + result = dfs_file_getdents(fd, (struct _dirent*)d->buf, sizeof(d->buf) - 1); if (result <= 0) { rt_set_errno(result); @@ -432,7 +432,7 @@ struct dfs_dirent* readdir(DIR *d) } fd_put(fd); - return (struct dfs_dirent*)(d->buf+d->cur); + return (struct _dirent*)(d->buf+d->cur); } /**