From 64d15df9ea3c61225d47b40f2e3863f3004ccc45 Mon Sep 17 00:00:00 2001 From: Far Date: Mon, 14 Nov 2022 15:56:01 +0800 Subject: [PATCH] fix: fix the MS_REMOUNT support The mount interface can't deal with MS_REMOUNT flag now, fix it. Signed-off-by: Far Change-Id: Id0960c8d92ce767b8d8ef98b3ba2e1d1ab7db15d --- components/fs/fatfs/fatfs.c | 11 +++++----- components/fs/littlefs/lfs_adapter.c | 6 ++++++ components/fs/vfs/vfs_mount.c | 32 ++++++++++++++++++++++++++-- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/components/fs/fatfs/fatfs.c b/components/fs/fatfs/fatfs.c index 988ffbaf..11a197df 100644 --- a/components/fs/fatfs/fatfs.c +++ b/components/fs/fatfs/fatfs.c @@ -282,6 +282,12 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags, return (int)LOS_NOK; } + if (mountflags & MS_REMOUNT) { + ret = Remount(mp, mountflags); + FsUnlock(); + return ret; + } + char *ldPath = GetLdPath(mp->mDev); if (ldPath == NULL) { errno = EFAULT; @@ -289,11 +295,6 @@ int FatfsMount(struct MountPoint *mp, unsigned long mountflags, goto ERROUT; } - if (mountflags & MS_REMOUNT) { - ret = Remount(mp, mountflags); - goto ERROUT; - } - fs = (FATFS *)malloc(sizeof(FATFS)); if (fs == NULL) { errno = ENOMEM; diff --git a/components/fs/littlefs/lfs_adapter.c b/components/fs/littlefs/lfs_adapter.c index 02589b75..3f161074 100644 --- a/components/fs/littlefs/lfs_adapter.c +++ b/components/fs/littlefs/lfs_adapter.c @@ -184,6 +184,12 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data) goto errout; } + if (mountflags & MS_REMOUNT) { + errno = ENOSYS; + ret = (int)LOS_NOK; + goto errout; + } + mountHdl = (lfs_t *)malloc(sizeof(lfs_t) + sizeof(struct lfs_config)); if (mountHdl == NULL) { errno = ENODEV; diff --git a/components/fs/vfs/vfs_mount.c b/components/fs/vfs/vfs_mount.c index b92792ad..81578911 100644 --- a/components/fs/vfs/vfs_mount.c +++ b/components/fs/vfs/vfs_mount.c @@ -33,6 +33,7 @@ #include "vfs_config.h" #include "stdlib.h" #include "string.h" +#include "errno.h" #include "vfs_operations.h" #include "los_compiler.h" #include "los_debug.h" @@ -122,7 +123,7 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp) return bestMp; } -STATIC struct MountPoint *MountPointInit(const char *target, const char *fsType, unsigned long mountflags) +STATIC struct MountPoint *VfsMountPointInit(const char *target, const char *fsType, unsigned long mountflags) { struct MountPoint *mp = NULL; const char *pathInMp = NULL; @@ -155,6 +156,27 @@ STATIC struct MountPoint *MountPointInit(const char *target, const char *fsType, return mp; } +STATIC int VfsRemount(const char *source ,const char *target, + const char *fsType, unsigned long mountflags, + const void *data) +{ + (VOID)source; + (VOID)fsType; + struct MountPoint *mp; + + mp = VfsMpFind(target, NULL); + if (mp == NULL) { + errno = EINVAL; + return (int)LOS_NOK; + } + + LOS_ASSERT(mp->mFs != NULL); + LOS_ASSERT(mp->mFs->fsMops != NULL); + LOS_ASSERT(mp->mFs->fsMops->mount != NULL); + + return mp->mFs->fsMops->mount(mp, mountflags, data); +} + int LOS_FsMount(const char *source, const char *target, const char *fsType, unsigned long mountflags, const void *data) @@ -169,7 +191,13 @@ int LOS_FsMount(const char *source, const char *target, (void)VfsLock(); - mp = MountPointInit(target, fsType, mountflags); + if (mountflags & MS_REMOUNT) { + ret = VfsRemount(source, target, fsType, mountflags, data); + VfsUnlock(); + return ret; + } + + mp = VfsMountPointInit(target, fsType, mountflags); if (mp == NULL) { VfsUnlock(); return (int)LOS_NOK;