1 (** Diskimage library implementation. *)
2 (* (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version,
9 with the OCaml linking exception described in ../COPYING.LIB.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 (** Don't use the functions and types in here directly. The safe ones
22 are reexported through the {!Diskimage} module, see [diskimage.mli].
29 (** {2 Device model} *)
31 class virtual device :
33 method virtual name : string
34 method virtual size : Int63.t
35 method read : Int63.t -> Int63.t -> string
36 method read_bitstring : Int63.t -> Int63.t -> Bitstring.bitstring
37 method virtual blocksize : Int63.t
38 method virtual map_block : Int63.t -> (device * Int63.t) list
39 method virtual contiguous : Int63.t -> Int63.t
42 class block_device : string -> Int63.t ->
46 method read : Int63.t -> Int63.t -> string
47 method read_bitstring : Int63.t -> Int63.t -> Bitstring.bitstring
48 method blocksize : Int63.t
49 method map_block : Int63.t -> (device * Int63.t) list
50 method contiguous : Int63.t -> Int63.t
51 method close : unit -> unit
54 class offset_device : string -> Int63.t -> Int63.t -> Int63.t -> device ->
58 method read : Int63.t -> Int63.t -> string
59 method read_bitstring : Int63.t -> Int63.t -> Bitstring.bitstring
60 method blocksize : Int63.t
61 method map_block : Int63.t -> (device * Int63.t) list
62 method contiguous : Int63.t -> Int63.t
65 class blocksize_overlay : Int63.t -> device ->
69 method read : Int63.t -> Int63.t -> string
70 method read_bitstring : Int63.t -> Int63.t -> Bitstring.bitstring
71 method blocksize : Int63.t
72 method map_block : Int63.t -> (device * Int63.t) list
73 method contiguous : Int63.t -> Int63.t
76 val null_device : device
82 (lv * filesystem) list;
88 d_content : disk_content;
92 [ `Filesystem of filesystem
93 | `Partitions of partitions
94 | `PhysicalVolume of pv
99 parts_cb : partitioner_callbacks;
101 parts : partition list;
104 part_status : partition_status;
107 part_content : partition_content;
110 and partition_status = Bootable | Nonbootable | Malformed | NullEntry
111 and partition_content =
112 [ `Filesystem of filesystem
113 | `PhysicalVolume of pv
118 fs_cb : filesystem_callbacks;
120 fs_blocksize : Int63.t;
121 fs_blocks_total : Int63.t;
123 fs_blocks_reserved : Int63.t;
124 fs_blocks_avail : Int63.t;
125 fs_blocks_used : Int63.t;
126 fs_inodes_total : Int63.t;
127 fs_inodes_reserved : Int63.t;
128 fs_inodes_avail : Int63.t;
129 fs_inodes_used : Int63.t;
133 pv_cb : lvm_callbacks;
141 (** {2 Table of callbacks from each type of plug-in} *)
143 and partitioner_probe = device -> partitions
145 and partitioner_callbacks = {
147 parts_cb_name : string;
148 parts_cb_offset_is_free : partitions -> Int63.t -> bool;
151 and filesystem_probe = device -> filesystem
153 and filesystem_callbacks = {
156 fs_cb_printable_name : string;
157 fs_cb_offset_is_free : filesystem -> Int63.t -> bool;
160 and lvm_probe = device -> pv
162 and lvm_callbacks = {
164 lvm_cb_name : string;
165 lvm_cb_list_lvs : pv list -> lv list;
166 lvm_cb_offset_is_free : pv -> Int63.t -> bool;
169 val name_of_filesystem : filesystem -> string
171 (** {3 Plug-in registration} *)
173 val register_plugin :
174 ?partitioner:partitioner_probe ->
175 ?filesystem:filesystem_probe ->
179 (** {3 Plug-in-specific data management} *)
181 val private_data_functions :
182 ('key -> int) -> ('key -> 'data -> unit) * ('key -> 'data)
184 (** {2 Internal functions used by the plug-ins} *)
186 val canonical_uuid : string -> string
187 (** Convert a UUID which may contain '-' characters to canonical form. *)
189 val group_by : ?cmp:('a -> 'a -> int) -> ('a * 'b) list -> ('a * 'b list) list
190 (** Group a sorted list of pairs by the first element of the pair. *)
192 val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
193 (** [sort_uniq xs] returns the list [xs], sorted and with all duplicate
196 val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
197 (** [uniq xs] removes adjacent duplicate elements from a list, like
198 the Unix uniq(1) command. *)
200 val range : int -> int -> int list
201 (** [range a b] returns the list of integers [a <= i < b].
202 If [a >= b] then the empty list is returned.
207 val open_machine : string -> (string * string) list -> machine
208 val open_machine_from_devices : string -> (string * block_device) list ->
210 val close_machine : machine -> unit
211 val scan_machine : machine -> machine
215 val create_ownership : machine -> ownership
218 [ `Filesystem of filesystem
219 | `Partitions of partitions
220 | `PhysicalVolume of pv ]
222 val get_owners_lookup : machine -> ownership -> block_device ->
223 (Int63.t -> (owner * Int63.t) list)
224 val offset_is_free : (owner * Int63.t) list -> bool