This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new ddd81a23c9e fs/littlefs: report the opened path from FIOC_FILEPATH
ddd81a23c9e is described below
commit ddd81a23c9e1487ee1f3f47d1bc77faf171d6cfb
Author: zhengyu16 <[email protected]>
AuthorDate: Thu Nov 12 14:05:02 2026 +0800
fs/littlefs: report the opened path from FIOC_FILEPATH
littlefs_ioctl() builds the FIOC_FILEPATH result with lfs_file_path(),
which walks the metadata tree back to the root. Once a directory
grows past one metadata block, lfs_fs_parent() finds no entry that
points at the continuation block and the walk fails with -ENOENT, so
F_GETPATH fails for most files in a large directory. The walk also
reads the disk on every close(), where notify and the path cache ask
for the path.
Keep the relative path given to open() in littlefs_file_s and report
that instead. A dup()'ed descriptor shares the same littlefs_file_s.
Signed-off-by: zhengyu16 <[email protected]>
Signed-off-by: jingfei <[email protected]>
---
fs/littlefs/lfs_vfs.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c
index 1e579a19200..ced608174ff 100644
--- a/fs/littlefs/lfs_vfs.c
+++ b/fs/littlefs/lfs_vfs.c
@@ -70,6 +70,7 @@ struct littlefs_file_s
{
struct lfs_file file;
int refs;
+ char relpath[1];
};
/* This structure represents the overall mountpoint state. An instance of
@@ -544,6 +545,7 @@ static int littlefs_open(FAR struct file *filep, FAR const
char *relpath,
#if defined(CONFIG_FS_PERMISSION) && defined(CONFIG_FS_LITTLEFS_ATTR_UPDATE)
struct lfs_info info;
#endif
+ size_t len;
int ret;
/* Get the mountpoint inode reference from the file structure and the
@@ -555,13 +557,15 @@ static int littlefs_open(FAR struct file *filep, FAR
const char *relpath,
/* Allocate memory for the open file */
- priv = fs_heap_malloc(sizeof(*priv));
+ len = strlen(relpath);
+ priv = fs_heap_malloc(sizeof(*priv) + len);
if (priv == NULL)
{
return -ENOMEM;
}
priv->refs = 1;
+ memcpy(priv->relpath, relpath, len + 1);
/* Lock */
@@ -906,12 +910,11 @@ static int littlefs_ioctl(FAR struct file *filep, int
cmd, unsigned long arg)
ret = inode_getpath(inode, path, PATH_MAX);
if (ret >= 0)
{
- size_t len = strlen(path);
+ /* lfs_file_path() cannot walk back from a directory's
+ * continuation block, so report the path given to open().
+ */
- ret = littlefs_convert_result(lfs_file_path(&fs->lfs,
- &priv->file,
- path + len,
- PATH_MAX - len));
+ strlcat(path, priv->relpath, PATH_MAX);
}
}
break;