Use tables of callbacks for the functions.
[virt-df.git] / lib / diskimage_utils.mli
index 91f43e0..07179d8 100644 (file)
@@ -25,28 +25,46 @@ val debug : bool ref
 class virtual device :
   object
     method virtual name : string
-    method virtual size : int64
-    method close : unit -> unit
-    method virtual read : int64 -> int -> string
-    method read_bitstring : int64 -> int -> Bitmatch.bitstring
+    method virtual size : Int63.t
+    method read : Int63.t -> Int63.t -> string
+    method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
+    method virtual blocksize : Int63.t
+    method virtual map_block : Int63.t -> (device * Int63.t) list
+    method virtual contiguous : Int63.t -> Int63.t
   end
 
-class block_device : string ->
+class block_device : string -> Int63.t ->
   object
     method name : string
-    method size : int64
+    method size : Int63.t
+    method read : Int63.t -> Int63.t -> string
+    method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
+    method blocksize : Int63.t
+    method map_block : Int63.t -> (device * Int63.t) list
+    method contiguous : Int63.t -> Int63.t
     method close : unit -> unit
-    method read : int64 -> int -> string
-    method read_bitstring : int64 -> int -> Bitmatch.bitstring
   end
 
-class offset_device : string -> int64 -> int64 -> device ->
+class offset_device : string -> Int63.t -> Int63.t -> Int63.t -> device ->
   object
     method name : string
-    method size : int64
-    method close : unit -> unit
-    method read : int64 -> int -> string
-    method read_bitstring : int64 -> int -> Bitmatch.bitstring
+    method size : Int63.t
+    method read : Int63.t -> Int63.t -> string
+    method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
+    method blocksize : Int63.t
+    method map_block : Int63.t -> (device * Int63.t) list
+    method contiguous : Int63.t -> Int63.t
+  end
+
+class blocksize_overlay : Int63.t -> device ->
+  object
+    method name : string
+    method size : Int63.t
+    method read : Int63.t -> Int63.t -> string
+    method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
+    method blocksize : Int63.t
+    method map_block : Int63.t -> (device * Int63.t) list
+    method contiguous : Int63.t -> Int63.t
   end
 
 val null_device : device
@@ -60,7 +78,7 @@ type machine = {
 
 and disk = {
   d_name : string;
-  d_dev : device;
+  d_dev : block_device;
   d_content : disk_content;
 }
 
@@ -72,7 +90,8 @@ and disk_content =
     ]
 
 and partitions = {
-  parts_name : string;
+  parts_plugin_id : parts_plugin_id;
+  parts_dev : device;
   parts : partition list;
 }
 and partition = {
@@ -90,31 +109,50 @@ and partition_content =
     ]
 
 and filesystem = {
-  fs_name : string;
-  fs_block_size : int64;
-  fs_blocks_total : int64;
+  fs_plugin_id : fs_plugin_id;
+  fs_dev : device;
+  fs_blocksize : Int63.t;
+  fs_blocks_total : Int63.t;
   fs_is_swap : bool;
-  fs_blocks_reserved : int64;
-  fs_blocks_avail : int64;
-  fs_blocks_used : int64;
-  fs_inodes_total : int64;
-  fs_inodes_reserved : int64;
-  fs_inodes_avail : int64;
-  fs_inodes_used : int64;
+  fs_blocks_reserved : Int63.t;
+  fs_blocks_avail : Int63.t;
+  fs_blocks_used : Int63.t;
+  fs_inodes_total : Int63.t;
+  fs_inodes_reserved : Int63.t;
+  fs_inodes_avail : Int63.t;
+  fs_inodes_used : Int63.t;
 }
 
 and pv = {
   lvm_plugin_id : lvm_plugin_id;
+  pv_dev : device;
   pv_uuid : string;
 }
 and lv = {
   lv_dev : device;
 }
 
+and parts_plugin_id = string
+and fs_plugin_id = string
 and lvm_plugin_id = string
 
-val string_of_partition : partition -> string
-val string_of_filesystem : filesystem -> string
+(** {2 Table of callbacks from each type of plug-in} *)
+
+type parts_cb = {
+  parts_cb_probe : device -> partitions;
+  parts_cb_offset_is_free : partitions -> Int63.t -> bool;
+}
+
+type fs_cb = {
+  fs_cb_probe : device -> filesystem;
+  fs_cb_offset_is_free : filesystem -> Int63.t -> bool;
+}
+
+type lvm_cb = {
+  lvm_cb_probe : lvm_plugin_id -> device -> pv;
+  lvm_cb_list_lvs : device list -> lv list;
+  lvm_cb_offset_is_free : pv -> Int63.t -> bool;
+}
 
 (** {2 Internal functions used by the plug-ins} *)
 
@@ -124,18 +162,15 @@ val canonical_uuid : string -> string
 val group_by : ?cmp:('a -> 'a -> int) -> ('a * 'b) list -> ('a * 'b list) list
 (** Group a sorted list of pairs by the first element of the pair. *)
 
+val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
+(** [sort_uniq xs] returns the list [xs], sorted and with all duplicate
+    elements removed. *)
+
+val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
+(** [uniq xs] removes adjacent duplicate elements from a list, like
+    the Unix uniq(1) command. *)
+
 val range : int -> int -> int list
 (** [range a b] returns the list of integers [a <= i < b].
     If [a >= b] then the empty list is returned.
 *)
-
-val ( +* ) : int32 -> int32 -> int32
-val ( -* ) : int32 -> int32 -> int32
-val ( ** ) : int32 -> int32 -> int32
-val ( /* ) : int32 -> int32 -> int32
-
-val ( +^ ) : int64 -> int64 -> int64
-val ( -^ ) : int64 -> int64 -> int64
-val ( *^ ) : int64 -> int64 -> int64
-val ( /^ ) : int64 -> int64 -> int64
-(** int32 and int64 infix operators for convenience. *)