Add .gitignore file for git.
[virt-df.git] / lib / diskimage_impl.mli
1 (** Diskimage library implementation. *)
2 (* (C) Copyright 2007-2008 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
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.
10
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.
15
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
19  *)
20
21 (** Don't use the functions and types in here directly.  The safe ones
22     are reexported through the {!Diskimage} module, see [diskimage.mli].
23 *)
24
25 (**/**)
26
27 val debug : bool ref
28
29 (** {2 Device model} *)
30
31 class virtual device :
32   object
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
40   end
41
42 class block_device : string -> Int63.t ->
43   object
44     method name : string
45     method size : 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
52   end
53
54 class offset_device : string -> Int63.t -> Int63.t -> Int63.t -> device ->
55   object
56     method name : string
57     method size : Int63.t
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
63   end
64
65 class blocksize_overlay : Int63.t -> device ->
66   object
67     method name : string
68     method size : Int63.t
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
74   end
75
76 val null_device : device
77
78 type machine = {
79   m_name : string;
80   m_disks : disk list;
81   m_lv_filesystems :
82     (lv * filesystem) list;
83 }
84
85 and disk = {
86   d_name : string;
87   d_dev : block_device;
88   d_content : disk_content;
89 }
90
91 and disk_content =
92     [ `Filesystem of filesystem
93     | `Partitions of partitions
94     | `PhysicalVolume of pv
95     | `Unknown
96     ]
97
98 and partitions = {
99   parts_cb : partitioner_callbacks;
100   parts_dev : device;
101   parts : partition list;
102 }
103 and partition = {
104   part_status : partition_status;
105   part_type : int;
106   part_dev : device;
107   part_content : partition_content;
108 }
109
110 and partition_status = Bootable | Nonbootable | Malformed | NullEntry
111 and partition_content =
112     [ `Filesystem of filesystem
113     | `PhysicalVolume of pv
114     | `Unknown
115     ]
116
117 and filesystem = {
118   fs_cb : filesystem_callbacks;
119   fs_dev : device;
120   fs_blocksize : Int63.t;
121   fs_blocks_total : Int63.t;
122   fs_is_swap : bool;
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;
130 }
131
132 and pv = {
133   pv_cb : lvm_callbacks;
134   pv_dev : device;
135   pv_uuid : string;
136 }
137 and lv = {
138   lv_dev : device;
139 }
140
141 (** {2 Table of callbacks from each type of plug-in} *)
142
143 and partitioner_probe = device -> partitions
144
145 and partitioner_callbacks = {
146   parts_cb_uq : int;
147   parts_cb_name : string;
148   parts_cb_offset_is_free : partitions -> Int63.t -> bool;
149 }
150
151 and filesystem_probe = device -> filesystem
152
153 and filesystem_callbacks = {
154   fs_cb_uq : int;
155   fs_cb_name : string;
156   fs_cb_printable_name : string;
157   fs_cb_offset_is_free : filesystem -> Int63.t -> bool;
158 }
159
160 and lvm_probe = device -> pv
161
162 and lvm_callbacks = {
163   lvm_cb_uq : int;
164   lvm_cb_name : string;
165   lvm_cb_list_lvs : pv list -> lv list;
166   lvm_cb_offset_is_free : pv -> Int63.t -> bool;
167 }
168
169 val name_of_filesystem : filesystem -> string
170
171 (** {3 Plug-in registration} *)
172
173 val register_plugin :
174   ?partitioner:partitioner_probe ->
175   ?filesystem:filesystem_probe ->
176   ?lvm:lvm_probe ->
177   string -> unit
178
179 (** {3 Plug-in-specific data management} *)
180
181 val private_data_functions :
182   ('key -> int) -> ('key -> 'data -> unit) * ('key -> 'data)
183
184 (** {2 Internal functions used by the plug-ins} *)
185
186 val canonical_uuid : string -> string
187   (** Convert a UUID which may contain '-' characters to canonical form. *)
188
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. *)
191
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
194     elements removed. *)
195
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. *)
199
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.
203 *)
204
205 (** {2 Functions} *)
206
207 val open_machine : string -> (string * string) list -> machine
208 val open_machine_from_devices : string -> (string * block_device) list ->
209   machine
210 val close_machine : machine -> unit
211 val scan_machine : machine -> machine
212
213 type ownership
214
215 val create_ownership : machine -> ownership
216
217 type owner =
218     [ `Filesystem of filesystem
219     | `Partitions of partitions
220     | `PhysicalVolume of pv ]
221
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