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