From f0413aec8e80cb69c9ffc91ea012cb216bdae624 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 17 Feb 2026 20:06:18 +0100 Subject: [PATCH] initfs: Fill in st_ino Otherwise ls and other tools will think they have already visited a directory when recursively enumerating all files. --- bootstrap/src/initfs.rs | 1 + initfs/src/lib.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/bootstrap/src/initfs.rs b/bootstrap/src/initfs.rs index d19c4507dd..3db98b067f 100644 --- a/bootstrap/src/initfs.rs +++ b/bootstrap/src/initfs.rs @@ -323,6 +323,7 @@ impl SchemeSync for InitFsScheme { let inode = Self::get_inode(&self.fs, handle.inode)?; + stat.st_ino = inode.id(); stat.st_mode = inode.mode() | match inode.kind() { InodeKind::Dir(_) => MODE_DIR, diff --git a/initfs/src/lib.rs b/initfs/src/lib.rs index 5787eccf8e..b004a52f23 100644 --- a/initfs/src/lib.rs +++ b/initfs/src/lib.rs @@ -32,6 +32,7 @@ type Result = core::result::Result; #[derive(Clone, Copy)] pub struct InodeStruct<'initfs> { initfs: InitFs<'initfs>, + inode_id: Inode, inode: &'initfs InodeHeader, } @@ -135,6 +136,9 @@ pub enum InodeKind<'initfs> { } impl<'initfs> InodeStruct<'initfs> { + pub fn id(&self) -> u64 { + self.inode_id.0.into() + } fn data(&self) -> Result<&'initfs [u8]> { let start: usize = self.inode.offset.0.get().try_into().map_err(|_| Error)?; @@ -276,17 +280,11 @@ impl<'initfs> InitFs<'initfs> { pub fn inode_count(&self) -> u16 { self.get_header_assume_valid().inode_count.get() } - pub fn get_inode(&self, inode: Inode) -> Option> { - // NOTE: Even for 16-bit architectures (obviously edge-case, but some bootloaders may - // perhaps use this code), we have already checked that the inode table can fit within - // usize, and the table byte size is always larger than the count. - let inode_usize = inode.0 as usize; - - let inode = self.inode_table().get(inode_usize)?; - + pub fn get_inode(&self, inode_id: Inode) -> Option> { Some(InodeStruct { initfs: *self, - inode, + inode_id, + inode: self.inode_table().get(usize::from(inode_id.0))?, }) } }