diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-12-25 17:36:47 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2022-12-25 17:36:47 +0100 |
commit | 38cb831d584b74a9e6d82f34d10f155edd11e34e (patch) | |
tree | e4204227f2699e99cfe39d3eaae6264d3f9d512e | |
parent | e3dd7025ecd2107e1f15a25d3c8b913eac4f93b2 (diff) |
move partition creation to partition function
less duplicate code and access to device size
-rw-r--r-- | src/main.rs | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/main.rs b/src/main.rs index 6949974..83e9c97 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,15 @@ fn write_mbr_partition_table(file: &mut File, dev_size: u64) -> anyhow::Result<( fn partition(file: &mut File, dev_size: u64) -> anyhow::Result<()> { write_mbr_partition_table(file, dev_size)?; + let mut boot_partition = StreamSlice::new( + file.try_clone()?, + 2048 * 512, + (2048 * 512 + 256 * MiB - 1).into(), + )?; + + write_boot(&mut boot_partition)?; + write_mbr(file)?; + Ok(()) } @@ -187,31 +196,11 @@ fn write_mbr(file: &mut File) -> anyhow::Result<()> { fn overwrite_device(file: &mut File, overwrite: String) -> anyhow::Result<()> { partition_device(file, overwrite)?; - - let mut boot_partition = StreamSlice::new( - file.try_clone()?, - 2048 * 512, - (2048 * 512 + 256 * MiB - 1).into(), - )?; - - write_boot(&mut boot_partition)?; - write_mbr(file)?; - Ok(()) } fn overwrite_file(file: &mut File, file_size: u64) -> anyhow::Result<()> { partition(file, file_size)?; - - let mut boot_partition = StreamSlice::new( - file.try_clone()?, - 2048 * 512, - (2048 * 512 + 256 * MiB - 1).into(), - )?; - - write_boot(&mut boot_partition)?; - write_mbr(file)?; - Ok(()) } |