diff --git a/components/fs/littlefs/lfs_api.c b/components/fs/littlefs/lfs_api.c index 67a2db90..043ffc0c 100644 --- a/components/fs/littlefs/lfs_api.c +++ b/components/fs/littlefs/lfs_api.c @@ -322,6 +322,7 @@ const struct FileOps g_lfsFops = { .Rename = LfsRename, .Getattr = LfsStat, .Fsync = LfsFsync, + .Fstat = LfsFstat, }; int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags, @@ -772,3 +773,33 @@ int LfsFsync(int fd) } return ret; } + +int LfsFstat(int fd, struct stat *buf) +{ + int ret; + struct lfs_info info; + + if (buf == NULL) { + errno = EFAULT; + return FS_FAILURE; + } + + if (LfsFdIsValid(fd) == FALSE) { + errno = EBADF; + return VFS_ERROR; + } + + ret = lfs_stat(g_handle[fd].lfsHandle, g_handle[fd].pathName, &info); + if (ret == 0) { + buf->st_size = info.size; + if (info.type == LFS_TYPE_REG) { + buf->st_mode = S_IFREG; + } else { + buf->st_mode = S_IFDIR; + } + } else { + errno = LittlefsErrno(ret); + ret = VFS_ERROR; + } + return ret; +} \ No newline at end of file diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index c9b749ed..a101217e 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -110,6 +110,7 @@ int LfsClose(int fd); int LfsRename(const char *oldName, const char *newName); int LfsStat(const char *path, struct stat *buf); int LfsFsync(int fd); +int LfsFstat(int fd, struct stat *buf); int SetDefaultMountPath(int pathNameIndex, const char* target); #endif /* _LFS_API_H_ */