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