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