generator: Don't use real uuidgen for UUIDs.
[libguestfs.git] / generator / generator_structs.ml
1 (* libguestfs
2  * Copyright (C) 2009-2010 Red Hat Inc.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  *)
18
19 (* Please read generator/README first. *)
20
21 open Generator_types
22 open Generator_utils
23
24 type cols = (string * field) list
25
26 (* Because we generate extra parsing code for LVM command line tools,
27  * we have to pull out the LVM columns separately here.
28  *)
29 let lvm_pv_cols = [
30   "pv_name", FString;
31   "pv_uuid", FUUID;
32   "pv_fmt", FString;
33   "pv_size", FBytes;
34   "dev_size", FBytes;
35   "pv_free", FBytes;
36   "pv_used", FBytes;
37   "pv_attr", FString (* XXX *);
38   "pv_pe_count", FInt64;
39   "pv_pe_alloc_count", FInt64;
40   "pv_tags", FString;
41   "pe_start", FBytes;
42   "pv_mda_count", FInt64;
43   "pv_mda_free", FBytes;
44   (* Not in Fedora 10:
45      "pv_mda_size", FBytes;
46   *)
47 ]
48 let lvm_vg_cols = [
49   "vg_name", FString;
50   "vg_uuid", FUUID;
51   "vg_fmt", FString;
52   "vg_attr", FString (* XXX *);
53   "vg_size", FBytes;
54   "vg_free", FBytes;
55   "vg_sysid", FString;
56   "vg_extent_size", FBytes;
57   "vg_extent_count", FInt64;
58   "vg_free_count", FInt64;
59   "max_lv", FInt64;
60   "max_pv", FInt64;
61   "pv_count", FInt64;
62   "lv_count", FInt64;
63   "snap_count", FInt64;
64   "vg_seqno", FInt64;
65   "vg_tags", FString;
66   "vg_mda_count", FInt64;
67   "vg_mda_free", FBytes;
68   (* Not in Fedora 10:
69      "vg_mda_size", FBytes;
70   *)
71 ]
72 let lvm_lv_cols = [
73   "lv_name", FString;
74   "lv_uuid", FUUID;
75   "lv_attr", FString (* XXX *);
76   "lv_major", FInt64;
77   "lv_minor", FInt64;
78   "lv_kernel_major", FInt64;
79   "lv_kernel_minor", FInt64;
80   "lv_size", FBytes;
81   "seg_count", FInt64;
82   "origin", FString;
83   "snap_percent", FOptPercent;
84   "copy_percent", FOptPercent;
85   "move_pv", FString;
86   "lv_tags", FString;
87   "mirror_log", FString;
88   "modules", FString;
89 ]
90
91 (* Names and fields in all structures (in RStruct and RStructList)
92  * that we support.
93  *)
94 let structs = [
95   (* The old RIntBool return type, only ever used for aug_defnode.  Do
96    * not use this struct in any new code.
97    *)
98   "int_bool", [
99     "i", FInt32;                (* for historical compatibility *)
100     "b", FInt32;                (* for historical compatibility *)
101   ];
102
103   (* LVM PVs, VGs, LVs. *)
104   "lvm_pv", lvm_pv_cols;
105   "lvm_vg", lvm_vg_cols;
106   "lvm_lv", lvm_lv_cols;
107
108   (* Column names and types from stat structures.
109    * NB. Can't use things like 'st_atime' because glibc header files
110    * define some of these as macros.  Ugh.
111    *)
112   "stat", [
113     "dev", FInt64;
114     "ino", FInt64;
115     "mode", FInt64;
116     "nlink", FInt64;
117     "uid", FInt64;
118     "gid", FInt64;
119     "rdev", FInt64;
120     "size", FInt64;
121     "blksize", FInt64;
122     "blocks", FInt64;
123     "atime", FInt64;
124     "mtime", FInt64;
125     "ctime", FInt64;
126   ];
127   "statvfs", [
128     "bsize", FInt64;
129     "frsize", FInt64;
130     "blocks", FInt64;
131     "bfree", FInt64;
132     "bavail", FInt64;
133     "files", FInt64;
134     "ffree", FInt64;
135     "favail", FInt64;
136     "fsid", FInt64;
137     "flag", FInt64;
138     "namemax", FInt64;
139   ];
140
141   (* Column names in dirent structure. *)
142   "dirent", [
143     "ino", FInt64;
144     (* 'b' 'c' 'd' 'f' (FIFO) 'l' 'r' (regular file) 's' 'u' '?' *)
145     "ftyp", FChar;
146     "name", FString;
147   ];
148
149   (* Version numbers. *)
150   "version", [
151     "major", FInt64;
152     "minor", FInt64;
153     "release", FInt64;
154     "extra", FString;
155   ];
156
157   (* Extended attribute. *)
158   "xattr", [
159     "attrname", FString;
160     "attrval", FBuffer;
161   ];
162
163   (* Inotify events. *)
164   "inotify_event", [
165     "in_wd", FInt64;
166     "in_mask", FUInt32;
167     "in_cookie", FUInt32;
168     "in_name", FString;
169   ];
170
171   (* Partition table entry. *)
172   "partition", [
173     "part_num", FInt32;
174     "part_start", FBytes;
175     "part_end", FBytes;
176     "part_size", FBytes;
177   ];
178 ] (* end of structs *)
179
180 (* Ugh, Java has to be different ..
181  * These names are also used by the Haskell bindings.
182  *)
183 let java_structs = [
184   "int_bool", "IntBool";
185   "lvm_pv", "PV";
186   "lvm_vg", "VG";
187   "lvm_lv", "LV";
188   "stat", "Stat";
189   "statvfs", "StatVFS";
190   "dirent", "Dirent";
191   "version", "Version";
192   "xattr", "XAttr";
193   "inotify_event", "INotifyEvent";
194   "partition", "Partition";
195 ]
196
197 let java_name_of_struct typ =
198   try List.assoc typ java_structs
199   with Not_found ->
200     failwithf
201       "java_name_of_struct: no java_structs entry corresponding to %s" typ
202
203 let cols_of_struct typ =
204   try List.assoc typ structs
205   with Not_found ->
206     failwithf "cols_of_struct: unknown struct %s" typ