aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-04-11 16:35:41 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-04-11 16:35:41 +0200
commit36f6b98bb60328d9d02622309c55e4da60bdef4c (patch)
tree903c3e3f0387a74713a9b41e3d55d48a285577d3
parentfa6df487b00509d277fde0f8a3f3e6982c42ab4a (diff)
only read boot partition to find kernel and cmdline extents
reading the entire image is too memory and disk read intensive
-rw-r--r--src/main.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 7a2d520..0e42274 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -147,7 +147,12 @@ fn partition(
let mut data_partition = StreamSlice::new(file.try_clone()?, root_b_end, data_end - 1)?;
let buf = write_boot(&mut boot_partition, &arch)?;
- write_mbr(file, &buf["kernel.img"], &buf["cmdline.txt"])?;
+ write_mbr(
+ file,
+ &mut boot_partition,
+ &buf["kernel.img"],
+ &buf["cmdline.txt"],
+ )?;
write_root(&mut root_partition_a, &arch, &crates, &git, &init)?;
write_empty_root(&mut root_partition_b)?;
@@ -250,9 +255,14 @@ fn write_boot(
Ok(buf)
}
-fn write_mbr(file: &mut File, kernel_buf: &[u8], cmdline_buf: &[u8]) -> anyhow::Result<()> {
+fn write_mbr(
+ file: &mut File,
+ boot_partition: &mut StreamSlice<File>,
+ kernel_buf: &[u8],
+ cmdline_buf: &[u8],
+) -> anyhow::Result<()> {
let mut buf = Vec::new();
- file.read_to_end(&mut buf)?;
+ boot_partition.read_to_end(&mut buf)?;
let kernel_offset: u32 = (buf
.windows(kernel_buf.len())