0a46197862e2892a931fcca2461d46fa204130fc
[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 : int64
29     method read : int64 -> int -> string
30     method read_bitstring : int64 -> int -> Bitmatch.bitstring
31     method virtual blocksize : int
32     method virtual mapblock : int64 -> (device * int64) list
33   end
34
35 class block_device : string -> int ->
36   object
37     method name : string
38     method size : int64
39     method read : int64 -> int -> string
40     method read_bitstring : int64 -> int -> Bitmatch.bitstring
41     method blocksize : int
42     method mapblock : int64 -> (device * int64) list
43     method close : unit -> unit
44   end
45
46 class offset_device : string -> int64 -> int64 -> int -> device ->
47   object
48     method name : string
49     method size : int64
50     method read : int64 -> int -> string
51     method read_bitstring : int64 -> int -> Bitmatch.bitstring
52     method blocksize : int
53     method mapblock : int64 -> (device * int64) list
54   end
55
56 val null_device : device
57
58 type machine = {
59   m_name : string;
60   m_disks : disk list;
61   m_lv_filesystems :
62     (lv * filesystem) list;
63 }
64
65 and disk = {
66   d_name : string;
67   d_dev : block_device;
68   d_content : disk_content;
69 }
70
71 and disk_content =
72     [ `Filesystem of filesystem
73     | `Partitions of partitions
74     | `PhysicalVolume of pv
75     | `Unknown
76     ]
77
78 and partitions = {
79   parts_plugin_id : parts_plugin_id;
80   parts : partition list;
81 }
82 and partition = {
83   part_status : partition_status;
84   part_type : int;
85   part_dev : device;
86   part_content : partition_content;
87 }
88
89 and partition_status = Bootable | Nonbootable | Malformed | NullEntry
90 and partition_content =
91     [ `Filesystem of filesystem
92     | `PhysicalVolume of pv
93     | `Unknown
94     ]
95
96 and filesystem = {
97   fs_plugin_id : fs_plugin_id;
98   fs_block_size : int64;
99   fs_blocks_total : int64;
100   fs_is_swap : bool;
101   fs_blocks_reserved : int64;
102   fs_blocks_avail : int64;
103   fs_blocks_used : int64;
104   fs_inodes_total : int64;
105   fs_inodes_reserved : int64;
106   fs_inodes_avail : int64;
107   fs_inodes_used : int64;
108 }
109
110 and pv = {
111   lvm_plugin_id : lvm_plugin_id;
112   pv_uuid : string;
113 }
114 and lv = {
115   lv_dev : device;
116 }
117
118 and parts_plugin_id = string
119 and fs_plugin_id = string
120 and lvm_plugin_id = string
121
122 (** {2 Internal functions used by the plug-ins} *)
123
124 val canonical_uuid : string -> string
125   (** Convert a UUID which may contain '-' characters to canonical form. *)
126
127 val group_by : ?cmp:('a -> 'a -> int) -> ('a * 'b) list -> ('a * 'b list) list
128 (** Group a sorted list of pairs by the first element of the pair. *)
129
130 val range : int -> int -> int list
131 (** [range a b] returns the list of integers [a <= i < b].
132     If [a >= b] then the empty list is returned.
133 *)
134
135 val ( +* ) : int32 -> int32 -> int32
136 val ( -* ) : int32 -> int32 -> int32
137 val ( ** ) : int32 -> int32 -> int32
138 val ( /* ) : int32 -> int32 -> int32
139
140 val ( +^ ) : int64 -> int64 -> int64
141 val ( -^ ) : int64 -> int64 -> int64
142 val ( *^ ) : int64 -> int64 -> int64
143 val ( /^ ) : int64 -> int64 -> int64
144 (** int32 and int64 infix operators for convenience. *)