From e0cffb0a36c06ac32667039e5aad8a65990d3db3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 25 Apr 2026 22:27:24 +0200 Subject: [PATCH] initfs: Allow building an initfs without assembling it on disk first --- initfs/tools/src/lib.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/initfs/tools/src/lib.rs b/initfs/tools/src/lib.rs index 3ac389bd15..64d64e39de 100644 --- a/initfs/tools/src/lib.rs +++ b/initfs/tools/src/lib.rs @@ -22,15 +22,15 @@ pub const DEFAULT_MAX_SIZE: u64 = 64 * MEBIBYTE; // FIXME make this configurable to handle systems with 16k and 64k pages. const PAGE_SIZE: u16 = 4096; -enum EntryKind { +pub enum EntryKind { File { file: File, executable: bool }, Dir(Vec), Link(PathBuf), } -struct Entry { - name: Vec, - kind: EntryKind, +pub struct Entry { + pub name: Vec, + pub kind: EntryKind, } struct State<'path> { @@ -458,6 +458,15 @@ pub fn archive( let root_path = source; let root = read_directory(root_path, root_path).context("failed to read root")?; + build_initfs(destination_path, max_size, bootstrap_code, root) +} + +pub fn build_initfs( + destination_path: &Path, + max_size: u64, + bootstrap_code: &Path, + root: Vec, +) -> std::result::Result<(), anyhow::Error> { let previous_extension = destination_path.extension().map_or("", |ext| { ext.to_str() .expect("expected destination path to be valid UTF-8")