39ce30f32a654aa4d89b2575023777ade090a2c7
[virt-df.git] / lib / diskimage_impl.mli
1 (* (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
2    http://libvirt.org/
3
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version,
8    with the OCaml linking exception described in ../COPYING.LIB.
9
10    This library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14
15    You should have received a copy of the GNU Lesser General Public
16    License along with this library; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
18  *)
19
20 (* Don't use the functions and types in here directly.  The safe ones
21  * are reexported through the Diskimage module, see diskimage.mli.
22  *)
23
24 (**/**)
25
26 val debug : bool ref
27
28 (** {2 Device model} *)
29
30 class virtual device :
31   object
32     method virtual name : string
33     method virtual size : Int63.t
34     method read : Int63.t -> Int63.t -> string
35     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
36     method virtual blocksize : Int63.t
37     method virtual map_block : Int63.t -> (device * Int63.t) list
38     method virtual contiguous : Int63.t -> Int63.t
39   end
40
41 class block_device : string -> Int63.t ->
42   object
43     method name : string
44     method size : Int63.t
45     method read : Int63.t -> Int63.t -> string
46     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
47     method blocksize : Int63.t
48     method map_block : Int63.t -> (device * Int63.t) list
49     method contiguous : Int63.t -> Int63.t
50     method close : unit -> unit
51   end
52
53 class offset_device : string -> Int63.t -> Int63.t -> Int63.t -> device ->
54   object
55     method name : string
56     method size : Int63.t
57     method read : Int63.t -> Int63.t -> string
58     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
59     method blocksize : Int63.t
60     method map_block : Int63.t -> (device * Int63.t) list
61     method contiguous : Int63.t -> Int63.t
62   end
63
64 class blocksize_overlay : Int63.t -> device ->
65   object
66     method name : string
67     method size : Int63.t
68     method read : Int63.t -> Int63.t -> string
69     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
70     method blocksize : Int63.t
71     method map_block : Int63.t -> (device * Int63.t) list
72     method contiguous : Int63.t -> Int63.t
73   end
74
75 val null_device : device
76
77 type machine = {
78   m_name : string;
79   m_disks : disk list;
80   m_lv_filesystems :
81     (lv * filesystem) list;
82 }
83
84 and disk = {
85   d_name : string;
86   d_dev : block_device;
87   d_content : disk_content;
88 }
89
90 and disk_content =
91     [ `Filesystem of filesystem
92     | `Partitions of partitions
93     | `PhysicalVolume of pv
94     | `Unknown
95     ]
96
97 and partitions = {
98   parts_cb : partitioner_callbacks;
99   parts_dev : device;
100   parts : partition list;
101 }
102 and partition = {
103   part_status : partition_status;
104   part_type : int;
105   part_dev : device;
106   part_content : partition_content;
107 }
108
109 and partition_status = Bootable | Nonbootable | Malformed | NullEntry
110 and partition_content =
111     [ `Filesystem of filesystem
112     | `PhysicalVolume of pv
113     | `Unknown
114     ]
115
116 and filesystem = {
117   fs_cb : filesystem_callbacks;
118   fs_dev : device;
119   fs_blocksize : Int63.t;
120   fs_blocks_total : Int63.t;
121   fs_is_swap : bool;
122   fs_blocks_reserved : Int63.t;
123   fs_blocks_avail : Int63.t;
124   fs_blocks_used : Int63.t;
125   fs_inodes_total : Int63.t;
126   fs_inodes_reserved : Int63.t;
127   fs_inodes_avail : Int63.t;
128   fs_inodes_used : Int63.t;
129 }
130
131 and pv = {
132   pv_cb : lvm_callbacks;
133   pv_dev : device;
134   pv_uuid : string;
135 }
136 and lv = {
137   lv_dev : device;
138 }
139
140 (** {2 Table of callbacks from each type of plug-in} *)
141
142 and partitioner_probe = device -> partitions
143
144 and partitioner_callbacks = {
145   parts_cb_uq : int;
146   parts_cb_name : string;
147   parts_cb_offset_is_free : partitions -> Int63.t -> bool;
148 }
149
150 and filesystem_probe = device -> filesystem
151
152 and filesystem_callbacks = {
153   fs_cb_uq : int;
154   fs_cb_name : string;
155   fs_cb_printable_name : string;
156   fs_cb_offset_is_free : filesystem -> Int63.t -> bool;
157 }
158
159 and lvm_probe = device -> pv
160
161 and lvm_callbacks = {
162   lvm_cb_uq : int;
163   lvm_cb_name : string;
164   lvm_cb_list_lvs : pv list -> lv list;
165   lvm_cb_offset_is_free : pv -> Int63.t -> bool;
166 }
167
168 val name_of_filesystem : filesystem -> string
169
170 (** {3 Plug-in registration} *)
171
172 val register_plugin :
173   ?partitioner:partitioner_probe ->
174   ?filesystem:filesystem_probe ->
175   ?lvm:lvm_probe ->
176   string -> unit
177
178 (** {3 Plug-in-specific data management. *)
179
180 val private_data_functions :
181   ('key -> int) -> ('key -> 'data -> unit) * ('key -> 'data)
182
183 (** {2 Internal functions used by the plug-ins} *)
184
185 val canonical_uuid : string -> string
186   (** Convert a UUID which may contain '-' characters to canonical form. *)
187
188 val group_by : ?cmp:('a -> 'a -> int) -> ('a * 'b) list -> ('a * 'b list) list
189 (** Group a sorted list of pairs by the first element of the pair. *)
190
191 val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
192 (** [sort_uniq xs] returns the list [xs], sorted and with all duplicate
193     elements removed. *)
194
195 val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
196 (** [uniq xs] removes adjacent duplicate elements from a list, like
197     the Unix uniq(1) command. *)
198
199 val range : int -> int -> int list
200 (** [range a b] returns the list of integers [a <= i < b].
201     If [a >= b] then the empty list is returned.
202 *)
203
204 (** {2 Functions} *)
205
206 val open_machine : string -> (string * string) list -> machine
207 val open_machine_from_devices : string -> (string * block_device) list ->
208   machine
209 val close_machine : machine -> unit
210 val scan_machine : machine -> machine
211
212 type ownership
213
214 val create_ownership : machine -> ownership
215
216 type owner =
217     [ `Filesystem of filesystem
218     | `Partitions of partitions
219     | `PhysicalVolume of pv ]
220
221 val get_owners_lookup : machine -> ownership -> block_device ->
222   (Int63.t -> (owner * Int63.t) list)
223 val offset_is_free : (owner * Int63.t) list -> bool