Reset the partitions when initializing the disk

THIS DESTROYS DATA
This commit is contained in:
Reynir Björnsson 2024-10-10 10:24:57 +02:00
parent 0d3a345e7e
commit 02f6c1fe09

View file

@ -114,8 +114,6 @@ module Make(BLOCK : Mirage_block.S) = struct
Lwt.return_error (`Msg "too small disk") Lwt.return_error (`Msg "too small disk")
else Lwt_result.return () else Lwt_result.return ()
in in
let gpt =
let partitions =
(* Current implementation of [Gpt.Partition.make] only returns [Ok _] or (* Current implementation of [Gpt.Partition.make] only returns [Ok _] or
raises [Invalid_argument _] :/ *) raises [Invalid_argument _] :/ *)
let attributes = 1L in let attributes = 1L in
@ -155,6 +153,8 @@ module Make(BLOCK : Mirage_block.S) = struct
(Int64.pred git_dump.starting_lba) (Int64.pred git_dump.starting_lba)
|> Result.get_ok |> Result.get_ok
in in
let gpt =
let partitions =
[ tar; git_dump; md5s; sha512s ] [ tar; git_dump; md5s; sha512s ]
in in
Gpt.make ~sector_size ~disk_sectors:size_sectors partitions Gpt.make ~sector_size ~disk_sectors:size_sectors partitions
@ -167,6 +167,23 @@ module Make(BLOCK : Mirage_block.S) = struct
Gpt.marshal_partition_table ~sector_size Gpt.marshal_partition_table ~sector_size
(Cstruct.shift buf (sector_size * Int64.to_int gpt.partition_entry_lba)) (Cstruct.shift buf (sector_size * Int64.to_int gpt.partition_entry_lba))
gpt; gpt;
BLOCK.write block 0L [ buf ] let write block sector_start buffers =
BLOCK.write block sector_start buffers
|> Lwt_result.map_error (fun e -> `Block e) |> Lwt_result.map_error (fun e -> `Block e)
in
let*? () =
write block 0L [ buf ]
in
(* Format the file systems by writing zeroes *)
let zeroes = Cstruct.create (max (2 * Tar.Header.length) sector_size) in
let*? () =
write block tar.starting_lba [ Cstruct.sub zeroes 0 (2 * Tar.Header.length) ]
in
let*? () =
write block git_dump.starting_lba [ Cstruct.sub zeroes 0 sector_size ]
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 ]
end end