From 248e97bdc87fc0c53b532861c209e68fadfa02ff Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Return a specialized function so we don't break type safety. --- diskzip/diskzip.ml | 1 + lib/diskimage.ml | 29 +++++++++++++++-------------- lib/diskimage.mli | 21 +++++++++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/diskzip/diskzip.ml b/diskzip/diskzip.ml index 21d2cc3..3de7f63 100644 --- a/diskzip/diskzip.ml +++ b/diskzip/diskzip.ml @@ -150,6 +150,7 @@ and go_compress extcompress images = (* Create ownership tables. *) let ownership = Diskimage.create_ownership machine in + (* Create ownership bitmap for each disk. *) (* Redirect output through external pipe if asked. *) diff --git a/lib/diskimage.ml b/lib/diskimage.ml index b12ba0e..697cb76 100644 --- a/lib/diskimage.ml +++ b/lib/diskimage.ml @@ -661,21 +661,22 @@ let create_ownership machine = (* Return the ownership structure. *) ownership -let get_owners machine ownership disk offset = +let get_owners_lookup machine ownership disk = (* Get the correct tree. *) let tree = List.assoc disk ownership in - let rec query = function - | Leaf (_, segments) -> segments - | Node ((Leaf ((_, leftend), _) | Node (_, ((_, leftend), _), _) as left), - (_, segments), - right) -> - let subsegments = - if offset < leftend then query left else query right in - segments @ subsegments - in - let owners = query tree in + fun offset -> + let rec query = function + | Leaf (_, segments) -> segments + | Node ((Leaf ((_, leftend), _) | Node (_, ((_, leftend), _), _) as left), + (_, segments), + right) -> + let subsegments = + if offset < leftend then query left else query right in + segments @ subsegments + in + let owners = query tree in - List.map ( - fun (_, _, owner, owner_offset) -> (owner, offset -^ owner_offset) - ) owners + List.map ( + fun (_, _, owner, owner_offset) -> (owner, offset -^ owner_offset) + ) owners diff --git a/lib/diskimage.mli b/lib/diskimage.mli index 22ba927..8cdd7a9 100644 --- a/lib/diskimage.mli +++ b/lib/diskimage.mli @@ -308,12 +308,17 @@ type owner = | `Partitions of partitions | `PhysicalVolume of pv ] -val get_owners : - machine -> ownership -> device -> Int63.t -> (owner * Int63.t) list - (** [get_owners machine ownership disk offset] returns the - owners (filesystems, etc.) which reside on block device [disk] - at the given byte offset. [disk] must be a block device - of the machine. +val get_owners_lookup : machine -> ownership -> device -> + (Int63.t -> (owner * Int63.t) list) + (** [get_owners_lookup machine disk] returns a specialized + function for looking up owners (filesystems, etc.) + which reside on block device [disk]. + + [disk] must be a block device of the machine. + + The specialized lookup function that is returned + can be called as [lookup offset] to look up the + owners of byte offset [offset]. Returns a list of [(owner, owner_offset)] where [owner] is the filesystem, etc., and [owner_offset] is the byte @@ -324,8 +329,8 @@ val get_owners : both the filesystem ([`Filesystem fs]) and partition scheme ([`Partitions parts]) will be returned. - This function is efficient. {!create_ownership} creates - a tree structure which allows ownership to be determined + The specialized function is efficient. {!create_ownership} + creates a tree structure which allows ownership to be determined in just a few steps. *) (** {2 Debugging} *) -- 1.8.3.1