From 30266f4e09e805e0e51f2696ab1da1aa64f8053b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reynir=20Bj=C3=B6rnsson?= Date: Thu, 10 Oct 2024 10:31:58 +0200 Subject: [PATCH] Fix sector alignment bug in formatting --- mirage/partitions.ml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mirage/partitions.ml b/mirage/partitions.ml index 583a629..2c1d19f 100644 --- a/mirage/partitions.ml +++ b/mirage/partitions.ml @@ -175,15 +175,23 @@ module Make(BLOCK : Mirage_block.S) = struct write block 0L [ buf ] in (* Format the file systems by writing zeroes *) - let zeroes = Cstruct.create (max (2 * Tar.Header.length) sector_size) in + (* For tar we need to zero (at least) the first 2*512 bytes so we round up + to the nearest sector alignment *) + let zeroes = + let sectors = + (2 * Tar.Header.length + sector_size - 1) / sector_size * sector_size + in + Cstruct.create sectors in let*? () = - write block tar.starting_lba [ Cstruct.sub zeroes 0 (2 * Tar.Header.length) ] + write block tar.starting_lba [ zeroes ] + in + (* For the OneFFS filesystems we just need to zero out the first sector *) + let zero_sector = Cstruct.create sector_size in + let*? () = + write block git_dump.starting_lba [ zero_sector ] in let*? () = - write block git_dump.starting_lba [ Cstruct.sub zeroes 0 sector_size ] + write block md5s.starting_lba [ zero_sector ] in - let*? () = - write block md5s.starting_lba [ Cstruct.sub zeroes 0 sector_size ] - in - write block sha512s.starting_lba [ Cstruct.sub zeroes 0 sector_size ] + write block sha512s.starting_lba [ zero_sector ] end