Compare commits

..

No commits in common. "2c606dbeb44884e7f1305fcbde67c719a9407626" and "2edc311a33d6a8f601fa64f45a9da5a359813ece" have entirely different histories.

2 changed files with 20 additions and 30 deletions

View file

@ -101,7 +101,7 @@ module Make(BLOCK : Mirage_block.S) = struct
and md5s = get_part md5s and sha512s = get_part sha512s in and md5s = get_part md5s and sha512s = get_part sha512s in
{ tar ; swap; git_dump ; md5s ; sha512s } { tar ; swap; git_dump ; md5s ; sha512s }
let format block ~cache_size ~git_size ~swap_size = let format block ~sectors_cache ~sectors_git ~sectors_swap =
let* { size_sectors; sector_size; _ } = BLOCK.get_info block in let* { size_sectors; sector_size; _ } = BLOCK.get_info block in
let ( let*? ) = Lwt_result.bind in let ( let*? ) = Lwt_result.bind in
(* ocaml-gpt uses a fixed size partition entries table. Create an empty GPT (* ocaml-gpt uses a fixed size partition entries table. Create an empty GPT
@ -110,16 +110,6 @@ module Make(BLOCK : Mirage_block.S) = struct
Gpt.make ~sector_size ~disk_sectors:size_sectors [] Gpt.make ~sector_size ~disk_sectors:size_sectors []
|> Result.get_ok |> Result.get_ok
in in
let mb_in_sectors mb =
(* 1 megabyte is 2^20 bytes (1024 * 1024) *)
let mb_in_bytes = Int64.(shift_left (of_int mb) 20) in
let ss = Int64.of_int sector_size in
Int64.(div (add mb_in_bytes (sub ss 1L)) ss)
in
let sectors_cache = mb_in_sectors cache_size
and sectors_git = mb_in_sectors git_size
and sectors_swap = mb_in_sectors swap_size
in
let*? () = let*? () =
if size_sectors < if size_sectors <
(* protective MBR + GPT header + GPT table *) (* protective MBR + GPT header + GPT table *)

View file

@ -59,20 +59,20 @@ module K = struct
let doc = Arg.info ~doc:"HTTP listen port." ["port"] in let doc = Arg.info ~doc:"HTTP listen port." ["port"] in
Mirage_runtime.register_arg Arg.(value & opt int 80 doc) Mirage_runtime.register_arg Arg.(value & opt int 80 doc)
let cache_size = let sectors_cache =
let doc = "Number of MB reserved for each checksum cache (md5, sha512). Only used with --initialize-disk." in let doc = "Number of sectors reserved for each checksum cache (md5, sha512). Only used with --initialize-disk." in
let doc = Arg.info ~doc ["cache-size"] in let doc = Arg.info ~doc ["sectors-cache"] in
Mirage_runtime.register_arg Arg.(value & opt int 4 doc) Mirage_runtime.register_arg Arg.(value & opt int64 Int64.(mul 4L 2048L) doc)
let git_size = let sectors_git =
let doc = "Number of MB reserved for git dump. Only used with --initialize-disk" in let doc = "Number of sectors reserved for git dump. Only used with --initialize-disk" in
let doc = Arg.info ~doc ["git-size"] in let doc = Arg.info ~doc ["sectors-git"] in
Mirage_runtime.register_arg Arg.(value & opt int 40 doc) Mirage_runtime.register_arg Arg.(value & opt int64 Int64.(mul 40L (mul 2L 1024L)) doc)
let swap_size = let sectors_swap =
let doc = "Number of MB reserved for swap. Only used with --initialize-disk" in let doc = "Number of sectors reserved for swap. Only used with --initialize-disk" in
let doc = Arg.info ~doc ["swap-size"] in let doc = Arg.info ~doc ["sectors-swap"] in
Mirage_runtime.register_arg Arg.(value & opt int 1024 doc) Mirage_runtime.register_arg Arg.(value & opt int64 Int64.(mul 1024L 2048L) doc)
let initialize_disk = let initialize_disk =
let doc = "Initialize the disk with a partition table. THIS IS DESTRUCTIVE!" in let doc = "Initialize the disk with a partition table. THIS IS DESTRUCTIVE!" in
@ -1123,11 +1123,11 @@ stamp: %S
let start block _time _pclock stack git_ctx http_ctx = let start block _time _pclock stack git_ctx http_ctx =
let initialize_disk = K.initialize_disk () let initialize_disk = K.initialize_disk ()
and cache_size = K.cache_size () and sectors_cache = K.sectors_cache ()
and git_size = K.git_size () and sectors_git = K.sectors_git ()
and swap_size = K.swap_size () in and sectors_swap = K.sectors_swap () in
if initialize_disk then if initialize_disk then
Part.format block ~cache_size ~git_size ~swap_size >>= function Part.format block ~sectors_cache ~sectors_git ~sectors_swap >>= function
| Ok () -> | Ok () ->
Logs.app (fun m -> m "Successfully initialized the disk! You may restart now without --initialize-disk."); Logs.app (fun m -> m "Successfully initialized the disk! You may restart now without --initialize-disk.");
Lwt.return_unit Lwt.return_unit