!409 littlefs新增FileOps->Fstat接口

Merge pull request !409 from Hongjin Li/liteos_m_add_fstats_to_littlefs
This commit is contained in:
openharmony_ci 2021-11-24 01:38:39 +00:00 committed by Gitee
commit ed64fb1b2f
2 changed files with 32 additions and 0 deletions

View File

@ -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;
}

View File

@ -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_ */