From 3dec8a92df519e6b877cc702e0abe38fa0395e2a Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Mon, 10 Oct 2022 09:11:15 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8C=91=E5=8D=95=20fs=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A53.2-beta3=20?= =?UTF-8?q?=E3=80=90=E8=83=8C=E6=99=AF=E3=80=91=E6=8C=91=E5=8D=95=20fs?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A53.2-beta3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1, 同步mount相关检视修改 2, 同步mount不可重入问题 3, 同步fcntl编译问题 【影响】 对现有的产品编译不会有影响。 re #I5UX7W Signed-off-by: wangchen --- components/fs/littlefs/lfs_adapter.c | 20 +++--- components/fs/vfs/vfs_mount.c | 62 ++++++++++++------- .../lwip-2.1/porting/include/lwip/lwipopts.h | 3 + .../lwip-2.1/porting/src/sockets_porting.c | 4 ++ 4 files changed, 58 insertions(+), 31 deletions(-) diff --git a/components/fs/littlefs/lfs_adapter.c b/components/fs/littlefs/lfs_adapter.c index 1a55831d..02589b75 100644 --- a/components/fs/littlefs/lfs_adapter.c +++ b/components/fs/littlefs/lfs_adapter.c @@ -43,7 +43,6 @@ static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER; static struct PartitionCfg g_partitionCfg; -static struct lfs_config g_lfsCfg; static struct DeviceDesc *g_lfsDevice = NULL; static uint32_t LfsGetStartAddr(int partition) @@ -177,6 +176,7 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data) { int ret; lfs_t *mountHdl = NULL; + struct lfs_config *cfg = NULL; if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) { errno = EFAULT; @@ -184,22 +184,23 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data) goto errout; } - mountHdl = (lfs_t *)malloc(sizeof(lfs_t)); + mountHdl = (lfs_t *)malloc(sizeof(lfs_t) + sizeof(struct lfs_config)); if (mountHdl == NULL) { errno = ENODEV; ret = (int)LOS_NOK; goto errout; } - (void)memset_s(mountHdl, sizeof(lfs_t), 0, sizeof(lfs_t)); + (void)memset_s(mountHdl, sizeof(lfs_t) + sizeof(struct lfs_config), 0, sizeof(lfs_t) + sizeof(struct lfs_config)); mp->mData = (void *)mountHdl; + cfg = (void *)((UINTPTR)mountHdl + sizeof(lfs_t)); - LfsConfigAdapter((struct PartitionCfg *)data, &g_lfsCfg); + LfsConfigAdapter((struct PartitionCfg *)data, cfg); - ret = lfs_mount((lfs_t *)mp->mData, &g_lfsCfg); + ret = lfs_mount((lfs_t *)mp->mData, cfg); if (ret != 0) { - ret = lfs_format((lfs_t *)mp->mData, &g_lfsCfg); + ret = lfs_format((lfs_t *)mp->mData, cfg); if (ret == 0) { - ret = lfs_mount((lfs_t *)mp->mData, &g_lfsCfg); + ret = lfs_mount((lfs_t *)mp->mData, cfg); } } if (ret != 0) { @@ -655,12 +656,13 @@ int LfsFormat(const char *partName, void *privData) { int ret; lfs_t lfs = {0}; + struct lfs_config cfg = {0}; (void)partName; - LfsConfigAdapter((struct PartitionCfg *)privData, &g_lfsCfg); + LfsConfigAdapter((struct PartitionCfg *)privData, &cfg); - ret = lfs_format(&lfs, &g_lfsCfg); + ret = lfs_format(&lfs, &cfg); if (ret != 0) { errno = LittlefsErrno(ret); ret = (int)LOS_NOK; 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; diff --git a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h index 1f1ac3c0..535da98f 100644 --- a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h +++ b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h @@ -240,4 +240,7 @@ #define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS #endif +#define LWIP_SOCKET_IOCTL 0 +#define LWIP_SOCKET_FCNTL 0 + #endif /* _LWIP_PORTING_LWIPOPTS_H_ */ diff --git a/components/net/lwip-2.1/porting/src/sockets_porting.c b/components/net/lwip-2.1/porting/src/sockets_porting.c index 7348e09b..7a883d91 100644 --- a/components/net/lwip-2.1/porting/src/sockets_porting.c +++ b/components/net/lwip-2.1/porting/src/sockets_porting.c @@ -211,6 +211,7 @@ int close(int fd) } #endif +#if LWIP_SOCKET_IOCTL #ifdef LWIP_SOCKET_IOCTL_FUNC int ioctl(int fd, int req, ...) { @@ -222,7 +223,9 @@ int ioctl(int fd, int req, ...) return lwip_ioctl(fd, (long)req, (void *)arg); } #endif +#endif +#if LWIP_SOCKET_FCNTL #ifdef LWIP_SOCKET_FCNTL_FUNC int fcntl(int fd, int cmd, ...) { @@ -234,6 +237,7 @@ int fcntl(int fd, int cmd, ...) return lwip_fcntl(fd, cmd, val); } #endif +#endif #if LWIP_SOCKET_SELECT #ifdef LWIP_SOCKET_SELECT_FUNC