Correctly free memory in RHashtable binding for OCaml & Python.
[libguestfs.git] / ocaml / guestfs_c_actions.c
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <caml/config.h>
27 #include <caml/alloc.h>
28 #include <caml/callback.h>
29 #include <caml/fail.h>
30 #include <caml/memory.h>
31 #include <caml/mlvalues.h>
32 #include <caml/signals.h>
33
34 #include <guestfs.h>
35
36 #include "guestfs_c.h"
37
38 /* Copy a hashtable of string pairs into an assoc-list.  We return
39  * the list in reverse order, but hashtables aren't supposed to be
40  * ordered anyway.
41  */
42 static CAMLprim value
43 copy_table (char * const * argv)
44 {
45   CAMLparam0 ();
46   CAMLlocal5 (rv, pairv, kv, vv, cons);
47   int i;
48
49   rv = Val_int (0);
50   for (i = 0; argv[i] != NULL; i += 2) {
51     kv = caml_copy_string (argv[i]);
52     vv = caml_copy_string (argv[i+1]);
53     pairv = caml_alloc (2, 0);
54     Store_field (pairv, 0, kv);
55     Store_field (pairv, 1, vv);
56     cons = caml_alloc (2, 0);
57     Store_field (cons, 1, rv);
58     rv = cons;
59     Store_field (cons, 0, pairv);
60   }
61
62   CAMLreturn (rv);
63 }
64
65 static CAMLprim value
66 copy_lvm_pv (const struct guestfs_lvm_pv *pv)
67 {
68   CAMLparam0 ();
69   CAMLlocal2 (rv, v);
70
71   rv = caml_alloc (14, 0);
72   v = caml_copy_string (pv->pv_name);
73   Store_field (rv, 0, v);
74   v = caml_alloc_string (32);
75   memcpy (String_val (v), pv->pv_uuid, 32);
76   Store_field (rv, 1, v);
77   v = caml_copy_string (pv->pv_fmt);
78   Store_field (rv, 2, v);
79   v = caml_copy_int64 (pv->pv_size);
80   Store_field (rv, 3, v);
81   v = caml_copy_int64 (pv->dev_size);
82   Store_field (rv, 4, v);
83   v = caml_copy_int64 (pv->pv_free);
84   Store_field (rv, 5, v);
85   v = caml_copy_int64 (pv->pv_used);
86   Store_field (rv, 6, v);
87   v = caml_copy_string (pv->pv_attr);
88   Store_field (rv, 7, v);
89   v = caml_copy_int64 (pv->pv_pe_count);
90   Store_field (rv, 8, v);
91   v = caml_copy_int64 (pv->pv_pe_alloc_count);
92   Store_field (rv, 9, v);
93   v = caml_copy_string (pv->pv_tags);
94   Store_field (rv, 10, v);
95   v = caml_copy_int64 (pv->pe_start);
96   Store_field (rv, 11, v);
97   v = caml_copy_int64 (pv->pv_mda_count);
98   Store_field (rv, 12, v);
99   v = caml_copy_int64 (pv->pv_mda_free);
100   Store_field (rv, 13, v);
101   CAMLreturn (rv);
102 }
103
104 static CAMLprim value
105 copy_lvm_pv_list (const struct guestfs_lvm_pv_list *pvs)
106 {
107   CAMLparam0 ();
108   CAMLlocal2 (rv, v);
109   int i;
110
111   if (pvs->len == 0)
112     CAMLreturn (Atom (0));
113   else {
114     rv = caml_alloc (pvs->len, 0);
115     for (i = 0; i < pvs->len; ++i) {
116       v = copy_lvm_pv (&pvs->val[i]);
117       caml_modify (&Field (rv, i), v);
118     }
119     CAMLreturn (rv);
120   }
121 }
122
123 static CAMLprim value
124 copy_lvm_vg (const struct guestfs_lvm_vg *vg)
125 {
126   CAMLparam0 ();
127   CAMLlocal2 (rv, v);
128
129   rv = caml_alloc (19, 0);
130   v = caml_copy_string (vg->vg_name);
131   Store_field (rv, 0, v);
132   v = caml_alloc_string (32);
133   memcpy (String_val (v), vg->vg_uuid, 32);
134   Store_field (rv, 1, v);
135   v = caml_copy_string (vg->vg_fmt);
136   Store_field (rv, 2, v);
137   v = caml_copy_string (vg->vg_attr);
138   Store_field (rv, 3, v);
139   v = caml_copy_int64 (vg->vg_size);
140   Store_field (rv, 4, v);
141   v = caml_copy_int64 (vg->vg_free);
142   Store_field (rv, 5, v);
143   v = caml_copy_string (vg->vg_sysid);
144   Store_field (rv, 6, v);
145   v = caml_copy_int64 (vg->vg_extent_size);
146   Store_field (rv, 7, v);
147   v = caml_copy_int64 (vg->vg_extent_count);
148   Store_field (rv, 8, v);
149   v = caml_copy_int64 (vg->vg_free_count);
150   Store_field (rv, 9, v);
151   v = caml_copy_int64 (vg->max_lv);
152   Store_field (rv, 10, v);
153   v = caml_copy_int64 (vg->max_pv);
154   Store_field (rv, 11, v);
155   v = caml_copy_int64 (vg->pv_count);
156   Store_field (rv, 12, v);
157   v = caml_copy_int64 (vg->lv_count);
158   Store_field (rv, 13, v);
159   v = caml_copy_int64 (vg->snap_count);
160   Store_field (rv, 14, v);
161   v = caml_copy_int64 (vg->vg_seqno);
162   Store_field (rv, 15, v);
163   v = caml_copy_string (vg->vg_tags);
164   Store_field (rv, 16, v);
165   v = caml_copy_int64 (vg->vg_mda_count);
166   Store_field (rv, 17, v);
167   v = caml_copy_int64 (vg->vg_mda_free);
168   Store_field (rv, 18, v);
169   CAMLreturn (rv);
170 }
171
172 static CAMLprim value
173 copy_lvm_vg_list (const struct guestfs_lvm_vg_list *vgs)
174 {
175   CAMLparam0 ();
176   CAMLlocal2 (rv, v);
177   int i;
178
179   if (vgs->len == 0)
180     CAMLreturn (Atom (0));
181   else {
182     rv = caml_alloc (vgs->len, 0);
183     for (i = 0; i < vgs->len; ++i) {
184       v = copy_lvm_vg (&vgs->val[i]);
185       caml_modify (&Field (rv, i), v);
186     }
187     CAMLreturn (rv);
188   }
189 }
190
191 static CAMLprim value
192 copy_lvm_lv (const struct guestfs_lvm_lv *lv)
193 {
194   CAMLparam0 ();
195   CAMLlocal3 (rv, v, v2);
196
197   rv = caml_alloc (16, 0);
198   v = caml_copy_string (lv->lv_name);
199   Store_field (rv, 0, v);
200   v = caml_alloc_string (32);
201   memcpy (String_val (v), lv->lv_uuid, 32);
202   Store_field (rv, 1, v);
203   v = caml_copy_string (lv->lv_attr);
204   Store_field (rv, 2, v);
205   v = caml_copy_int64 (lv->lv_major);
206   Store_field (rv, 3, v);
207   v = caml_copy_int64 (lv->lv_minor);
208   Store_field (rv, 4, v);
209   v = caml_copy_int64 (lv->lv_kernel_major);
210   Store_field (rv, 5, v);
211   v = caml_copy_int64 (lv->lv_kernel_minor);
212   Store_field (rv, 6, v);
213   v = caml_copy_int64 (lv->lv_size);
214   Store_field (rv, 7, v);
215   v = caml_copy_int64 (lv->seg_count);
216   Store_field (rv, 8, v);
217   v = caml_copy_string (lv->origin);
218   Store_field (rv, 9, v);
219   if (lv->snap_percent >= 0) { /* Some snap_percent */
220     v2 = caml_copy_double (lv->snap_percent);
221     v = caml_alloc (1, 0);
222     Store_field (v, 0, v2);
223   } else /* None */
224     v = Val_int (0);
225   Store_field (rv, 10, v);
226   if (lv->copy_percent >= 0) { /* Some copy_percent */
227     v2 = caml_copy_double (lv->copy_percent);
228     v = caml_alloc (1, 0);
229     Store_field (v, 0, v2);
230   } else /* None */
231     v = Val_int (0);
232   Store_field (rv, 11, v);
233   v = caml_copy_string (lv->move_pv);
234   Store_field (rv, 12, v);
235   v = caml_copy_string (lv->lv_tags);
236   Store_field (rv, 13, v);
237   v = caml_copy_string (lv->mirror_log);
238   Store_field (rv, 14, v);
239   v = caml_copy_string (lv->modules);
240   Store_field (rv, 15, v);
241   CAMLreturn (rv);
242 }
243
244 static CAMLprim value
245 copy_lvm_lv_list (const struct guestfs_lvm_lv_list *lvs)
246 {
247   CAMLparam0 ();
248   CAMLlocal2 (rv, v);
249   int i;
250
251   if (lvs->len == 0)
252     CAMLreturn (Atom (0));
253   else {
254     rv = caml_alloc (lvs->len, 0);
255     for (i = 0; i < lvs->len; ++i) {
256       v = copy_lvm_lv (&lvs->val[i]);
257       caml_modify (&Field (rv, i), v);
258     }
259     CAMLreturn (rv);
260   }
261 }
262
263 static CAMLprim value
264 copy_stat (const struct guestfs_stat *stat)
265 {
266   CAMLparam0 ();
267   CAMLlocal2 (rv, v);
268
269   rv = caml_alloc (13, 0);
270   v = caml_copy_int64 (stat->dev);
271   Store_field (rv, 0, v);
272   v = caml_copy_int64 (stat->ino);
273   Store_field (rv, 1, v);
274   v = caml_copy_int64 (stat->mode);
275   Store_field (rv, 2, v);
276   v = caml_copy_int64 (stat->nlink);
277   Store_field (rv, 3, v);
278   v = caml_copy_int64 (stat->uid);
279   Store_field (rv, 4, v);
280   v = caml_copy_int64 (stat->gid);
281   Store_field (rv, 5, v);
282   v = caml_copy_int64 (stat->rdev);
283   Store_field (rv, 6, v);
284   v = caml_copy_int64 (stat->size);
285   Store_field (rv, 7, v);
286   v = caml_copy_int64 (stat->blksize);
287   Store_field (rv, 8, v);
288   v = caml_copy_int64 (stat->blocks);
289   Store_field (rv, 9, v);
290   v = caml_copy_int64 (stat->atime);
291   Store_field (rv, 10, v);
292   v = caml_copy_int64 (stat->mtime);
293   Store_field (rv, 11, v);
294   v = caml_copy_int64 (stat->ctime);
295   Store_field (rv, 12, v);
296   CAMLreturn (rv);
297 }
298
299 static CAMLprim value
300 copy_statvfs (const struct guestfs_statvfs *statvfs)
301 {
302   CAMLparam0 ();
303   CAMLlocal2 (rv, v);
304
305   rv = caml_alloc (11, 0);
306   v = caml_copy_int64 (statvfs->bsize);
307   Store_field (rv, 0, v);
308   v = caml_copy_int64 (statvfs->frsize);
309   Store_field (rv, 1, v);
310   v = caml_copy_int64 (statvfs->blocks);
311   Store_field (rv, 2, v);
312   v = caml_copy_int64 (statvfs->bfree);
313   Store_field (rv, 3, v);
314   v = caml_copy_int64 (statvfs->bavail);
315   Store_field (rv, 4, v);
316   v = caml_copy_int64 (statvfs->files);
317   Store_field (rv, 5, v);
318   v = caml_copy_int64 (statvfs->ffree);
319   Store_field (rv, 6, v);
320   v = caml_copy_int64 (statvfs->favail);
321   Store_field (rv, 7, v);
322   v = caml_copy_int64 (statvfs->fsid);
323   Store_field (rv, 8, v);
324   v = caml_copy_int64 (statvfs->flag);
325   Store_field (rv, 9, v);
326   v = caml_copy_int64 (statvfs->namemax);
327   Store_field (rv, 10, v);
328   CAMLreturn (rv);
329 }
330
331 CAMLprim value
332 ocaml_guestfs_launch (value gv)
333 {
334   CAMLparam1 (gv);
335   CAMLlocal1 (rv);
336
337   guestfs_h *g = Guestfs_val (gv);
338   if (g == NULL)
339     caml_failwith ("launch: used handle after closing it");
340
341   int r;
342
343   caml_enter_blocking_section ();
344   r = guestfs_launch (g);
345   caml_leave_blocking_section ();
346   if (r == -1)
347     ocaml_guestfs_raise_error (g, "launch");
348
349   rv = Val_unit;
350   CAMLreturn (rv);
351 }
352
353 CAMLprim value
354 ocaml_guestfs_wait_ready (value gv)
355 {
356   CAMLparam1 (gv);
357   CAMLlocal1 (rv);
358
359   guestfs_h *g = Guestfs_val (gv);
360   if (g == NULL)
361     caml_failwith ("wait_ready: used handle after closing it");
362
363   int r;
364
365   caml_enter_blocking_section ();
366   r = guestfs_wait_ready (g);
367   caml_leave_blocking_section ();
368   if (r == -1)
369     ocaml_guestfs_raise_error (g, "wait_ready");
370
371   rv = Val_unit;
372   CAMLreturn (rv);
373 }
374
375 CAMLprim value
376 ocaml_guestfs_kill_subprocess (value gv)
377 {
378   CAMLparam1 (gv);
379   CAMLlocal1 (rv);
380
381   guestfs_h *g = Guestfs_val (gv);
382   if (g == NULL)
383     caml_failwith ("kill_subprocess: used handle after closing it");
384
385   int r;
386
387   caml_enter_blocking_section ();
388   r = guestfs_kill_subprocess (g);
389   caml_leave_blocking_section ();
390   if (r == -1)
391     ocaml_guestfs_raise_error (g, "kill_subprocess");
392
393   rv = Val_unit;
394   CAMLreturn (rv);
395 }
396
397 CAMLprim value
398 ocaml_guestfs_add_drive (value gv, value filenamev)
399 {
400   CAMLparam2 (gv, filenamev);
401   CAMLlocal1 (rv);
402
403   guestfs_h *g = Guestfs_val (gv);
404   if (g == NULL)
405     caml_failwith ("add_drive: used handle after closing it");
406
407   const char *filename = String_val (filenamev);
408   int r;
409
410   caml_enter_blocking_section ();
411   r = guestfs_add_drive (g, filename);
412   caml_leave_blocking_section ();
413   if (r == -1)
414     ocaml_guestfs_raise_error (g, "add_drive");
415
416   rv = Val_unit;
417   CAMLreturn (rv);
418 }
419
420 CAMLprim value
421 ocaml_guestfs_add_cdrom (value gv, value filenamev)
422 {
423   CAMLparam2 (gv, filenamev);
424   CAMLlocal1 (rv);
425
426   guestfs_h *g = Guestfs_val (gv);
427   if (g == NULL)
428     caml_failwith ("add_cdrom: used handle after closing it");
429
430   const char *filename = String_val (filenamev);
431   int r;
432
433   caml_enter_blocking_section ();
434   r = guestfs_add_cdrom (g, filename);
435   caml_leave_blocking_section ();
436   if (r == -1)
437     ocaml_guestfs_raise_error (g, "add_cdrom");
438
439   rv = Val_unit;
440   CAMLreturn (rv);
441 }
442
443 CAMLprim value
444 ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
445 {
446   CAMLparam3 (gv, qemuparamv, qemuvaluev);
447   CAMLlocal1 (rv);
448
449   guestfs_h *g = Guestfs_val (gv);
450   if (g == NULL)
451     caml_failwith ("config: used handle after closing it");
452
453   const char *qemuparam = String_val (qemuparamv);
454   const char *qemuvalue =
455     qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
456   int r;
457
458   caml_enter_blocking_section ();
459   r = guestfs_config (g, qemuparam, qemuvalue);
460   caml_leave_blocking_section ();
461   if (r == -1)
462     ocaml_guestfs_raise_error (g, "config");
463
464   rv = Val_unit;
465   CAMLreturn (rv);
466 }
467
468 CAMLprim value
469 ocaml_guestfs_set_path (value gv, value pathv)
470 {
471   CAMLparam2 (gv, pathv);
472   CAMLlocal1 (rv);
473
474   guestfs_h *g = Guestfs_val (gv);
475   if (g == NULL)
476     caml_failwith ("set_path: used handle after closing it");
477
478   const char *path = String_val (pathv);
479   int r;
480
481   caml_enter_blocking_section ();
482   r = guestfs_set_path (g, path);
483   caml_leave_blocking_section ();
484   if (r == -1)
485     ocaml_guestfs_raise_error (g, "set_path");
486
487   rv = Val_unit;
488   CAMLreturn (rv);
489 }
490
491 CAMLprim value
492 ocaml_guestfs_get_path (value gv)
493 {
494   CAMLparam1 (gv);
495   CAMLlocal1 (rv);
496
497   guestfs_h *g = Guestfs_val (gv);
498   if (g == NULL)
499     caml_failwith ("get_path: used handle after closing it");
500
501   const char *r;
502
503   caml_enter_blocking_section ();
504   r = guestfs_get_path (g);
505   caml_leave_blocking_section ();
506   if (r == NULL)
507     ocaml_guestfs_raise_error (g, "get_path");
508
509   rv = caml_copy_string (r);
510   CAMLreturn (rv);
511 }
512
513 CAMLprim value
514 ocaml_guestfs_set_autosync (value gv, value autosyncv)
515 {
516   CAMLparam2 (gv, autosyncv);
517   CAMLlocal1 (rv);
518
519   guestfs_h *g = Guestfs_val (gv);
520   if (g == NULL)
521     caml_failwith ("set_autosync: used handle after closing it");
522
523   int autosync = Bool_val (autosyncv);
524   int r;
525
526   caml_enter_blocking_section ();
527   r = guestfs_set_autosync (g, autosync);
528   caml_leave_blocking_section ();
529   if (r == -1)
530     ocaml_guestfs_raise_error (g, "set_autosync");
531
532   rv = Val_unit;
533   CAMLreturn (rv);
534 }
535
536 CAMLprim value
537 ocaml_guestfs_get_autosync (value gv)
538 {
539   CAMLparam1 (gv);
540   CAMLlocal1 (rv);
541
542   guestfs_h *g = Guestfs_val (gv);
543   if (g == NULL)
544     caml_failwith ("get_autosync: used handle after closing it");
545
546   int r;
547
548   caml_enter_blocking_section ();
549   r = guestfs_get_autosync (g);
550   caml_leave_blocking_section ();
551   if (r == -1)
552     ocaml_guestfs_raise_error (g, "get_autosync");
553
554   rv = Val_bool (r);
555   CAMLreturn (rv);
556 }
557
558 CAMLprim value
559 ocaml_guestfs_set_verbose (value gv, value verbosev)
560 {
561   CAMLparam2 (gv, verbosev);
562   CAMLlocal1 (rv);
563
564   guestfs_h *g = Guestfs_val (gv);
565   if (g == NULL)
566     caml_failwith ("set_verbose: used handle after closing it");
567
568   int verbose = Bool_val (verbosev);
569   int r;
570
571   caml_enter_blocking_section ();
572   r = guestfs_set_verbose (g, verbose);
573   caml_leave_blocking_section ();
574   if (r == -1)
575     ocaml_guestfs_raise_error (g, "set_verbose");
576
577   rv = Val_unit;
578   CAMLreturn (rv);
579 }
580
581 CAMLprim value
582 ocaml_guestfs_get_verbose (value gv)
583 {
584   CAMLparam1 (gv);
585   CAMLlocal1 (rv);
586
587   guestfs_h *g = Guestfs_val (gv);
588   if (g == NULL)
589     caml_failwith ("get_verbose: used handle after closing it");
590
591   int r;
592
593   caml_enter_blocking_section ();
594   r = guestfs_get_verbose (g);
595   caml_leave_blocking_section ();
596   if (r == -1)
597     ocaml_guestfs_raise_error (g, "get_verbose");
598
599   rv = Val_bool (r);
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
605 {
606   CAMLparam3 (gv, devicev, mountpointv);
607   CAMLlocal1 (rv);
608
609   guestfs_h *g = Guestfs_val (gv);
610   if (g == NULL)
611     caml_failwith ("mount: used handle after closing it");
612
613   const char *device = String_val (devicev);
614   const char *mountpoint = String_val (mountpointv);
615   int r;
616
617   caml_enter_blocking_section ();
618   r = guestfs_mount (g, device, mountpoint);
619   caml_leave_blocking_section ();
620   if (r == -1)
621     ocaml_guestfs_raise_error (g, "mount");
622
623   rv = Val_unit;
624   CAMLreturn (rv);
625 }
626
627 CAMLprim value
628 ocaml_guestfs_sync (value gv)
629 {
630   CAMLparam1 (gv);
631   CAMLlocal1 (rv);
632
633   guestfs_h *g = Guestfs_val (gv);
634   if (g == NULL)
635     caml_failwith ("sync: used handle after closing it");
636
637   int r;
638
639   caml_enter_blocking_section ();
640   r = guestfs_sync (g);
641   caml_leave_blocking_section ();
642   if (r == -1)
643     ocaml_guestfs_raise_error (g, "sync");
644
645   rv = Val_unit;
646   CAMLreturn (rv);
647 }
648
649 CAMLprim value
650 ocaml_guestfs_touch (value gv, value pathv)
651 {
652   CAMLparam2 (gv, pathv);
653   CAMLlocal1 (rv);
654
655   guestfs_h *g = Guestfs_val (gv);
656   if (g == NULL)
657     caml_failwith ("touch: used handle after closing it");
658
659   const char *path = String_val (pathv);
660   int r;
661
662   caml_enter_blocking_section ();
663   r = guestfs_touch (g, path);
664   caml_leave_blocking_section ();
665   if (r == -1)
666     ocaml_guestfs_raise_error (g, "touch");
667
668   rv = Val_unit;
669   CAMLreturn (rv);
670 }
671
672 CAMLprim value
673 ocaml_guestfs_cat (value gv, value pathv)
674 {
675   CAMLparam2 (gv, pathv);
676   CAMLlocal1 (rv);
677
678   guestfs_h *g = Guestfs_val (gv);
679   if (g == NULL)
680     caml_failwith ("cat: used handle after closing it");
681
682   const char *path = String_val (pathv);
683   char *r;
684
685   caml_enter_blocking_section ();
686   r = guestfs_cat (g, path);
687   caml_leave_blocking_section ();
688   if (r == NULL)
689     ocaml_guestfs_raise_error (g, "cat");
690
691   rv = caml_copy_string (r);
692   free (r);
693   CAMLreturn (rv);
694 }
695
696 CAMLprim value
697 ocaml_guestfs_ll (value gv, value directoryv)
698 {
699   CAMLparam2 (gv, directoryv);
700   CAMLlocal1 (rv);
701
702   guestfs_h *g = Guestfs_val (gv);
703   if (g == NULL)
704     caml_failwith ("ll: used handle after closing it");
705
706   const char *directory = String_val (directoryv);
707   char *r;
708
709   caml_enter_blocking_section ();
710   r = guestfs_ll (g, directory);
711   caml_leave_blocking_section ();
712   if (r == NULL)
713     ocaml_guestfs_raise_error (g, "ll");
714
715   rv = caml_copy_string (r);
716   free (r);
717   CAMLreturn (rv);
718 }
719
720 CAMLprim value
721 ocaml_guestfs_ls (value gv, value directoryv)
722 {
723   CAMLparam2 (gv, directoryv);
724   CAMLlocal1 (rv);
725
726   guestfs_h *g = Guestfs_val (gv);
727   if (g == NULL)
728     caml_failwith ("ls: used handle after closing it");
729
730   const char *directory = String_val (directoryv);
731   int i;
732   char **r;
733
734   caml_enter_blocking_section ();
735   r = guestfs_ls (g, directory);
736   caml_leave_blocking_section ();
737   if (r == NULL)
738     ocaml_guestfs_raise_error (g, "ls");
739
740   rv = caml_copy_string_array ((const char **) r);
741   for (i = 0; r[i] != NULL; ++i) free (r[i]);
742   free (r);
743   CAMLreturn (rv);
744 }
745
746 CAMLprim value
747 ocaml_guestfs_list_devices (value gv)
748 {
749   CAMLparam1 (gv);
750   CAMLlocal1 (rv);
751
752   guestfs_h *g = Guestfs_val (gv);
753   if (g == NULL)
754     caml_failwith ("list_devices: used handle after closing it");
755
756   int i;
757   char **r;
758
759   caml_enter_blocking_section ();
760   r = guestfs_list_devices (g);
761   caml_leave_blocking_section ();
762   if (r == NULL)
763     ocaml_guestfs_raise_error (g, "list_devices");
764
765   rv = caml_copy_string_array ((const char **) r);
766   for (i = 0; r[i] != NULL; ++i) free (r[i]);
767   free (r);
768   CAMLreturn (rv);
769 }
770
771 CAMLprim value
772 ocaml_guestfs_list_partitions (value gv)
773 {
774   CAMLparam1 (gv);
775   CAMLlocal1 (rv);
776
777   guestfs_h *g = Guestfs_val (gv);
778   if (g == NULL)
779     caml_failwith ("list_partitions: used handle after closing it");
780
781   int i;
782   char **r;
783
784   caml_enter_blocking_section ();
785   r = guestfs_list_partitions (g);
786   caml_leave_blocking_section ();
787   if (r == NULL)
788     ocaml_guestfs_raise_error (g, "list_partitions");
789
790   rv = caml_copy_string_array ((const char **) r);
791   for (i = 0; r[i] != NULL; ++i) free (r[i]);
792   free (r);
793   CAMLreturn (rv);
794 }
795
796 CAMLprim value
797 ocaml_guestfs_pvs (value gv)
798 {
799   CAMLparam1 (gv);
800   CAMLlocal1 (rv);
801
802   guestfs_h *g = Guestfs_val (gv);
803   if (g == NULL)
804     caml_failwith ("pvs: used handle after closing it");
805
806   int i;
807   char **r;
808
809   caml_enter_blocking_section ();
810   r = guestfs_pvs (g);
811   caml_leave_blocking_section ();
812   if (r == NULL)
813     ocaml_guestfs_raise_error (g, "pvs");
814
815   rv = caml_copy_string_array ((const char **) r);
816   for (i = 0; r[i] != NULL; ++i) free (r[i]);
817   free (r);
818   CAMLreturn (rv);
819 }
820
821 CAMLprim value
822 ocaml_guestfs_vgs (value gv)
823 {
824   CAMLparam1 (gv);
825   CAMLlocal1 (rv);
826
827   guestfs_h *g = Guestfs_val (gv);
828   if (g == NULL)
829     caml_failwith ("vgs: used handle after closing it");
830
831   int i;
832   char **r;
833
834   caml_enter_blocking_section ();
835   r = guestfs_vgs (g);
836   caml_leave_blocking_section ();
837   if (r == NULL)
838     ocaml_guestfs_raise_error (g, "vgs");
839
840   rv = caml_copy_string_array ((const char **) r);
841   for (i = 0; r[i] != NULL; ++i) free (r[i]);
842   free (r);
843   CAMLreturn (rv);
844 }
845
846 CAMLprim value
847 ocaml_guestfs_lvs (value gv)
848 {
849   CAMLparam1 (gv);
850   CAMLlocal1 (rv);
851
852   guestfs_h *g = Guestfs_val (gv);
853   if (g == NULL)
854     caml_failwith ("lvs: used handle after closing it");
855
856   int i;
857   char **r;
858
859   caml_enter_blocking_section ();
860   r = guestfs_lvs (g);
861   caml_leave_blocking_section ();
862   if (r == NULL)
863     ocaml_guestfs_raise_error (g, "lvs");
864
865   rv = caml_copy_string_array ((const char **) r);
866   for (i = 0; r[i] != NULL; ++i) free (r[i]);
867   free (r);
868   CAMLreturn (rv);
869 }
870
871 CAMLprim value
872 ocaml_guestfs_pvs_full (value gv)
873 {
874   CAMLparam1 (gv);
875   CAMLlocal1 (rv);
876
877   guestfs_h *g = Guestfs_val (gv);
878   if (g == NULL)
879     caml_failwith ("pvs_full: used handle after closing it");
880
881   struct guestfs_lvm_pv_list *r;
882
883   caml_enter_blocking_section ();
884   r = guestfs_pvs_full (g);
885   caml_leave_blocking_section ();
886   if (r == NULL)
887     ocaml_guestfs_raise_error (g, "pvs_full");
888
889   rv = copy_lvm_pv_list (r);
890   guestfs_free_lvm_pv_list (r);
891   CAMLreturn (rv);
892 }
893
894 CAMLprim value
895 ocaml_guestfs_vgs_full (value gv)
896 {
897   CAMLparam1 (gv);
898   CAMLlocal1 (rv);
899
900   guestfs_h *g = Guestfs_val (gv);
901   if (g == NULL)
902     caml_failwith ("vgs_full: used handle after closing it");
903
904   struct guestfs_lvm_vg_list *r;
905
906   caml_enter_blocking_section ();
907   r = guestfs_vgs_full (g);
908   caml_leave_blocking_section ();
909   if (r == NULL)
910     ocaml_guestfs_raise_error (g, "vgs_full");
911
912   rv = copy_lvm_vg_list (r);
913   guestfs_free_lvm_vg_list (r);
914   CAMLreturn (rv);
915 }
916
917 CAMLprim value
918 ocaml_guestfs_lvs_full (value gv)
919 {
920   CAMLparam1 (gv);
921   CAMLlocal1 (rv);
922
923   guestfs_h *g = Guestfs_val (gv);
924   if (g == NULL)
925     caml_failwith ("lvs_full: used handle after closing it");
926
927   struct guestfs_lvm_lv_list *r;
928
929   caml_enter_blocking_section ();
930   r = guestfs_lvs_full (g);
931   caml_leave_blocking_section ();
932   if (r == NULL)
933     ocaml_guestfs_raise_error (g, "lvs_full");
934
935   rv = copy_lvm_lv_list (r);
936   guestfs_free_lvm_lv_list (r);
937   CAMLreturn (rv);
938 }
939
940 CAMLprim value
941 ocaml_guestfs_read_lines (value gv, value pathv)
942 {
943   CAMLparam2 (gv, pathv);
944   CAMLlocal1 (rv);
945
946   guestfs_h *g = Guestfs_val (gv);
947   if (g == NULL)
948     caml_failwith ("read_lines: used handle after closing it");
949
950   const char *path = String_val (pathv);
951   int i;
952   char **r;
953
954   caml_enter_blocking_section ();
955   r = guestfs_read_lines (g, path);
956   caml_leave_blocking_section ();
957   if (r == NULL)
958     ocaml_guestfs_raise_error (g, "read_lines");
959
960   rv = caml_copy_string_array ((const char **) r);
961   for (i = 0; r[i] != NULL; ++i) free (r[i]);
962   free (r);
963   CAMLreturn (rv);
964 }
965
966 CAMLprim value
967 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
968 {
969   CAMLparam3 (gv, rootv, flagsv);
970   CAMLlocal1 (rv);
971
972   guestfs_h *g = Guestfs_val (gv);
973   if (g == NULL)
974     caml_failwith ("aug_init: used handle after closing it");
975
976   const char *root = String_val (rootv);
977   int flags = Int_val (flagsv);
978   int r;
979
980   caml_enter_blocking_section ();
981   r = guestfs_aug_init (g, root, flags);
982   caml_leave_blocking_section ();
983   if (r == -1)
984     ocaml_guestfs_raise_error (g, "aug_init");
985
986   rv = Val_unit;
987   CAMLreturn (rv);
988 }
989
990 CAMLprim value
991 ocaml_guestfs_aug_close (value gv)
992 {
993   CAMLparam1 (gv);
994   CAMLlocal1 (rv);
995
996   guestfs_h *g = Guestfs_val (gv);
997   if (g == NULL)
998     caml_failwith ("aug_close: used handle after closing it");
999
1000   int r;
1001
1002   caml_enter_blocking_section ();
1003   r = guestfs_aug_close (g);
1004   caml_leave_blocking_section ();
1005   if (r == -1)
1006     ocaml_guestfs_raise_error (g, "aug_close");
1007
1008   rv = Val_unit;
1009   CAMLreturn (rv);
1010 }
1011
1012 CAMLprim value
1013 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
1014 {
1015   CAMLparam3 (gv, namev, exprv);
1016   CAMLlocal1 (rv);
1017
1018   guestfs_h *g = Guestfs_val (gv);
1019   if (g == NULL)
1020     caml_failwith ("aug_defvar: used handle after closing it");
1021
1022   const char *name = String_val (namev);
1023   const char *expr =
1024     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
1025   int r;
1026
1027   caml_enter_blocking_section ();
1028   r = guestfs_aug_defvar (g, name, expr);
1029   caml_leave_blocking_section ();
1030   if (r == -1)
1031     ocaml_guestfs_raise_error (g, "aug_defvar");
1032
1033   rv = Val_int (r);
1034   CAMLreturn (rv);
1035 }
1036
1037 CAMLprim value
1038 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1039 {
1040   CAMLparam4 (gv, namev, exprv, valv);
1041   CAMLlocal1 (rv);
1042
1043   guestfs_h *g = Guestfs_val (gv);
1044   if (g == NULL)
1045     caml_failwith ("aug_defnode: used handle after closing it");
1046
1047   const char *name = String_val (namev);
1048   const char *expr = String_val (exprv);
1049   const char *val = String_val (valv);
1050   struct guestfs_int_bool *r;
1051
1052   caml_enter_blocking_section ();
1053   r = guestfs_aug_defnode (g, name, expr, val);
1054   caml_leave_blocking_section ();
1055   if (r == NULL)
1056     ocaml_guestfs_raise_error (g, "aug_defnode");
1057
1058   rv = caml_alloc (2, 0);
1059   Store_field (rv, 0, Val_int (r->i));
1060   Store_field (rv, 1, Val_bool (r->b));
1061   guestfs_free_int_bool (r);
1062   CAMLreturn (rv);
1063 }
1064
1065 CAMLprim value
1066 ocaml_guestfs_aug_get (value gv, value pathv)
1067 {
1068   CAMLparam2 (gv, pathv);
1069   CAMLlocal1 (rv);
1070
1071   guestfs_h *g = Guestfs_val (gv);
1072   if (g == NULL)
1073     caml_failwith ("aug_get: used handle after closing it");
1074
1075   const char *path = String_val (pathv);
1076   char *r;
1077
1078   caml_enter_blocking_section ();
1079   r = guestfs_aug_get (g, path);
1080   caml_leave_blocking_section ();
1081   if (r == NULL)
1082     ocaml_guestfs_raise_error (g, "aug_get");
1083
1084   rv = caml_copy_string (r);
1085   free (r);
1086   CAMLreturn (rv);
1087 }
1088
1089 CAMLprim value
1090 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
1091 {
1092   CAMLparam3 (gv, pathv, valv);
1093   CAMLlocal1 (rv);
1094
1095   guestfs_h *g = Guestfs_val (gv);
1096   if (g == NULL)
1097     caml_failwith ("aug_set: used handle after closing it");
1098
1099   const char *path = String_val (pathv);
1100   const char *val = String_val (valv);
1101   int r;
1102
1103   caml_enter_blocking_section ();
1104   r = guestfs_aug_set (g, path, val);
1105   caml_leave_blocking_section ();
1106   if (r == -1)
1107     ocaml_guestfs_raise_error (g, "aug_set");
1108
1109   rv = Val_unit;
1110   CAMLreturn (rv);
1111 }
1112
1113 CAMLprim value
1114 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1115 {
1116   CAMLparam4 (gv, pathv, labelv, beforev);
1117   CAMLlocal1 (rv);
1118
1119   guestfs_h *g = Guestfs_val (gv);
1120   if (g == NULL)
1121     caml_failwith ("aug_insert: used handle after closing it");
1122
1123   const char *path = String_val (pathv);
1124   const char *label = String_val (labelv);
1125   int before = Bool_val (beforev);
1126   int r;
1127
1128   caml_enter_blocking_section ();
1129   r = guestfs_aug_insert (g, path, label, before);
1130   caml_leave_blocking_section ();
1131   if (r == -1)
1132     ocaml_guestfs_raise_error (g, "aug_insert");
1133
1134   rv = Val_unit;
1135   CAMLreturn (rv);
1136 }
1137
1138 CAMLprim value
1139 ocaml_guestfs_aug_rm (value gv, value pathv)
1140 {
1141   CAMLparam2 (gv, pathv);
1142   CAMLlocal1 (rv);
1143
1144   guestfs_h *g = Guestfs_val (gv);
1145   if (g == NULL)
1146     caml_failwith ("aug_rm: used handle after closing it");
1147
1148   const char *path = String_val (pathv);
1149   int r;
1150
1151   caml_enter_blocking_section ();
1152   r = guestfs_aug_rm (g, path);
1153   caml_leave_blocking_section ();
1154   if (r == -1)
1155     ocaml_guestfs_raise_error (g, "aug_rm");
1156
1157   rv = Val_int (r);
1158   CAMLreturn (rv);
1159 }
1160
1161 CAMLprim value
1162 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1163 {
1164   CAMLparam3 (gv, srcv, destv);
1165   CAMLlocal1 (rv);
1166
1167   guestfs_h *g = Guestfs_val (gv);
1168   if (g == NULL)
1169     caml_failwith ("aug_mv: used handle after closing it");
1170
1171   const char *src = String_val (srcv);
1172   const char *dest = String_val (destv);
1173   int r;
1174
1175   caml_enter_blocking_section ();
1176   r = guestfs_aug_mv (g, src, dest);
1177   caml_leave_blocking_section ();
1178   if (r == -1)
1179     ocaml_guestfs_raise_error (g, "aug_mv");
1180
1181   rv = Val_unit;
1182   CAMLreturn (rv);
1183 }
1184
1185 CAMLprim value
1186 ocaml_guestfs_aug_match (value gv, value pathv)
1187 {
1188   CAMLparam2 (gv, pathv);
1189   CAMLlocal1 (rv);
1190
1191   guestfs_h *g = Guestfs_val (gv);
1192   if (g == NULL)
1193     caml_failwith ("aug_match: used handle after closing it");
1194
1195   const char *path = String_val (pathv);
1196   int i;
1197   char **r;
1198
1199   caml_enter_blocking_section ();
1200   r = guestfs_aug_match (g, path);
1201   caml_leave_blocking_section ();
1202   if (r == NULL)
1203     ocaml_guestfs_raise_error (g, "aug_match");
1204
1205   rv = caml_copy_string_array ((const char **) r);
1206   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1207   free (r);
1208   CAMLreturn (rv);
1209 }
1210
1211 CAMLprim value
1212 ocaml_guestfs_aug_save (value gv)
1213 {
1214   CAMLparam1 (gv);
1215   CAMLlocal1 (rv);
1216
1217   guestfs_h *g = Guestfs_val (gv);
1218   if (g == NULL)
1219     caml_failwith ("aug_save: used handle after closing it");
1220
1221   int r;
1222
1223   caml_enter_blocking_section ();
1224   r = guestfs_aug_save (g);
1225   caml_leave_blocking_section ();
1226   if (r == -1)
1227     ocaml_guestfs_raise_error (g, "aug_save");
1228
1229   rv = Val_unit;
1230   CAMLreturn (rv);
1231 }
1232
1233 CAMLprim value
1234 ocaml_guestfs_aug_load (value gv)
1235 {
1236   CAMLparam1 (gv);
1237   CAMLlocal1 (rv);
1238
1239   guestfs_h *g = Guestfs_val (gv);
1240   if (g == NULL)
1241     caml_failwith ("aug_load: used handle after closing it");
1242
1243   int r;
1244
1245   caml_enter_blocking_section ();
1246   r = guestfs_aug_load (g);
1247   caml_leave_blocking_section ();
1248   if (r == -1)
1249     ocaml_guestfs_raise_error (g, "aug_load");
1250
1251   rv = Val_unit;
1252   CAMLreturn (rv);
1253 }
1254
1255 CAMLprim value
1256 ocaml_guestfs_aug_ls (value gv, value pathv)
1257 {
1258   CAMLparam2 (gv, pathv);
1259   CAMLlocal1 (rv);
1260
1261   guestfs_h *g = Guestfs_val (gv);
1262   if (g == NULL)
1263     caml_failwith ("aug_ls: used handle after closing it");
1264
1265   const char *path = String_val (pathv);
1266   int i;
1267   char **r;
1268
1269   caml_enter_blocking_section ();
1270   r = guestfs_aug_ls (g, path);
1271   caml_leave_blocking_section ();
1272   if (r == NULL)
1273     ocaml_guestfs_raise_error (g, "aug_ls");
1274
1275   rv = caml_copy_string_array ((const char **) r);
1276   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1277   free (r);
1278   CAMLreturn (rv);
1279 }
1280
1281 CAMLprim value
1282 ocaml_guestfs_rm (value gv, value pathv)
1283 {
1284   CAMLparam2 (gv, pathv);
1285   CAMLlocal1 (rv);
1286
1287   guestfs_h *g = Guestfs_val (gv);
1288   if (g == NULL)
1289     caml_failwith ("rm: used handle after closing it");
1290
1291   const char *path = String_val (pathv);
1292   int r;
1293
1294   caml_enter_blocking_section ();
1295   r = guestfs_rm (g, path);
1296   caml_leave_blocking_section ();
1297   if (r == -1)
1298     ocaml_guestfs_raise_error (g, "rm");
1299
1300   rv = Val_unit;
1301   CAMLreturn (rv);
1302 }
1303
1304 CAMLprim value
1305 ocaml_guestfs_rmdir (value gv, value pathv)
1306 {
1307   CAMLparam2 (gv, pathv);
1308   CAMLlocal1 (rv);
1309
1310   guestfs_h *g = Guestfs_val (gv);
1311   if (g == NULL)
1312     caml_failwith ("rmdir: used handle after closing it");
1313
1314   const char *path = String_val (pathv);
1315   int r;
1316
1317   caml_enter_blocking_section ();
1318   r = guestfs_rmdir (g, path);
1319   caml_leave_blocking_section ();
1320   if (r == -1)
1321     ocaml_guestfs_raise_error (g, "rmdir");
1322
1323   rv = Val_unit;
1324   CAMLreturn (rv);
1325 }
1326
1327 CAMLprim value
1328 ocaml_guestfs_rm_rf (value gv, value pathv)
1329 {
1330   CAMLparam2 (gv, pathv);
1331   CAMLlocal1 (rv);
1332
1333   guestfs_h *g = Guestfs_val (gv);
1334   if (g == NULL)
1335     caml_failwith ("rm_rf: used handle after closing it");
1336
1337   const char *path = String_val (pathv);
1338   int r;
1339
1340   caml_enter_blocking_section ();
1341   r = guestfs_rm_rf (g, path);
1342   caml_leave_blocking_section ();
1343   if (r == -1)
1344     ocaml_guestfs_raise_error (g, "rm_rf");
1345
1346   rv = Val_unit;
1347   CAMLreturn (rv);
1348 }
1349
1350 CAMLprim value
1351 ocaml_guestfs_mkdir (value gv, value pathv)
1352 {
1353   CAMLparam2 (gv, pathv);
1354   CAMLlocal1 (rv);
1355
1356   guestfs_h *g = Guestfs_val (gv);
1357   if (g == NULL)
1358     caml_failwith ("mkdir: used handle after closing it");
1359
1360   const char *path = String_val (pathv);
1361   int r;
1362
1363   caml_enter_blocking_section ();
1364   r = guestfs_mkdir (g, path);
1365   caml_leave_blocking_section ();
1366   if (r == -1)
1367     ocaml_guestfs_raise_error (g, "mkdir");
1368
1369   rv = Val_unit;
1370   CAMLreturn (rv);
1371 }
1372
1373 CAMLprim value
1374 ocaml_guestfs_mkdir_p (value gv, value pathv)
1375 {
1376   CAMLparam2 (gv, pathv);
1377   CAMLlocal1 (rv);
1378
1379   guestfs_h *g = Guestfs_val (gv);
1380   if (g == NULL)
1381     caml_failwith ("mkdir_p: used handle after closing it");
1382
1383   const char *path = String_val (pathv);
1384   int r;
1385
1386   caml_enter_blocking_section ();
1387   r = guestfs_mkdir_p (g, path);
1388   caml_leave_blocking_section ();
1389   if (r == -1)
1390     ocaml_guestfs_raise_error (g, "mkdir_p");
1391
1392   rv = Val_unit;
1393   CAMLreturn (rv);
1394 }
1395
1396 CAMLprim value
1397 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1398 {
1399   CAMLparam3 (gv, modev, pathv);
1400   CAMLlocal1 (rv);
1401
1402   guestfs_h *g = Guestfs_val (gv);
1403   if (g == NULL)
1404     caml_failwith ("chmod: used handle after closing it");
1405
1406   int mode = Int_val (modev);
1407   const char *path = String_val (pathv);
1408   int r;
1409
1410   caml_enter_blocking_section ();
1411   r = guestfs_chmod (g, mode, path);
1412   caml_leave_blocking_section ();
1413   if (r == -1)
1414     ocaml_guestfs_raise_error (g, "chmod");
1415
1416   rv = Val_unit;
1417   CAMLreturn (rv);
1418 }
1419
1420 CAMLprim value
1421 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1422 {
1423   CAMLparam4 (gv, ownerv, groupv, pathv);
1424   CAMLlocal1 (rv);
1425
1426   guestfs_h *g = Guestfs_val (gv);
1427   if (g == NULL)
1428     caml_failwith ("chown: used handle after closing it");
1429
1430   int owner = Int_val (ownerv);
1431   int group = Int_val (groupv);
1432   const char *path = String_val (pathv);
1433   int r;
1434
1435   caml_enter_blocking_section ();
1436   r = guestfs_chown (g, owner, group, path);
1437   caml_leave_blocking_section ();
1438   if (r == -1)
1439     ocaml_guestfs_raise_error (g, "chown");
1440
1441   rv = Val_unit;
1442   CAMLreturn (rv);
1443 }
1444
1445 CAMLprim value
1446 ocaml_guestfs_exists (value gv, value pathv)
1447 {
1448   CAMLparam2 (gv, pathv);
1449   CAMLlocal1 (rv);
1450
1451   guestfs_h *g = Guestfs_val (gv);
1452   if (g == NULL)
1453     caml_failwith ("exists: used handle after closing it");
1454
1455   const char *path = String_val (pathv);
1456   int r;
1457
1458   caml_enter_blocking_section ();
1459   r = guestfs_exists (g, path);
1460   caml_leave_blocking_section ();
1461   if (r == -1)
1462     ocaml_guestfs_raise_error (g, "exists");
1463
1464   rv = Val_bool (r);
1465   CAMLreturn (rv);
1466 }
1467
1468 CAMLprim value
1469 ocaml_guestfs_is_file (value gv, value pathv)
1470 {
1471   CAMLparam2 (gv, pathv);
1472   CAMLlocal1 (rv);
1473
1474   guestfs_h *g = Guestfs_val (gv);
1475   if (g == NULL)
1476     caml_failwith ("is_file: used handle after closing it");
1477
1478   const char *path = String_val (pathv);
1479   int r;
1480
1481   caml_enter_blocking_section ();
1482   r = guestfs_is_file (g, path);
1483   caml_leave_blocking_section ();
1484   if (r == -1)
1485     ocaml_guestfs_raise_error (g, "is_file");
1486
1487   rv = Val_bool (r);
1488   CAMLreturn (rv);
1489 }
1490
1491 CAMLprim value
1492 ocaml_guestfs_is_dir (value gv, value pathv)
1493 {
1494   CAMLparam2 (gv, pathv);
1495   CAMLlocal1 (rv);
1496
1497   guestfs_h *g = Guestfs_val (gv);
1498   if (g == NULL)
1499     caml_failwith ("is_dir: used handle after closing it");
1500
1501   const char *path = String_val (pathv);
1502   int r;
1503
1504   caml_enter_blocking_section ();
1505   r = guestfs_is_dir (g, path);
1506   caml_leave_blocking_section ();
1507   if (r == -1)
1508     ocaml_guestfs_raise_error (g, "is_dir");
1509
1510   rv = Val_bool (r);
1511   CAMLreturn (rv);
1512 }
1513
1514 CAMLprim value
1515 ocaml_guestfs_pvcreate (value gv, value devicev)
1516 {
1517   CAMLparam2 (gv, devicev);
1518   CAMLlocal1 (rv);
1519
1520   guestfs_h *g = Guestfs_val (gv);
1521   if (g == NULL)
1522     caml_failwith ("pvcreate: used handle after closing it");
1523
1524   const char *device = String_val (devicev);
1525   int r;
1526
1527   caml_enter_blocking_section ();
1528   r = guestfs_pvcreate (g, device);
1529   caml_leave_blocking_section ();
1530   if (r == -1)
1531     ocaml_guestfs_raise_error (g, "pvcreate");
1532
1533   rv = Val_unit;
1534   CAMLreturn (rv);
1535 }
1536
1537 CAMLprim value
1538 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
1539 {
1540   CAMLparam3 (gv, volgroupv, physvolsv);
1541   CAMLlocal1 (rv);
1542
1543   guestfs_h *g = Guestfs_val (gv);
1544   if (g == NULL)
1545     caml_failwith ("vgcreate: used handle after closing it");
1546
1547   const char *volgroup = String_val (volgroupv);
1548   char **physvols = ocaml_guestfs_strings_val (physvolsv);
1549   int r;
1550
1551   caml_enter_blocking_section ();
1552   r = guestfs_vgcreate (g, volgroup, physvols);
1553   caml_leave_blocking_section ();
1554   ocaml_guestfs_free_strings (physvols);
1555   if (r == -1)
1556     ocaml_guestfs_raise_error (g, "vgcreate");
1557
1558   rv = Val_unit;
1559   CAMLreturn (rv);
1560 }
1561
1562 CAMLprim value
1563 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
1564 {
1565   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
1566   CAMLlocal1 (rv);
1567
1568   guestfs_h *g = Guestfs_val (gv);
1569   if (g == NULL)
1570     caml_failwith ("lvcreate: used handle after closing it");
1571
1572   const char *logvol = String_val (logvolv);
1573   const char *volgroup = String_val (volgroupv);
1574   int mbytes = Int_val (mbytesv);
1575   int r;
1576
1577   caml_enter_blocking_section ();
1578   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
1579   caml_leave_blocking_section ();
1580   if (r == -1)
1581     ocaml_guestfs_raise_error (g, "lvcreate");
1582
1583   rv = Val_unit;
1584   CAMLreturn (rv);
1585 }
1586
1587 CAMLprim value
1588 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
1589 {
1590   CAMLparam3 (gv, fstypev, devicev);
1591   CAMLlocal1 (rv);
1592
1593   guestfs_h *g = Guestfs_val (gv);
1594   if (g == NULL)
1595     caml_failwith ("mkfs: used handle after closing it");
1596
1597   const char *fstype = String_val (fstypev);
1598   const char *device = String_val (devicev);
1599   int r;
1600
1601   caml_enter_blocking_section ();
1602   r = guestfs_mkfs (g, fstype, device);
1603   caml_leave_blocking_section ();
1604   if (r == -1)
1605     ocaml_guestfs_raise_error (g, "mkfs");
1606
1607   rv = Val_unit;
1608   CAMLreturn (rv);
1609 }
1610
1611 CAMLprim value
1612 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
1613 {
1614   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
1615   CAMLxparam1 (linesv);
1616   CAMLlocal1 (rv);
1617
1618   guestfs_h *g = Guestfs_val (gv);
1619   if (g == NULL)
1620     caml_failwith ("sfdisk: used handle after closing it");
1621
1622   const char *device = String_val (devicev);
1623   int cyls = Int_val (cylsv);
1624   int heads = Int_val (headsv);
1625   int sectors = Int_val (sectorsv);
1626   char **lines = ocaml_guestfs_strings_val (linesv);
1627   int r;
1628
1629   caml_enter_blocking_section ();
1630   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
1631   caml_leave_blocking_section ();
1632   ocaml_guestfs_free_strings (lines);
1633   if (r == -1)
1634     ocaml_guestfs_raise_error (g, "sfdisk");
1635
1636   rv = Val_unit;
1637   CAMLreturn (rv);
1638 }
1639
1640 CAMLprim value
1641 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
1642 {
1643   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
1644 }
1645
1646 CAMLprim value
1647 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
1648 {
1649   CAMLparam4 (gv, pathv, contentv, sizev);
1650   CAMLlocal1 (rv);
1651
1652   guestfs_h *g = Guestfs_val (gv);
1653   if (g == NULL)
1654     caml_failwith ("write_file: used handle after closing it");
1655
1656   const char *path = String_val (pathv);
1657   const char *content = String_val (contentv);
1658   int size = Int_val (sizev);
1659   int r;
1660
1661   caml_enter_blocking_section ();
1662   r = guestfs_write_file (g, path, content, size);
1663   caml_leave_blocking_section ();
1664   if (r == -1)
1665     ocaml_guestfs_raise_error (g, "write_file");
1666
1667   rv = Val_unit;
1668   CAMLreturn (rv);
1669 }
1670
1671 CAMLprim value
1672 ocaml_guestfs_umount (value gv, value pathordevicev)
1673 {
1674   CAMLparam2 (gv, pathordevicev);
1675   CAMLlocal1 (rv);
1676
1677   guestfs_h *g = Guestfs_val (gv);
1678   if (g == NULL)
1679     caml_failwith ("umount: used handle after closing it");
1680
1681   const char *pathordevice = String_val (pathordevicev);
1682   int r;
1683
1684   caml_enter_blocking_section ();
1685   r = guestfs_umount (g, pathordevice);
1686   caml_leave_blocking_section ();
1687   if (r == -1)
1688     ocaml_guestfs_raise_error (g, "umount");
1689
1690   rv = Val_unit;
1691   CAMLreturn (rv);
1692 }
1693
1694 CAMLprim value
1695 ocaml_guestfs_mounts (value gv)
1696 {
1697   CAMLparam1 (gv);
1698   CAMLlocal1 (rv);
1699
1700   guestfs_h *g = Guestfs_val (gv);
1701   if (g == NULL)
1702     caml_failwith ("mounts: used handle after closing it");
1703
1704   int i;
1705   char **r;
1706
1707   caml_enter_blocking_section ();
1708   r = guestfs_mounts (g);
1709   caml_leave_blocking_section ();
1710   if (r == NULL)
1711     ocaml_guestfs_raise_error (g, "mounts");
1712
1713   rv = caml_copy_string_array ((const char **) r);
1714   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1715   free (r);
1716   CAMLreturn (rv);
1717 }
1718
1719 CAMLprim value
1720 ocaml_guestfs_umount_all (value gv)
1721 {
1722   CAMLparam1 (gv);
1723   CAMLlocal1 (rv);
1724
1725   guestfs_h *g = Guestfs_val (gv);
1726   if (g == NULL)
1727     caml_failwith ("umount_all: used handle after closing it");
1728
1729   int r;
1730
1731   caml_enter_blocking_section ();
1732   r = guestfs_umount_all (g);
1733   caml_leave_blocking_section ();
1734   if (r == -1)
1735     ocaml_guestfs_raise_error (g, "umount_all");
1736
1737   rv = Val_unit;
1738   CAMLreturn (rv);
1739 }
1740
1741 CAMLprim value
1742 ocaml_guestfs_lvm_remove_all (value gv)
1743 {
1744   CAMLparam1 (gv);
1745   CAMLlocal1 (rv);
1746
1747   guestfs_h *g = Guestfs_val (gv);
1748   if (g == NULL)
1749     caml_failwith ("lvm_remove_all: used handle after closing it");
1750
1751   int r;
1752
1753   caml_enter_blocking_section ();
1754   r = guestfs_lvm_remove_all (g);
1755   caml_leave_blocking_section ();
1756   if (r == -1)
1757     ocaml_guestfs_raise_error (g, "lvm_remove_all");
1758
1759   rv = Val_unit;
1760   CAMLreturn (rv);
1761 }
1762
1763 CAMLprim value
1764 ocaml_guestfs_file (value gv, value pathv)
1765 {
1766   CAMLparam2 (gv, pathv);
1767   CAMLlocal1 (rv);
1768
1769   guestfs_h *g = Guestfs_val (gv);
1770   if (g == NULL)
1771     caml_failwith ("file: used handle after closing it");
1772
1773   const char *path = String_val (pathv);
1774   char *r;
1775
1776   caml_enter_blocking_section ();
1777   r = guestfs_file (g, path);
1778   caml_leave_blocking_section ();
1779   if (r == NULL)
1780     ocaml_guestfs_raise_error (g, "file");
1781
1782   rv = caml_copy_string (r);
1783   free (r);
1784   CAMLreturn (rv);
1785 }
1786
1787 CAMLprim value
1788 ocaml_guestfs_command (value gv, value argumentsv)
1789 {
1790   CAMLparam2 (gv, argumentsv);
1791   CAMLlocal1 (rv);
1792
1793   guestfs_h *g = Guestfs_val (gv);
1794   if (g == NULL)
1795     caml_failwith ("command: used handle after closing it");
1796
1797   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1798   char *r;
1799
1800   caml_enter_blocking_section ();
1801   r = guestfs_command (g, arguments);
1802   caml_leave_blocking_section ();
1803   ocaml_guestfs_free_strings (arguments);
1804   if (r == NULL)
1805     ocaml_guestfs_raise_error (g, "command");
1806
1807   rv = caml_copy_string (r);
1808   free (r);
1809   CAMLreturn (rv);
1810 }
1811
1812 CAMLprim value
1813 ocaml_guestfs_command_lines (value gv, value argumentsv)
1814 {
1815   CAMLparam2 (gv, argumentsv);
1816   CAMLlocal1 (rv);
1817
1818   guestfs_h *g = Guestfs_val (gv);
1819   if (g == NULL)
1820     caml_failwith ("command_lines: used handle after closing it");
1821
1822   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1823   int i;
1824   char **r;
1825
1826   caml_enter_blocking_section ();
1827   r = guestfs_command_lines (g, arguments);
1828   caml_leave_blocking_section ();
1829   ocaml_guestfs_free_strings (arguments);
1830   if (r == NULL)
1831     ocaml_guestfs_raise_error (g, "command_lines");
1832
1833   rv = caml_copy_string_array ((const char **) r);
1834   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1835   free (r);
1836   CAMLreturn (rv);
1837 }
1838
1839 CAMLprim value
1840 ocaml_guestfs_stat (value gv, value pathv)
1841 {
1842   CAMLparam2 (gv, pathv);
1843   CAMLlocal1 (rv);
1844
1845   guestfs_h *g = Guestfs_val (gv);
1846   if (g == NULL)
1847     caml_failwith ("stat: used handle after closing it");
1848
1849   const char *path = String_val (pathv);
1850   struct guestfs_stat *r;
1851
1852   caml_enter_blocking_section ();
1853   r = guestfs_stat (g, path);
1854   caml_leave_blocking_section ();
1855   if (r == NULL)
1856     ocaml_guestfs_raise_error (g, "stat");
1857
1858   rv = copy_stat (r);
1859   free (r);
1860   CAMLreturn (rv);
1861 }
1862
1863 CAMLprim value
1864 ocaml_guestfs_lstat (value gv, value pathv)
1865 {
1866   CAMLparam2 (gv, pathv);
1867   CAMLlocal1 (rv);
1868
1869   guestfs_h *g = Guestfs_val (gv);
1870   if (g == NULL)
1871     caml_failwith ("lstat: used handle after closing it");
1872
1873   const char *path = String_val (pathv);
1874   struct guestfs_stat *r;
1875
1876   caml_enter_blocking_section ();
1877   r = guestfs_lstat (g, path);
1878   caml_leave_blocking_section ();
1879   if (r == NULL)
1880     ocaml_guestfs_raise_error (g, "lstat");
1881
1882   rv = copy_stat (r);
1883   free (r);
1884   CAMLreturn (rv);
1885 }
1886
1887 CAMLprim value
1888 ocaml_guestfs_statvfs (value gv, value pathv)
1889 {
1890   CAMLparam2 (gv, pathv);
1891   CAMLlocal1 (rv);
1892
1893   guestfs_h *g = Guestfs_val (gv);
1894   if (g == NULL)
1895     caml_failwith ("statvfs: used handle after closing it");
1896
1897   const char *path = String_val (pathv);
1898   struct guestfs_statvfs *r;
1899
1900   caml_enter_blocking_section ();
1901   r = guestfs_statvfs (g, path);
1902   caml_leave_blocking_section ();
1903   if (r == NULL)
1904     ocaml_guestfs_raise_error (g, "statvfs");
1905
1906   rv = copy_statvfs (r);
1907   free (r);
1908   CAMLreturn (rv);
1909 }
1910
1911 CAMLprim value
1912 ocaml_guestfs_tune2fs_l (value gv, value devicev)
1913 {
1914   CAMLparam2 (gv, devicev);
1915   CAMLlocal1 (rv);
1916
1917   guestfs_h *g = Guestfs_val (gv);
1918   if (g == NULL)
1919     caml_failwith ("tune2fs_l: used handle after closing it");
1920
1921   const char *device = String_val (devicev);
1922   int i;
1923   char **r;
1924
1925   caml_enter_blocking_section ();
1926   r = guestfs_tune2fs_l (g, device);
1927   caml_leave_blocking_section ();
1928   if (r == NULL)
1929     ocaml_guestfs_raise_error (g, "tune2fs_l");
1930
1931   rv = copy_table (r);
1932   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1933   free (r);
1934   CAMLreturn (rv);
1935 }
1936