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
commit a01b12fbc1f45c5afecb221832bc89e40056b44b Author: Xiang Xiao <[email protected]> AuthorDate: Thu Nov 12 01:04:14 2026 +0800 fs/vfs: do not double the slash in a directory's fd_path dir_allocate() stores the directory path as "%s%s/" of inode_getpath() and the relative path. inode_getpath() already ends a mountpoint and a pseudo directory that has children with '/', so opening the root of a mount or such a pseudo directory records "/tmp//" or "/dev//", which FIOC_FILEPATH, F_GETPATH and dirfd-relative lookups then report. Add the separator only when the path does not already end with one. Signed-off-by: Xiang Xiao <[email protected]> Signed-off-by: jingfei <[email protected]> --- fs/vfs/fs_dir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c index 1e0d1753a00..8a1e3f6175c 100644 --- a/fs/vfs/fs_dir.c +++ b/fs/vfs/fs_dir.c @@ -626,7 +626,9 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) { FAR struct fs_dirent_s *dir; FAR struct inode *inode = filep->f_inode; + FAR const char *last; FAR char *path_prefix; + size_t len; int ret; path_prefix = lib_get_pathbuffer(); @@ -660,8 +662,15 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath) } } + /* inode_getpath() already ends a mountpoint with '/', so only add the + * separator when the path does not end with one. + */ + inode_getpath(inode, path_prefix, PATH_MAX); - ret = fs_heap_asprintf(&dir->fd_path, "%s%s/", path_prefix, relpath); + last = *relpath != '\0' ? relpath : path_prefix; + len = strlen(last); + ret = fs_heap_asprintf(&dir->fd_path, "%s%s%s", path_prefix, relpath, + len > 0 && last[len - 1] == '/' ? "" : "/"); if (ret < 0) { dir->fd_path = NULL;
