Add 'readdir' call.
[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 static CAMLprim value
332 copy_dirent (const struct guestfs_dirent *dirent)
333 {
334   CAMLparam0 ();
335   CAMLlocal2 (rv, v);
336
337   rv = caml_alloc (3, 0);
338   v = caml_copy_int64 (dirent->ino);
339   Store_field (rv, 0, v);
340   v = Val_int (dirent->ftyp);
341   Store_field (rv, 1, v);
342   v = caml_copy_string (dirent->name);
343   Store_field (rv, 2, v);
344   CAMLreturn (rv);
345 }
346
347 static CAMLprim value
348 copy_dirent_list (const struct guestfs_dirent_list *dirents)
349 {
350   CAMLparam0 ();
351   CAMLlocal2 (rv, v);
352   int i;
353
354   if (dirents->len == 0)
355     CAMLreturn (Atom (0));
356   else {
357     rv = caml_alloc (dirents->len, 0);
358     for (i = 0; i < dirents->len; ++i) {
359       v = copy_dirent (&dirents->val[i]);
360       caml_modify (&Field (rv, i), v);
361     }
362     CAMLreturn (rv);
363   }
364 }
365
366 CAMLprim value
367 ocaml_guestfs_test0 (value gv, value strv, value optstrv, value strlistv, value bv, value integerv, value fileinv, value fileoutv)
368 {
369   CAMLparam5 (gv, strv, optstrv, strlistv, bv);
370   CAMLxparam3 (integerv, fileinv, fileoutv);
371   CAMLlocal1 (rv);
372
373   guestfs_h *g = Guestfs_val (gv);
374   if (g == NULL)
375     caml_failwith ("test0: used handle after closing it");
376
377   const char *str = String_val (strv);
378   const char *optstr =
379     optstrv != Val_int (0) ? String_val (Field (optstrv, 0)) : NULL;
380   char **strlist = ocaml_guestfs_strings_val (g, strlistv);
381   int b = Bool_val (bv);
382   int integer = Int_val (integerv);
383   const char *filein = String_val (fileinv);
384   const char *fileout = String_val (fileoutv);
385   int r;
386
387   caml_enter_blocking_section ();
388   r = guestfs_test0 (g, str, optstr, strlist, b, integer, filein, fileout);
389   caml_leave_blocking_section ();
390   ocaml_guestfs_free_strings (strlist);
391   if (r == -1)
392     ocaml_guestfs_raise_error (g, "test0");
393
394   rv = Val_unit;
395   CAMLreturn (rv);
396 }
397
398 CAMLprim value
399 ocaml_guestfs_test0_byte (value *argv, int argn)
400 {
401   return ocaml_guestfs_test0 (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6]);
402 }
403
404 CAMLprim value
405 ocaml_guestfs_test0rint (value gv, value valv)
406 {
407   CAMLparam2 (gv, valv);
408   CAMLlocal1 (rv);
409
410   guestfs_h *g = Guestfs_val (gv);
411   if (g == NULL)
412     caml_failwith ("test0rint: used handle after closing it");
413
414   const char *val = String_val (valv);
415   int r;
416
417   caml_enter_blocking_section ();
418   r = guestfs_test0rint (g, val);
419   caml_leave_blocking_section ();
420   if (r == -1)
421     ocaml_guestfs_raise_error (g, "test0rint");
422
423   rv = Val_int (r);
424   CAMLreturn (rv);
425 }
426
427 CAMLprim value
428 ocaml_guestfs_test0rinterr (value gv)
429 {
430   CAMLparam1 (gv);
431   CAMLlocal1 (rv);
432
433   guestfs_h *g = Guestfs_val (gv);
434   if (g == NULL)
435     caml_failwith ("test0rinterr: used handle after closing it");
436
437   int r;
438
439   caml_enter_blocking_section ();
440   r = guestfs_test0rinterr (g);
441   caml_leave_blocking_section ();
442   if (r == -1)
443     ocaml_guestfs_raise_error (g, "test0rinterr");
444
445   rv = Val_int (r);
446   CAMLreturn (rv);
447 }
448
449 CAMLprim value
450 ocaml_guestfs_test0rint64 (value gv, value valv)
451 {
452   CAMLparam2 (gv, valv);
453   CAMLlocal1 (rv);
454
455   guestfs_h *g = Guestfs_val (gv);
456   if (g == NULL)
457     caml_failwith ("test0rint64: used handle after closing it");
458
459   const char *val = String_val (valv);
460   int64_t r;
461
462   caml_enter_blocking_section ();
463   r = guestfs_test0rint64 (g, val);
464   caml_leave_blocking_section ();
465   if (r == -1)
466     ocaml_guestfs_raise_error (g, "test0rint64");
467
468   rv = caml_copy_int64 (r);
469   CAMLreturn (rv);
470 }
471
472 CAMLprim value
473 ocaml_guestfs_test0rint64err (value gv)
474 {
475   CAMLparam1 (gv);
476   CAMLlocal1 (rv);
477
478   guestfs_h *g = Guestfs_val (gv);
479   if (g == NULL)
480     caml_failwith ("test0rint64err: used handle after closing it");
481
482   int64_t r;
483
484   caml_enter_blocking_section ();
485   r = guestfs_test0rint64err (g);
486   caml_leave_blocking_section ();
487   if (r == -1)
488     ocaml_guestfs_raise_error (g, "test0rint64err");
489
490   rv = caml_copy_int64 (r);
491   CAMLreturn (rv);
492 }
493
494 CAMLprim value
495 ocaml_guestfs_test0rbool (value gv, value valv)
496 {
497   CAMLparam2 (gv, valv);
498   CAMLlocal1 (rv);
499
500   guestfs_h *g = Guestfs_val (gv);
501   if (g == NULL)
502     caml_failwith ("test0rbool: used handle after closing it");
503
504   const char *val = String_val (valv);
505   int r;
506
507   caml_enter_blocking_section ();
508   r = guestfs_test0rbool (g, val);
509   caml_leave_blocking_section ();
510   if (r == -1)
511     ocaml_guestfs_raise_error (g, "test0rbool");
512
513   rv = Val_bool (r);
514   CAMLreturn (rv);
515 }
516
517 CAMLprim value
518 ocaml_guestfs_test0rboolerr (value gv)
519 {
520   CAMLparam1 (gv);
521   CAMLlocal1 (rv);
522
523   guestfs_h *g = Guestfs_val (gv);
524   if (g == NULL)
525     caml_failwith ("test0rboolerr: used handle after closing it");
526
527   int r;
528
529   caml_enter_blocking_section ();
530   r = guestfs_test0rboolerr (g);
531   caml_leave_blocking_section ();
532   if (r == -1)
533     ocaml_guestfs_raise_error (g, "test0rboolerr");
534
535   rv = Val_bool (r);
536   CAMLreturn (rv);
537 }
538
539 CAMLprim value
540 ocaml_guestfs_test0rconststring (value gv, value valv)
541 {
542   CAMLparam2 (gv, valv);
543   CAMLlocal1 (rv);
544
545   guestfs_h *g = Guestfs_val (gv);
546   if (g == NULL)
547     caml_failwith ("test0rconststring: used handle after closing it");
548
549   const char *val = String_val (valv);
550   const char *r;
551
552   caml_enter_blocking_section ();
553   r = guestfs_test0rconststring (g, val);
554   caml_leave_blocking_section ();
555   if (r == NULL)
556     ocaml_guestfs_raise_error (g, "test0rconststring");
557
558   rv = caml_copy_string (r);
559   CAMLreturn (rv);
560 }
561
562 CAMLprim value
563 ocaml_guestfs_test0rconststringerr (value gv)
564 {
565   CAMLparam1 (gv);
566   CAMLlocal1 (rv);
567
568   guestfs_h *g = Guestfs_val (gv);
569   if (g == NULL)
570     caml_failwith ("test0rconststringerr: used handle after closing it");
571
572   const char *r;
573
574   caml_enter_blocking_section ();
575   r = guestfs_test0rconststringerr (g);
576   caml_leave_blocking_section ();
577   if (r == NULL)
578     ocaml_guestfs_raise_error (g, "test0rconststringerr");
579
580   rv = caml_copy_string (r);
581   CAMLreturn (rv);
582 }
583
584 CAMLprim value
585 ocaml_guestfs_test0rstring (value gv, value valv)
586 {
587   CAMLparam2 (gv, valv);
588   CAMLlocal1 (rv);
589
590   guestfs_h *g = Guestfs_val (gv);
591   if (g == NULL)
592     caml_failwith ("test0rstring: used handle after closing it");
593
594   const char *val = String_val (valv);
595   char *r;
596
597   caml_enter_blocking_section ();
598   r = guestfs_test0rstring (g, val);
599   caml_leave_blocking_section ();
600   if (r == NULL)
601     ocaml_guestfs_raise_error (g, "test0rstring");
602
603   rv = caml_copy_string (r);
604   free (r);
605   CAMLreturn (rv);
606 }
607
608 CAMLprim value
609 ocaml_guestfs_test0rstringerr (value gv)
610 {
611   CAMLparam1 (gv);
612   CAMLlocal1 (rv);
613
614   guestfs_h *g = Guestfs_val (gv);
615   if (g == NULL)
616     caml_failwith ("test0rstringerr: used handle after closing it");
617
618   char *r;
619
620   caml_enter_blocking_section ();
621   r = guestfs_test0rstringerr (g);
622   caml_leave_blocking_section ();
623   if (r == NULL)
624     ocaml_guestfs_raise_error (g, "test0rstringerr");
625
626   rv = caml_copy_string (r);
627   free (r);
628   CAMLreturn (rv);
629 }
630
631 CAMLprim value
632 ocaml_guestfs_test0rstringlist (value gv, value valv)
633 {
634   CAMLparam2 (gv, valv);
635   CAMLlocal1 (rv);
636
637   guestfs_h *g = Guestfs_val (gv);
638   if (g == NULL)
639     caml_failwith ("test0rstringlist: used handle after closing it");
640
641   const char *val = String_val (valv);
642   int i;
643   char **r;
644
645   caml_enter_blocking_section ();
646   r = guestfs_test0rstringlist (g, val);
647   caml_leave_blocking_section ();
648   if (r == NULL)
649     ocaml_guestfs_raise_error (g, "test0rstringlist");
650
651   rv = caml_copy_string_array ((const char **) r);
652   for (i = 0; r[i] != NULL; ++i) free (r[i]);
653   free (r);
654   CAMLreturn (rv);
655 }
656
657 CAMLprim value
658 ocaml_guestfs_test0rstringlisterr (value gv)
659 {
660   CAMLparam1 (gv);
661   CAMLlocal1 (rv);
662
663   guestfs_h *g = Guestfs_val (gv);
664   if (g == NULL)
665     caml_failwith ("test0rstringlisterr: used handle after closing it");
666
667   int i;
668   char **r;
669
670   caml_enter_blocking_section ();
671   r = guestfs_test0rstringlisterr (g);
672   caml_leave_blocking_section ();
673   if (r == NULL)
674     ocaml_guestfs_raise_error (g, "test0rstringlisterr");
675
676   rv = caml_copy_string_array ((const char **) r);
677   for (i = 0; r[i] != NULL; ++i) free (r[i]);
678   free (r);
679   CAMLreturn (rv);
680 }
681
682 CAMLprim value
683 ocaml_guestfs_test0rintbool (value gv, value valv)
684 {
685   CAMLparam2 (gv, valv);
686   CAMLlocal1 (rv);
687
688   guestfs_h *g = Guestfs_val (gv);
689   if (g == NULL)
690     caml_failwith ("test0rintbool: used handle after closing it");
691
692   const char *val = String_val (valv);
693   struct guestfs_int_bool *r;
694
695   caml_enter_blocking_section ();
696   r = guestfs_test0rintbool (g, val);
697   caml_leave_blocking_section ();
698   if (r == NULL)
699     ocaml_guestfs_raise_error (g, "test0rintbool");
700
701   rv = caml_alloc (2, 0);
702   Store_field (rv, 0, Val_int (r->i));
703   Store_field (rv, 1, Val_bool (r->b));
704   guestfs_free_int_bool (r);
705   CAMLreturn (rv);
706 }
707
708 CAMLprim value
709 ocaml_guestfs_test0rintboolerr (value gv)
710 {
711   CAMLparam1 (gv);
712   CAMLlocal1 (rv);
713
714   guestfs_h *g = Guestfs_val (gv);
715   if (g == NULL)
716     caml_failwith ("test0rintboolerr: used handle after closing it");
717
718   struct guestfs_int_bool *r;
719
720   caml_enter_blocking_section ();
721   r = guestfs_test0rintboolerr (g);
722   caml_leave_blocking_section ();
723   if (r == NULL)
724     ocaml_guestfs_raise_error (g, "test0rintboolerr");
725
726   rv = caml_alloc (2, 0);
727   Store_field (rv, 0, Val_int (r->i));
728   Store_field (rv, 1, Val_bool (r->b));
729   guestfs_free_int_bool (r);
730   CAMLreturn (rv);
731 }
732
733 CAMLprim value
734 ocaml_guestfs_test0rpvlist (value gv, value valv)
735 {
736   CAMLparam2 (gv, valv);
737   CAMLlocal1 (rv);
738
739   guestfs_h *g = Guestfs_val (gv);
740   if (g == NULL)
741     caml_failwith ("test0rpvlist: used handle after closing it");
742
743   const char *val = String_val (valv);
744   struct guestfs_lvm_pv_list *r;
745
746   caml_enter_blocking_section ();
747   r = guestfs_test0rpvlist (g, val);
748   caml_leave_blocking_section ();
749   if (r == NULL)
750     ocaml_guestfs_raise_error (g, "test0rpvlist");
751
752   rv = copy_lvm_pv_list (r);
753   guestfs_free_lvm_pv_list (r);
754   CAMLreturn (rv);
755 }
756
757 CAMLprim value
758 ocaml_guestfs_test0rpvlisterr (value gv)
759 {
760   CAMLparam1 (gv);
761   CAMLlocal1 (rv);
762
763   guestfs_h *g = Guestfs_val (gv);
764   if (g == NULL)
765     caml_failwith ("test0rpvlisterr: used handle after closing it");
766
767   struct guestfs_lvm_pv_list *r;
768
769   caml_enter_blocking_section ();
770   r = guestfs_test0rpvlisterr (g);
771   caml_leave_blocking_section ();
772   if (r == NULL)
773     ocaml_guestfs_raise_error (g, "test0rpvlisterr");
774
775   rv = copy_lvm_pv_list (r);
776   guestfs_free_lvm_pv_list (r);
777   CAMLreturn (rv);
778 }
779
780 CAMLprim value
781 ocaml_guestfs_test0rvglist (value gv, value valv)
782 {
783   CAMLparam2 (gv, valv);
784   CAMLlocal1 (rv);
785
786   guestfs_h *g = Guestfs_val (gv);
787   if (g == NULL)
788     caml_failwith ("test0rvglist: used handle after closing it");
789
790   const char *val = String_val (valv);
791   struct guestfs_lvm_vg_list *r;
792
793   caml_enter_blocking_section ();
794   r = guestfs_test0rvglist (g, val);
795   caml_leave_blocking_section ();
796   if (r == NULL)
797     ocaml_guestfs_raise_error (g, "test0rvglist");
798
799   rv = copy_lvm_vg_list (r);
800   guestfs_free_lvm_vg_list (r);
801   CAMLreturn (rv);
802 }
803
804 CAMLprim value
805 ocaml_guestfs_test0rvglisterr (value gv)
806 {
807   CAMLparam1 (gv);
808   CAMLlocal1 (rv);
809
810   guestfs_h *g = Guestfs_val (gv);
811   if (g == NULL)
812     caml_failwith ("test0rvglisterr: used handle after closing it");
813
814   struct guestfs_lvm_vg_list *r;
815
816   caml_enter_blocking_section ();
817   r = guestfs_test0rvglisterr (g);
818   caml_leave_blocking_section ();
819   if (r == NULL)
820     ocaml_guestfs_raise_error (g, "test0rvglisterr");
821
822   rv = copy_lvm_vg_list (r);
823   guestfs_free_lvm_vg_list (r);
824   CAMLreturn (rv);
825 }
826
827 CAMLprim value
828 ocaml_guestfs_test0rlvlist (value gv, value valv)
829 {
830   CAMLparam2 (gv, valv);
831   CAMLlocal1 (rv);
832
833   guestfs_h *g = Guestfs_val (gv);
834   if (g == NULL)
835     caml_failwith ("test0rlvlist: used handle after closing it");
836
837   const char *val = String_val (valv);
838   struct guestfs_lvm_lv_list *r;
839
840   caml_enter_blocking_section ();
841   r = guestfs_test0rlvlist (g, val);
842   caml_leave_blocking_section ();
843   if (r == NULL)
844     ocaml_guestfs_raise_error (g, "test0rlvlist");
845
846   rv = copy_lvm_lv_list (r);
847   guestfs_free_lvm_lv_list (r);
848   CAMLreturn (rv);
849 }
850
851 CAMLprim value
852 ocaml_guestfs_test0rlvlisterr (value gv)
853 {
854   CAMLparam1 (gv);
855   CAMLlocal1 (rv);
856
857   guestfs_h *g = Guestfs_val (gv);
858   if (g == NULL)
859     caml_failwith ("test0rlvlisterr: used handle after closing it");
860
861   struct guestfs_lvm_lv_list *r;
862
863   caml_enter_blocking_section ();
864   r = guestfs_test0rlvlisterr (g);
865   caml_leave_blocking_section ();
866   if (r == NULL)
867     ocaml_guestfs_raise_error (g, "test0rlvlisterr");
868
869   rv = copy_lvm_lv_list (r);
870   guestfs_free_lvm_lv_list (r);
871   CAMLreturn (rv);
872 }
873
874 CAMLprim value
875 ocaml_guestfs_test0rstat (value gv, value valv)
876 {
877   CAMLparam2 (gv, valv);
878   CAMLlocal1 (rv);
879
880   guestfs_h *g = Guestfs_val (gv);
881   if (g == NULL)
882     caml_failwith ("test0rstat: used handle after closing it");
883
884   const char *val = String_val (valv);
885   struct guestfs_stat *r;
886
887   caml_enter_blocking_section ();
888   r = guestfs_test0rstat (g, val);
889   caml_leave_blocking_section ();
890   if (r == NULL)
891     ocaml_guestfs_raise_error (g, "test0rstat");
892
893   rv = copy_stat (r);
894   free (r);
895   CAMLreturn (rv);
896 }
897
898 CAMLprim value
899 ocaml_guestfs_test0rstaterr (value gv)
900 {
901   CAMLparam1 (gv);
902   CAMLlocal1 (rv);
903
904   guestfs_h *g = Guestfs_val (gv);
905   if (g == NULL)
906     caml_failwith ("test0rstaterr: used handle after closing it");
907
908   struct guestfs_stat *r;
909
910   caml_enter_blocking_section ();
911   r = guestfs_test0rstaterr (g);
912   caml_leave_blocking_section ();
913   if (r == NULL)
914     ocaml_guestfs_raise_error (g, "test0rstaterr");
915
916   rv = copy_stat (r);
917   free (r);
918   CAMLreturn (rv);
919 }
920
921 CAMLprim value
922 ocaml_guestfs_test0rstatvfs (value gv, value valv)
923 {
924   CAMLparam2 (gv, valv);
925   CAMLlocal1 (rv);
926
927   guestfs_h *g = Guestfs_val (gv);
928   if (g == NULL)
929     caml_failwith ("test0rstatvfs: used handle after closing it");
930
931   const char *val = String_val (valv);
932   struct guestfs_statvfs *r;
933
934   caml_enter_blocking_section ();
935   r = guestfs_test0rstatvfs (g, val);
936   caml_leave_blocking_section ();
937   if (r == NULL)
938     ocaml_guestfs_raise_error (g, "test0rstatvfs");
939
940   rv = copy_statvfs (r);
941   free (r);
942   CAMLreturn (rv);
943 }
944
945 CAMLprim value
946 ocaml_guestfs_test0rstatvfserr (value gv)
947 {
948   CAMLparam1 (gv);
949   CAMLlocal1 (rv);
950
951   guestfs_h *g = Guestfs_val (gv);
952   if (g == NULL)
953     caml_failwith ("test0rstatvfserr: used handle after closing it");
954
955   struct guestfs_statvfs *r;
956
957   caml_enter_blocking_section ();
958   r = guestfs_test0rstatvfserr (g);
959   caml_leave_blocking_section ();
960   if (r == NULL)
961     ocaml_guestfs_raise_error (g, "test0rstatvfserr");
962
963   rv = copy_statvfs (r);
964   free (r);
965   CAMLreturn (rv);
966 }
967
968 CAMLprim value
969 ocaml_guestfs_test0rhashtable (value gv, value valv)
970 {
971   CAMLparam2 (gv, valv);
972   CAMLlocal1 (rv);
973
974   guestfs_h *g = Guestfs_val (gv);
975   if (g == NULL)
976     caml_failwith ("test0rhashtable: used handle after closing it");
977
978   const char *val = String_val (valv);
979   int i;
980   char **r;
981
982   caml_enter_blocking_section ();
983   r = guestfs_test0rhashtable (g, val);
984   caml_leave_blocking_section ();
985   if (r == NULL)
986     ocaml_guestfs_raise_error (g, "test0rhashtable");
987
988   rv = copy_table (r);
989   for (i = 0; r[i] != NULL; ++i) free (r[i]);
990   free (r);
991   CAMLreturn (rv);
992 }
993
994 CAMLprim value
995 ocaml_guestfs_test0rhashtableerr (value gv)
996 {
997   CAMLparam1 (gv);
998   CAMLlocal1 (rv);
999
1000   guestfs_h *g = Guestfs_val (gv);
1001   if (g == NULL)
1002     caml_failwith ("test0rhashtableerr: used handle after closing it");
1003
1004   int i;
1005   char **r;
1006
1007   caml_enter_blocking_section ();
1008   r = guestfs_test0rhashtableerr (g);
1009   caml_leave_blocking_section ();
1010   if (r == NULL)
1011     ocaml_guestfs_raise_error (g, "test0rhashtableerr");
1012
1013   rv = copy_table (r);
1014   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1015   free (r);
1016   CAMLreturn (rv);
1017 }
1018
1019 CAMLprim value
1020 ocaml_guestfs_launch (value gv)
1021 {
1022   CAMLparam1 (gv);
1023   CAMLlocal1 (rv);
1024
1025   guestfs_h *g = Guestfs_val (gv);
1026   if (g == NULL)
1027     caml_failwith ("launch: used handle after closing it");
1028
1029   int r;
1030
1031   caml_enter_blocking_section ();
1032   r = guestfs_launch (g);
1033   caml_leave_blocking_section ();
1034   if (r == -1)
1035     ocaml_guestfs_raise_error (g, "launch");
1036
1037   rv = Val_unit;
1038   CAMLreturn (rv);
1039 }
1040
1041 CAMLprim value
1042 ocaml_guestfs_wait_ready (value gv)
1043 {
1044   CAMLparam1 (gv);
1045   CAMLlocal1 (rv);
1046
1047   guestfs_h *g = Guestfs_val (gv);
1048   if (g == NULL)
1049     caml_failwith ("wait_ready: used handle after closing it");
1050
1051   int r;
1052
1053   caml_enter_blocking_section ();
1054   r = guestfs_wait_ready (g);
1055   caml_leave_blocking_section ();
1056   if (r == -1)
1057     ocaml_guestfs_raise_error (g, "wait_ready");
1058
1059   rv = Val_unit;
1060   CAMLreturn (rv);
1061 }
1062
1063 CAMLprim value
1064 ocaml_guestfs_kill_subprocess (value gv)
1065 {
1066   CAMLparam1 (gv);
1067   CAMLlocal1 (rv);
1068
1069   guestfs_h *g = Guestfs_val (gv);
1070   if (g == NULL)
1071     caml_failwith ("kill_subprocess: used handle after closing it");
1072
1073   int r;
1074
1075   caml_enter_blocking_section ();
1076   r = guestfs_kill_subprocess (g);
1077   caml_leave_blocking_section ();
1078   if (r == -1)
1079     ocaml_guestfs_raise_error (g, "kill_subprocess");
1080
1081   rv = Val_unit;
1082   CAMLreturn (rv);
1083 }
1084
1085 CAMLprim value
1086 ocaml_guestfs_add_drive (value gv, value filenamev)
1087 {
1088   CAMLparam2 (gv, filenamev);
1089   CAMLlocal1 (rv);
1090
1091   guestfs_h *g = Guestfs_val (gv);
1092   if (g == NULL)
1093     caml_failwith ("add_drive: used handle after closing it");
1094
1095   const char *filename = String_val (filenamev);
1096   int r;
1097
1098   caml_enter_blocking_section ();
1099   r = guestfs_add_drive (g, filename);
1100   caml_leave_blocking_section ();
1101   if (r == -1)
1102     ocaml_guestfs_raise_error (g, "add_drive");
1103
1104   rv = Val_unit;
1105   CAMLreturn (rv);
1106 }
1107
1108 CAMLprim value
1109 ocaml_guestfs_add_cdrom (value gv, value filenamev)
1110 {
1111   CAMLparam2 (gv, filenamev);
1112   CAMLlocal1 (rv);
1113
1114   guestfs_h *g = Guestfs_val (gv);
1115   if (g == NULL)
1116     caml_failwith ("add_cdrom: used handle after closing it");
1117
1118   const char *filename = String_val (filenamev);
1119   int r;
1120
1121   caml_enter_blocking_section ();
1122   r = guestfs_add_cdrom (g, filename);
1123   caml_leave_blocking_section ();
1124   if (r == -1)
1125     ocaml_guestfs_raise_error (g, "add_cdrom");
1126
1127   rv = Val_unit;
1128   CAMLreturn (rv);
1129 }
1130
1131 CAMLprim value
1132 ocaml_guestfs_add_drive_ro (value gv, value filenamev)
1133 {
1134   CAMLparam2 (gv, filenamev);
1135   CAMLlocal1 (rv);
1136
1137   guestfs_h *g = Guestfs_val (gv);
1138   if (g == NULL)
1139     caml_failwith ("add_drive_ro: used handle after closing it");
1140
1141   const char *filename = String_val (filenamev);
1142   int r;
1143
1144   caml_enter_blocking_section ();
1145   r = guestfs_add_drive_ro (g, filename);
1146   caml_leave_blocking_section ();
1147   if (r == -1)
1148     ocaml_guestfs_raise_error (g, "add_drive_ro");
1149
1150   rv = Val_unit;
1151   CAMLreturn (rv);
1152 }
1153
1154 CAMLprim value
1155 ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
1156 {
1157   CAMLparam3 (gv, qemuparamv, qemuvaluev);
1158   CAMLlocal1 (rv);
1159
1160   guestfs_h *g = Guestfs_val (gv);
1161   if (g == NULL)
1162     caml_failwith ("config: used handle after closing it");
1163
1164   const char *qemuparam = String_val (qemuparamv);
1165   const char *qemuvalue =
1166     qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
1167   int r;
1168
1169   caml_enter_blocking_section ();
1170   r = guestfs_config (g, qemuparam, qemuvalue);
1171   caml_leave_blocking_section ();
1172   if (r == -1)
1173     ocaml_guestfs_raise_error (g, "config");
1174
1175   rv = Val_unit;
1176   CAMLreturn (rv);
1177 }
1178
1179 CAMLprim value
1180 ocaml_guestfs_set_qemu (value gv, value qemuv)
1181 {
1182   CAMLparam2 (gv, qemuv);
1183   CAMLlocal1 (rv);
1184
1185   guestfs_h *g = Guestfs_val (gv);
1186   if (g == NULL)
1187     caml_failwith ("set_qemu: used handle after closing it");
1188
1189   const char *qemu = String_val (qemuv);
1190   int r;
1191
1192   caml_enter_blocking_section ();
1193   r = guestfs_set_qemu (g, qemu);
1194   caml_leave_blocking_section ();
1195   if (r == -1)
1196     ocaml_guestfs_raise_error (g, "set_qemu");
1197
1198   rv = Val_unit;
1199   CAMLreturn (rv);
1200 }
1201
1202 CAMLprim value
1203 ocaml_guestfs_get_qemu (value gv)
1204 {
1205   CAMLparam1 (gv);
1206   CAMLlocal1 (rv);
1207
1208   guestfs_h *g = Guestfs_val (gv);
1209   if (g == NULL)
1210     caml_failwith ("get_qemu: used handle after closing it");
1211
1212   const char *r;
1213
1214   caml_enter_blocking_section ();
1215   r = guestfs_get_qemu (g);
1216   caml_leave_blocking_section ();
1217   if (r == NULL)
1218     ocaml_guestfs_raise_error (g, "get_qemu");
1219
1220   rv = caml_copy_string (r);
1221   CAMLreturn (rv);
1222 }
1223
1224 CAMLprim value
1225 ocaml_guestfs_set_path (value gv, value pathv)
1226 {
1227   CAMLparam2 (gv, pathv);
1228   CAMLlocal1 (rv);
1229
1230   guestfs_h *g = Guestfs_val (gv);
1231   if (g == NULL)
1232     caml_failwith ("set_path: used handle after closing it");
1233
1234   const char *path = String_val (pathv);
1235   int r;
1236
1237   caml_enter_blocking_section ();
1238   r = guestfs_set_path (g, path);
1239   caml_leave_blocking_section ();
1240   if (r == -1)
1241     ocaml_guestfs_raise_error (g, "set_path");
1242
1243   rv = Val_unit;
1244   CAMLreturn (rv);
1245 }
1246
1247 CAMLprim value
1248 ocaml_guestfs_get_path (value gv)
1249 {
1250   CAMLparam1 (gv);
1251   CAMLlocal1 (rv);
1252
1253   guestfs_h *g = Guestfs_val (gv);
1254   if (g == NULL)
1255     caml_failwith ("get_path: used handle after closing it");
1256
1257   const char *r;
1258
1259   caml_enter_blocking_section ();
1260   r = guestfs_get_path (g);
1261   caml_leave_blocking_section ();
1262   if (r == NULL)
1263     ocaml_guestfs_raise_error (g, "get_path");
1264
1265   rv = caml_copy_string (r);
1266   CAMLreturn (rv);
1267 }
1268
1269 CAMLprim value
1270 ocaml_guestfs_set_append (value gv, value appendv)
1271 {
1272   CAMLparam2 (gv, appendv);
1273   CAMLlocal1 (rv);
1274
1275   guestfs_h *g = Guestfs_val (gv);
1276   if (g == NULL)
1277     caml_failwith ("set_append: used handle after closing it");
1278
1279   const char *append = String_val (appendv);
1280   int r;
1281
1282   caml_enter_blocking_section ();
1283   r = guestfs_set_append (g, append);
1284   caml_leave_blocking_section ();
1285   if (r == -1)
1286     ocaml_guestfs_raise_error (g, "set_append");
1287
1288   rv = Val_unit;
1289   CAMLreturn (rv);
1290 }
1291
1292 CAMLprim value
1293 ocaml_guestfs_get_append (value gv)
1294 {
1295   CAMLparam1 (gv);
1296   CAMLlocal1 (rv);
1297
1298   guestfs_h *g = Guestfs_val (gv);
1299   if (g == NULL)
1300     caml_failwith ("get_append: used handle after closing it");
1301
1302   const char *r;
1303
1304   caml_enter_blocking_section ();
1305   r = guestfs_get_append (g);
1306   caml_leave_blocking_section ();
1307   if (r == NULL)
1308     ocaml_guestfs_raise_error (g, "get_append");
1309
1310   rv = caml_copy_string (r);
1311   CAMLreturn (rv);
1312 }
1313
1314 CAMLprim value
1315 ocaml_guestfs_set_autosync (value gv, value autosyncv)
1316 {
1317   CAMLparam2 (gv, autosyncv);
1318   CAMLlocal1 (rv);
1319
1320   guestfs_h *g = Guestfs_val (gv);
1321   if (g == NULL)
1322     caml_failwith ("set_autosync: used handle after closing it");
1323
1324   int autosync = Bool_val (autosyncv);
1325   int r;
1326
1327   caml_enter_blocking_section ();
1328   r = guestfs_set_autosync (g, autosync);
1329   caml_leave_blocking_section ();
1330   if (r == -1)
1331     ocaml_guestfs_raise_error (g, "set_autosync");
1332
1333   rv = Val_unit;
1334   CAMLreturn (rv);
1335 }
1336
1337 CAMLprim value
1338 ocaml_guestfs_get_autosync (value gv)
1339 {
1340   CAMLparam1 (gv);
1341   CAMLlocal1 (rv);
1342
1343   guestfs_h *g = Guestfs_val (gv);
1344   if (g == NULL)
1345     caml_failwith ("get_autosync: used handle after closing it");
1346
1347   int r;
1348
1349   caml_enter_blocking_section ();
1350   r = guestfs_get_autosync (g);
1351   caml_leave_blocking_section ();
1352   if (r == -1)
1353     ocaml_guestfs_raise_error (g, "get_autosync");
1354
1355   rv = Val_bool (r);
1356   CAMLreturn (rv);
1357 }
1358
1359 CAMLprim value
1360 ocaml_guestfs_set_verbose (value gv, value verbosev)
1361 {
1362   CAMLparam2 (gv, verbosev);
1363   CAMLlocal1 (rv);
1364
1365   guestfs_h *g = Guestfs_val (gv);
1366   if (g == NULL)
1367     caml_failwith ("set_verbose: used handle after closing it");
1368
1369   int verbose = Bool_val (verbosev);
1370   int r;
1371
1372   caml_enter_blocking_section ();
1373   r = guestfs_set_verbose (g, verbose);
1374   caml_leave_blocking_section ();
1375   if (r == -1)
1376     ocaml_guestfs_raise_error (g, "set_verbose");
1377
1378   rv = Val_unit;
1379   CAMLreturn (rv);
1380 }
1381
1382 CAMLprim value
1383 ocaml_guestfs_get_verbose (value gv)
1384 {
1385   CAMLparam1 (gv);
1386   CAMLlocal1 (rv);
1387
1388   guestfs_h *g = Guestfs_val (gv);
1389   if (g == NULL)
1390     caml_failwith ("get_verbose: used handle after closing it");
1391
1392   int r;
1393
1394   caml_enter_blocking_section ();
1395   r = guestfs_get_verbose (g);
1396   caml_leave_blocking_section ();
1397   if (r == -1)
1398     ocaml_guestfs_raise_error (g, "get_verbose");
1399
1400   rv = Val_bool (r);
1401   CAMLreturn (rv);
1402 }
1403
1404 CAMLprim value
1405 ocaml_guestfs_is_ready (value gv)
1406 {
1407   CAMLparam1 (gv);
1408   CAMLlocal1 (rv);
1409
1410   guestfs_h *g = Guestfs_val (gv);
1411   if (g == NULL)
1412     caml_failwith ("is_ready: used handle after closing it");
1413
1414   int r;
1415
1416   caml_enter_blocking_section ();
1417   r = guestfs_is_ready (g);
1418   caml_leave_blocking_section ();
1419   if (r == -1)
1420     ocaml_guestfs_raise_error (g, "is_ready");
1421
1422   rv = Val_bool (r);
1423   CAMLreturn (rv);
1424 }
1425
1426 CAMLprim value
1427 ocaml_guestfs_is_config (value gv)
1428 {
1429   CAMLparam1 (gv);
1430   CAMLlocal1 (rv);
1431
1432   guestfs_h *g = Guestfs_val (gv);
1433   if (g == NULL)
1434     caml_failwith ("is_config: used handle after closing it");
1435
1436   int r;
1437
1438   caml_enter_blocking_section ();
1439   r = guestfs_is_config (g);
1440   caml_leave_blocking_section ();
1441   if (r == -1)
1442     ocaml_guestfs_raise_error (g, "is_config");
1443
1444   rv = Val_bool (r);
1445   CAMLreturn (rv);
1446 }
1447
1448 CAMLprim value
1449 ocaml_guestfs_is_launching (value gv)
1450 {
1451   CAMLparam1 (gv);
1452   CAMLlocal1 (rv);
1453
1454   guestfs_h *g = Guestfs_val (gv);
1455   if (g == NULL)
1456     caml_failwith ("is_launching: used handle after closing it");
1457
1458   int r;
1459
1460   caml_enter_blocking_section ();
1461   r = guestfs_is_launching (g);
1462   caml_leave_blocking_section ();
1463   if (r == -1)
1464     ocaml_guestfs_raise_error (g, "is_launching");
1465
1466   rv = Val_bool (r);
1467   CAMLreturn (rv);
1468 }
1469
1470 CAMLprim value
1471 ocaml_guestfs_is_busy (value gv)
1472 {
1473   CAMLparam1 (gv);
1474   CAMLlocal1 (rv);
1475
1476   guestfs_h *g = Guestfs_val (gv);
1477   if (g == NULL)
1478     caml_failwith ("is_busy: used handle after closing it");
1479
1480   int r;
1481
1482   caml_enter_blocking_section ();
1483   r = guestfs_is_busy (g);
1484   caml_leave_blocking_section ();
1485   if (r == -1)
1486     ocaml_guestfs_raise_error (g, "is_busy");
1487
1488   rv = Val_bool (r);
1489   CAMLreturn (rv);
1490 }
1491
1492 CAMLprim value
1493 ocaml_guestfs_get_state (value gv)
1494 {
1495   CAMLparam1 (gv);
1496   CAMLlocal1 (rv);
1497
1498   guestfs_h *g = Guestfs_val (gv);
1499   if (g == NULL)
1500     caml_failwith ("get_state: used handle after closing it");
1501
1502   int r;
1503
1504   caml_enter_blocking_section ();
1505   r = guestfs_get_state (g);
1506   caml_leave_blocking_section ();
1507   if (r == -1)
1508     ocaml_guestfs_raise_error (g, "get_state");
1509
1510   rv = Val_int (r);
1511   CAMLreturn (rv);
1512 }
1513
1514 CAMLprim value
1515 ocaml_guestfs_set_busy (value gv)
1516 {
1517   CAMLparam1 (gv);
1518   CAMLlocal1 (rv);
1519
1520   guestfs_h *g = Guestfs_val (gv);
1521   if (g == NULL)
1522     caml_failwith ("set_busy: used handle after closing it");
1523
1524   int r;
1525
1526   caml_enter_blocking_section ();
1527   r = guestfs_set_busy (g);
1528   caml_leave_blocking_section ();
1529   if (r == -1)
1530     ocaml_guestfs_raise_error (g, "set_busy");
1531
1532   rv = Val_unit;
1533   CAMLreturn (rv);
1534 }
1535
1536 CAMLprim value
1537 ocaml_guestfs_set_ready (value gv)
1538 {
1539   CAMLparam1 (gv);
1540   CAMLlocal1 (rv);
1541
1542   guestfs_h *g = Guestfs_val (gv);
1543   if (g == NULL)
1544     caml_failwith ("set_ready: used handle after closing it");
1545
1546   int r;
1547
1548   caml_enter_blocking_section ();
1549   r = guestfs_set_ready (g);
1550   caml_leave_blocking_section ();
1551   if (r == -1)
1552     ocaml_guestfs_raise_error (g, "set_ready");
1553
1554   rv = Val_unit;
1555   CAMLreturn (rv);
1556 }
1557
1558 CAMLprim value
1559 ocaml_guestfs_end_busy (value gv)
1560 {
1561   CAMLparam1 (gv);
1562   CAMLlocal1 (rv);
1563
1564   guestfs_h *g = Guestfs_val (gv);
1565   if (g == NULL)
1566     caml_failwith ("end_busy: used handle after closing it");
1567
1568   int r;
1569
1570   caml_enter_blocking_section ();
1571   r = guestfs_end_busy (g);
1572   caml_leave_blocking_section ();
1573   if (r == -1)
1574     ocaml_guestfs_raise_error (g, "end_busy");
1575
1576   rv = Val_unit;
1577   CAMLreturn (rv);
1578 }
1579
1580 CAMLprim value
1581 ocaml_guestfs_set_memsize (value gv, value memsizev)
1582 {
1583   CAMLparam2 (gv, memsizev);
1584   CAMLlocal1 (rv);
1585
1586   guestfs_h *g = Guestfs_val (gv);
1587   if (g == NULL)
1588     caml_failwith ("set_memsize: used handle after closing it");
1589
1590   int memsize = Int_val (memsizev);
1591   int r;
1592
1593   caml_enter_blocking_section ();
1594   r = guestfs_set_memsize (g, memsize);
1595   caml_leave_blocking_section ();
1596   if (r == -1)
1597     ocaml_guestfs_raise_error (g, "set_memsize");
1598
1599   rv = Val_unit;
1600   CAMLreturn (rv);
1601 }
1602
1603 CAMLprim value
1604 ocaml_guestfs_get_memsize (value gv)
1605 {
1606   CAMLparam1 (gv);
1607   CAMLlocal1 (rv);
1608
1609   guestfs_h *g = Guestfs_val (gv);
1610   if (g == NULL)
1611     caml_failwith ("get_memsize: used handle after closing it");
1612
1613   int r;
1614
1615   caml_enter_blocking_section ();
1616   r = guestfs_get_memsize (g);
1617   caml_leave_blocking_section ();
1618   if (r == -1)
1619     ocaml_guestfs_raise_error (g, "get_memsize");
1620
1621   rv = Val_int (r);
1622   CAMLreturn (rv);
1623 }
1624
1625 CAMLprim value
1626 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
1627 {
1628   CAMLparam3 (gv, devicev, mountpointv);
1629   CAMLlocal1 (rv);
1630
1631   guestfs_h *g = Guestfs_val (gv);
1632   if (g == NULL)
1633     caml_failwith ("mount: used handle after closing it");
1634
1635   const char *device = String_val (devicev);
1636   const char *mountpoint = String_val (mountpointv);
1637   int r;
1638
1639   caml_enter_blocking_section ();
1640   r = guestfs_mount (g, device, mountpoint);
1641   caml_leave_blocking_section ();
1642   if (r == -1)
1643     ocaml_guestfs_raise_error (g, "mount");
1644
1645   rv = Val_unit;
1646   CAMLreturn (rv);
1647 }
1648
1649 CAMLprim value
1650 ocaml_guestfs_sync (value gv)
1651 {
1652   CAMLparam1 (gv);
1653   CAMLlocal1 (rv);
1654
1655   guestfs_h *g = Guestfs_val (gv);
1656   if (g == NULL)
1657     caml_failwith ("sync: used handle after closing it");
1658
1659   int r;
1660
1661   caml_enter_blocking_section ();
1662   r = guestfs_sync (g);
1663   caml_leave_blocking_section ();
1664   if (r == -1)
1665     ocaml_guestfs_raise_error (g, "sync");
1666
1667   rv = Val_unit;
1668   CAMLreturn (rv);
1669 }
1670
1671 CAMLprim value
1672 ocaml_guestfs_touch (value gv, value pathv)
1673 {
1674   CAMLparam2 (gv, pathv);
1675   CAMLlocal1 (rv);
1676
1677   guestfs_h *g = Guestfs_val (gv);
1678   if (g == NULL)
1679     caml_failwith ("touch: used handle after closing it");
1680
1681   const char *path = String_val (pathv);
1682   int r;
1683
1684   caml_enter_blocking_section ();
1685   r = guestfs_touch (g, path);
1686   caml_leave_blocking_section ();
1687   if (r == -1)
1688     ocaml_guestfs_raise_error (g, "touch");
1689
1690   rv = Val_unit;
1691   CAMLreturn (rv);
1692 }
1693
1694 CAMLprim value
1695 ocaml_guestfs_cat (value gv, value pathv)
1696 {
1697   CAMLparam2 (gv, pathv);
1698   CAMLlocal1 (rv);
1699
1700   guestfs_h *g = Guestfs_val (gv);
1701   if (g == NULL)
1702     caml_failwith ("cat: used handle after closing it");
1703
1704   const char *path = String_val (pathv);
1705   char *r;
1706
1707   caml_enter_blocking_section ();
1708   r = guestfs_cat (g, path);
1709   caml_leave_blocking_section ();
1710   if (r == NULL)
1711     ocaml_guestfs_raise_error (g, "cat");
1712
1713   rv = caml_copy_string (r);
1714   free (r);
1715   CAMLreturn (rv);
1716 }
1717
1718 CAMLprim value
1719 ocaml_guestfs_ll (value gv, value directoryv)
1720 {
1721   CAMLparam2 (gv, directoryv);
1722   CAMLlocal1 (rv);
1723
1724   guestfs_h *g = Guestfs_val (gv);
1725   if (g == NULL)
1726     caml_failwith ("ll: used handle after closing it");
1727
1728   const char *directory = String_val (directoryv);
1729   char *r;
1730
1731   caml_enter_blocking_section ();
1732   r = guestfs_ll (g, directory);
1733   caml_leave_blocking_section ();
1734   if (r == NULL)
1735     ocaml_guestfs_raise_error (g, "ll");
1736
1737   rv = caml_copy_string (r);
1738   free (r);
1739   CAMLreturn (rv);
1740 }
1741
1742 CAMLprim value
1743 ocaml_guestfs_ls (value gv, value directoryv)
1744 {
1745   CAMLparam2 (gv, directoryv);
1746   CAMLlocal1 (rv);
1747
1748   guestfs_h *g = Guestfs_val (gv);
1749   if (g == NULL)
1750     caml_failwith ("ls: used handle after closing it");
1751
1752   const char *directory = String_val (directoryv);
1753   int i;
1754   char **r;
1755
1756   caml_enter_blocking_section ();
1757   r = guestfs_ls (g, directory);
1758   caml_leave_blocking_section ();
1759   if (r == NULL)
1760     ocaml_guestfs_raise_error (g, "ls");
1761
1762   rv = caml_copy_string_array ((const char **) r);
1763   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1764   free (r);
1765   CAMLreturn (rv);
1766 }
1767
1768 CAMLprim value
1769 ocaml_guestfs_list_devices (value gv)
1770 {
1771   CAMLparam1 (gv);
1772   CAMLlocal1 (rv);
1773
1774   guestfs_h *g = Guestfs_val (gv);
1775   if (g == NULL)
1776     caml_failwith ("list_devices: used handle after closing it");
1777
1778   int i;
1779   char **r;
1780
1781   caml_enter_blocking_section ();
1782   r = guestfs_list_devices (g);
1783   caml_leave_blocking_section ();
1784   if (r == NULL)
1785     ocaml_guestfs_raise_error (g, "list_devices");
1786
1787   rv = caml_copy_string_array ((const char **) r);
1788   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1789   free (r);
1790   CAMLreturn (rv);
1791 }
1792
1793 CAMLprim value
1794 ocaml_guestfs_list_partitions (value gv)
1795 {
1796   CAMLparam1 (gv);
1797   CAMLlocal1 (rv);
1798
1799   guestfs_h *g = Guestfs_val (gv);
1800   if (g == NULL)
1801     caml_failwith ("list_partitions: used handle after closing it");
1802
1803   int i;
1804   char **r;
1805
1806   caml_enter_blocking_section ();
1807   r = guestfs_list_partitions (g);
1808   caml_leave_blocking_section ();
1809   if (r == NULL)
1810     ocaml_guestfs_raise_error (g, "list_partitions");
1811
1812   rv = caml_copy_string_array ((const char **) r);
1813   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1814   free (r);
1815   CAMLreturn (rv);
1816 }
1817
1818 CAMLprim value
1819 ocaml_guestfs_pvs (value gv)
1820 {
1821   CAMLparam1 (gv);
1822   CAMLlocal1 (rv);
1823
1824   guestfs_h *g = Guestfs_val (gv);
1825   if (g == NULL)
1826     caml_failwith ("pvs: used handle after closing it");
1827
1828   int i;
1829   char **r;
1830
1831   caml_enter_blocking_section ();
1832   r = guestfs_pvs (g);
1833   caml_leave_blocking_section ();
1834   if (r == NULL)
1835     ocaml_guestfs_raise_error (g, "pvs");
1836
1837   rv = caml_copy_string_array ((const char **) r);
1838   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1839   free (r);
1840   CAMLreturn (rv);
1841 }
1842
1843 CAMLprim value
1844 ocaml_guestfs_vgs (value gv)
1845 {
1846   CAMLparam1 (gv);
1847   CAMLlocal1 (rv);
1848
1849   guestfs_h *g = Guestfs_val (gv);
1850   if (g == NULL)
1851     caml_failwith ("vgs: used handle after closing it");
1852
1853   int i;
1854   char **r;
1855
1856   caml_enter_blocking_section ();
1857   r = guestfs_vgs (g);
1858   caml_leave_blocking_section ();
1859   if (r == NULL)
1860     ocaml_guestfs_raise_error (g, "vgs");
1861
1862   rv = caml_copy_string_array ((const char **) r);
1863   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1864   free (r);
1865   CAMLreturn (rv);
1866 }
1867
1868 CAMLprim value
1869 ocaml_guestfs_lvs (value gv)
1870 {
1871   CAMLparam1 (gv);
1872   CAMLlocal1 (rv);
1873
1874   guestfs_h *g = Guestfs_val (gv);
1875   if (g == NULL)
1876     caml_failwith ("lvs: used handle after closing it");
1877
1878   int i;
1879   char **r;
1880
1881   caml_enter_blocking_section ();
1882   r = guestfs_lvs (g);
1883   caml_leave_blocking_section ();
1884   if (r == NULL)
1885     ocaml_guestfs_raise_error (g, "lvs");
1886
1887   rv = caml_copy_string_array ((const char **) r);
1888   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1889   free (r);
1890   CAMLreturn (rv);
1891 }
1892
1893 CAMLprim value
1894 ocaml_guestfs_pvs_full (value gv)
1895 {
1896   CAMLparam1 (gv);
1897   CAMLlocal1 (rv);
1898
1899   guestfs_h *g = Guestfs_val (gv);
1900   if (g == NULL)
1901     caml_failwith ("pvs_full: used handle after closing it");
1902
1903   struct guestfs_lvm_pv_list *r;
1904
1905   caml_enter_blocking_section ();
1906   r = guestfs_pvs_full (g);
1907   caml_leave_blocking_section ();
1908   if (r == NULL)
1909     ocaml_guestfs_raise_error (g, "pvs_full");
1910
1911   rv = copy_lvm_pv_list (r);
1912   guestfs_free_lvm_pv_list (r);
1913   CAMLreturn (rv);
1914 }
1915
1916 CAMLprim value
1917 ocaml_guestfs_vgs_full (value gv)
1918 {
1919   CAMLparam1 (gv);
1920   CAMLlocal1 (rv);
1921
1922   guestfs_h *g = Guestfs_val (gv);
1923   if (g == NULL)
1924     caml_failwith ("vgs_full: used handle after closing it");
1925
1926   struct guestfs_lvm_vg_list *r;
1927
1928   caml_enter_blocking_section ();
1929   r = guestfs_vgs_full (g);
1930   caml_leave_blocking_section ();
1931   if (r == NULL)
1932     ocaml_guestfs_raise_error (g, "vgs_full");
1933
1934   rv = copy_lvm_vg_list (r);
1935   guestfs_free_lvm_vg_list (r);
1936   CAMLreturn (rv);
1937 }
1938
1939 CAMLprim value
1940 ocaml_guestfs_lvs_full (value gv)
1941 {
1942   CAMLparam1 (gv);
1943   CAMLlocal1 (rv);
1944
1945   guestfs_h *g = Guestfs_val (gv);
1946   if (g == NULL)
1947     caml_failwith ("lvs_full: used handle after closing it");
1948
1949   struct guestfs_lvm_lv_list *r;
1950
1951   caml_enter_blocking_section ();
1952   r = guestfs_lvs_full (g);
1953   caml_leave_blocking_section ();
1954   if (r == NULL)
1955     ocaml_guestfs_raise_error (g, "lvs_full");
1956
1957   rv = copy_lvm_lv_list (r);
1958   guestfs_free_lvm_lv_list (r);
1959   CAMLreturn (rv);
1960 }
1961
1962 CAMLprim value
1963 ocaml_guestfs_read_lines (value gv, value pathv)
1964 {
1965   CAMLparam2 (gv, pathv);
1966   CAMLlocal1 (rv);
1967
1968   guestfs_h *g = Guestfs_val (gv);
1969   if (g == NULL)
1970     caml_failwith ("read_lines: used handle after closing it");
1971
1972   const char *path = String_val (pathv);
1973   int i;
1974   char **r;
1975
1976   caml_enter_blocking_section ();
1977   r = guestfs_read_lines (g, path);
1978   caml_leave_blocking_section ();
1979   if (r == NULL)
1980     ocaml_guestfs_raise_error (g, "read_lines");
1981
1982   rv = caml_copy_string_array ((const char **) r);
1983   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1984   free (r);
1985   CAMLreturn (rv);
1986 }
1987
1988 CAMLprim value
1989 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
1990 {
1991   CAMLparam3 (gv, rootv, flagsv);
1992   CAMLlocal1 (rv);
1993
1994   guestfs_h *g = Guestfs_val (gv);
1995   if (g == NULL)
1996     caml_failwith ("aug_init: used handle after closing it");
1997
1998   const char *root = String_val (rootv);
1999   int flags = Int_val (flagsv);
2000   int r;
2001
2002   caml_enter_blocking_section ();
2003   r = guestfs_aug_init (g, root, flags);
2004   caml_leave_blocking_section ();
2005   if (r == -1)
2006     ocaml_guestfs_raise_error (g, "aug_init");
2007
2008   rv = Val_unit;
2009   CAMLreturn (rv);
2010 }
2011
2012 CAMLprim value
2013 ocaml_guestfs_aug_close (value gv)
2014 {
2015   CAMLparam1 (gv);
2016   CAMLlocal1 (rv);
2017
2018   guestfs_h *g = Guestfs_val (gv);
2019   if (g == NULL)
2020     caml_failwith ("aug_close: used handle after closing it");
2021
2022   int r;
2023
2024   caml_enter_blocking_section ();
2025   r = guestfs_aug_close (g);
2026   caml_leave_blocking_section ();
2027   if (r == -1)
2028     ocaml_guestfs_raise_error (g, "aug_close");
2029
2030   rv = Val_unit;
2031   CAMLreturn (rv);
2032 }
2033
2034 CAMLprim value
2035 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
2036 {
2037   CAMLparam3 (gv, namev, exprv);
2038   CAMLlocal1 (rv);
2039
2040   guestfs_h *g = Guestfs_val (gv);
2041   if (g == NULL)
2042     caml_failwith ("aug_defvar: used handle after closing it");
2043
2044   const char *name = String_val (namev);
2045   const char *expr =
2046     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
2047   int r;
2048
2049   caml_enter_blocking_section ();
2050   r = guestfs_aug_defvar (g, name, expr);
2051   caml_leave_blocking_section ();
2052   if (r == -1)
2053     ocaml_guestfs_raise_error (g, "aug_defvar");
2054
2055   rv = Val_int (r);
2056   CAMLreturn (rv);
2057 }
2058
2059 CAMLprim value
2060 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
2061 {
2062   CAMLparam4 (gv, namev, exprv, valv);
2063   CAMLlocal1 (rv);
2064
2065   guestfs_h *g = Guestfs_val (gv);
2066   if (g == NULL)
2067     caml_failwith ("aug_defnode: used handle after closing it");
2068
2069   const char *name = String_val (namev);
2070   const char *expr = String_val (exprv);
2071   const char *val = String_val (valv);
2072   struct guestfs_int_bool *r;
2073
2074   caml_enter_blocking_section ();
2075   r = guestfs_aug_defnode (g, name, expr, val);
2076   caml_leave_blocking_section ();
2077   if (r == NULL)
2078     ocaml_guestfs_raise_error (g, "aug_defnode");
2079
2080   rv = caml_alloc (2, 0);
2081   Store_field (rv, 0, Val_int (r->i));
2082   Store_field (rv, 1, Val_bool (r->b));
2083   guestfs_free_int_bool (r);
2084   CAMLreturn (rv);
2085 }
2086
2087 CAMLprim value
2088 ocaml_guestfs_aug_get (value gv, value pathv)
2089 {
2090   CAMLparam2 (gv, pathv);
2091   CAMLlocal1 (rv);
2092
2093   guestfs_h *g = Guestfs_val (gv);
2094   if (g == NULL)
2095     caml_failwith ("aug_get: used handle after closing it");
2096
2097   const char *path = String_val (pathv);
2098   char *r;
2099
2100   caml_enter_blocking_section ();
2101   r = guestfs_aug_get (g, path);
2102   caml_leave_blocking_section ();
2103   if (r == NULL)
2104     ocaml_guestfs_raise_error (g, "aug_get");
2105
2106   rv = caml_copy_string (r);
2107   free (r);
2108   CAMLreturn (rv);
2109 }
2110
2111 CAMLprim value
2112 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
2113 {
2114   CAMLparam3 (gv, pathv, valv);
2115   CAMLlocal1 (rv);
2116
2117   guestfs_h *g = Guestfs_val (gv);
2118   if (g == NULL)
2119     caml_failwith ("aug_set: used handle after closing it");
2120
2121   const char *path = String_val (pathv);
2122   const char *val = String_val (valv);
2123   int r;
2124
2125   caml_enter_blocking_section ();
2126   r = guestfs_aug_set (g, path, val);
2127   caml_leave_blocking_section ();
2128   if (r == -1)
2129     ocaml_guestfs_raise_error (g, "aug_set");
2130
2131   rv = Val_unit;
2132   CAMLreturn (rv);
2133 }
2134
2135 CAMLprim value
2136 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
2137 {
2138   CAMLparam4 (gv, pathv, labelv, beforev);
2139   CAMLlocal1 (rv);
2140
2141   guestfs_h *g = Guestfs_val (gv);
2142   if (g == NULL)
2143     caml_failwith ("aug_insert: used handle after closing it");
2144
2145   const char *path = String_val (pathv);
2146   const char *label = String_val (labelv);
2147   int before = Bool_val (beforev);
2148   int r;
2149
2150   caml_enter_blocking_section ();
2151   r = guestfs_aug_insert (g, path, label, before);
2152   caml_leave_blocking_section ();
2153   if (r == -1)
2154     ocaml_guestfs_raise_error (g, "aug_insert");
2155
2156   rv = Val_unit;
2157   CAMLreturn (rv);
2158 }
2159
2160 CAMLprim value
2161 ocaml_guestfs_aug_rm (value gv, value pathv)
2162 {
2163   CAMLparam2 (gv, pathv);
2164   CAMLlocal1 (rv);
2165
2166   guestfs_h *g = Guestfs_val (gv);
2167   if (g == NULL)
2168     caml_failwith ("aug_rm: used handle after closing it");
2169
2170   const char *path = String_val (pathv);
2171   int r;
2172
2173   caml_enter_blocking_section ();
2174   r = guestfs_aug_rm (g, path);
2175   caml_leave_blocking_section ();
2176   if (r == -1)
2177     ocaml_guestfs_raise_error (g, "aug_rm");
2178
2179   rv = Val_int (r);
2180   CAMLreturn (rv);
2181 }
2182
2183 CAMLprim value
2184 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
2185 {
2186   CAMLparam3 (gv, srcv, destv);
2187   CAMLlocal1 (rv);
2188
2189   guestfs_h *g = Guestfs_val (gv);
2190   if (g == NULL)
2191     caml_failwith ("aug_mv: used handle after closing it");
2192
2193   const char *src = String_val (srcv);
2194   const char *dest = String_val (destv);
2195   int r;
2196
2197   caml_enter_blocking_section ();
2198   r = guestfs_aug_mv (g, src, dest);
2199   caml_leave_blocking_section ();
2200   if (r == -1)
2201     ocaml_guestfs_raise_error (g, "aug_mv");
2202
2203   rv = Val_unit;
2204   CAMLreturn (rv);
2205 }
2206
2207 CAMLprim value
2208 ocaml_guestfs_aug_match (value gv, value pathv)
2209 {
2210   CAMLparam2 (gv, pathv);
2211   CAMLlocal1 (rv);
2212
2213   guestfs_h *g = Guestfs_val (gv);
2214   if (g == NULL)
2215     caml_failwith ("aug_match: used handle after closing it");
2216
2217   const char *path = String_val (pathv);
2218   int i;
2219   char **r;
2220
2221   caml_enter_blocking_section ();
2222   r = guestfs_aug_match (g, path);
2223   caml_leave_blocking_section ();
2224   if (r == NULL)
2225     ocaml_guestfs_raise_error (g, "aug_match");
2226
2227   rv = caml_copy_string_array ((const char **) r);
2228   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2229   free (r);
2230   CAMLreturn (rv);
2231 }
2232
2233 CAMLprim value
2234 ocaml_guestfs_aug_save (value gv)
2235 {
2236   CAMLparam1 (gv);
2237   CAMLlocal1 (rv);
2238
2239   guestfs_h *g = Guestfs_val (gv);
2240   if (g == NULL)
2241     caml_failwith ("aug_save: used handle after closing it");
2242
2243   int r;
2244
2245   caml_enter_blocking_section ();
2246   r = guestfs_aug_save (g);
2247   caml_leave_blocking_section ();
2248   if (r == -1)
2249     ocaml_guestfs_raise_error (g, "aug_save");
2250
2251   rv = Val_unit;
2252   CAMLreturn (rv);
2253 }
2254
2255 CAMLprim value
2256 ocaml_guestfs_aug_load (value gv)
2257 {
2258   CAMLparam1 (gv);
2259   CAMLlocal1 (rv);
2260
2261   guestfs_h *g = Guestfs_val (gv);
2262   if (g == NULL)
2263     caml_failwith ("aug_load: used handle after closing it");
2264
2265   int r;
2266
2267   caml_enter_blocking_section ();
2268   r = guestfs_aug_load (g);
2269   caml_leave_blocking_section ();
2270   if (r == -1)
2271     ocaml_guestfs_raise_error (g, "aug_load");
2272
2273   rv = Val_unit;
2274   CAMLreturn (rv);
2275 }
2276
2277 CAMLprim value
2278 ocaml_guestfs_aug_ls (value gv, value pathv)
2279 {
2280   CAMLparam2 (gv, pathv);
2281   CAMLlocal1 (rv);
2282
2283   guestfs_h *g = Guestfs_val (gv);
2284   if (g == NULL)
2285     caml_failwith ("aug_ls: used handle after closing it");
2286
2287   const char *path = String_val (pathv);
2288   int i;
2289   char **r;
2290
2291   caml_enter_blocking_section ();
2292   r = guestfs_aug_ls (g, path);
2293   caml_leave_blocking_section ();
2294   if (r == NULL)
2295     ocaml_guestfs_raise_error (g, "aug_ls");
2296
2297   rv = caml_copy_string_array ((const char **) r);
2298   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2299   free (r);
2300   CAMLreturn (rv);
2301 }
2302
2303 CAMLprim value
2304 ocaml_guestfs_rm (value gv, value pathv)
2305 {
2306   CAMLparam2 (gv, pathv);
2307   CAMLlocal1 (rv);
2308
2309   guestfs_h *g = Guestfs_val (gv);
2310   if (g == NULL)
2311     caml_failwith ("rm: used handle after closing it");
2312
2313   const char *path = String_val (pathv);
2314   int r;
2315
2316   caml_enter_blocking_section ();
2317   r = guestfs_rm (g, path);
2318   caml_leave_blocking_section ();
2319   if (r == -1)
2320     ocaml_guestfs_raise_error (g, "rm");
2321
2322   rv = Val_unit;
2323   CAMLreturn (rv);
2324 }
2325
2326 CAMLprim value
2327 ocaml_guestfs_rmdir (value gv, value pathv)
2328 {
2329   CAMLparam2 (gv, pathv);
2330   CAMLlocal1 (rv);
2331
2332   guestfs_h *g = Guestfs_val (gv);
2333   if (g == NULL)
2334     caml_failwith ("rmdir: used handle after closing it");
2335
2336   const char *path = String_val (pathv);
2337   int r;
2338
2339   caml_enter_blocking_section ();
2340   r = guestfs_rmdir (g, path);
2341   caml_leave_blocking_section ();
2342   if (r == -1)
2343     ocaml_guestfs_raise_error (g, "rmdir");
2344
2345   rv = Val_unit;
2346   CAMLreturn (rv);
2347 }
2348
2349 CAMLprim value
2350 ocaml_guestfs_rm_rf (value gv, value pathv)
2351 {
2352   CAMLparam2 (gv, pathv);
2353   CAMLlocal1 (rv);
2354
2355   guestfs_h *g = Guestfs_val (gv);
2356   if (g == NULL)
2357     caml_failwith ("rm_rf: used handle after closing it");
2358
2359   const char *path = String_val (pathv);
2360   int r;
2361
2362   caml_enter_blocking_section ();
2363   r = guestfs_rm_rf (g, path);
2364   caml_leave_blocking_section ();
2365   if (r == -1)
2366     ocaml_guestfs_raise_error (g, "rm_rf");
2367
2368   rv = Val_unit;
2369   CAMLreturn (rv);
2370 }
2371
2372 CAMLprim value
2373 ocaml_guestfs_mkdir (value gv, value pathv)
2374 {
2375   CAMLparam2 (gv, pathv);
2376   CAMLlocal1 (rv);
2377
2378   guestfs_h *g = Guestfs_val (gv);
2379   if (g == NULL)
2380     caml_failwith ("mkdir: used handle after closing it");
2381
2382   const char *path = String_val (pathv);
2383   int r;
2384
2385   caml_enter_blocking_section ();
2386   r = guestfs_mkdir (g, path);
2387   caml_leave_blocking_section ();
2388   if (r == -1)
2389     ocaml_guestfs_raise_error (g, "mkdir");
2390
2391   rv = Val_unit;
2392   CAMLreturn (rv);
2393 }
2394
2395 CAMLprim value
2396 ocaml_guestfs_mkdir_p (value gv, value pathv)
2397 {
2398   CAMLparam2 (gv, pathv);
2399   CAMLlocal1 (rv);
2400
2401   guestfs_h *g = Guestfs_val (gv);
2402   if (g == NULL)
2403     caml_failwith ("mkdir_p: used handle after closing it");
2404
2405   const char *path = String_val (pathv);
2406   int r;
2407
2408   caml_enter_blocking_section ();
2409   r = guestfs_mkdir_p (g, path);
2410   caml_leave_blocking_section ();
2411   if (r == -1)
2412     ocaml_guestfs_raise_error (g, "mkdir_p");
2413
2414   rv = Val_unit;
2415   CAMLreturn (rv);
2416 }
2417
2418 CAMLprim value
2419 ocaml_guestfs_chmod (value gv, value modev, value pathv)
2420 {
2421   CAMLparam3 (gv, modev, pathv);
2422   CAMLlocal1 (rv);
2423
2424   guestfs_h *g = Guestfs_val (gv);
2425   if (g == NULL)
2426     caml_failwith ("chmod: used handle after closing it");
2427
2428   int mode = Int_val (modev);
2429   const char *path = String_val (pathv);
2430   int r;
2431
2432   caml_enter_blocking_section ();
2433   r = guestfs_chmod (g, mode, path);
2434   caml_leave_blocking_section ();
2435   if (r == -1)
2436     ocaml_guestfs_raise_error (g, "chmod");
2437
2438   rv = Val_unit;
2439   CAMLreturn (rv);
2440 }
2441
2442 CAMLprim value
2443 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
2444 {
2445   CAMLparam4 (gv, ownerv, groupv, pathv);
2446   CAMLlocal1 (rv);
2447
2448   guestfs_h *g = Guestfs_val (gv);
2449   if (g == NULL)
2450     caml_failwith ("chown: used handle after closing it");
2451
2452   int owner = Int_val (ownerv);
2453   int group = Int_val (groupv);
2454   const char *path = String_val (pathv);
2455   int r;
2456
2457   caml_enter_blocking_section ();
2458   r = guestfs_chown (g, owner, group, path);
2459   caml_leave_blocking_section ();
2460   if (r == -1)
2461     ocaml_guestfs_raise_error (g, "chown");
2462
2463   rv = Val_unit;
2464   CAMLreturn (rv);
2465 }
2466
2467 CAMLprim value
2468 ocaml_guestfs_exists (value gv, value pathv)
2469 {
2470   CAMLparam2 (gv, pathv);
2471   CAMLlocal1 (rv);
2472
2473   guestfs_h *g = Guestfs_val (gv);
2474   if (g == NULL)
2475     caml_failwith ("exists: used handle after closing it");
2476
2477   const char *path = String_val (pathv);
2478   int r;
2479
2480   caml_enter_blocking_section ();
2481   r = guestfs_exists (g, path);
2482   caml_leave_blocking_section ();
2483   if (r == -1)
2484     ocaml_guestfs_raise_error (g, "exists");
2485
2486   rv = Val_bool (r);
2487   CAMLreturn (rv);
2488 }
2489
2490 CAMLprim value
2491 ocaml_guestfs_is_file (value gv, value pathv)
2492 {
2493   CAMLparam2 (gv, pathv);
2494   CAMLlocal1 (rv);
2495
2496   guestfs_h *g = Guestfs_val (gv);
2497   if (g == NULL)
2498     caml_failwith ("is_file: used handle after closing it");
2499
2500   const char *path = String_val (pathv);
2501   int r;
2502
2503   caml_enter_blocking_section ();
2504   r = guestfs_is_file (g, path);
2505   caml_leave_blocking_section ();
2506   if (r == -1)
2507     ocaml_guestfs_raise_error (g, "is_file");
2508
2509   rv = Val_bool (r);
2510   CAMLreturn (rv);
2511 }
2512
2513 CAMLprim value
2514 ocaml_guestfs_is_dir (value gv, value pathv)
2515 {
2516   CAMLparam2 (gv, pathv);
2517   CAMLlocal1 (rv);
2518
2519   guestfs_h *g = Guestfs_val (gv);
2520   if (g == NULL)
2521     caml_failwith ("is_dir: used handle after closing it");
2522
2523   const char *path = String_val (pathv);
2524   int r;
2525
2526   caml_enter_blocking_section ();
2527   r = guestfs_is_dir (g, path);
2528   caml_leave_blocking_section ();
2529   if (r == -1)
2530     ocaml_guestfs_raise_error (g, "is_dir");
2531
2532   rv = Val_bool (r);
2533   CAMLreturn (rv);
2534 }
2535
2536 CAMLprim value
2537 ocaml_guestfs_pvcreate (value gv, value devicev)
2538 {
2539   CAMLparam2 (gv, devicev);
2540   CAMLlocal1 (rv);
2541
2542   guestfs_h *g = Guestfs_val (gv);
2543   if (g == NULL)
2544     caml_failwith ("pvcreate: used handle after closing it");
2545
2546   const char *device = String_val (devicev);
2547   int r;
2548
2549   caml_enter_blocking_section ();
2550   r = guestfs_pvcreate (g, device);
2551   caml_leave_blocking_section ();
2552   if (r == -1)
2553     ocaml_guestfs_raise_error (g, "pvcreate");
2554
2555   rv = Val_unit;
2556   CAMLreturn (rv);
2557 }
2558
2559 CAMLprim value
2560 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
2561 {
2562   CAMLparam3 (gv, volgroupv, physvolsv);
2563   CAMLlocal1 (rv);
2564
2565   guestfs_h *g = Guestfs_val (gv);
2566   if (g == NULL)
2567     caml_failwith ("vgcreate: used handle after closing it");
2568
2569   const char *volgroup = String_val (volgroupv);
2570   char **physvols = ocaml_guestfs_strings_val (g, physvolsv);
2571   int r;
2572
2573   caml_enter_blocking_section ();
2574   r = guestfs_vgcreate (g, volgroup, physvols);
2575   caml_leave_blocking_section ();
2576   ocaml_guestfs_free_strings (physvols);
2577   if (r == -1)
2578     ocaml_guestfs_raise_error (g, "vgcreate");
2579
2580   rv = Val_unit;
2581   CAMLreturn (rv);
2582 }
2583
2584 CAMLprim value
2585 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
2586 {
2587   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
2588   CAMLlocal1 (rv);
2589
2590   guestfs_h *g = Guestfs_val (gv);
2591   if (g == NULL)
2592     caml_failwith ("lvcreate: used handle after closing it");
2593
2594   const char *logvol = String_val (logvolv);
2595   const char *volgroup = String_val (volgroupv);
2596   int mbytes = Int_val (mbytesv);
2597   int r;
2598
2599   caml_enter_blocking_section ();
2600   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
2601   caml_leave_blocking_section ();
2602   if (r == -1)
2603     ocaml_guestfs_raise_error (g, "lvcreate");
2604
2605   rv = Val_unit;
2606   CAMLreturn (rv);
2607 }
2608
2609 CAMLprim value
2610 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
2611 {
2612   CAMLparam3 (gv, fstypev, devicev);
2613   CAMLlocal1 (rv);
2614
2615   guestfs_h *g = Guestfs_val (gv);
2616   if (g == NULL)
2617     caml_failwith ("mkfs: used handle after closing it");
2618
2619   const char *fstype = String_val (fstypev);
2620   const char *device = String_val (devicev);
2621   int r;
2622
2623   caml_enter_blocking_section ();
2624   r = guestfs_mkfs (g, fstype, device);
2625   caml_leave_blocking_section ();
2626   if (r == -1)
2627     ocaml_guestfs_raise_error (g, "mkfs");
2628
2629   rv = Val_unit;
2630   CAMLreturn (rv);
2631 }
2632
2633 CAMLprim value
2634 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
2635 {
2636   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
2637   CAMLxparam1 (linesv);
2638   CAMLlocal1 (rv);
2639
2640   guestfs_h *g = Guestfs_val (gv);
2641   if (g == NULL)
2642     caml_failwith ("sfdisk: used handle after closing it");
2643
2644   const char *device = String_val (devicev);
2645   int cyls = Int_val (cylsv);
2646   int heads = Int_val (headsv);
2647   int sectors = Int_val (sectorsv);
2648   char **lines = ocaml_guestfs_strings_val (g, linesv);
2649   int r;
2650
2651   caml_enter_blocking_section ();
2652   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
2653   caml_leave_blocking_section ();
2654   ocaml_guestfs_free_strings (lines);
2655   if (r == -1)
2656     ocaml_guestfs_raise_error (g, "sfdisk");
2657
2658   rv = Val_unit;
2659   CAMLreturn (rv);
2660 }
2661
2662 CAMLprim value
2663 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
2664 {
2665   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
2666 }
2667
2668 CAMLprim value
2669 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
2670 {
2671   CAMLparam4 (gv, pathv, contentv, sizev);
2672   CAMLlocal1 (rv);
2673
2674   guestfs_h *g = Guestfs_val (gv);
2675   if (g == NULL)
2676     caml_failwith ("write_file: used handle after closing it");
2677
2678   const char *path = String_val (pathv);
2679   const char *content = String_val (contentv);
2680   int size = Int_val (sizev);
2681   int r;
2682
2683   caml_enter_blocking_section ();
2684   r = guestfs_write_file (g, path, content, size);
2685   caml_leave_blocking_section ();
2686   if (r == -1)
2687     ocaml_guestfs_raise_error (g, "write_file");
2688
2689   rv = Val_unit;
2690   CAMLreturn (rv);
2691 }
2692
2693 CAMLprim value
2694 ocaml_guestfs_umount (value gv, value pathordevicev)
2695 {
2696   CAMLparam2 (gv, pathordevicev);
2697   CAMLlocal1 (rv);
2698
2699   guestfs_h *g = Guestfs_val (gv);
2700   if (g == NULL)
2701     caml_failwith ("umount: used handle after closing it");
2702
2703   const char *pathordevice = String_val (pathordevicev);
2704   int r;
2705
2706   caml_enter_blocking_section ();
2707   r = guestfs_umount (g, pathordevice);
2708   caml_leave_blocking_section ();
2709   if (r == -1)
2710     ocaml_guestfs_raise_error (g, "umount");
2711
2712   rv = Val_unit;
2713   CAMLreturn (rv);
2714 }
2715
2716 CAMLprim value
2717 ocaml_guestfs_mounts (value gv)
2718 {
2719   CAMLparam1 (gv);
2720   CAMLlocal1 (rv);
2721
2722   guestfs_h *g = Guestfs_val (gv);
2723   if (g == NULL)
2724     caml_failwith ("mounts: used handle after closing it");
2725
2726   int i;
2727   char **r;
2728
2729   caml_enter_blocking_section ();
2730   r = guestfs_mounts (g);
2731   caml_leave_blocking_section ();
2732   if (r == NULL)
2733     ocaml_guestfs_raise_error (g, "mounts");
2734
2735   rv = caml_copy_string_array ((const char **) r);
2736   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2737   free (r);
2738   CAMLreturn (rv);
2739 }
2740
2741 CAMLprim value
2742 ocaml_guestfs_umount_all (value gv)
2743 {
2744   CAMLparam1 (gv);
2745   CAMLlocal1 (rv);
2746
2747   guestfs_h *g = Guestfs_val (gv);
2748   if (g == NULL)
2749     caml_failwith ("umount_all: used handle after closing it");
2750
2751   int r;
2752
2753   caml_enter_blocking_section ();
2754   r = guestfs_umount_all (g);
2755   caml_leave_blocking_section ();
2756   if (r == -1)
2757     ocaml_guestfs_raise_error (g, "umount_all");
2758
2759   rv = Val_unit;
2760   CAMLreturn (rv);
2761 }
2762
2763 CAMLprim value
2764 ocaml_guestfs_lvm_remove_all (value gv)
2765 {
2766   CAMLparam1 (gv);
2767   CAMLlocal1 (rv);
2768
2769   guestfs_h *g = Guestfs_val (gv);
2770   if (g == NULL)
2771     caml_failwith ("lvm_remove_all: used handle after closing it");
2772
2773   int r;
2774
2775   caml_enter_blocking_section ();
2776   r = guestfs_lvm_remove_all (g);
2777   caml_leave_blocking_section ();
2778   if (r == -1)
2779     ocaml_guestfs_raise_error (g, "lvm_remove_all");
2780
2781   rv = Val_unit;
2782   CAMLreturn (rv);
2783 }
2784
2785 CAMLprim value
2786 ocaml_guestfs_file (value gv, value pathv)
2787 {
2788   CAMLparam2 (gv, pathv);
2789   CAMLlocal1 (rv);
2790
2791   guestfs_h *g = Guestfs_val (gv);
2792   if (g == NULL)
2793     caml_failwith ("file: used handle after closing it");
2794
2795   const char *path = String_val (pathv);
2796   char *r;
2797
2798   caml_enter_blocking_section ();
2799   r = guestfs_file (g, path);
2800   caml_leave_blocking_section ();
2801   if (r == NULL)
2802     ocaml_guestfs_raise_error (g, "file");
2803
2804   rv = caml_copy_string (r);
2805   free (r);
2806   CAMLreturn (rv);
2807 }
2808
2809 CAMLprim value
2810 ocaml_guestfs_command (value gv, value argumentsv)
2811 {
2812   CAMLparam2 (gv, argumentsv);
2813   CAMLlocal1 (rv);
2814
2815   guestfs_h *g = Guestfs_val (gv);
2816   if (g == NULL)
2817     caml_failwith ("command: used handle after closing it");
2818
2819   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2820   char *r;
2821
2822   caml_enter_blocking_section ();
2823   r = guestfs_command (g, arguments);
2824   caml_leave_blocking_section ();
2825   ocaml_guestfs_free_strings (arguments);
2826   if (r == NULL)
2827     ocaml_guestfs_raise_error (g, "command");
2828
2829   rv = caml_copy_string (r);
2830   free (r);
2831   CAMLreturn (rv);
2832 }
2833
2834 CAMLprim value
2835 ocaml_guestfs_command_lines (value gv, value argumentsv)
2836 {
2837   CAMLparam2 (gv, argumentsv);
2838   CAMLlocal1 (rv);
2839
2840   guestfs_h *g = Guestfs_val (gv);
2841   if (g == NULL)
2842     caml_failwith ("command_lines: used handle after closing it");
2843
2844   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2845   int i;
2846   char **r;
2847
2848   caml_enter_blocking_section ();
2849   r = guestfs_command_lines (g, arguments);
2850   caml_leave_blocking_section ();
2851   ocaml_guestfs_free_strings (arguments);
2852   if (r == NULL)
2853     ocaml_guestfs_raise_error (g, "command_lines");
2854
2855   rv = caml_copy_string_array ((const char **) r);
2856   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2857   free (r);
2858   CAMLreturn (rv);
2859 }
2860
2861 CAMLprim value
2862 ocaml_guestfs_stat (value gv, value pathv)
2863 {
2864   CAMLparam2 (gv, pathv);
2865   CAMLlocal1 (rv);
2866
2867   guestfs_h *g = Guestfs_val (gv);
2868   if (g == NULL)
2869     caml_failwith ("stat: used handle after closing it");
2870
2871   const char *path = String_val (pathv);
2872   struct guestfs_stat *r;
2873
2874   caml_enter_blocking_section ();
2875   r = guestfs_stat (g, path);
2876   caml_leave_blocking_section ();
2877   if (r == NULL)
2878     ocaml_guestfs_raise_error (g, "stat");
2879
2880   rv = copy_stat (r);
2881   free (r);
2882   CAMLreturn (rv);
2883 }
2884
2885 CAMLprim value
2886 ocaml_guestfs_lstat (value gv, value pathv)
2887 {
2888   CAMLparam2 (gv, pathv);
2889   CAMLlocal1 (rv);
2890
2891   guestfs_h *g = Guestfs_val (gv);
2892   if (g == NULL)
2893     caml_failwith ("lstat: used handle after closing it");
2894
2895   const char *path = String_val (pathv);
2896   struct guestfs_stat *r;
2897
2898   caml_enter_blocking_section ();
2899   r = guestfs_lstat (g, path);
2900   caml_leave_blocking_section ();
2901   if (r == NULL)
2902     ocaml_guestfs_raise_error (g, "lstat");
2903
2904   rv = copy_stat (r);
2905   free (r);
2906   CAMLreturn (rv);
2907 }
2908
2909 CAMLprim value
2910 ocaml_guestfs_statvfs (value gv, value pathv)
2911 {
2912   CAMLparam2 (gv, pathv);
2913   CAMLlocal1 (rv);
2914
2915   guestfs_h *g = Guestfs_val (gv);
2916   if (g == NULL)
2917     caml_failwith ("statvfs: used handle after closing it");
2918
2919   const char *path = String_val (pathv);
2920   struct guestfs_statvfs *r;
2921
2922   caml_enter_blocking_section ();
2923   r = guestfs_statvfs (g, path);
2924   caml_leave_blocking_section ();
2925   if (r == NULL)
2926     ocaml_guestfs_raise_error (g, "statvfs");
2927
2928   rv = copy_statvfs (r);
2929   free (r);
2930   CAMLreturn (rv);
2931 }
2932
2933 CAMLprim value
2934 ocaml_guestfs_tune2fs_l (value gv, value devicev)
2935 {
2936   CAMLparam2 (gv, devicev);
2937   CAMLlocal1 (rv);
2938
2939   guestfs_h *g = Guestfs_val (gv);
2940   if (g == NULL)
2941     caml_failwith ("tune2fs_l: used handle after closing it");
2942
2943   const char *device = String_val (devicev);
2944   int i;
2945   char **r;
2946
2947   caml_enter_blocking_section ();
2948   r = guestfs_tune2fs_l (g, device);
2949   caml_leave_blocking_section ();
2950   if (r == NULL)
2951     ocaml_guestfs_raise_error (g, "tune2fs_l");
2952
2953   rv = copy_table (r);
2954   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2955   free (r);
2956   CAMLreturn (rv);
2957 }
2958
2959 CAMLprim value
2960 ocaml_guestfs_blockdev_setro (value gv, value devicev)
2961 {
2962   CAMLparam2 (gv, devicev);
2963   CAMLlocal1 (rv);
2964
2965   guestfs_h *g = Guestfs_val (gv);
2966   if (g == NULL)
2967     caml_failwith ("blockdev_setro: used handle after closing it");
2968
2969   const char *device = String_val (devicev);
2970   int r;
2971
2972   caml_enter_blocking_section ();
2973   r = guestfs_blockdev_setro (g, device);
2974   caml_leave_blocking_section ();
2975   if (r == -1)
2976     ocaml_guestfs_raise_error (g, "blockdev_setro");
2977
2978   rv = Val_unit;
2979   CAMLreturn (rv);
2980 }
2981
2982 CAMLprim value
2983 ocaml_guestfs_blockdev_setrw (value gv, value devicev)
2984 {
2985   CAMLparam2 (gv, devicev);
2986   CAMLlocal1 (rv);
2987
2988   guestfs_h *g = Guestfs_val (gv);
2989   if (g == NULL)
2990     caml_failwith ("blockdev_setrw: used handle after closing it");
2991
2992   const char *device = String_val (devicev);
2993   int r;
2994
2995   caml_enter_blocking_section ();
2996   r = guestfs_blockdev_setrw (g, device);
2997   caml_leave_blocking_section ();
2998   if (r == -1)
2999     ocaml_guestfs_raise_error (g, "blockdev_setrw");
3000
3001   rv = Val_unit;
3002   CAMLreturn (rv);
3003 }
3004
3005 CAMLprim value
3006 ocaml_guestfs_blockdev_getro (value gv, value devicev)
3007 {
3008   CAMLparam2 (gv, devicev);
3009   CAMLlocal1 (rv);
3010
3011   guestfs_h *g = Guestfs_val (gv);
3012   if (g == NULL)
3013     caml_failwith ("blockdev_getro: used handle after closing it");
3014
3015   const char *device = String_val (devicev);
3016   int r;
3017
3018   caml_enter_blocking_section ();
3019   r = guestfs_blockdev_getro (g, device);
3020   caml_leave_blocking_section ();
3021   if (r == -1)
3022     ocaml_guestfs_raise_error (g, "blockdev_getro");
3023
3024   rv = Val_bool (r);
3025   CAMLreturn (rv);
3026 }
3027
3028 CAMLprim value
3029 ocaml_guestfs_blockdev_getss (value gv, value devicev)
3030 {
3031   CAMLparam2 (gv, devicev);
3032   CAMLlocal1 (rv);
3033
3034   guestfs_h *g = Guestfs_val (gv);
3035   if (g == NULL)
3036     caml_failwith ("blockdev_getss: used handle after closing it");
3037
3038   const char *device = String_val (devicev);
3039   int r;
3040
3041   caml_enter_blocking_section ();
3042   r = guestfs_blockdev_getss (g, device);
3043   caml_leave_blocking_section ();
3044   if (r == -1)
3045     ocaml_guestfs_raise_error (g, "blockdev_getss");
3046
3047   rv = Val_int (r);
3048   CAMLreturn (rv);
3049 }
3050
3051 CAMLprim value
3052 ocaml_guestfs_blockdev_getbsz (value gv, value devicev)
3053 {
3054   CAMLparam2 (gv, devicev);
3055   CAMLlocal1 (rv);
3056
3057   guestfs_h *g = Guestfs_val (gv);
3058   if (g == NULL)
3059     caml_failwith ("blockdev_getbsz: used handle after closing it");
3060
3061   const char *device = String_val (devicev);
3062   int r;
3063
3064   caml_enter_blocking_section ();
3065   r = guestfs_blockdev_getbsz (g, device);
3066   caml_leave_blocking_section ();
3067   if (r == -1)
3068     ocaml_guestfs_raise_error (g, "blockdev_getbsz");
3069
3070   rv = Val_int (r);
3071   CAMLreturn (rv);
3072 }
3073
3074 CAMLprim value
3075 ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev)
3076 {
3077   CAMLparam3 (gv, devicev, blocksizev);
3078   CAMLlocal1 (rv);
3079
3080   guestfs_h *g = Guestfs_val (gv);
3081   if (g == NULL)
3082     caml_failwith ("blockdev_setbsz: used handle after closing it");
3083
3084   const char *device = String_val (devicev);
3085   int blocksize = Int_val (blocksizev);
3086   int r;
3087
3088   caml_enter_blocking_section ();
3089   r = guestfs_blockdev_setbsz (g, device, blocksize);
3090   caml_leave_blocking_section ();
3091   if (r == -1)
3092     ocaml_guestfs_raise_error (g, "blockdev_setbsz");
3093
3094   rv = Val_unit;
3095   CAMLreturn (rv);
3096 }
3097
3098 CAMLprim value
3099 ocaml_guestfs_blockdev_getsz (value gv, value devicev)
3100 {
3101   CAMLparam2 (gv, devicev);
3102   CAMLlocal1 (rv);
3103
3104   guestfs_h *g = Guestfs_val (gv);
3105   if (g == NULL)
3106     caml_failwith ("blockdev_getsz: used handle after closing it");
3107
3108   const char *device = String_val (devicev);
3109   int64_t r;
3110
3111   caml_enter_blocking_section ();
3112   r = guestfs_blockdev_getsz (g, device);
3113   caml_leave_blocking_section ();
3114   if (r == -1)
3115     ocaml_guestfs_raise_error (g, "blockdev_getsz");
3116
3117   rv = caml_copy_int64 (r);
3118   CAMLreturn (rv);
3119 }
3120
3121 CAMLprim value
3122 ocaml_guestfs_blockdev_getsize64 (value gv, value devicev)
3123 {
3124   CAMLparam2 (gv, devicev);
3125   CAMLlocal1 (rv);
3126
3127   guestfs_h *g = Guestfs_val (gv);
3128   if (g == NULL)
3129     caml_failwith ("blockdev_getsize64: used handle after closing it");
3130
3131   const char *device = String_val (devicev);
3132   int64_t r;
3133
3134   caml_enter_blocking_section ();
3135   r = guestfs_blockdev_getsize64 (g, device);
3136   caml_leave_blocking_section ();
3137   if (r == -1)
3138     ocaml_guestfs_raise_error (g, "blockdev_getsize64");
3139
3140   rv = caml_copy_int64 (r);
3141   CAMLreturn (rv);
3142 }
3143
3144 CAMLprim value
3145 ocaml_guestfs_blockdev_flushbufs (value gv, value devicev)
3146 {
3147   CAMLparam2 (gv, devicev);
3148   CAMLlocal1 (rv);
3149
3150   guestfs_h *g = Guestfs_val (gv);
3151   if (g == NULL)
3152     caml_failwith ("blockdev_flushbufs: used handle after closing it");
3153
3154   const char *device = String_val (devicev);
3155   int r;
3156
3157   caml_enter_blocking_section ();
3158   r = guestfs_blockdev_flushbufs (g, device);
3159   caml_leave_blocking_section ();
3160   if (r == -1)
3161     ocaml_guestfs_raise_error (g, "blockdev_flushbufs");
3162
3163   rv = Val_unit;
3164   CAMLreturn (rv);
3165 }
3166
3167 CAMLprim value
3168 ocaml_guestfs_blockdev_rereadpt (value gv, value devicev)
3169 {
3170   CAMLparam2 (gv, devicev);
3171   CAMLlocal1 (rv);
3172
3173   guestfs_h *g = Guestfs_val (gv);
3174   if (g == NULL)
3175     caml_failwith ("blockdev_rereadpt: used handle after closing it");
3176
3177   const char *device = String_val (devicev);
3178   int r;
3179
3180   caml_enter_blocking_section ();
3181   r = guestfs_blockdev_rereadpt (g, device);
3182   caml_leave_blocking_section ();
3183   if (r == -1)
3184     ocaml_guestfs_raise_error (g, "blockdev_rereadpt");
3185
3186   rv = Val_unit;
3187   CAMLreturn (rv);
3188 }
3189
3190 CAMLprim value
3191 ocaml_guestfs_upload (value gv, value filenamev, value remotefilenamev)
3192 {
3193   CAMLparam3 (gv, filenamev, remotefilenamev);
3194   CAMLlocal1 (rv);
3195
3196   guestfs_h *g = Guestfs_val (gv);
3197   if (g == NULL)
3198     caml_failwith ("upload: used handle after closing it");
3199
3200   const char *filename = String_val (filenamev);
3201   const char *remotefilename = String_val (remotefilenamev);
3202   int r;
3203
3204   caml_enter_blocking_section ();
3205   r = guestfs_upload (g, filename, remotefilename);
3206   caml_leave_blocking_section ();
3207   if (r == -1)
3208     ocaml_guestfs_raise_error (g, "upload");
3209
3210   rv = Val_unit;
3211   CAMLreturn (rv);
3212 }
3213
3214 CAMLprim value
3215 ocaml_guestfs_download (value gv, value remotefilenamev, value filenamev)
3216 {
3217   CAMLparam3 (gv, remotefilenamev, filenamev);
3218   CAMLlocal1 (rv);
3219
3220   guestfs_h *g = Guestfs_val (gv);
3221   if (g == NULL)
3222     caml_failwith ("download: used handle after closing it");
3223
3224   const char *remotefilename = String_val (remotefilenamev);
3225   const char *filename = String_val (filenamev);
3226   int r;
3227
3228   caml_enter_blocking_section ();
3229   r = guestfs_download (g, remotefilename, filename);
3230   caml_leave_blocking_section ();
3231   if (r == -1)
3232     ocaml_guestfs_raise_error (g, "download");
3233
3234   rv = Val_unit;
3235   CAMLreturn (rv);
3236 }
3237
3238 CAMLprim value
3239 ocaml_guestfs_checksum (value gv, value csumtypev, value pathv)
3240 {
3241   CAMLparam3 (gv, csumtypev, pathv);
3242   CAMLlocal1 (rv);
3243
3244   guestfs_h *g = Guestfs_val (gv);
3245   if (g == NULL)
3246     caml_failwith ("checksum: used handle after closing it");
3247
3248   const char *csumtype = String_val (csumtypev);
3249   const char *path = String_val (pathv);
3250   char *r;
3251
3252   caml_enter_blocking_section ();
3253   r = guestfs_checksum (g, csumtype, path);
3254   caml_leave_blocking_section ();
3255   if (r == NULL)
3256     ocaml_guestfs_raise_error (g, "checksum");
3257
3258   rv = caml_copy_string (r);
3259   free (r);
3260   CAMLreturn (rv);
3261 }
3262
3263 CAMLprim value
3264 ocaml_guestfs_tar_in (value gv, value tarfilev, value directoryv)
3265 {
3266   CAMLparam3 (gv, tarfilev, directoryv);
3267   CAMLlocal1 (rv);
3268
3269   guestfs_h *g = Guestfs_val (gv);
3270   if (g == NULL)
3271     caml_failwith ("tar_in: used handle after closing it");
3272
3273   const char *tarfile = String_val (tarfilev);
3274   const char *directory = String_val (directoryv);
3275   int r;
3276
3277   caml_enter_blocking_section ();
3278   r = guestfs_tar_in (g, tarfile, directory);
3279   caml_leave_blocking_section ();
3280   if (r == -1)
3281     ocaml_guestfs_raise_error (g, "tar_in");
3282
3283   rv = Val_unit;
3284   CAMLreturn (rv);
3285 }
3286
3287 CAMLprim value
3288 ocaml_guestfs_tar_out (value gv, value directoryv, value tarfilev)
3289 {
3290   CAMLparam3 (gv, directoryv, tarfilev);
3291   CAMLlocal1 (rv);
3292
3293   guestfs_h *g = Guestfs_val (gv);
3294   if (g == NULL)
3295     caml_failwith ("tar_out: used handle after closing it");
3296
3297   const char *directory = String_val (directoryv);
3298   const char *tarfile = String_val (tarfilev);
3299   int r;
3300
3301   caml_enter_blocking_section ();
3302   r = guestfs_tar_out (g, directory, tarfile);
3303   caml_leave_blocking_section ();
3304   if (r == -1)
3305     ocaml_guestfs_raise_error (g, "tar_out");
3306
3307   rv = Val_unit;
3308   CAMLreturn (rv);
3309 }
3310
3311 CAMLprim value
3312 ocaml_guestfs_tgz_in (value gv, value tarballv, value directoryv)
3313 {
3314   CAMLparam3 (gv, tarballv, directoryv);
3315   CAMLlocal1 (rv);
3316
3317   guestfs_h *g = Guestfs_val (gv);
3318   if (g == NULL)
3319     caml_failwith ("tgz_in: used handle after closing it");
3320
3321   const char *tarball = String_val (tarballv);
3322   const char *directory = String_val (directoryv);
3323   int r;
3324
3325   caml_enter_blocking_section ();
3326   r = guestfs_tgz_in (g, tarball, directory);
3327   caml_leave_blocking_section ();
3328   if (r == -1)
3329     ocaml_guestfs_raise_error (g, "tgz_in");
3330
3331   rv = Val_unit;
3332   CAMLreturn (rv);
3333 }
3334
3335 CAMLprim value
3336 ocaml_guestfs_tgz_out (value gv, value directoryv, value tarballv)
3337 {
3338   CAMLparam3 (gv, directoryv, tarballv);
3339   CAMLlocal1 (rv);
3340
3341   guestfs_h *g = Guestfs_val (gv);
3342   if (g == NULL)
3343     caml_failwith ("tgz_out: used handle after closing it");
3344
3345   const char *directory = String_val (directoryv);
3346   const char *tarball = String_val (tarballv);
3347   int r;
3348
3349   caml_enter_blocking_section ();
3350   r = guestfs_tgz_out (g, directory, tarball);
3351   caml_leave_blocking_section ();
3352   if (r == -1)
3353     ocaml_guestfs_raise_error (g, "tgz_out");
3354
3355   rv = Val_unit;
3356   CAMLreturn (rv);
3357 }
3358
3359 CAMLprim value
3360 ocaml_guestfs_mount_ro (value gv, value devicev, value mountpointv)
3361 {
3362   CAMLparam3 (gv, devicev, mountpointv);
3363   CAMLlocal1 (rv);
3364
3365   guestfs_h *g = Guestfs_val (gv);
3366   if (g == NULL)
3367     caml_failwith ("mount_ro: used handle after closing it");
3368
3369   const char *device = String_val (devicev);
3370   const char *mountpoint = String_val (mountpointv);
3371   int r;
3372
3373   caml_enter_blocking_section ();
3374   r = guestfs_mount_ro (g, device, mountpoint);
3375   caml_leave_blocking_section ();
3376   if (r == -1)
3377     ocaml_guestfs_raise_error (g, "mount_ro");
3378
3379   rv = Val_unit;
3380   CAMLreturn (rv);
3381 }
3382
3383 CAMLprim value
3384 ocaml_guestfs_mount_options (value gv, value optionsv, value devicev, value mountpointv)
3385 {
3386   CAMLparam4 (gv, optionsv, devicev, mountpointv);
3387   CAMLlocal1 (rv);
3388
3389   guestfs_h *g = Guestfs_val (gv);
3390   if (g == NULL)
3391     caml_failwith ("mount_options: used handle after closing it");
3392
3393   const char *options = String_val (optionsv);
3394   const char *device = String_val (devicev);
3395   const char *mountpoint = String_val (mountpointv);
3396   int r;
3397
3398   caml_enter_blocking_section ();
3399   r = guestfs_mount_options (g, options, device, mountpoint);
3400   caml_leave_blocking_section ();
3401   if (r == -1)
3402     ocaml_guestfs_raise_error (g, "mount_options");
3403
3404   rv = Val_unit;
3405   CAMLreturn (rv);
3406 }
3407
3408 CAMLprim value
3409 ocaml_guestfs_mount_vfs (value gv, value optionsv, value vfstypev, value devicev, value mountpointv)
3410 {
3411   CAMLparam5 (gv, optionsv, vfstypev, devicev, mountpointv);
3412   CAMLlocal1 (rv);
3413
3414   guestfs_h *g = Guestfs_val (gv);
3415   if (g == NULL)
3416     caml_failwith ("mount_vfs: used handle after closing it");
3417
3418   const char *options = String_val (optionsv);
3419   const char *vfstype = String_val (vfstypev);
3420   const char *device = String_val (devicev);
3421   const char *mountpoint = String_val (mountpointv);
3422   int r;
3423
3424   caml_enter_blocking_section ();
3425   r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
3426   caml_leave_blocking_section ();
3427   if (r == -1)
3428     ocaml_guestfs_raise_error (g, "mount_vfs");
3429
3430   rv = Val_unit;
3431   CAMLreturn (rv);
3432 }
3433
3434 CAMLprim value
3435 ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
3436 {
3437   CAMLparam3 (gv, subcmdv, extraargsv);
3438   CAMLlocal1 (rv);
3439
3440   guestfs_h *g = Guestfs_val (gv);
3441   if (g == NULL)
3442     caml_failwith ("debug: used handle after closing it");
3443
3444   const char *subcmd = String_val (subcmdv);
3445   char **extraargs = ocaml_guestfs_strings_val (g, extraargsv);
3446   char *r;
3447
3448   caml_enter_blocking_section ();
3449   r = guestfs_debug (g, subcmd, extraargs);
3450   caml_leave_blocking_section ();
3451   ocaml_guestfs_free_strings (extraargs);
3452   if (r == NULL)
3453     ocaml_guestfs_raise_error (g, "debug");
3454
3455   rv = caml_copy_string (r);
3456   free (r);
3457   CAMLreturn (rv);
3458 }
3459
3460 CAMLprim value
3461 ocaml_guestfs_lvremove (value gv, value devicev)
3462 {
3463   CAMLparam2 (gv, devicev);
3464   CAMLlocal1 (rv);
3465
3466   guestfs_h *g = Guestfs_val (gv);
3467   if (g == NULL)
3468     caml_failwith ("lvremove: used handle after closing it");
3469
3470   const char *device = String_val (devicev);
3471   int r;
3472
3473   caml_enter_blocking_section ();
3474   r = guestfs_lvremove (g, device);
3475   caml_leave_blocking_section ();
3476   if (r == -1)
3477     ocaml_guestfs_raise_error (g, "lvremove");
3478
3479   rv = Val_unit;
3480   CAMLreturn (rv);
3481 }
3482
3483 CAMLprim value
3484 ocaml_guestfs_vgremove (value gv, value vgnamev)
3485 {
3486   CAMLparam2 (gv, vgnamev);
3487   CAMLlocal1 (rv);
3488
3489   guestfs_h *g = Guestfs_val (gv);
3490   if (g == NULL)
3491     caml_failwith ("vgremove: used handle after closing it");
3492
3493   const char *vgname = String_val (vgnamev);
3494   int r;
3495
3496   caml_enter_blocking_section ();
3497   r = guestfs_vgremove (g, vgname);
3498   caml_leave_blocking_section ();
3499   if (r == -1)
3500     ocaml_guestfs_raise_error (g, "vgremove");
3501
3502   rv = Val_unit;
3503   CAMLreturn (rv);
3504 }
3505
3506 CAMLprim value
3507 ocaml_guestfs_pvremove (value gv, value devicev)
3508 {
3509   CAMLparam2 (gv, devicev);
3510   CAMLlocal1 (rv);
3511
3512   guestfs_h *g = Guestfs_val (gv);
3513   if (g == NULL)
3514     caml_failwith ("pvremove: used handle after closing it");
3515
3516   const char *device = String_val (devicev);
3517   int r;
3518
3519   caml_enter_blocking_section ();
3520   r = guestfs_pvremove (g, device);
3521   caml_leave_blocking_section ();
3522   if (r == -1)
3523     ocaml_guestfs_raise_error (g, "pvremove");
3524
3525   rv = Val_unit;
3526   CAMLreturn (rv);
3527 }
3528
3529 CAMLprim value
3530 ocaml_guestfs_set_e2label (value gv, value devicev, value labelv)
3531 {
3532   CAMLparam3 (gv, devicev, labelv);
3533   CAMLlocal1 (rv);
3534
3535   guestfs_h *g = Guestfs_val (gv);
3536   if (g == NULL)
3537     caml_failwith ("set_e2label: used handle after closing it");
3538
3539   const char *device = String_val (devicev);
3540   const char *label = String_val (labelv);
3541   int r;
3542
3543   caml_enter_blocking_section ();
3544   r = guestfs_set_e2label (g, device, label);
3545   caml_leave_blocking_section ();
3546   if (r == -1)
3547     ocaml_guestfs_raise_error (g, "set_e2label");
3548
3549   rv = Val_unit;
3550   CAMLreturn (rv);
3551 }
3552
3553 CAMLprim value
3554 ocaml_guestfs_get_e2label (value gv, value devicev)
3555 {
3556   CAMLparam2 (gv, devicev);
3557   CAMLlocal1 (rv);
3558
3559   guestfs_h *g = Guestfs_val (gv);
3560   if (g == NULL)
3561     caml_failwith ("get_e2label: used handle after closing it");
3562
3563   const char *device = String_val (devicev);
3564   char *r;
3565
3566   caml_enter_blocking_section ();
3567   r = guestfs_get_e2label (g, device);
3568   caml_leave_blocking_section ();
3569   if (r == NULL)
3570     ocaml_guestfs_raise_error (g, "get_e2label");
3571
3572   rv = caml_copy_string (r);
3573   free (r);
3574   CAMLreturn (rv);
3575 }
3576
3577 CAMLprim value
3578 ocaml_guestfs_set_e2uuid (value gv, value devicev, value uuidv)
3579 {
3580   CAMLparam3 (gv, devicev, uuidv);
3581   CAMLlocal1 (rv);
3582
3583   guestfs_h *g = Guestfs_val (gv);
3584   if (g == NULL)
3585     caml_failwith ("set_e2uuid: used handle after closing it");
3586
3587   const char *device = String_val (devicev);
3588   const char *uuid = String_val (uuidv);
3589   int r;
3590
3591   caml_enter_blocking_section ();
3592   r = guestfs_set_e2uuid (g, device, uuid);
3593   caml_leave_blocking_section ();
3594   if (r == -1)
3595     ocaml_guestfs_raise_error (g, "set_e2uuid");
3596
3597   rv = Val_unit;
3598   CAMLreturn (rv);
3599 }
3600
3601 CAMLprim value
3602 ocaml_guestfs_get_e2uuid (value gv, value devicev)
3603 {
3604   CAMLparam2 (gv, devicev);
3605   CAMLlocal1 (rv);
3606
3607   guestfs_h *g = Guestfs_val (gv);
3608   if (g == NULL)
3609     caml_failwith ("get_e2uuid: used handle after closing it");
3610
3611   const char *device = String_val (devicev);
3612   char *r;
3613
3614   caml_enter_blocking_section ();
3615   r = guestfs_get_e2uuid (g, device);
3616   caml_leave_blocking_section ();
3617   if (r == NULL)
3618     ocaml_guestfs_raise_error (g, "get_e2uuid");
3619
3620   rv = caml_copy_string (r);
3621   free (r);
3622   CAMLreturn (rv);
3623 }
3624
3625 CAMLprim value
3626 ocaml_guestfs_fsck (value gv, value fstypev, value devicev)
3627 {
3628   CAMLparam3 (gv, fstypev, devicev);
3629   CAMLlocal1 (rv);
3630
3631   guestfs_h *g = Guestfs_val (gv);
3632   if (g == NULL)
3633     caml_failwith ("fsck: used handle after closing it");
3634
3635   const char *fstype = String_val (fstypev);
3636   const char *device = String_val (devicev);
3637   int r;
3638
3639   caml_enter_blocking_section ();
3640   r = guestfs_fsck (g, fstype, device);
3641   caml_leave_blocking_section ();
3642   if (r == -1)
3643     ocaml_guestfs_raise_error (g, "fsck");
3644
3645   rv = Val_int (r);
3646   CAMLreturn (rv);
3647 }
3648
3649 CAMLprim value
3650 ocaml_guestfs_zero (value gv, value devicev)
3651 {
3652   CAMLparam2 (gv, devicev);
3653   CAMLlocal1 (rv);
3654
3655   guestfs_h *g = Guestfs_val (gv);
3656   if (g == NULL)
3657     caml_failwith ("zero: used handle after closing it");
3658
3659   const char *device = String_val (devicev);
3660   int r;
3661
3662   caml_enter_blocking_section ();
3663   r = guestfs_zero (g, device);
3664   caml_leave_blocking_section ();
3665   if (r == -1)
3666     ocaml_guestfs_raise_error (g, "zero");
3667
3668   rv = Val_unit;
3669   CAMLreturn (rv);
3670 }
3671
3672 CAMLprim value
3673 ocaml_guestfs_grub_install (value gv, value rootv, value devicev)
3674 {
3675   CAMLparam3 (gv, rootv, devicev);
3676   CAMLlocal1 (rv);
3677
3678   guestfs_h *g = Guestfs_val (gv);
3679   if (g == NULL)
3680     caml_failwith ("grub_install: used handle after closing it");
3681
3682   const char *root = String_val (rootv);
3683   const char *device = String_val (devicev);
3684   int r;
3685
3686   caml_enter_blocking_section ();
3687   r = guestfs_grub_install (g, root, device);
3688   caml_leave_blocking_section ();
3689   if (r == -1)
3690     ocaml_guestfs_raise_error (g, "grub_install");
3691
3692   rv = Val_unit;
3693   CAMLreturn (rv);
3694 }
3695
3696 CAMLprim value
3697 ocaml_guestfs_cp (value gv, value srcv, value destv)
3698 {
3699   CAMLparam3 (gv, srcv, destv);
3700   CAMLlocal1 (rv);
3701
3702   guestfs_h *g = Guestfs_val (gv);
3703   if (g == NULL)
3704     caml_failwith ("cp: used handle after closing it");
3705
3706   const char *src = String_val (srcv);
3707   const char *dest = String_val (destv);
3708   int r;
3709
3710   caml_enter_blocking_section ();
3711   r = guestfs_cp (g, src, dest);
3712   caml_leave_blocking_section ();
3713   if (r == -1)
3714     ocaml_guestfs_raise_error (g, "cp");
3715
3716   rv = Val_unit;
3717   CAMLreturn (rv);
3718 }
3719
3720 CAMLprim value
3721 ocaml_guestfs_cp_a (value gv, value srcv, value destv)
3722 {
3723   CAMLparam3 (gv, srcv, destv);
3724   CAMLlocal1 (rv);
3725
3726   guestfs_h *g = Guestfs_val (gv);
3727   if (g == NULL)
3728     caml_failwith ("cp_a: used handle after closing it");
3729
3730   const char *src = String_val (srcv);
3731   const char *dest = String_val (destv);
3732   int r;
3733
3734   caml_enter_blocking_section ();
3735   r = guestfs_cp_a (g, src, dest);
3736   caml_leave_blocking_section ();
3737   if (r == -1)
3738     ocaml_guestfs_raise_error (g, "cp_a");
3739
3740   rv = Val_unit;
3741   CAMLreturn (rv);
3742 }
3743
3744 CAMLprim value
3745 ocaml_guestfs_mv (value gv, value srcv, value destv)
3746 {
3747   CAMLparam3 (gv, srcv, destv);
3748   CAMLlocal1 (rv);
3749
3750   guestfs_h *g = Guestfs_val (gv);
3751   if (g == NULL)
3752     caml_failwith ("mv: used handle after closing it");
3753
3754   const char *src = String_val (srcv);
3755   const char *dest = String_val (destv);
3756   int r;
3757
3758   caml_enter_blocking_section ();
3759   r = guestfs_mv (g, src, dest);
3760   caml_leave_blocking_section ();
3761   if (r == -1)
3762     ocaml_guestfs_raise_error (g, "mv");
3763
3764   rv = Val_unit;
3765   CAMLreturn (rv);
3766 }
3767
3768 CAMLprim value
3769 ocaml_guestfs_drop_caches (value gv, value whattodropv)
3770 {
3771   CAMLparam2 (gv, whattodropv);
3772   CAMLlocal1 (rv);
3773
3774   guestfs_h *g = Guestfs_val (gv);
3775   if (g == NULL)
3776     caml_failwith ("drop_caches: used handle after closing it");
3777
3778   int whattodrop = Int_val (whattodropv);
3779   int r;
3780
3781   caml_enter_blocking_section ();
3782   r = guestfs_drop_caches (g, whattodrop);
3783   caml_leave_blocking_section ();
3784   if (r == -1)
3785     ocaml_guestfs_raise_error (g, "drop_caches");
3786
3787   rv = Val_unit;
3788   CAMLreturn (rv);
3789 }
3790
3791 CAMLprim value
3792 ocaml_guestfs_dmesg (value gv)
3793 {
3794   CAMLparam1 (gv);
3795   CAMLlocal1 (rv);
3796
3797   guestfs_h *g = Guestfs_val (gv);
3798   if (g == NULL)
3799     caml_failwith ("dmesg: used handle after closing it");
3800
3801   char *r;
3802
3803   caml_enter_blocking_section ();
3804   r = guestfs_dmesg (g);
3805   caml_leave_blocking_section ();
3806   if (r == NULL)
3807     ocaml_guestfs_raise_error (g, "dmesg");
3808
3809   rv = caml_copy_string (r);
3810   free (r);
3811   CAMLreturn (rv);
3812 }
3813
3814 CAMLprim value
3815 ocaml_guestfs_ping_daemon (value gv)
3816 {
3817   CAMLparam1 (gv);
3818   CAMLlocal1 (rv);
3819
3820   guestfs_h *g = Guestfs_val (gv);
3821   if (g == NULL)
3822     caml_failwith ("ping_daemon: used handle after closing it");
3823
3824   int r;
3825
3826   caml_enter_blocking_section ();
3827   r = guestfs_ping_daemon (g);
3828   caml_leave_blocking_section ();
3829   if (r == -1)
3830     ocaml_guestfs_raise_error (g, "ping_daemon");
3831
3832   rv = Val_unit;
3833   CAMLreturn (rv);
3834 }
3835
3836 CAMLprim value
3837 ocaml_guestfs_equal (value gv, value file1v, value file2v)
3838 {
3839   CAMLparam3 (gv, file1v, file2v);
3840   CAMLlocal1 (rv);
3841
3842   guestfs_h *g = Guestfs_val (gv);
3843   if (g == NULL)
3844     caml_failwith ("equal: used handle after closing it");
3845
3846   const char *file1 = String_val (file1v);
3847   const char *file2 = String_val (file2v);
3848   int r;
3849
3850   caml_enter_blocking_section ();
3851   r = guestfs_equal (g, file1, file2);
3852   caml_leave_blocking_section ();
3853   if (r == -1)
3854     ocaml_guestfs_raise_error (g, "equal");
3855
3856   rv = Val_bool (r);
3857   CAMLreturn (rv);
3858 }
3859
3860 CAMLprim value
3861 ocaml_guestfs_strings (value gv, value pathv)
3862 {
3863   CAMLparam2 (gv, pathv);
3864   CAMLlocal1 (rv);
3865
3866   guestfs_h *g = Guestfs_val (gv);
3867   if (g == NULL)
3868     caml_failwith ("strings: used handle after closing it");
3869
3870   const char *path = String_val (pathv);
3871   int i;
3872   char **r;
3873
3874   caml_enter_blocking_section ();
3875   r = guestfs_strings (g, path);
3876   caml_leave_blocking_section ();
3877   if (r == NULL)
3878     ocaml_guestfs_raise_error (g, "strings");
3879
3880   rv = caml_copy_string_array ((const char **) r);
3881   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3882   free (r);
3883   CAMLreturn (rv);
3884 }
3885
3886 CAMLprim value
3887 ocaml_guestfs_strings_e (value gv, value encodingv, value pathv)
3888 {
3889   CAMLparam3 (gv, encodingv, pathv);
3890   CAMLlocal1 (rv);
3891
3892   guestfs_h *g = Guestfs_val (gv);
3893   if (g == NULL)
3894     caml_failwith ("strings_e: used handle after closing it");
3895
3896   const char *encoding = String_val (encodingv);
3897   const char *path = String_val (pathv);
3898   int i;
3899   char **r;
3900
3901   caml_enter_blocking_section ();
3902   r = guestfs_strings_e (g, encoding, path);
3903   caml_leave_blocking_section ();
3904   if (r == NULL)
3905     ocaml_guestfs_raise_error (g, "strings_e");
3906
3907   rv = caml_copy_string_array ((const char **) r);
3908   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3909   free (r);
3910   CAMLreturn (rv);
3911 }
3912
3913 CAMLprim value
3914 ocaml_guestfs_hexdump (value gv, value pathv)
3915 {
3916   CAMLparam2 (gv, pathv);
3917   CAMLlocal1 (rv);
3918
3919   guestfs_h *g = Guestfs_val (gv);
3920   if (g == NULL)
3921     caml_failwith ("hexdump: used handle after closing it");
3922
3923   const char *path = String_val (pathv);
3924   char *r;
3925
3926   caml_enter_blocking_section ();
3927   r = guestfs_hexdump (g, path);
3928   caml_leave_blocking_section ();
3929   if (r == NULL)
3930     ocaml_guestfs_raise_error (g, "hexdump");
3931
3932   rv = caml_copy_string (r);
3933   free (r);
3934   CAMLreturn (rv);
3935 }
3936
3937 CAMLprim value
3938 ocaml_guestfs_zerofree (value gv, value devicev)
3939 {
3940   CAMLparam2 (gv, devicev);
3941   CAMLlocal1 (rv);
3942
3943   guestfs_h *g = Guestfs_val (gv);
3944   if (g == NULL)
3945     caml_failwith ("zerofree: used handle after closing it");
3946
3947   const char *device = String_val (devicev);
3948   int r;
3949
3950   caml_enter_blocking_section ();
3951   r = guestfs_zerofree (g, device);
3952   caml_leave_blocking_section ();
3953   if (r == -1)
3954     ocaml_guestfs_raise_error (g, "zerofree");
3955
3956   rv = Val_unit;
3957   CAMLreturn (rv);
3958 }
3959
3960 CAMLprim value
3961 ocaml_guestfs_pvresize (value gv, value devicev)
3962 {
3963   CAMLparam2 (gv, devicev);
3964   CAMLlocal1 (rv);
3965
3966   guestfs_h *g = Guestfs_val (gv);
3967   if (g == NULL)
3968     caml_failwith ("pvresize: used handle after closing it");
3969
3970   const char *device = String_val (devicev);
3971   int r;
3972
3973   caml_enter_blocking_section ();
3974   r = guestfs_pvresize (g, device);
3975   caml_leave_blocking_section ();
3976   if (r == -1)
3977     ocaml_guestfs_raise_error (g, "pvresize");
3978
3979   rv = Val_unit;
3980   CAMLreturn (rv);
3981 }
3982
3983 CAMLprim value
3984 ocaml_guestfs_sfdisk_N (value gv, value devicev, value partnumv, value cylsv, value headsv, value sectorsv, value linev)
3985 {
3986   CAMLparam5 (gv, devicev, partnumv, cylsv, headsv);
3987   CAMLxparam2 (sectorsv, linev);
3988   CAMLlocal1 (rv);
3989
3990   guestfs_h *g = Guestfs_val (gv);
3991   if (g == NULL)
3992     caml_failwith ("sfdisk_N: used handle after closing it");
3993
3994   const char *device = String_val (devicev);
3995   int partnum = Int_val (partnumv);
3996   int cyls = Int_val (cylsv);
3997   int heads = Int_val (headsv);
3998   int sectors = Int_val (sectorsv);
3999   const char *line = String_val (linev);
4000   int r;
4001
4002   caml_enter_blocking_section ();
4003   r = guestfs_sfdisk_N (g, device, partnum, cyls, heads, sectors, line);
4004   caml_leave_blocking_section ();
4005   if (r == -1)
4006     ocaml_guestfs_raise_error (g, "sfdisk_N");
4007
4008   rv = Val_unit;
4009   CAMLreturn (rv);
4010 }
4011
4012 CAMLprim value
4013 ocaml_guestfs_sfdisk_N_byte (value *argv, int argn)
4014 {
4015   return ocaml_guestfs_sfdisk_N (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
4016 }
4017
4018 CAMLprim value
4019 ocaml_guestfs_sfdisk_l (value gv, value devicev)
4020 {
4021   CAMLparam2 (gv, devicev);
4022   CAMLlocal1 (rv);
4023
4024   guestfs_h *g = Guestfs_val (gv);
4025   if (g == NULL)
4026     caml_failwith ("sfdisk_l: used handle after closing it");
4027
4028   const char *device = String_val (devicev);
4029   char *r;
4030
4031   caml_enter_blocking_section ();
4032   r = guestfs_sfdisk_l (g, device);
4033   caml_leave_blocking_section ();
4034   if (r == NULL)
4035     ocaml_guestfs_raise_error (g, "sfdisk_l");
4036
4037   rv = caml_copy_string (r);
4038   free (r);
4039   CAMLreturn (rv);
4040 }
4041
4042 CAMLprim value
4043 ocaml_guestfs_sfdisk_kernel_geometry (value gv, value devicev)
4044 {
4045   CAMLparam2 (gv, devicev);
4046   CAMLlocal1 (rv);
4047
4048   guestfs_h *g = Guestfs_val (gv);
4049   if (g == NULL)
4050     caml_failwith ("sfdisk_kernel_geometry: used handle after closing it");
4051
4052   const char *device = String_val (devicev);
4053   char *r;
4054
4055   caml_enter_blocking_section ();
4056   r = guestfs_sfdisk_kernel_geometry (g, device);
4057   caml_leave_blocking_section ();
4058   if (r == NULL)
4059     ocaml_guestfs_raise_error (g, "sfdisk_kernel_geometry");
4060
4061   rv = caml_copy_string (r);
4062   free (r);
4063   CAMLreturn (rv);
4064 }
4065
4066 CAMLprim value
4067 ocaml_guestfs_sfdisk_disk_geometry (value gv, value devicev)
4068 {
4069   CAMLparam2 (gv, devicev);
4070   CAMLlocal1 (rv);
4071
4072   guestfs_h *g = Guestfs_val (gv);
4073   if (g == NULL)
4074     caml_failwith ("sfdisk_disk_geometry: used handle after closing it");
4075
4076   const char *device = String_val (devicev);
4077   char *r;
4078
4079   caml_enter_blocking_section ();
4080   r = guestfs_sfdisk_disk_geometry (g, device);
4081   caml_leave_blocking_section ();
4082   if (r == NULL)
4083     ocaml_guestfs_raise_error (g, "sfdisk_disk_geometry");
4084
4085   rv = caml_copy_string (r);
4086   free (r);
4087   CAMLreturn (rv);
4088 }
4089
4090 CAMLprim value
4091 ocaml_guestfs_vg_activate_all (value gv, value activatev)
4092 {
4093   CAMLparam2 (gv, activatev);
4094   CAMLlocal1 (rv);
4095
4096   guestfs_h *g = Guestfs_val (gv);
4097   if (g == NULL)
4098     caml_failwith ("vg_activate_all: used handle after closing it");
4099
4100   int activate = Bool_val (activatev);
4101   int r;
4102
4103   caml_enter_blocking_section ();
4104   r = guestfs_vg_activate_all (g, activate);
4105   caml_leave_blocking_section ();
4106   if (r == -1)
4107     ocaml_guestfs_raise_error (g, "vg_activate_all");
4108
4109   rv = Val_unit;
4110   CAMLreturn (rv);
4111 }
4112
4113 CAMLprim value
4114 ocaml_guestfs_vg_activate (value gv, value activatev, value volgroupsv)
4115 {
4116   CAMLparam3 (gv, activatev, volgroupsv);
4117   CAMLlocal1 (rv);
4118
4119   guestfs_h *g = Guestfs_val (gv);
4120   if (g == NULL)
4121     caml_failwith ("vg_activate: used handle after closing it");
4122
4123   int activate = Bool_val (activatev);
4124   char **volgroups = ocaml_guestfs_strings_val (g, volgroupsv);
4125   int r;
4126
4127   caml_enter_blocking_section ();
4128   r = guestfs_vg_activate (g, activate, volgroups);
4129   caml_leave_blocking_section ();
4130   ocaml_guestfs_free_strings (volgroups);
4131   if (r == -1)
4132     ocaml_guestfs_raise_error (g, "vg_activate");
4133
4134   rv = Val_unit;
4135   CAMLreturn (rv);
4136 }
4137
4138 CAMLprim value
4139 ocaml_guestfs_lvresize (value gv, value devicev, value mbytesv)
4140 {
4141   CAMLparam3 (gv, devicev, mbytesv);
4142   CAMLlocal1 (rv);
4143
4144   guestfs_h *g = Guestfs_val (gv);
4145   if (g == NULL)
4146     caml_failwith ("lvresize: used handle after closing it");
4147
4148   const char *device = String_val (devicev);
4149   int mbytes = Int_val (mbytesv);
4150   int r;
4151
4152   caml_enter_blocking_section ();
4153   r = guestfs_lvresize (g, device, mbytes);
4154   caml_leave_blocking_section ();
4155   if (r == -1)
4156     ocaml_guestfs_raise_error (g, "lvresize");
4157
4158   rv = Val_unit;
4159   CAMLreturn (rv);
4160 }
4161
4162 CAMLprim value
4163 ocaml_guestfs_resize2fs (value gv, value devicev)
4164 {
4165   CAMLparam2 (gv, devicev);
4166   CAMLlocal1 (rv);
4167
4168   guestfs_h *g = Guestfs_val (gv);
4169   if (g == NULL)
4170     caml_failwith ("resize2fs: used handle after closing it");
4171
4172   const char *device = String_val (devicev);
4173   int r;
4174
4175   caml_enter_blocking_section ();
4176   r = guestfs_resize2fs (g, device);
4177   caml_leave_blocking_section ();
4178   if (r == -1)
4179     ocaml_guestfs_raise_error (g, "resize2fs");
4180
4181   rv = Val_unit;
4182   CAMLreturn (rv);
4183 }
4184
4185 CAMLprim value
4186 ocaml_guestfs_find (value gv, value directoryv)
4187 {
4188   CAMLparam2 (gv, directoryv);
4189   CAMLlocal1 (rv);
4190
4191   guestfs_h *g = Guestfs_val (gv);
4192   if (g == NULL)
4193     caml_failwith ("find: used handle after closing it");
4194
4195   const char *directory = String_val (directoryv);
4196   int i;
4197   char **r;
4198
4199   caml_enter_blocking_section ();
4200   r = guestfs_find (g, directory);
4201   caml_leave_blocking_section ();
4202   if (r == NULL)
4203     ocaml_guestfs_raise_error (g, "find");
4204
4205   rv = caml_copy_string_array ((const char **) r);
4206   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4207   free (r);
4208   CAMLreturn (rv);
4209 }
4210
4211 CAMLprim value
4212 ocaml_guestfs_e2fsck_f (value gv, value devicev)
4213 {
4214   CAMLparam2 (gv, devicev);
4215   CAMLlocal1 (rv);
4216
4217   guestfs_h *g = Guestfs_val (gv);
4218   if (g == NULL)
4219     caml_failwith ("e2fsck_f: used handle after closing it");
4220
4221   const char *device = String_val (devicev);
4222   int r;
4223
4224   caml_enter_blocking_section ();
4225   r = guestfs_e2fsck_f (g, device);
4226   caml_leave_blocking_section ();
4227   if (r == -1)
4228     ocaml_guestfs_raise_error (g, "e2fsck_f");
4229
4230   rv = Val_unit;
4231   CAMLreturn (rv);
4232 }
4233
4234 CAMLprim value
4235 ocaml_guestfs_sleep (value gv, value secsv)
4236 {
4237   CAMLparam2 (gv, secsv);
4238   CAMLlocal1 (rv);
4239
4240   guestfs_h *g = Guestfs_val (gv);
4241   if (g == NULL)
4242     caml_failwith ("sleep: used handle after closing it");
4243
4244   int secs = Int_val (secsv);
4245   int r;
4246
4247   caml_enter_blocking_section ();
4248   r = guestfs_sleep (g, secs);
4249   caml_leave_blocking_section ();
4250   if (r == -1)
4251     ocaml_guestfs_raise_error (g, "sleep");
4252
4253   rv = Val_unit;
4254   CAMLreturn (rv);
4255 }
4256
4257 CAMLprim value
4258 ocaml_guestfs_ntfs_3g_probe (value gv, value rwv, value devicev)
4259 {
4260   CAMLparam3 (gv, rwv, devicev);
4261   CAMLlocal1 (rv);
4262
4263   guestfs_h *g = Guestfs_val (gv);
4264   if (g == NULL)
4265     caml_failwith ("ntfs_3g_probe: used handle after closing it");
4266
4267   int rw = Bool_val (rwv);
4268   const char *device = String_val (devicev);
4269   int r;
4270
4271   caml_enter_blocking_section ();
4272   r = guestfs_ntfs_3g_probe (g, rw, device);
4273   caml_leave_blocking_section ();
4274   if (r == -1)
4275     ocaml_guestfs_raise_error (g, "ntfs_3g_probe");
4276
4277   rv = Val_int (r);
4278   CAMLreturn (rv);
4279 }
4280
4281 CAMLprim value
4282 ocaml_guestfs_sh (value gv, value commandv)
4283 {
4284   CAMLparam2 (gv, commandv);
4285   CAMLlocal1 (rv);
4286
4287   guestfs_h *g = Guestfs_val (gv);
4288   if (g == NULL)
4289     caml_failwith ("sh: used handle after closing it");
4290
4291   const char *command = String_val (commandv);
4292   char *r;
4293
4294   caml_enter_blocking_section ();
4295   r = guestfs_sh (g, command);
4296   caml_leave_blocking_section ();
4297   if (r == NULL)
4298     ocaml_guestfs_raise_error (g, "sh");
4299
4300   rv = caml_copy_string (r);
4301   free (r);
4302   CAMLreturn (rv);
4303 }
4304
4305 CAMLprim value
4306 ocaml_guestfs_sh_lines (value gv, value commandv)
4307 {
4308   CAMLparam2 (gv, commandv);
4309   CAMLlocal1 (rv);
4310
4311   guestfs_h *g = Guestfs_val (gv);
4312   if (g == NULL)
4313     caml_failwith ("sh_lines: used handle after closing it");
4314
4315   const char *command = String_val (commandv);
4316   int i;
4317   char **r;
4318
4319   caml_enter_blocking_section ();
4320   r = guestfs_sh_lines (g, command);
4321   caml_leave_blocking_section ();
4322   if (r == NULL)
4323     ocaml_guestfs_raise_error (g, "sh_lines");
4324
4325   rv = caml_copy_string_array ((const char **) r);
4326   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4327   free (r);
4328   CAMLreturn (rv);
4329 }
4330
4331 CAMLprim value
4332 ocaml_guestfs_glob_expand (value gv, value patternv)
4333 {
4334   CAMLparam2 (gv, patternv);
4335   CAMLlocal1 (rv);
4336
4337   guestfs_h *g = Guestfs_val (gv);
4338   if (g == NULL)
4339     caml_failwith ("glob_expand: used handle after closing it");
4340
4341   const char *pattern = String_val (patternv);
4342   int i;
4343   char **r;
4344
4345   caml_enter_blocking_section ();
4346   r = guestfs_glob_expand (g, pattern);
4347   caml_leave_blocking_section ();
4348   if (r == NULL)
4349     ocaml_guestfs_raise_error (g, "glob_expand");
4350
4351   rv = caml_copy_string_array ((const char **) r);
4352   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4353   free (r);
4354   CAMLreturn (rv);
4355 }
4356
4357 CAMLprim value
4358 ocaml_guestfs_scrub_device (value gv, value devicev)
4359 {
4360   CAMLparam2 (gv, devicev);
4361   CAMLlocal1 (rv);
4362
4363   guestfs_h *g = Guestfs_val (gv);
4364   if (g == NULL)
4365     caml_failwith ("scrub_device: used handle after closing it");
4366
4367   const char *device = String_val (devicev);
4368   int r;
4369
4370   caml_enter_blocking_section ();
4371   r = guestfs_scrub_device (g, device);
4372   caml_leave_blocking_section ();
4373   if (r == -1)
4374     ocaml_guestfs_raise_error (g, "scrub_device");
4375
4376   rv = Val_unit;
4377   CAMLreturn (rv);
4378 }
4379
4380 CAMLprim value
4381 ocaml_guestfs_scrub_file (value gv, value filev)
4382 {
4383   CAMLparam2 (gv, filev);
4384   CAMLlocal1 (rv);
4385
4386   guestfs_h *g = Guestfs_val (gv);
4387   if (g == NULL)
4388     caml_failwith ("scrub_file: used handle after closing it");
4389
4390   const char *file = String_val (filev);
4391   int r;
4392
4393   caml_enter_blocking_section ();
4394   r = guestfs_scrub_file (g, file);
4395   caml_leave_blocking_section ();
4396   if (r == -1)
4397     ocaml_guestfs_raise_error (g, "scrub_file");
4398
4399   rv = Val_unit;
4400   CAMLreturn (rv);
4401 }
4402
4403 CAMLprim value
4404 ocaml_guestfs_scrub_freespace (value gv, value dirv)
4405 {
4406   CAMLparam2 (gv, dirv);
4407   CAMLlocal1 (rv);
4408
4409   guestfs_h *g = Guestfs_val (gv);
4410   if (g == NULL)
4411     caml_failwith ("scrub_freespace: used handle after closing it");
4412
4413   const char *dir = String_val (dirv);
4414   int r;
4415
4416   caml_enter_blocking_section ();
4417   r = guestfs_scrub_freespace (g, dir);
4418   caml_leave_blocking_section ();
4419   if (r == -1)
4420     ocaml_guestfs_raise_error (g, "scrub_freespace");
4421
4422   rv = Val_unit;
4423   CAMLreturn (rv);
4424 }
4425
4426 CAMLprim value
4427 ocaml_guestfs_mkdtemp (value gv, value templatev)
4428 {
4429   CAMLparam2 (gv, templatev);
4430   CAMLlocal1 (rv);
4431
4432   guestfs_h *g = Guestfs_val (gv);
4433   if (g == NULL)
4434     caml_failwith ("mkdtemp: used handle after closing it");
4435
4436   const char *template = String_val (templatev);
4437   char *r;
4438
4439   caml_enter_blocking_section ();
4440   r = guestfs_mkdtemp (g, template);
4441   caml_leave_blocking_section ();
4442   if (r == NULL)
4443     ocaml_guestfs_raise_error (g, "mkdtemp");
4444
4445   rv = caml_copy_string (r);
4446   free (r);
4447   CAMLreturn (rv);
4448 }
4449
4450 CAMLprim value
4451 ocaml_guestfs_wc_l (value gv, value pathv)
4452 {
4453   CAMLparam2 (gv, pathv);
4454   CAMLlocal1 (rv);
4455
4456   guestfs_h *g = Guestfs_val (gv);
4457   if (g == NULL)
4458     caml_failwith ("wc_l: used handle after closing it");
4459
4460   const char *path = String_val (pathv);
4461   int r;
4462
4463   caml_enter_blocking_section ();
4464   r = guestfs_wc_l (g, path);
4465   caml_leave_blocking_section ();
4466   if (r == -1)
4467     ocaml_guestfs_raise_error (g, "wc_l");
4468
4469   rv = Val_int (r);
4470   CAMLreturn (rv);
4471 }
4472
4473 CAMLprim value
4474 ocaml_guestfs_wc_w (value gv, value pathv)
4475 {
4476   CAMLparam2 (gv, pathv);
4477   CAMLlocal1 (rv);
4478
4479   guestfs_h *g = Guestfs_val (gv);
4480   if (g == NULL)
4481     caml_failwith ("wc_w: used handle after closing it");
4482
4483   const char *path = String_val (pathv);
4484   int r;
4485
4486   caml_enter_blocking_section ();
4487   r = guestfs_wc_w (g, path);
4488   caml_leave_blocking_section ();
4489   if (r == -1)
4490     ocaml_guestfs_raise_error (g, "wc_w");
4491
4492   rv = Val_int (r);
4493   CAMLreturn (rv);
4494 }
4495
4496 CAMLprim value
4497 ocaml_guestfs_wc_c (value gv, value pathv)
4498 {
4499   CAMLparam2 (gv, pathv);
4500   CAMLlocal1 (rv);
4501
4502   guestfs_h *g = Guestfs_val (gv);
4503   if (g == NULL)
4504     caml_failwith ("wc_c: used handle after closing it");
4505
4506   const char *path = String_val (pathv);
4507   int r;
4508
4509   caml_enter_blocking_section ();
4510   r = guestfs_wc_c (g, path);
4511   caml_leave_blocking_section ();
4512   if (r == -1)
4513     ocaml_guestfs_raise_error (g, "wc_c");
4514
4515   rv = Val_int (r);
4516   CAMLreturn (rv);
4517 }
4518
4519 CAMLprim value
4520 ocaml_guestfs_head (value gv, value pathv)
4521 {
4522   CAMLparam2 (gv, pathv);
4523   CAMLlocal1 (rv);
4524
4525   guestfs_h *g = Guestfs_val (gv);
4526   if (g == NULL)
4527     caml_failwith ("head: used handle after closing it");
4528
4529   const char *path = String_val (pathv);
4530   int i;
4531   char **r;
4532
4533   caml_enter_blocking_section ();
4534   r = guestfs_head (g, path);
4535   caml_leave_blocking_section ();
4536   if (r == NULL)
4537     ocaml_guestfs_raise_error (g, "head");
4538
4539   rv = caml_copy_string_array ((const char **) r);
4540   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4541   free (r);
4542   CAMLreturn (rv);
4543 }
4544
4545 CAMLprim value
4546 ocaml_guestfs_head_n (value gv, value nrlinesv, value pathv)
4547 {
4548   CAMLparam3 (gv, nrlinesv, pathv);
4549   CAMLlocal1 (rv);
4550
4551   guestfs_h *g = Guestfs_val (gv);
4552   if (g == NULL)
4553     caml_failwith ("head_n: used handle after closing it");
4554
4555   int nrlines = Int_val (nrlinesv);
4556   const char *path = String_val (pathv);
4557   int i;
4558   char **r;
4559
4560   caml_enter_blocking_section ();
4561   r = guestfs_head_n (g, nrlines, path);
4562   caml_leave_blocking_section ();
4563   if (r == NULL)
4564     ocaml_guestfs_raise_error (g, "head_n");
4565
4566   rv = caml_copy_string_array ((const char **) r);
4567   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4568   free (r);
4569   CAMLreturn (rv);
4570 }
4571
4572 CAMLprim value
4573 ocaml_guestfs_tail (value gv, value pathv)
4574 {
4575   CAMLparam2 (gv, pathv);
4576   CAMLlocal1 (rv);
4577
4578   guestfs_h *g = Guestfs_val (gv);
4579   if (g == NULL)
4580     caml_failwith ("tail: used handle after closing it");
4581
4582   const char *path = String_val (pathv);
4583   int i;
4584   char **r;
4585
4586   caml_enter_blocking_section ();
4587   r = guestfs_tail (g, path);
4588   caml_leave_blocking_section ();
4589   if (r == NULL)
4590     ocaml_guestfs_raise_error (g, "tail");
4591
4592   rv = caml_copy_string_array ((const char **) r);
4593   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4594   free (r);
4595   CAMLreturn (rv);
4596 }
4597
4598 CAMLprim value
4599 ocaml_guestfs_tail_n (value gv, value nrlinesv, value pathv)
4600 {
4601   CAMLparam3 (gv, nrlinesv, pathv);
4602   CAMLlocal1 (rv);
4603
4604   guestfs_h *g = Guestfs_val (gv);
4605   if (g == NULL)
4606     caml_failwith ("tail_n: used handle after closing it");
4607
4608   int nrlines = Int_val (nrlinesv);
4609   const char *path = String_val (pathv);
4610   int i;
4611   char **r;
4612
4613   caml_enter_blocking_section ();
4614   r = guestfs_tail_n (g, nrlines, path);
4615   caml_leave_blocking_section ();
4616   if (r == NULL)
4617     ocaml_guestfs_raise_error (g, "tail_n");
4618
4619   rv = caml_copy_string_array ((const char **) r);
4620   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4621   free (r);
4622   CAMLreturn (rv);
4623 }
4624
4625 CAMLprim value
4626 ocaml_guestfs_df (value gv)
4627 {
4628   CAMLparam1 (gv);
4629   CAMLlocal1 (rv);
4630
4631   guestfs_h *g = Guestfs_val (gv);
4632   if (g == NULL)
4633     caml_failwith ("df: used handle after closing it");
4634
4635   char *r;
4636
4637   caml_enter_blocking_section ();
4638   r = guestfs_df (g);
4639   caml_leave_blocking_section ();
4640   if (r == NULL)
4641     ocaml_guestfs_raise_error (g, "df");
4642
4643   rv = caml_copy_string (r);
4644   free (r);
4645   CAMLreturn (rv);
4646 }
4647
4648 CAMLprim value
4649 ocaml_guestfs_df_h (value gv)
4650 {
4651   CAMLparam1 (gv);
4652   CAMLlocal1 (rv);
4653
4654   guestfs_h *g = Guestfs_val (gv);
4655   if (g == NULL)
4656     caml_failwith ("df_h: used handle after closing it");
4657
4658   char *r;
4659
4660   caml_enter_blocking_section ();
4661   r = guestfs_df_h (g);
4662   caml_leave_blocking_section ();
4663   if (r == NULL)
4664     ocaml_guestfs_raise_error (g, "df_h");
4665
4666   rv = caml_copy_string (r);
4667   free (r);
4668   CAMLreturn (rv);
4669 }
4670
4671 CAMLprim value
4672 ocaml_guestfs_du (value gv, value pathv)
4673 {
4674   CAMLparam2 (gv, pathv);
4675   CAMLlocal1 (rv);
4676
4677   guestfs_h *g = Guestfs_val (gv);
4678   if (g == NULL)
4679     caml_failwith ("du: used handle after closing it");
4680
4681   const char *path = String_val (pathv);
4682   int64_t r;
4683
4684   caml_enter_blocking_section ();
4685   r = guestfs_du (g, path);
4686   caml_leave_blocking_section ();
4687   if (r == -1)
4688     ocaml_guestfs_raise_error (g, "du");
4689
4690   rv = caml_copy_int64 (r);
4691   CAMLreturn (rv);
4692 }
4693
4694 CAMLprim value
4695 ocaml_guestfs_initrd_list (value gv, value pathv)
4696 {
4697   CAMLparam2 (gv, pathv);
4698   CAMLlocal1 (rv);
4699
4700   guestfs_h *g = Guestfs_val (gv);
4701   if (g == NULL)
4702     caml_failwith ("initrd_list: used handle after closing it");
4703
4704   const char *path = String_val (pathv);
4705   int i;
4706   char **r;
4707
4708   caml_enter_blocking_section ();
4709   r = guestfs_initrd_list (g, path);
4710   caml_leave_blocking_section ();
4711   if (r == NULL)
4712     ocaml_guestfs_raise_error (g, "initrd_list");
4713
4714   rv = caml_copy_string_array ((const char **) r);
4715   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4716   free (r);
4717   CAMLreturn (rv);
4718 }
4719
4720 CAMLprim value
4721 ocaml_guestfs_mount_loop (value gv, value filev, value mountpointv)
4722 {
4723   CAMLparam3 (gv, filev, mountpointv);
4724   CAMLlocal1 (rv);
4725
4726   guestfs_h *g = Guestfs_val (gv);
4727   if (g == NULL)
4728     caml_failwith ("mount_loop: used handle after closing it");
4729
4730   const char *file = String_val (filev);
4731   const char *mountpoint = String_val (mountpointv);
4732   int r;
4733
4734   caml_enter_blocking_section ();
4735   r = guestfs_mount_loop (g, file, mountpoint);
4736   caml_leave_blocking_section ();
4737   if (r == -1)
4738     ocaml_guestfs_raise_error (g, "mount_loop");
4739
4740   rv = Val_unit;
4741   CAMLreturn (rv);
4742 }
4743
4744 CAMLprim value
4745 ocaml_guestfs_mkswap (value gv, value devicev)
4746 {
4747   CAMLparam2 (gv, devicev);
4748   CAMLlocal1 (rv);
4749
4750   guestfs_h *g = Guestfs_val (gv);
4751   if (g == NULL)
4752     caml_failwith ("mkswap: used handle after closing it");
4753
4754   const char *device = String_val (devicev);
4755   int r;
4756
4757   caml_enter_blocking_section ();
4758   r = guestfs_mkswap (g, device);
4759   caml_leave_blocking_section ();
4760   if (r == -1)
4761     ocaml_guestfs_raise_error (g, "mkswap");
4762
4763   rv = Val_unit;
4764   CAMLreturn (rv);
4765 }
4766
4767 CAMLprim value
4768 ocaml_guestfs_mkswap_L (value gv, value labelv, value devicev)
4769 {
4770   CAMLparam3 (gv, labelv, devicev);
4771   CAMLlocal1 (rv);
4772
4773   guestfs_h *g = Guestfs_val (gv);
4774   if (g == NULL)
4775     caml_failwith ("mkswap_L: used handle after closing it");
4776
4777   const char *label = String_val (labelv);
4778   const char *device = String_val (devicev);
4779   int r;
4780
4781   caml_enter_blocking_section ();
4782   r = guestfs_mkswap_L (g, label, device);
4783   caml_leave_blocking_section ();
4784   if (r == -1)
4785     ocaml_guestfs_raise_error (g, "mkswap_L");
4786
4787   rv = Val_unit;
4788   CAMLreturn (rv);
4789 }
4790
4791 CAMLprim value
4792 ocaml_guestfs_mkswap_U (value gv, value uuidv, value devicev)
4793 {
4794   CAMLparam3 (gv, uuidv, devicev);
4795   CAMLlocal1 (rv);
4796
4797   guestfs_h *g = Guestfs_val (gv);
4798   if (g == NULL)
4799     caml_failwith ("mkswap_U: used handle after closing it");
4800
4801   const char *uuid = String_val (uuidv);
4802   const char *device = String_val (devicev);
4803   int r;
4804
4805   caml_enter_blocking_section ();
4806   r = guestfs_mkswap_U (g, uuid, device);
4807   caml_leave_blocking_section ();
4808   if (r == -1)
4809     ocaml_guestfs_raise_error (g, "mkswap_U");
4810
4811   rv = Val_unit;
4812   CAMLreturn (rv);
4813 }
4814
4815 CAMLprim value
4816 ocaml_guestfs_mknod (value gv, value modev, value devmajorv, value devminorv, value pathv)
4817 {
4818   CAMLparam5 (gv, modev, devmajorv, devminorv, pathv);
4819   CAMLlocal1 (rv);
4820
4821   guestfs_h *g = Guestfs_val (gv);
4822   if (g == NULL)
4823     caml_failwith ("mknod: used handle after closing it");
4824
4825   int mode = Int_val (modev);
4826   int devmajor = Int_val (devmajorv);
4827   int devminor = Int_val (devminorv);
4828   const char *path = String_val (pathv);
4829   int r;
4830
4831   caml_enter_blocking_section ();
4832   r = guestfs_mknod (g, mode, devmajor, devminor, path);
4833   caml_leave_blocking_section ();
4834   if (r == -1)
4835     ocaml_guestfs_raise_error (g, "mknod");
4836
4837   rv = Val_unit;
4838   CAMLreturn (rv);
4839 }
4840
4841 CAMLprim value
4842 ocaml_guestfs_mkfifo (value gv, value modev, value pathv)
4843 {
4844   CAMLparam3 (gv, modev, pathv);
4845   CAMLlocal1 (rv);
4846
4847   guestfs_h *g = Guestfs_val (gv);
4848   if (g == NULL)
4849     caml_failwith ("mkfifo: used handle after closing it");
4850
4851   int mode = Int_val (modev);
4852   const char *path = String_val (pathv);
4853   int r;
4854
4855   caml_enter_blocking_section ();
4856   r = guestfs_mkfifo (g, mode, path);
4857   caml_leave_blocking_section ();
4858   if (r == -1)
4859     ocaml_guestfs_raise_error (g, "mkfifo");
4860
4861   rv = Val_unit;
4862   CAMLreturn (rv);
4863 }
4864
4865 CAMLprim value
4866 ocaml_guestfs_mknod_b (value gv, value modev, value devmajorv, value devminorv, value pathv)
4867 {
4868   CAMLparam5 (gv, modev, devmajorv, devminorv, pathv);
4869   CAMLlocal1 (rv);
4870
4871   guestfs_h *g = Guestfs_val (gv);
4872   if (g == NULL)
4873     caml_failwith ("mknod_b: used handle after closing it");
4874
4875   int mode = Int_val (modev);
4876   int devmajor = Int_val (devmajorv);
4877   int devminor = Int_val (devminorv);
4878   const char *path = String_val (pathv);
4879   int r;
4880
4881   caml_enter_blocking_section ();
4882   r = guestfs_mknod_b (g, mode, devmajor, devminor, path);
4883   caml_leave_blocking_section ();
4884   if (r == -1)
4885     ocaml_guestfs_raise_error (g, "mknod_b");
4886
4887   rv = Val_unit;
4888   CAMLreturn (rv);
4889 }
4890
4891 CAMLprim value
4892 ocaml_guestfs_mknod_c (value gv, value modev, value devmajorv, value devminorv, value pathv)
4893 {
4894   CAMLparam5 (gv, modev, devmajorv, devminorv, pathv);
4895   CAMLlocal1 (rv);
4896
4897   guestfs_h *g = Guestfs_val (gv);
4898   if (g == NULL)
4899     caml_failwith ("mknod_c: used handle after closing it");
4900
4901   int mode = Int_val (modev);
4902   int devmajor = Int_val (devmajorv);
4903   int devminor = Int_val (devminorv);
4904   const char *path = String_val (pathv);
4905   int r;
4906
4907   caml_enter_blocking_section ();
4908   r = guestfs_mknod_c (g, mode, devmajor, devminor, path);
4909   caml_leave_blocking_section ();
4910   if (r == -1)
4911     ocaml_guestfs_raise_error (g, "mknod_c");
4912
4913   rv = Val_unit;
4914   CAMLreturn (rv);
4915 }
4916
4917 CAMLprim value
4918 ocaml_guestfs_umask (value gv, value maskv)
4919 {
4920   CAMLparam2 (gv, maskv);
4921   CAMLlocal1 (rv);
4922
4923   guestfs_h *g = Guestfs_val (gv);
4924   if (g == NULL)
4925     caml_failwith ("umask: used handle after closing it");
4926
4927   int mask = Int_val (maskv);
4928   int r;
4929
4930   caml_enter_blocking_section ();
4931   r = guestfs_umask (g, mask);
4932   caml_leave_blocking_section ();
4933   if (r == -1)
4934     ocaml_guestfs_raise_error (g, "umask");
4935
4936   rv = Val_int (r);
4937   CAMLreturn (rv);
4938 }
4939
4940 CAMLprim value
4941 ocaml_guestfs_readdir (value gv, value dirv)
4942 {
4943   CAMLparam2 (gv, dirv);
4944   CAMLlocal1 (rv);
4945
4946   guestfs_h *g = Guestfs_val (gv);
4947   if (g == NULL)
4948     caml_failwith ("readdir: used handle after closing it");
4949
4950   const char *dir = String_val (dirv);
4951   struct guestfs_dirent_list *r;
4952
4953   caml_enter_blocking_section ();
4954   r = guestfs_readdir (g, dir);
4955   caml_leave_blocking_section ();
4956   if (r == NULL)
4957     ocaml_guestfs_raise_error (g, "readdir");
4958
4959   rv = copy_dirent_list (r);
4960   guestfs_free_dirent_list (r);
4961   CAMLreturn (rv);
4962 }
4963