From bd7f5781897529881c2bfec51b1150600140a383 Mon Sep 17 00:00:00 2001 From: Eineje Ameh <123401643+neyjay12@users.noreply.github.com> Date: Fri, 24 Mar 2023 14:44:13 +0100 Subject: [PATCH] :mem Update-mirage-block-partition --- README.md | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9680251..27be60a 100644 --- a/README.md +++ b/README.md @@ -6,29 +6,42 @@ The reason for this at times perhaps slightly inconvenient interface is it makes ```OCaml module Make(B : Mirage_block.S)(Clock : Mirage_clock.PCLOCK) = struct - + (* Create a module for partitioning a Mirage block device *) module Partitioned = Mirage_block_partition.Make(B) + + (* Create a module for accessing a tar KV store on a partitioned block device *) module Tar = Tar_mirage.Make_KV_RO(Partitioned) - module Chamelon = Kv.Make(Partitioned)(Clock) + + (* Create a module for accessing a Chameleon filesystem on a partitioned block device *) + module Chameleon = Kv.Make(Partitioned)(Clock) + + (* Connect to the block device and partition it into three sub-blocks *) + let%bind connect_and_partition b = + let%bind b1, rest = Partitioned.connect (Sectors.of_int 20) b in + let b2, b3 = Partitioned.subpartition (Sectors.of_int 8192) rest in + (* Return a tuple containing the three sub-blocks *) + return (b1, b2, b3) let start b = let open Lwt.Syntax in - (* b1 is the first twenty sectors, b2 is the next 8k sectors (4 MiB), - and b3 is the remaining space. Note that the initial [connect] call is - asynchronous while the later [subpartition] calls are not. If the - partition point is outside the block device or subpartition then an - exception is raised. *) - let* b1, rest = Partitioned.connect 20L b in - let b2, b3 = Partitioned.subpartition 8192L rest in - (* now use e.g. b1 as a tar KV store, b2 as a chamelon filesystem, - b3 as a raw block device... *) - let* tar = Tar.connect b1 - and* chamelon = Chamelon.connect ~program_size:16 b2 in - ... + (* Connect to the block device and partition it into three sub-blocks *) + let* b1, rest = Partitioned.connect (Sectors.of_int 20) b in + let b2, b3 = Partitioned.subpartition (Sectors.of_int 8192) rest in + + (* Connect to the tar KV store on the first sub-block *) + let* tar = Tar.connect b1 in + (* Connect to the Chameleon filesystem on the second sub-block *) + let* chameleon = Chameleon.connect ~program_size:16 b2 in + + (* Other code using the connected devices *) + ... end + ``` + + ### mirage-block-partition-mbr This module reads a disk labeled with a Master Boot Record and returns a list of pairs of `Mbr.Partition.t` and a block device representing the partition according to the MBR.