This is an automated email from the ASF dual-hosted git repository.

linguini1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 2ea2655bc6c130cdef1a7cc36fa0dda33abccb66
Author: Xiang Xiao <[email protected]>
AuthorDate: Tue Jun 9 13:29:16 2026 +0800

    fs/dirent: add d_ino member to struct dirent
    
    Add the POSIX d_ino (file serial number) member to struct dirent and
    populate it on every readdir() path, so portable callers (e.g. scp in
    dropbear) that read dp->d_ino observe a meaningful, non-zero inode
    number:
    
      - include/dirent.h: declare d_ino in struct dirent and drop the
        outdated comment claiming the field is unimplemented.
      - include/nuttx/fs/hostfs.h: add d_ino to struct nuttx_dirent_s so
        the hostfs ABI can carry the inode number across the VFS boundary.
      - arch/sim/src/sim/posix/sim_hostfs.c: forward the host's
        ent->d_ino into entry->d_ino.
      - fs/vfs/fs_dir.c (read_pseudodir): copy the in-memory inode's
        i_ino into entry->d_ino for the pseudo filesystem.
      - fs/yaffs/yaffs_vfs.c: forward yaffs's dirent->d_ino into
        entry->d_ino.
      - fs/rpmsgfs: extend struct rpmsgfs_readdir_s with an 'ino' field
        and propagate it across the RPC in both rpmsgfs_server (fills it
        from the underlying entry) and rpmsgfs_client (writes it back to
        the caller's nuttx_dirent_s).
    
    Signed-off-by: Xiang Xiao <[email protected]>
---
 arch/sim/src/sim/posix/sim_hostfs.c | 2 ++
 fs/rpmsgfs/rpmsgfs.h                | 1 +
 fs/rpmsgfs/rpmsgfs_client.c         | 1 +
 fs/rpmsgfs/rpmsgfs_server.c         | 1 +
 fs/vfs/fs_dir.c                     | 2 ++
 include/dirent.h                    | 3 ++-
 include/nuttx/fs/hostfs.h           | 1 +
 7 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/sim/src/sim/posix/sim_hostfs.c 
b/arch/sim/src/sim/posix/sim_hostfs.c
index 8597b036f1c..2cf414f9818 100644
--- a/arch/sim/src/sim/posix/sim_hostfs.c
+++ b/arch/sim/src/sim/posix/sim_hostfs.c
@@ -443,6 +443,8 @@ int host_readdir(void *dirp, struct nuttx_dirent_s *entry)
       strncpy(entry->d_name, ent->d_name, sizeof(entry->d_name) - 1);
       entry->d_name[sizeof(entry->d_name) - 1] = 0;
 
+      entry->d_ino = ent->d_ino;
+
       /* Map the type */
 
       if (ent->d_type == DT_REG)
diff --git a/fs/rpmsgfs/rpmsgfs.h b/fs/rpmsgfs/rpmsgfs.h
index 0d9f94c1c1a..aa6aa805d95 100644
--- a/fs/rpmsgfs/rpmsgfs.h
+++ b/fs/rpmsgfs/rpmsgfs.h
@@ -166,6 +166,7 @@ begin_packed_struct struct rpmsgfs_readdir_s
 {
   struct rpmsgfs_header_s header;
   int32_t                 fd;
+  uint32_t                ino;
   uint32_t                type;
   char                    name[0];
 } end_packed_struct;
diff --git a/fs/rpmsgfs/rpmsgfs_client.c b/fs/rpmsgfs/rpmsgfs_client.c
index 1451ccd658e..dd1883a2ce2 100644
--- a/fs/rpmsgfs/rpmsgfs_client.c
+++ b/fs/rpmsgfs/rpmsgfs_client.c
@@ -209,6 +209,7 @@ static int rpmsgfs_readdir_handler(FAR struct 
rpmsg_endpoint *ept,
     {
       strlcpy(entry->d_name, rsp->name, sizeof(entry->d_name));
       entry->d_type = rsp->type;
+      entry->d_ino = rsp->ino;
     }
 
   rpmsg_post(ept, &cookie->sem);
diff --git a/fs/rpmsgfs/rpmsgfs_server.c b/fs/rpmsgfs/rpmsgfs_server.c
index 1e87da502bb..4377bf14f99 100644
--- a/fs/rpmsgfs/rpmsgfs_server.c
+++ b/fs/rpmsgfs/rpmsgfs_server.c
@@ -622,6 +622,7 @@ static int rpmsgfs_readdir_handler(FAR struct 
rpmsg_endpoint *ept,
           size = MIN(size - len, strlen(entry->d_name) + 1);
           msg->type = entry->d_type;
           strlcpy(msg->name, entry->d_name, size);
+          msg->ino = entry->d_ino;
           len += size;
           ret = 0;
         }
diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c
index 14c172bdc62..bf8b899bb9a 100644
--- a/fs/vfs/fs_dir.c
+++ b/fs/vfs/fs_dir.c
@@ -376,6 +376,8 @@ static int read_pseudodir(FAR struct fs_dirent_s *dir,
       entry->d_type = DTYPE_DIRECTORY;
     }
 
+  entry->d_ino = pdir->next->i_ino;
+
   /* Now get the inode to visit next time that readdir() is called */
 
   inode_lock();
diff --git a/include/dirent.h b/include/dirent.h
index 23da8e06bb9..3b8b95254c8 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -107,11 +107,12 @@
  * of char containing at least {NAME_MAX} plus one elements.
  *
  * POSIX also requires the field d_ino (type ino_t) that provides the file
- * serial number.  This functionality is not implemented in NuttX.
+ * serial number.
  */
 
 struct dirent
 {
+  ino_t    d_ino;                 /* File serial number */
   uint8_t  d_type;                /* Type of file */
   char     d_name[NAME_MAX + 1];  /* File name */
 };
diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h
index 2221591d256..94589ddc4f0 100644
--- a/include/nuttx/fs/hostfs.h
+++ b/include/nuttx/fs/hostfs.h
@@ -150,6 +150,7 @@ struct nuttx_timespec
 
 struct nuttx_dirent_s
 {
+  nuttx_ino_t  d_ino;
   uint8_t      d_type;                      /* type of file */
   char         d_name[CONFIG_NAME_MAX + 1]; /* filename */
 };

Reply via email to