From bfef7bfb2e731513a5d32590b781d3a0e2f46c65 Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Fri, 23 Sep 2022 03:45:18 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20LOS=5FFsMount=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=A4=9A=E5=A4=84=E5=8A=9F=E8=83=BD=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20=E3=80=90=E8=83=8C=E6=99=AF=E3=80=91LOS=5FFsMount?= =?UTF-8?q?=20=E6=8E=A5=E5=8F=A3=E5=AD=98=E5=9C=A8=E5=A4=9A=E5=A4=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1, 修改goto逻辑 2,把过长的函数重新封装 【影响】 对现有的产品编译不会有影响。 re #I5SP1I Signed-off-by: wangchen --- components/fs/vfs/vfs_mount.c | 62 ++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 22 deletions(-) diff --git a/components/fs/vfs/vfs_mount.c b/components/fs/vfs/vfs_mount.c index ff007dba..3bb2a327 100644 --- a/components/fs/vfs/vfs_mount.c +++ b/components/fs/vfs/vfs_mount.c @@ -122,14 +122,45 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp) return bestMp; } +STATIC struct MountPoint *MountPointInit(const char *target, const char *fsType, unsigned long mountflags) +{ + struct MountPoint *mp = NULL; + const char *pathInMp = NULL; + struct FsMap *mFs = NULL; + + /* find mp by target, to see if it was mounted */ + mp = VfsMpFind(target, &pathInMp); + if (mp != NULL && pathInMp != NULL) { + return NULL; + } + + /* Find fsMap coresponding to the fsType */ + mFs = VfsFsMapGet(fsType); + if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) { + return NULL; + } + + mp = (struct MountPoint *)malloc(sizeof(struct MountPoint)); + if (mp == NULL) { + return NULL; + } + + mp->mFs = mFs; + mp->mDev = NULL; + mp->mRefs = 0; + mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE; + mp->mFs->fsRefs++; + mp->mNext = g_mountPoints; + + return mp; +} + int LOS_FsMount(const char *source, const char *target, const char *fsType, unsigned long mountflags, const void *data) { int ret; struct MountPoint *mp = NULL; - struct FsMap *mFs = NULL; - const char *pathInMp = NULL; /* target must begin with '/', for example /system, /data, etc. */ if ((target == NULL) || (target[0] != '/')) { @@ -137,29 +168,19 @@ int LOS_FsMount(const char *source, const char *target, } (void)VfsLock(); - /* find mp by target, to see if it was mounted */ - mp = VfsMpFind(target, &pathInMp); - if (mp != NULL && pathInMp != NULL) { - goto errout; - } - /* Find fsMap coresponding to the fsType */ - mFs = VfsFsMapGet(fsType); - if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) { - goto errout; - } - - mp = (struct MountPoint *)malloc(sizeof(struct MountPoint)); + mp = MountPointInit(target, fsType, mountflags); if (mp == NULL) { - goto errout; + VfsUnlock(); + return (int)LOS_NOK; } - mp->mFs = mFs; - mp->mDev = NULL; if (source != NULL) { mp->mDev = strdup(source); if (mp->mDev == NULL) { - goto errout; + free(mp); + VfsUnlock(); + return (int)LOS_NOK; } } @@ -174,10 +195,7 @@ int LOS_FsMount(const char *source, const char *target, PRINT_ERR("mount failed, target %s.\n", target); goto errout; } - mp->mRefs = 0; - mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE; - mp->mFs->fsRefs++; - mp->mNext = g_mountPoints; + g_mountPoints = mp; VfsUnlock(); return LOS_OK;