From 34471854e23a24f8545be6e7a22ed5b1fd3eedf0 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:24:47 +0200 Subject: [PATCH] initfs: Remove Dir wrapper --- initfs/tools/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/initfs/tools/src/lib.rs b/initfs/tools/src/lib.rs index 29e3679635..657a8962e7 100644 --- a/initfs/tools/src/lib.rs +++ b/initfs/tools/src/lib.rs @@ -24,7 +24,7 @@ const PAGE_SIZE: u16 = 4096; enum EntryKind { File { file: File, executable: bool }, - Dir(Dir), + Dir(Vec), Link(PathBuf), } @@ -32,9 +32,6 @@ struct Entry { name: Vec, kind: EntryKind, } -struct Dir { - entries: Vec, -} struct State<'path> { file: OutputImageGuard<'path>, @@ -55,7 +52,7 @@ fn write_all_at(file: &File, buf: &[u8], offset: u64, r#where: &str) -> Result<( Ok(()) } -fn read_directory(path: &Path, root_path: &Path) -> Result { +fn read_directory(path: &Path, root_path: &Path) -> Result> { let read_dir = path .read_dir() .with_context(|| anyhow!("failed to read directory `{}`", path.to_string_lossy(),))?; @@ -147,7 +144,7 @@ fn read_directory(path: &Path, root_path: &Path) -> Result { }) .collect::>>()?; - Ok(Dir { entries }) + Ok(entries) } fn bump_alloc(state: &mut State, size: u64, why: &str) -> Result { @@ -230,10 +227,10 @@ fn allocate_and_write_link(state: &mut State, link: &Path) -> Result Result { +fn allocate_and_write_dir(state: &mut State, dir: &[Entry]) -> Result { let entry_size = u16::try_from(std::mem::size_of::()).context("entry size too large")?; - let entry_count = u16::try_from(dir.entries.len()).context("too many subdirectories")?; + let entry_count = u16::try_from(dir.len()).context("too many subdirectories")?; let entry_table_length = u32::from(entry_count) .checked_mul(u32::from(entry_size)) @@ -245,7 +242,7 @@ fn allocate_and_write_dir(state: &mut State, dir: &Dir) -> Result { .try_into() .context("directory entries offset too high")?; - for (index, entry) in dir.entries.iter().enumerate() { + for (index, entry) in dir.iter().enumerate() { let (write_result, ty) = match entry.kind { EntryKind::Dir(ref subdir) => { let write_result = allocate_and_write_dir(state, subdir).with_context(|| { @@ -334,7 +331,7 @@ fn allocate_and_write_dir(state: &mut State, dir: &Dir) -> Result { offset: entry_table_offset, }) } -fn allocate_contents(state: &mut State, dir: &Dir) -> Result { +fn allocate_contents(state: &mut State, dir: &[Entry]) -> Result { let write_result = allocate_and_write_dir(state, dir) .context("failed to allocate and write all directories and files")?;