Skip to content

fs: widen ino_t to uint32_t and add d_ino to struct dirent#19179

Open
xiaoxiang781216 wants to merge 3 commits into
apache:masterfrom
xiaoxiang781216:widen-ino_t-add-d_ino
Open

fs: widen ino_t to uint32_t and add d_ino to struct dirent#19179
xiaoxiang781216 wants to merge 3 commits into
apache:masterfrom
xiaoxiang781216:widen-ino_t-add-d_ino

Conversation

@xiaoxiang781216

@xiaoxiang781216 xiaoxiang781216 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

This series widens NuttX's inode/uid integer types and adds the POSIX
d_ino member to struct dirent, so portable software (e.g. dropbear's
scp) that relies on a meaningful, wide file serial number works correctly.

  • sys/types: always use unsigned int for uid_t/gid_t — move
    uid_t/gid_t out of the CONFIG_SMALL_MEMORY #ifdef so they are
    always unsigned int; keep include/nuttx/fs/hostfs.h in sync (drop the
    int16_t variants of nuttx_gid_t/nuttx_uid_t).
  • fs: widen ino_t from uint16_t to uint32_t — a 16-bit ino_t only
    addresses 65536 file serial numbers, which breaks large directory trees
    and portable callers. Widen ino_t (and nuttx_ino_t in the hostfs ABI)
    to uint32_t. Adjust fs/rpmsgfs/rpmsgfs.h so the packed
    rpmsgfs_stat_priv_s layout/size stays unchanged.
  • fs/dirent: add d_ino member to struct dirent — declare d_ino and
    populate it on every readdir() path (pseudofs, hostfs/sim, yaffs,
    rpmsgfs), so callers observe a non-zero inode number.

Impact

  • Adds the POSIX d_ino field to struct dirent (was previously absent).
  • ino_t widened from 16-bit to 32-bit; uid_t/gid_t are now always
    unsigned int regardless of CONFIG_SMALL_MEMORY.
  • hostfs RPC ABI (struct nuttx_dirent_s, nuttx_ino_t,
    nuttx_uid_t/nuttx_gid_t) updated to match; rpmsgfs packed struct size
    preserved (verified 112 bytes before and after).
  • No new configuration options; no defconfig changes.

Testing

Style: tools/checkpatch.sh -g apache/master..HEAD → all checks pass.

