summaryrefslogtreecommitdiffstats
path: root/generator/structs.ml
blob: d62fcc5d57cdb76fa9038c17c25daa44ecc4daef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
(* libguestfs
 * Copyright (C) 2009-2012 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *)

(* Please read generator/README first. *)

open Types
open Utils

type cols = (string * field) list

(* Because we generate extra parsing code for LVM command line tools,
 * we have to pull out the LVM columns separately here.
 *)
let lvm_pv_cols = [
  "pv_name", FString;
  "pv_uuid", FUUID;
  "pv_fmt", FString;
  "pv_size", FBytes;
  "dev_size", FBytes;
  "pv_free", FBytes;
  "pv_used", FBytes;
  "pv_attr", FString (* XXX *);
  "pv_pe_count", FInt64;
  "pv_pe_alloc_count", FInt64;
  "pv_tags", FString;
  "pe_start", FBytes;
  "pv_mda_count", FInt64;
  "pv_mda_free", FBytes;
  (* Not in Fedora 10:
     "pv_mda_size", FBytes;
  *)
]
let lvm_vg_cols = [
  "vg_name", FString;
  "vg_uuid", FUUID;
  "vg_fmt", FString;
  "vg_attr", FString (* XXX *);
  "vg_size", FBytes;
  "vg_free", FBytes;
  "vg_sysid", FString;
  "vg_extent_size", FBytes;
  "vg_extent_count", FInt64;
  "vg_free_count", FInt64;
  "max_lv", FInt64;
  "max_pv", FInt64;
  "pv_count", FInt64;
  "lv_count", FInt64;
  "snap_count", FInt64;
  "vg_seqno", FInt64;
  "vg_tags", FString;
  "vg_mda_count", FInt64;
  "vg_mda_free", FBytes;
  (* Not in Fedora 10:
     "vg_mda_size", FBytes;
  *)
]
let lvm_lv_cols = [
  "lv_name", FString;
  "lv_uuid", FUUID;
  "lv_attr", FString (* XXX *);
  "lv_major", FInt64;
  "lv_minor", FInt64;
  "lv_kernel_major", FInt64;
  "lv_kernel_minor", FInt64;
  "lv_size", FBytes;
  "seg_count", FInt64;
  "origin", FString;
  "snap_percent", FOptPercent;
  "copy_percent", FOptPercent;
  "move_pv", FString;
  "lv_tags", FString;
  "mirror_log", FString;
  "modules", FString;
]

(* Names and fields in all structures (in RStruct and RStructList)
 * that we support.
 *)
