Use tables of callbacks for the functions.
[virt-df.git] / lib / diskimage_utils.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 (**/**)
20
21 val debug : bool ref
22
23 (** {2 Device model} *)
24
25 class virtual device :
26   object
27     method virtual name : string
28     method virtual size : Int63.t
29     method read : Int63.t -> Int63.t -> string
30     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
31     method virtual blocksize : Int63.t
32     method virtual map_block : Int63.t -> (device * Int63.t) list
33     method virtual contiguous : Int63.t -> Int63.t
34   end
35
36 class block_device : string -> Int63.t ->
37   object
38     method name : string
39     method size : Int63.t
40     method read : Int63.t -> Int63.t -> string
41     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
42     method blocksize : Int63.t
43     method map_block : Int63.t -> (device * Int63.t) list
44     method contiguous : Int63.t -> Int63.t
45     method close : unit -> unit
46   end
47
48 class offset_device : string -> Int63.t -> Int63.t -> Int63.t -> device ->
49   object
50     method name : string
51     method size : Int63.t
52     method read : Int63.t -> Int63.t -> string
53     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
54     method blocksize : Int63.t
55     method map_block : Int63.t -> (device * Int63.t) list
56     method contiguous : Int63.t -> Int63.t
57   end
58
59 class blocksize_overlay : Int63.t -> device ->
60   object
61     method name : string
62     method size : Int63.t
63     method read : Int63.t -> Int63.t -> string
64     method read_bitstring : Int63.t -> Int63.t -> Bitmatch.bitstring
65     method blocksize : Int63.t
66     method map_block : Int63.t -> (device * Int63.t) list
67     method contiguous : Int63.t -> Int63.t
68   end
69
70 val null_device : device
71
72 type machine = {
73   m_name : string;
74   m_disks : disk list;
75   m_lv_filesystems :
76     (lv * filesystem) list;
77 }
78
79 and disk = {
80   d_name : string;
81   d_dev : block_device;
82   d_content : disk_content;
83 }
84
85 and disk_content =
86     [ `Filesystem of filesystem
87     | `Partitions of partitions
88     | `PhysicalVolume of pv
89     | `Unknown
90     ]
91
92 and partitions = {
93   parts_plugin_id : parts_plugin_id;
94   parts_dev : device;
95   parts : partition list;
96 }
97 and partition = {
98   part_status : partition_status;
99   part_type : int;
100   part_dev : device;
101   part_content : partition_content;
102 }
103
104 and partition_status = Bootable | Nonbootable | Malformed | NullEntry
105 and partition_content =
106     [ `Filesystem of filesystem
107     | `PhysicalVolume of pv
108     | `Unknown
109     ]
110
111 and filesystem = {
112   fs_plugin_id : fs_plugin_id;
113   fs_dev : device;
114   fs_blocksize : Int63.t;
115   fs_blocks_total : Int63.t;
116   fs_is_swap : bool;
117   fs_blocks_reserved : Int63.t;
118   fs_blocks_avail : Int63.t;
119   fs_blocks_used : Int63.t;
120   fs_inodes_total : Int63.t;
121   fs_inodes_reserved : Int63.t;
122   fs_inodes_avail : Int63.t;
123   fs_inodes_used : Int63.t;
124 }
125
126 and pv = {
127   lvm_plugin_id : lvm_plugin_id;
128   pv_dev : device;
129   pv_uuid : string;
130 }
131 and lv = {
132   lv_dev : device;
133 }
134
135 and parts_plugin_id = string
136 and fs_plugin_id = string
137 and lvm_plugin_id = string
138
139 (** {2 Table of callbacks from each type of plug-in} *)
140
141 type parts_cb = {
142   parts_cb_probe : device -> partitions;
143   parts_cb_offset_is_free : partitions -> Int63.t -> bool;
144 }
145
146 type fs_cb = {
147   fs_cb_probe : device -> filesystem;
148   fs_cb_offset_is_free : filesystem -> Int63.t -> bool;
149 }
150
151 type lvm_cb = {
152   lvm_cb_probe : lvm_plugin_id -> device -> pv;
153   lvm_cb_list_lvs : device list -> lv list;
154   lvm_cb_offset_is_free : pv -> Int63.t -> bool;
155 }
156
157 (** {2 Internal functions used by the plug-ins} *)
158
159 val canonical_uuid : string -> string
160   (** Convert a UUID which may contain '-' characters to canonical form. *)
161
162 val group_by : ?cmp:('a -> 'a -> int) -> ('a * 'b) list -> ('a * 'b list) list
163 (** Group a sorted list of pairs by the first element of the pair. *)
164
165 val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
166 (** [sort_uniq xs] returns the list [xs], sorted and with all duplicate
167     elements removed. *)
168
169 val uniq : ?cmp:('a -> 'a -> int) -> 'a list -> 'a list
170 (** [uniq xs] removes adjacent duplicate elements from a list, like
171     the Unix uniq(1) command. *)
172
173 val range : int -> int -> int list
174 (** [range a b] returns the list of integers [a <= i < b].
175     If [a >= b] then the empty list is returned.
176 *)