Build: sim:nsh builds cleanly (all changed files — fs/vfs/fs_dir.c,
fs/rpmsgfs/*, arch/sim/src/sim/posix/sim_hostfs.c, and the headers —
compile and link without errors/warnings).

Runtime (sim:nsh): A small readdir() test confirms sizeof(d_ino) == 4
(ino_t is now 32-bit) and every entry reports a non-zero d_ino:

nsh> readdir /dev (sizeof d_ino=4):
  d_ino=2 d_type=2 console
  d_ino=11 d_type=2 gpio0
  d_ino=4 d_type=2 null
  d_ino=3 d_type=6 ram0
  ...
total=12 nonzero_ino=12

nsh> readdir /proc (sizeof d_ino=4):
  d_ino=28977 d_type=4 0
  d_ino=28977 d_type=8 version
  ...
total=14 nonzero_ino=14

ABI size check: A standalone host program reproducing the
rpmsgfs_stat_priv_s packed layout confirms the struct size is unchanged
(old=112 new=112) after moving nlink into the former reserved slot and
widening ino to 32-bit.

Changelog

  • v2: Drop the "fs/dir: reuse close_mountpoint/close_pseudodir helpers"
    commit (those helpers do not exist upstream, which broke the CI build),
    and correct read_pseudodir() to assign entry->d_ino = pdir->next->i_ino
    (the prior next->i_ino referenced an undeclared variable). The net
    change to fs/vfs/fs_dir.c is now a single added line.

Related

Move uid_t/gid_t out of the CONFIG_SMALL_MEMORY #ifdef so they are
always defined as unsigned int regardless of SMALL_MEMORY.

Update include/nuttx/fs/hostfs.h to match: drop the int16_t variants
of nuttx_gid_t/nuttx_uid_t and keep a single unsigned int definition
so the hostfs RPC ABI stays in sync with sys/types.h.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
A 16-bit ino_t can only address 65536 distinct file serial numbers,
which is not enough for filesystems with large directory trees and
breaks portable software (e.g. dropbear's scp) that expects a wider
inode number space.  Widen ino_t (and nuttx_ino_t in the hostfs ABI)
to uint32_t to match common POSIX practice.

Update fs/rpmsgfs/rpmsgfs.h accordingly: promote the 'ino' field in
struct rpmsgfs_stat_priv_s from uint16_t to uint32_t and move 'nlink'
into the trailing 16-bit slot previously occupied by the reserved
field, keeping the overall packed-struct layout/size unchanged.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Copilot AI review requested due to automatic review settings June 20, 2026 14:12
@github-actions github-actions Bot added Arch: simulator Issues related to the SIMulator Area: File System File System issues Size: S The size of the change in this PR is small labels Jun 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR widens core filesystem identity types (notably ino_t) and adds the POSIX-required d_ino field to struct dirent, then threads inode numbers through multiple readdir() implementations (pseudofs, sim hostfs, rpmsgfs) to support portable software that expects stable/non-zero inode serial numbers.

Changes:

  • Make uid_t/gid_t consistently unsigned int and widen ino_t to uint32_t.
  • Add d_ino to struct dirent and hostfs’ nuttx_dirent_s, and propagate inode numbers through rpmsgfs + sim hostfs readdir.
  • Refactor dir_close() cleanup logic (currently introduces build issues).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
include/sys/types.h Makes uid_t/gid_t unconditional and widens ino_t to 32-bit.
include/nuttx/fs/hostfs.h Keeps hostfs ABI types in sync; adds d_ino to nuttx_dirent_s.
include/dirent.h Adds POSIX d_ino to struct dirent.
fs/vfs/fs_dir.c Populates d_ino for pseudodir entries; modifies dir_close() cleanup path.
fs/rpmsgfs/rpmsgfs.h Updates rpmsgfs stat/readdir wire structs to carry 32-bit inode.
fs/rpmsgfs/rpmsgfs_server.c Sends inode number back in rpmsgfs readdir response.
fs/rpmsgfs/rpmsgfs_client.c Receives inode number and populates entry->d_ino.
arch/sim/src/sim/posix/sim_hostfs.c Propagates host dirent.d_ino into NuttX hostfs dirent ABI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread fs/vfs/fs_dir.c
Comment thread fs/vfs/fs_dir.c Outdated
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 <xiaoxiang@xiaomi.com>
@xiaoxiang781216 xiaoxiang781216 force-pushed the widen-ino_t-add-d_ino branch from 331f152 to 5d32630 Compare June 20, 2026 14:55
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .data +2 B, .text +56 B (+0.1%, 66,413 B / 262,144 B, total: 25% used)
  • sram: .data +2 B (+0.1%, 2,697 B / 8,192 B, total: 33% used)

esp32-devkitc

  • ROM: .flash.text -8 B (-0.0%, 119,740 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text -8 B (-0.0%, 85,020 B / 3,342,304 B, total: 3% used)

mirtoo

  • kseg0_progmem: .text +16 B (+0.0%, 66,140 B / 131,072 B, total: 50% used)

qemu-armv8a

  • Code: .text.dir_read +12 B, .text.ps_callback +8 B (+0.0%, 312,002 B)
  • Data: .bss.g_ino +2 B (+0.0%, 76,962 B)

qemu-intel64

  • Code: .text +19 B (+0.0%, 8,653,203 B)

s698pm-dkit

  • Code: .text +16 B (+0.0%, 357,136 B)
  • Data: .bss +16 B (+0.1%, 11,851 B)

stm32-nucleo-f103rb

  • flash: .text +8 B (+0.0%, 33,200 B / 131,072 B, total: 25% used)
    No memory changes detected for:
  • hifive1-revb
  • rx65n-rsk2mb

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

need merge apache/nuttx-apps#3554 first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: simulator Issues related to the SIMulator Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants