From cf50cde1b7e4ecb5cd329459ac6c30a5cf03749a Mon Sep 17 00:00:00 2001 From: wangchen <253227059@qq.com> Date: Thu, 22 Sep 2022 03:06:35 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20lfs=5Fmount=20=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=A4=9A=E5=AE=9E=E4=BE=8B=20=E3=80=90=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E3=80=91=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E8=B0=83=E7=94=A8?= =?UTF-8?q?lfs=5Fmount()=E7=9A=84=E5=88=86=E5=8C=BA=E6=98=AF=E6=9C=89?= =?UTF-8?q?=E6=95=88=E7=9A=84=EF=BC=8C=E5=89=8D=E9=9D=A2=E7=9A=84=E4=BC=9A?= =?UTF-8?q?=E8=A2=AB=E5=86=B2=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 1, 增加一个存放cfg的空间, 每个mount点有独自的配置存储空间 【影响】 对现有的产品编译不会有影响。 re #I5RIGH Signed-off-by: wangchen --- components/fs/littlefs/lfs_adapter.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 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;