fs/littlefs: Add to get the full path

Signed-off-by: zhouliang3 <zhouliang3@xiaomi.com>
This commit is contained in:
zhouliang3 2021-08-25 09:50:15 +08:00 committed by Xiang Xiao
parent 4456b2db29
commit 161ae0ef5c
1 changed files with 47 additions and 7 deletions

View File

@ -29,6 +29,7 @@
#include <string.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mtd/mtd.h>
#include <nuttx/mutex.h>
@ -36,6 +37,7 @@
#include <sys/stat.h>
#include <sys/statfs.h>
#include "inode/inode.h"
#include "littlefs/lfs.h"
#include "littlefs/lfs_util.h"
@ -543,31 +545,69 @@ static off_t littlefs_seek(FAR struct file *filep, off_t offset, int whence)
static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct littlefs_mountpt_s *fs;
FAR struct littlefs_file_s *priv;
FAR struct inode *inode;
FAR struct inode *drv;
int ret;
/* Recover our private data from the struct file instance */
priv = filep->f_priv;
inode = filep->f_inode;
fs = inode->i_private;
drv = fs->drv;
ret = nxmutex_lock(&fs->lock);
if (ret < 0)
{
return ret;
}
switch (cmd)
{
case FIOC_FILEPATH:
{
FAR char *path = (FAR char *)(uintptr_t)arg;
ret = inode_getpath(inode, path, PATH_MAX);
if (ret >= 0)
{
size_t len = strlen(path);
if (path[len - 1] != '/')
{
path[len++] = '/';
}
ret = littlefs_convert_result(lfs_file_path(&fs->lfs,
&priv->file,
path + len,
PATH_MAX - len));
}
}
break;
default:
{
if (INODE_IS_MTD(drv))
{
return MTD_IOCTL(drv->u.i_mtd, cmd, arg);
ret = MTD_IOCTL(drv->u.i_mtd, cmd, arg);
}
else
{
if (drv->u.i_bops->ioctl != NULL)
{
return drv->u.i_bops->ioctl(drv, cmd, arg);
ret = drv->u.i_bops->ioctl(drv, cmd, arg);
}
else
{
return -ENOTTY;
ret = -ENOTTY;
}
}
}
}
nxmutex_unlock(&fs->lock);
return ret;
}
/****************************************************************************
* Name: littlefs_sync