let structs = [
  (* The old RIntBool return type, only ever used for aug_defnode.  Do
   * not use this struct in any new code.
   *)
  "int_bool", [
    "i", FInt32;		(* for historical compatibility *)
    "b", FInt32;		(* for historical compatibility *)
  ];

  (* LVM PVs, VGs, LVs. *)
  "lvm_pv", lvm_pv_cols;
  "lvm_vg", lvm_vg_cols;
  "lvm_lv", lvm_lv_cols;

  (* Column names and types from stat structures.
   * NB. Can't use things like 'st_atime' because glibc header files
   * define some of these as macros.  Ugh.
   *)
  "stat", [
    "dev", FInt64;
    "ino", FInt64;
    "mode", FInt64;
    "nlink", FInt64;
    "uid", FInt64;
    "gid", FInt64;
    "rdev", FInt64;
    "size", FInt64;
    "blksize", FInt64;
    "blocks", FInt64;
    "atime", FInt64;
    "mtime", FInt64;
    "ctime", FInt64;
  ];
  "statvfs", [
    "bsize", FInt64;
    "frsize", FInt64;
    "blocks", FInt64;
    "bfree", FInt64;
    "bavail", FInt64;
    "files", FInt64;
    "ffree", FInt64;
    "favail", FInt64;
    "fsid", FInt64;
    "flag", FInt64;
    "namemax", FInt64;
  ];

  (* Column names in dirent structure. *)
  "dirent", [
    "ino", FInt64;
    (* 'b' 'c' 'd' 'f' (FIFO) 'l' 'r' (regular file) 's' 'u' '?' *)
    "ftyp", FChar;
    "name", FString;
  ];

  (* Version numbers. *)
  "version", [
    "major", FInt64;
    "minor", FInt64;
    "release", FInt64;
    "extra", FString;
  ];

  (* Extended attribute. *)
  "xattr", [
    "attrname", FString;
    "attrval", FBuffer;
  ];

  (* Inotify events. *)
  "inotify_event", [
    "in_wd", FInt64;
    "in_mask", FUInt32;
    "in_cookie", FUInt32;
    "in_name", FString;
  ];

  (* Partition table entry. *)
  "partition", [
    "part_num", FInt32;
    "part_start", FBytes;
    "part_end", FBytes;
    "part_size", FBytes;
  ];

  (* Application. *)
  "application", [
    "app_name", FString;
    "app_display_name", FString;
    "app_epoch", FInt32;
    "app_version", FString;
    "app_release", FString;
    "app_install_path", FString;
    "app_trans_path", FString;
    "app_publisher", FString;
    "app_url", FString;
    "app_source_package", FString;
    "app_summary", FString;
    "app_description", FString;
  ];

  (* ISO primary volume descriptor. *)
  "isoinfo", [
    "iso_system_id", FString;
    "iso_volume_id", FString;
    "iso_volume_space_size", FUInt32;
    "iso_volume_set_size", FUInt32;
    "iso_volume_sequence_number", FUInt32;
    "iso_logical_block_size", FUInt32;
    "iso_volume_set_id", FString;
    "iso_publisher_id", FString;
    "iso_data_preparer_id", FString;
    "iso_application_id", FString;
    "iso_copyright_file_id", FString;
    "iso_abstract_file_id", FString;
    "iso_bibliographic_file_id", FString;
    "iso_volume_creation_t", FInt64;
    "iso_volume_modification_t", FInt64;
    "iso_volume_expiration_t", FInt64;
    "iso_volume_effective_t", FInt64;
  ];

  (* /proc/mdstat information.  See linux.git/drivers/md/md.c *)
  "mdstat", [
    "mdstat_device", FString;
    "mdstat_index", FInt32;
    "mdstat_flags", FString;
  ];

  (* btrfs subvolume list output *)
  "btrfssubvolume", [
    "btrfssubvolume_id", FUInt64;
    "btrfssubvolume_top_level_id", FUInt64;
    "btrfssubvolume_path", FString;
  ];

  (* XFS info descriptor. *)
  "xfsinfo", [
    "xfs_mntpoint", FString;
    "xfs_inodesize", FUInt32;
    "xfs_agcount", FUInt32;
    "xfs_agsize", FUInt32;
    "xfs_sectsize", FUInt32;
    "xfs_attr", FUInt32;
    "xfs_blocksize", FUInt32;
    "xfs_datablocks", FUInt64;
    "xfs_imaxpct", FUInt32;
    "xfs_sunit", FUInt32;
    "xfs_swidth", FUInt32;
    "xfs_dirversion", FUInt32;
    "xfs_dirblocksize", FUInt32;
    "xfs_cimode", FUInt32;
    "xfs_logname", FString;
    "xfs_logblocksize", FUInt32;
    "xfs_logblocks", FUInt32;
    "xfs_logversion", FUInt32;
    "xfs_logsectsize", FUInt32;
    "xfs_logsunit", FUInt32;
    "xfs_lazycount", FUInt32;
    "xfs_rtname", FString;
    "xfs_rtextsize", FUInt32;
    "xfs_rtblocks", FUInt64;
    "xfs_rtextents", FUInt64;
  ];

  (* utsname *)
  "utsname", [
    "uts_sysname", FString;
    "uts_release", FString;
    "uts_version", FString;
    "uts_machine", FString;
  ];

  (* Used by hivex_* APIs to return a list of int64 handles (node
   * handles and value handles).  Note that we can't add a putative
   * 'RInt64List' type to the generator because we need to return
   * length and size, and RStructList does this already.
   *)
  "hivex_node", [
    "hivex_node_h", FInt64;
  ];
  "hivex_value", [
    "hivex_value_h", FInt64;
  ];
] (* end of structs *)

(* For bindings which want camel case *)
let camel_structs = [
  "int_bool", "IntBool";
  "lvm_pv", "PV";
  "lvm_vg", "VG";
  "lvm_lv", "LV";
  "stat", "Stat";
  "statvfs", "StatVFS";
  "dirent", "Dirent";
  "version", "Version";
  "xattr", "XAttr";
  "inotify_event", "INotifyEvent";
  "partition", "Partition";
  "application", "Application";
  "isoinfo", "ISOInfo";
  "xfsinfo", "XFSInfo";
  "mdstat", "MDStat";
  "btrfssubvolume", "BTRFSSubvolume";
  "utsname", "UTSName";
  "hivex_node", "HivexNode";
  "hivex_value", "HivexValue";
]
let camel_structs = List.sort (fun (_,a) (_,b) -> compare a b) camel_structs

let camel_name_of_struct typ =
  try List.assoc typ camel_structs
  with Not_found ->
    failwithf
      "camel_name_of_struct: no camel_structs entry corresponding to %s" typ

let cols_of_struct typ =
  try List.assoc typ structs
  with Not_found ->
    failwithf "cols_of_struct: unknown struct %s" typ