feat: add sync() to vfs

新增sync方法,该方法每次调用,会遍历系统内所有的mount点,调用各个文件系统注册
的sync方法,完成对所有已挂载文件系统的sync操作。

close #I480HV

Signed-off-by: Guangyao Ma <guangyao.ma@outlook.com>
Change-Id: I57ced9c3f7685a448defd17ae56c842796b5668f
This commit is contained in:
Guangyao Ma 2021-08-31 15:50:00 +08:00
parent de8257bc82
commit f67c4dae51
7 changed files with 29 additions and 27 deletions

View File

@ -34,6 +34,7 @@
#include "ff.h"
#include "disk_pri.h"
#include "diskio.h"
#include "fs/file.h"
#include "fs/fs.h"
#include "fs/dirent_fs.h"
#include "fs/mount.h"
@ -1297,6 +1298,29 @@ int fatfs_umount(struct Mount *mnt, struct Vnode **blkdriver)
return 0;
}
int fatfs_sync_adapt(struct Mount *mnt)
{
(void)mnt;
int ret = 0;
#ifdef LOSCFG_FS_FAT_CACHE
struct Vnode *dev = NULL;
los_part *part = NULL;
if (mnt == NULL) {
return -EINVAL;
}
dev = mnt->vnodeDev;
part = los_part_find(dev);
if (part == NULL) {
return -EINVAL;
}
ret = OsSdSync(part->disk_id);
#endif
return ret;
}
int fatfs_statfs(struct Mount *mnt, struct statfs *info)
{
FATFS *fs = (FATFS *)mnt->data;
@ -2207,6 +2231,7 @@ struct MountOps fatfs_mops = {
.Mount = fatfs_mount,
.Unmount = fatfs_umount,
.Statfs = fatfs_statfs,
.Sync = fatfs_sync_adapt,
};
struct file_operations_vfs fatfs_fops = {

View File

@ -61,6 +61,7 @@ struct MountOps {
int (*Mount)(struct Mount *mount, struct Vnode *vnode, const void *data);
int (*Unmount)(struct Mount *mount, struct Vnode **blkdriver);
int (*Statfs)(struct Mount *mount, struct statfs *sbp);
int (*Sync)(struct Mount *mount);
};
typedef int (*foreach_mountpoint_t)(const char *devpoint,

View File

@ -71,6 +71,7 @@ kernel_module(module_name) {
"$LITEOSTHIRDPARTY/NuttX/fs/inode/fs_files.c",
"$LITEOSTHIRDPARTY/NuttX/fs/mount/fs_foreachmountpoint.c",
"$LITEOSTHIRDPARTY/NuttX/fs/mount/fs_mount.c",
"$LITEOSTHIRDPARTY/NuttX/fs/mount/fs_sync.c",
"$LITEOSTHIRDPARTY/NuttX/fs/mount/fs_umount.c",
"$LITEOSTHIRDPARTY/NuttX/fs/vfs/fs_close.c",
"$LITEOSTHIRDPARTY/NuttX/fs/vfs/fs_dup.c",

View File

@ -80,6 +80,7 @@ $(LITEOSTHIRDPARTY)/NuttX/fs/dirent/fs_telldir.c \
\
$(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_mount.c \
$(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_umount.c \
$(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_sync.c \
\
$(LITEOSTHIRDPARTY)/NuttX/fs/driver/fs_blockproxy.c \
$(LITEOSTHIRDPARTY)/NuttX/fs/mount/fs_foreachmountpoint.c \

View File

@ -1087,8 +1087,6 @@ OsBcache *BlockCacheInit(struct Vnode *devNode, UINT32 sectorSize, UINT32 sector
return NULL;
}
set_sd_sync_fn(OsSdSync);
bcacheMem = (UINT8 *)zalloc(memSize);
if (bcacheMem == NULL) {
PRINT_ERR("bcache_init : malloc %u Bytes failed!\n", memSize);

View File

@ -444,28 +444,6 @@ char *rindex(const char *s, int c)
return (char *)strrchr(s, c);
}
int (*sd_sync_fn)(int) = NULL;
int (*nand_sync_fn)(void) = NULL;
void set_sd_sync_fn(int (*sync_fn)(int))
{
sd_sync_fn = sync_fn;
}
void sync(void)
{
#ifdef LOSCFG_FS_FAT_CACHE
if (sd_sync_fn != NULL)
{
(void)sd_sync_fn(0);
(void)sd_sync_fn(1);
return;
}
#endif
PRINT_ERR("Unsupport syscall %s\n", __FUNCTION__);
}
static char *ls_get_fullpath(const char *path, struct dirent *pdirent)
{
char *fullpath = NULL;

View File

@ -1569,13 +1569,11 @@ int osShellCmdChgrp(int argc, const char **argv)
SHELLCMD_ENTRY(lsfd_shellcmd, CMD_TYPE_EX, "lsfd", XARGS, (CmdCallBackFunc)osShellCmdLsfd);
SHELLCMD_ENTRY(statfs_shellcmd, CMD_TYPE_EX, "statfs", XARGS, (CmdCallBackFunc)osShellCmdStatfs);
SHELLCMD_ENTRY(touch_shellcmd, CMD_TYPE_EX, "touch", XARGS, (CmdCallBackFunc)osShellCmdTouch);
#if (defined(LOSCFG_FS_FAT))
SHELLCMD_ENTRY(sync_shellcmd, CMD_TYPE_EX, "sync", XARGS, (CmdCallBackFunc)osShellCmdSync);
#endif
#ifdef LOSCFG_KERNEL_SYSCALL
SHELLCMD_ENTRY(su_shellcmd, CMD_TYPE_EX, "su", XARGS, (CmdCallBackFunc)osShellCmdSu);
#endif
#endif
SHELLCMD_ENTRY(sync_shellcmd, CMD_TYPE_EX, "sync", XARGS, (CmdCallBackFunc)osShellCmdSync);
SHELLCMD_ENTRY(ls_shellcmd, CMD_TYPE_EX, "ls", XARGS, (CmdCallBackFunc)osShellCmdLs);
SHELLCMD_ENTRY(pwd_shellcmd, CMD_TYPE_EX, "pwd", XARGS, (CmdCallBackFunc)osShellCmdPwd);
SHELLCMD_ENTRY(cd_shellcmd, CMD_TYPE_EX, "cd", XARGS, (CmdCallBackFunc)osShellCmdCd);