fix: lfs_mount 不能多实例
【背景】最后一个调用lfs_mount()的分区是有效的,前面的会被冲掉 【修改方案】 1, 增加一个存放cfg的空间, 每个mount点有独自的配置存储空间 【影响】 对现有的产品编译不会有影响。 re #I5RIGH Signed-off-by: wangchen <wangchen240@huawei.com>
This commit is contained in:
parent
3398937b1b
commit
cf50cde1b7
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue