2024-12-07 15:04:56 +00:00
|
|
|
let cachet_of_block ~cachesize blk () =
|
|
|
|
let map blk ~pos len =
|
|
|
|
let bstr = Bigarray.(Array1.create char c_layout len) in
|
2024-12-08 16:00:01 +00:00
|
|
|
Miou_solo5.Block.read blk ~off:pos bstr;
|
|
|
|
bstr
|
|
|
|
in
|
2024-12-07 15:04:56 +00:00
|
|
|
let pagesize = Miou_solo5.Block.pagesize blk in
|
|
|
|
Cachet.make ~cachesize ~pagesize ~map blk
|
2024-12-06 13:45:17 +00:00
|
|
|
|
2024-12-07 15:04:56 +00:00
|
|
|
let cachet ~cachesize name =
|
|
|
|
let open Miou_solo5 in
|
|
|
|
map (cachet_of_block ~cachesize) [ block name ]
|
2024-12-06 13:45:17 +00:00
|
|
|
|
2024-12-07 15:04:56 +00:00
|
|
|
let run cachesize =
|
|
|
|
Miou_solo5.(run [ cachet ~cachesize "simple" ]) @@ fun blk () ->
|
|
|
|
let pagesize = Cachet.pagesize blk in
|
2024-12-06 14:38:24 +00:00
|
|
|
let prm =
|
|
|
|
Miou.async @@ fun () ->
|
2024-12-07 15:04:56 +00:00
|
|
|
let bstr = Bigarray.(Array1.create char c_layout pagesize) in
|
|
|
|
let blk = Cachet.fd blk in
|
2024-12-06 13:45:17 +00:00
|
|
|
Miou_solo5.Block.atomic_read blk ~off:0 bstr;
|
2024-12-07 15:04:56 +00:00
|
|
|
let bstr = Cachet.Bstr.of_bigstring bstr in
|
|
|
|
let str = Cachet.Bstr.to_string bstr in
|
2024-12-06 13:45:17 +00:00
|
|
|
let hash = Digest.string str in
|
|
|
|
Fmt.pr "%08x: %s\n%!" 0 (Digest.to_hex hash)
|
|
|
|
in
|
2024-12-07 15:04:56 +00:00
|
|
|
let str = Cachet.get_string blk pagesize ~len:pagesize in
|
2024-12-06 13:45:17 +00:00
|
|
|
let hash = Digest.string str in
|
|
|
|
Fmt.pr "%08x: %s\n%!" pagesize (Digest.to_hex hash);
|
|
|
|
Miou.await_exn prm
|
2024-12-07 15:04:56 +00:00
|
|
|
|
|
|
|
open Cmdliner
|
|
|
|
|
|
|
|
let cachesize =
|
|
|
|
let doc = "The size of the cache (must be a power of two)." in
|
|
|
|
let open Arg in
|
|
|
|
value & opt int 0x100 & info [ "cachesize" ] ~doc ~docv:"NUMBER"
|
|
|
|
|
|
|
|
let term =
|
|
|
|
let open Term in
|
|
|
|
const run $ cachesize
|
|
|
|
|
|
|
|
let cmd =
|
|
|
|
let doc = "A simple unikernel to read a block device." in
|
|
|
|
let man = [] in
|
|
|
|
let info = Cmd.info "blk" ~doc ~man in
|
|
|
|
Cmd.v info term
|
|
|
|
|
|
|
|
let () = Cmd.(exit @@ eval cmd)
|