This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 1c1ce03014485e95082373a4234a654746f09593 Author: Marco Casaroli <[email protected]> AuthorDate: Wed Nov 11 06:04:21 2026 +0100 fs/vfs: Give the files of each mounted volume a device number. POSIX says that st_dev and st_ino together identify a file. st_dev was 0 for every file, but each file system counts st_ino on its own: the root of the first tmpfs and the second node of the pseudo file system both have the serial number 1. A program that compares st_dev and st_ino (find, tar, cp -r, or ftw() of another libc) took them for one file. If the file system gives st_dev 0, stat(), lstat() and fstat() now give the serial number of the mount point. The pseudo file system keeps st_dev 0. hostfs and rpmsgfs keep the device number that the host gives. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- fs/vfs/fs_fstat.c | 10 ++++++++++ fs/vfs/fs_stat.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/fs/vfs/fs_fstat.c b/fs/vfs/fs_fstat.c index 11f242338c5..abce32d3250 100644 --- a/fs/vfs/fs_fstat.c +++ b/fs/vfs/fs_fstat.c @@ -200,6 +200,16 @@ int file_fstat(FAR struct file *filep, FAR struct stat *buf) ret = inode->u.i_mops->fstat(filep, buf); } + /* A file system that gives no device number gets the serial number + * of its mount point: st_dev and st_ino then tell the files of two + * volumes apart. + */ + + if (ret >= 0 && buf->st_dev == 0) + { + buf->st_dev = inode->i_ino; + } + /* No file on a mount with MS_NOEXEC can be executed */ if (ret >= 0 && INODE_IS_NOEXEC(inode) && S_ISREG(buf->st_mode)) diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index 249bba6216e..3cee7e05368 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -144,6 +144,16 @@ static int stat_recursive(FAR const char *path, ret = -ENOSYS; } + /* A file system that gives no device number gets the serial number + * of its mount point: st_dev and st_ino then tell the files of two + * volumes apart. + */ + + if (ret >= 0 && buf->st_dev == 0) + { + buf->st_dev = inode->i_ino; + } + /* No file on a mount with MS_NOEXEC can be executed */ if (ret >= 0 && INODE_IS_NOEXEC(inode) && S_ISREG(buf->st_mode))
