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 f8682a5679c fs/vfs: fstatfs() of a directory gives its file system.
f8682a5679c is described below
commit f8682a5679cb884a72c9edcf60c478eb256b595d
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 12 15:15:44 2026 +0100
fs/vfs: fstatfs() of a directory gives its file system.
open() of a directory gives the file a stand-in inode (dir_allocate()),
not the mount point of the file system of the directory. fstatfs() and
fstatvfs() of such a descriptor took the stand-in inode as a node of the
pseudo file system, for a directory on any mounted file system. For
example, fstatfs() of a directory on a v9fs mount gave f_type
PROC_SUPER_MAGIC, f_bsize 0 and f_namelen 32, while statfs() of its path
gave the values of v9fs.
fstatfs() now takes the inode where the directory starts (fd_root): the
mount point, or the node of the pseudo file system. The new helper
dir_isdirectory() tells if a file is such a directory.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
fs/inode/inode.h | 17 +++++++++++++++++
fs/vfs/fs_dir.c | 13 +++++++++++++
fs/vfs/fs_fstatfs.c | 10 +++++++++-
3 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/fs/inode/inode.h b/fs/inode/inode.h
index eef669de089..fb41cac38da 100644
--- a/fs/inode/inode.h
+++ b/fs/inode/inode.h
@@ -589,6 +589,23 @@ static inline int dir_fstat(FAR struct file *filep, FAR
struct stat *buf)
int dir_fstat(FAR struct file *filep, FAR struct stat *buf);
#endif
+/****************************************************************************
+ * Name: dir_isdirectory
+ *
+ * Description:
+ * Return true if filep is a directory opened with open().
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_DISABLE_DIRECTORY_OPERATIONS
+static inline bool dir_isdirectory(FAR struct file *filep)
+{
+ return false;
+}
+#else
+bool dir_isdirectory(FAR struct file *filep);
+#endif
+
/****************************************************************************
* Name: pseudofile_create
*
diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c
index 795ba09e913..13211f2bed6 100644
--- a/fs/vfs/fs_dir.c
+++ b/fs/vfs/fs_dir.c
@@ -733,3 +733,16 @@ int dir_fstat(FAR struct file *filep, FAR struct stat *buf)
dir = filep->f_priv;
return nx_stat(dir->fd_path, buf, 1);
}
+
+/****************************************************************************
+ * Name: dir_isdirectory
+ *
+ * Description:
+ * Return true if filep is a directory opened with open().
+ *
+ ****************************************************************************/
+
+bool dir_isdirectory(FAR struct file *filep)
+{
+ return filep->f_inode == &g_dir_inode;
+}
diff --git a/fs/vfs/fs_fstatfs.c b/fs/vfs/fs_fstatfs.c
index 345e6a0b1e9..cfcbc187f77 100644
--- a/fs/vfs/fs_fstatfs.c
+++ b/fs/vfs/fs_fstatfs.c
@@ -78,9 +78,17 @@ int fstatfs(int fd, FAR struct statfs *buf)
}
#ifndef CONFIG_DISABLE_MOUNTPOINT
- /* Get the inode from the file structure */
+ /* Get the inode from the file structure. A directory that open() opened
+ * has a stand-in inode: use the inode where the directory starts.
+ */
inode = filep->f_inode;
+ if (dir_isdirectory(filep))
+ {
+ FAR struct fs_dirent_s *dir = filep->f_priv;
+
+ inode = dir->fd_root;
+ }
/* The way we handle the stat depends on the type of inode that we
* are dealing with.