From 7bbabc74fbb6dfa2389242f447ff78ed87de105e Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Thu, 2 Feb 2023 14:20:22 +0800 Subject: [PATCH] fs/dir: provide absolute directory path for F_GETPATH by fcntl Signed-off-by: dongjiuzhu1 --- fs/vfs/fs_dir.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index 243116ad06..1f1ad3a5ba 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -24,6 +24,7 @@ #include +#include #include #include @@ -571,6 +572,7 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) { FAR struct fs_dirent_s *dir; FAR struct inode *inode = filep->f_inode; + char path_prefix[PATH_MAX]; int ret; /* Is this a node in the pseudo filesystem? Or a mountpoint? */ @@ -596,7 +598,8 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) } } - dir->fd_path = strdup(relpath); + inode_getpath(inode, path_prefix); + asprintf(&dir->fd_path, "%s%s/", path_prefix, relpath); filep->f_inode = &g_dir_inode; filep->f_priv = dir; inode_addref(&g_dir_inode);