From f67c4dae5141914df2e069dce0196b14780649d8 Mon Sep 17 00:00:00 2001 From: Guangyao Ma Date: Tue, 31 Aug 2021 15:50:00 +0800 Subject: [PATCH] feat: add sync() to vfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增sync方法,该方法每次调用,会遍历系统内所有的mount点,调用各个文件系统注册 的sync方法,完成对所有已挂载文件系统的sync操作。 close #I480HV Signed-off-by: Guangyao Ma Change-Id: I57ced9c3f7685a448defd17ae56c842796b5668f --- fs/fat/os_adapt/fatfs.c | 25 +++++++++++++++++++++++++ fs/include/fs/mount.h | 1 + fs/vfs/BUILD.gn | 1 + fs/vfs/Makefile | 1 + fs/vfs/bcache/src/bcache.c | 2 -- fs/vfs/operation/vfs_other.c | 22 ---------------------- fs/vfs/vfs_cmd/vfs_shellcmd.c | 4 +--- 7 files changed, 29 insertions(+), 27 deletions(-) diff --git a/fs/fat/os_adapt/fatfs.c b/fs/fat/os_adapt/fatfs.c index abbf6990..51b1adaf 100644 --- a/fs/fat/os_adapt/fatfs.c +++ b/fs/fat/os_adapt/fatfs.c @@ -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 = { diff --git a/fs/include/fs/mount.h b/fs/include/fs/mount.h index 8f9460d7..28c92e6a 100644 --- a/fs/include/fs/mount.h +++ b/fs/include/fs/mount.h @@ -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, diff --git a/fs/vfs/BUILD.gn b/fs/vfs/BUILD.gn index e8429448..5ef3b80f 100644 --- a/fs/vfs/BUILD.gn +++ b/fs/vfs/BUILD.gn @@ -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", diff --git a/fs/vfs/Makefile b/fs/vfs/Makefile index 1db706b0..c45a4f30 100644 --- a/fs/vfs/Makefile +++ b/fs/vfs/Makefile @@ -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 \ diff --git a/fs/vfs/bcache/src/bcache.c b/fs/vfs/bcache/src/bcache.c index c531065a..b0841f41 100644 --- a/fs/vfs/bcache/src/bcache.c +++ b/fs/vfs/bcache/src/bcache.c @@ -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); diff --git a/fs/vfs/operation/vfs_other.c b/fs/vfs/operation/vfs_other.c index 9d3a6e8b..49358049 100644 --- a/fs/vfs/operation/vfs_other.c +++ b/fs/vfs/operation/vfs_other.c @@ -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; diff --git a/fs/vfs/vfs_cmd/vfs_shellcmd.c b/fs/vfs/vfs_cmd/vfs_shellcmd.c index 58016998..a591d2d6 100644 --- a/fs/vfs/vfs_cmd/vfs_shellcmd.c +++ b/fs/vfs/vfs_cmd/vfs_shellcmd.c @@ -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);