diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index d798c5bbdbfae983309a3491b38ea06f7075a6f2..c720c42279133a0f4a2cc895840734dc3c927ce8 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -220,7 +220,6 @@ int dfs_elm_open(struct dfs_fd* file) } } - /* open directory */ dir = (DIR *)rt_malloc(sizeof(DIR)); if (dir == RT_NULL) diff --git a/components/dfs/include/dfs_posix.h b/components/dfs/include/dfs_posix.h index 7897893bef844a394e48e169b43c78599bacba5d..b4b87b0a1147d88accadc1f951c87de98eff2f05 100644 --- a/components/dfs/include/dfs_posix.h +++ b/components/dfs/include/dfs_posix.h @@ -99,6 +99,7 @@ off_t lseek(int fd, off_t offset, int whence); int rename(const char* old, const char* new ); int unlink(const char *pathname); int stat(const char *file, struct stat *buf); +int fstat(int fildes, struct stat *buf); int statfs(const char *path, struct statfs *buf); /* directory api*/ diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index 26395aafc6ac0a636cd525499b040cc21541c622..f1c01605f924ef5c0bf45665f0eb32a939f1dde0 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -257,7 +257,7 @@ int unlink(const char *pathname) * this function is a POSIX compliant version, which will get file information. * * @param file the file name - * @param buf the the data buffer to save stat description. + * @param buf the data buffer to save stat description. * * @return 0 on successful, -1 on failed. */ @@ -274,6 +274,45 @@ int stat(const char *file, struct stat *buf) return result; } +/** + * this function is a POSIX compliant version, which will get file status. + * + * @param fildes the file description + * @param buf the data buffer to save stat description. + */ +int fstat(int fildes, struct stat *buf) +{ + int result; + struct dfs_fd* d; + + /* get the fd */ + d = fd_get(fildes); + if (d == RT_NULL) + { + rt_set_errno(-RT_ERROR); + return -1; + } + + /* it's the root directory */ + buf->st_dev = 0; + + buf->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH | + DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH; + if (d->type == FT_DIRECTORY) + { + buf->st_mode &= ~DFS_S_IFREG; + buf->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH; + } + + buf->st_size = d->size; + buf->st_mtime = 0; + buf->st_blksize = 512; + + fd_put(d); + + return DFS_STATUS_OK; +} + /** * this function is a POSIX compliant version, which will return the * information about a mounted file system.