Skip to content

Commit 69f3774

Browse files
guohao15GUIDINGLI
authored andcommitted
littlefs:remove the '/' in the end of relpath in mkdir
mkdir /data/log success mkdir /data/log/ failed in littlefs (but fatfs/yaffs/tmpfs success) Signed-off-by: guohao15 <guohao15@xiaomi.com>
1 parent da5839c commit 69f3774

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

fs/littlefs/lfs_vfs.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,29 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
14911491
mode_t mode)
14921492
{
14931493
FAR struct littlefs_mountpt_s *fs;
1494+
FAR char *path = (FAR char *)relpath;
1495+
size_t len = strlen(relpath);
14941496
int ret;
14951497

1498+
/* We need remove all the '/' in the end of relpath */
1499+
1500+
if (len > 0 && relpath[len - 1] == '/')
1501+
{
1502+
path = lib_get_pathbuffer();
1503+
if (path == NULL)
1504+
{
1505+
return -ENOMEM;
1506+
}
1507+
1508+
while (len > 0 && relpath[len - 1] == '/')
1509+
{
1510+
len--;
1511+
}
1512+
1513+
memcpy(path, relpath, len);
1514+
path[len] = '\0';
1515+
}
1516+
14961517
/* Get the mountpoint private data from the inode structure */
14971518

14981519
fs = mountpt->i_private;
@@ -1502,10 +1523,10 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
15021523
ret = nxmutex_lock(&fs->lock);
15031524
if (ret < 0)
15041525
{
1505-
return ret;
1526+
goto errout;
15061527
}
15071528

1508-
ret = lfs_mkdir(&fs->lfs, relpath);
1529+
ret = littlefs_convert_result(lfs_mkdir(&fs->lfs, path));
15091530
if (ret >= 0)
15101531
{
15111532
struct littlefs_attr_s attr;
@@ -1517,16 +1538,22 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
15171538
attr.at_ctim = 1000000000ull * time.tv_sec + time.tv_nsec;
15181539
attr.at_atim = attr.at_ctim;
15191540
attr.at_mtim = attr.at_ctim;
1520-
ret = littlefs_convert_result(lfs_setattr(&fs->lfs, relpath, 0,
1541+
ret = littlefs_convert_result(lfs_setattr(&fs->lfs, path, 0,
15211542
&attr, sizeof(attr)));
15221543
if (ret < 0)
15231544
{
1524-
lfs_remove(&fs->lfs, relpath);
1545+
lfs_remove(&fs->lfs, path);
15251546
}
15261547
}
15271548

15281549
nxmutex_unlock(&fs->lock);
15291550

1551+
errout:
1552+
if (path != relpath)
1553+
{
1554+
lib_put_pathbuffer(path);
1555+
}
1556+
15301557
return ret;
15311558
}
15321559

0 commit comments

Comments
 (0)