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>
This commit is contained in:
parent
da5839c6f2
commit
69f3774f30
|
@ -1491,8 +1491,29 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
|
|||
mode_t mode)
|
||||
{
|
||||
FAR struct littlefs_mountpt_s *fs;
|
||||
FAR char *path = (FAR char *)relpath;
|
||||
size_t len = strlen(relpath);
|
||||
int ret;
|
||||
|
||||
/* We need remove all the '/' in the end of relpath */
|
||||
|
||||
if (len > 0 && relpath[len - 1] == '/')
|
||||
{
|
||||
path = lib_get_pathbuffer();
|
||||
if (path == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
while (len > 0 && relpath[len - 1] == '/')
|
||||
{
|
||||
len--;
|
||||
}
|
||||
|
||||
memcpy(path, relpath, len);
|
||||
path[len] = '\0';
|
||||
}
|
||||
|
||||
/* Get the mountpoint private data from the inode structure */
|
||||
|
||||
fs = mountpt->i_private;
|
||||
|
@ -1502,10 +1523,10 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
|
|||
ret = nxmutex_lock(&fs->lock);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = lfs_mkdir(&fs->lfs, relpath);
|
||||
ret = littlefs_convert_result(lfs_mkdir(&fs->lfs, path));
|
||||
if (ret >= 0)
|
||||
{
|
||||
struct littlefs_attr_s attr;
|
||||
|
@ -1517,16 +1538,22 @@ static int littlefs_mkdir(FAR struct inode *mountpt, FAR const char *relpath,
|
|||
attr.at_ctim = 1000000000ull * time.tv_sec + time.tv_nsec;
|
||||
attr.at_atim = attr.at_ctim;
|
||||
attr.at_mtim = attr.at_ctim;
|
||||
ret = littlefs_convert_result(lfs_setattr(&fs->lfs, relpath, 0,
|
||||
ret = littlefs_convert_result(lfs_setattr(&fs->lfs, path, 0,
|
||||
&attr, sizeof(attr)));
|
||||
if (ret < 0)
|
||||
{
|
||||
lfs_remove(&fs->lfs, relpath);
|
||||
lfs_remove(&fs->lfs, path);
|
||||
}
|
||||
}
|
||||
|
||||
nxmutex_unlock(&fs->lock);
|
||||
|
||||
errout:
|
||||
if (path != relpath)
|
||||
{
|
||||
lib_put_pathbuffer(path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue