From 36b7577c5e6ac0e76a6c0e8942c7353fd63e8b7f Mon Sep 17 00:00:00 2001 From: Hongjin Li Date: Mon, 22 Nov 2021 10:49:56 +0800 Subject: [PATCH] =?UTF-8?q?liteos=5Fm=E6=96=87=E4=BB=B6=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=AD=EF=BC=8Ccomponents/fs/littlefs/lfs=5Fapi.c=E4=B8=AD?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B3=A8=E5=86=8C.Fstat=20=3D=20LfsFstat?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ic56364d1df71b369abfa5be617fc63b77a65b27b Signed-off-by: Hongjin Li --- components/fs/littlefs/lfs_api.c | 31 +++++++++++++++++++++++++++++++ components/fs/littlefs/lfs_api.h | 1 + 2 files changed, 32 insertions(+) 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_ */