1ce55f0ac1fbefd8dab02485fa76a1578c84cf11
[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_mount (value gv, value devicev, value mountpointv)
1547 {
1548   CAMLparam3 (gv, devicev, mountpointv);
1549   CAMLlocal1 (rv);
1550
1551   guestfs_h *g = Guestfs_val (gv);
1552   if (g == NULL)
1553     caml_failwith ("mount: used handle after closing it");
1554
1555   const char *device = String_val (devicev);
1556   const char *mountpoint = String_val (mountpointv);
1557   int r;
1558
1559   caml_enter_blocking_section ();
1560   r = guestfs_mount (g, device, mountpoint);
1561   caml_leave_blocking_section ();
1562   if (r == -1)
1563     ocaml_guestfs_raise_error (g, "mount");
1564
1565   rv = Val_unit;
1566   CAMLreturn (rv);
1567 }
1568
1569 CAMLprim value
1570 ocaml_guestfs_sync (value gv)
1571 {
1572   CAMLparam1 (gv);
1573   CAMLlocal1 (rv);
1574
1575   guestfs_h *g = Guestfs_val (gv);
1576   if (g == NULL)
1577     caml_failwith ("sync: used handle after closing it");
1578
1579   int r;
1580
1581   caml_enter_blocking_section ();
1582   r = guestfs_sync (g);
1583   caml_leave_blocking_section ();
1584   if (r == -1)
1585     ocaml_guestfs_raise_error (g, "sync");
1586
1587   rv = Val_unit;
1588   CAMLreturn (rv);
1589 }
1590
1591 CAMLprim value
1592 ocaml_guestfs_touch (value gv, value pathv)
1593 {
1594   CAMLparam2 (gv, pathv);
1595   CAMLlocal1 (rv);
1596
1597   guestfs_h *g = Guestfs_val (gv);
1598   if (g == NULL)
1599     caml_failwith ("touch: used handle after closing it");
1600
1601   const char *path = String_val (pathv);
1602   int r;
1603
1604   caml_enter_blocking_section ();
1605   r = guestfs_touch (g, path);
1606   caml_leave_blocking_section ();
1607   if (r == -1)
1608     ocaml_guestfs_raise_error (g, "touch");
1609
1610   rv = Val_unit;
1611   CAMLreturn (rv);
1612 }
1613
1614 CAMLprim value
1615 ocaml_guestfs_cat (value gv, value pathv)
1616 {
1617   CAMLparam2 (gv, pathv);
1618   CAMLlocal1 (rv);
1619
1620   guestfs_h *g = Guestfs_val (gv);
1621   if (g == NULL)
1622     caml_failwith ("cat: used handle after closing it");
1623
1624   const char *path = String_val (pathv);
1625   char *r;
1626
1627   caml_enter_blocking_section ();
1628   r = guestfs_cat (g, path);
1629   caml_leave_blocking_section ();
1630   if (r == NULL)
1631     ocaml_guestfs_raise_error (g, "cat");
1632
1633   rv = caml_copy_string (r);
1634   free (r);
1635   CAMLreturn (rv);
1636 }
1637
1638 CAMLprim value
1639 ocaml_guestfs_ll (value gv, value directoryv)
1640 {
1641   CAMLparam2 (gv, directoryv);
1642   CAMLlocal1 (rv);
1643
1644   guestfs_h *g = Guestfs_val (gv);
1645   if (g == NULL)
1646     caml_failwith ("ll: used handle after closing it");
1647
1648   const char *directory = String_val (directoryv);
1649   char *r;
1650
1651   caml_enter_blocking_section ();
1652   r = guestfs_ll (g, directory);
1653   caml_leave_blocking_section ();
1654   if (r == NULL)
1655     ocaml_guestfs_raise_error (g, "ll");
1656
1657   rv = caml_copy_string (r);
1658   free (r);
1659   CAMLreturn (rv);
1660 }
1661
1662 CAMLprim value
1663 ocaml_guestfs_ls (value gv, value directoryv)
1664 {
1665   CAMLparam2 (gv, directoryv);
1666   CAMLlocal1 (rv);
1667
1668   guestfs_h *g = Guestfs_val (gv);
1669   if (g == NULL)
1670     caml_failwith ("ls: used handle after closing it");
1671
1672   const char *directory = String_val (directoryv);
1673   int i;
1674   char **r;
1675
1676   caml_enter_blocking_section ();
1677   r = guestfs_ls (g, directory);
1678   caml_leave_blocking_section ();
1679   if (r == NULL)
1680     ocaml_guestfs_raise_error (g, "ls");
1681
1682   rv = caml_copy_string_array ((const char **) r);
1683   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1684   free (r);
1685   CAMLreturn (rv);
1686 }
1687
1688 CAMLprim value
1689 ocaml_guestfs_list_devices (value gv)
1690 {
1691   CAMLparam1 (gv);
1692   CAMLlocal1 (rv);
1693
1694   guestfs_h *g = Guestfs_val (gv);
1695   if (g == NULL)
1696     caml_failwith ("list_devices: used handle after closing it");
1697
1698   int i;
1699   char **r;
1700
1701   caml_enter_blocking_section ();
1702   r = guestfs_list_devices (g);
1703   caml_leave_blocking_section ();
1704   if (r == NULL)
1705     ocaml_guestfs_raise_error (g, "list_devices");
1706
1707   rv = caml_copy_string_array ((const char **) r);
1708   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1709   free (r);
1710   CAMLreturn (rv);
1711 }
1712
1713 CAMLprim value
1714 ocaml_guestfs_list_partitions (value gv)
1715 {
1716   CAMLparam1 (gv);
1717   CAMLlocal1 (rv);
1718
1719   guestfs_h *g = Guestfs_val (gv);
1720   if (g == NULL)
1721     caml_failwith ("list_partitions: used handle after closing it");
1722
1723   int i;
1724   char **r;
1725
1726   caml_enter_blocking_section ();
1727   r = guestfs_list_partitions (g);
1728   caml_leave_blocking_section ();
1729   if (r == NULL)
1730     ocaml_guestfs_raise_error (g, "list_partitions");
1731
1732   rv = caml_copy_string_array ((const char **) r);
1733   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1734   free (r);
1735   CAMLreturn (rv);
1736 }
1737
1738 CAMLprim value
1739 ocaml_guestfs_pvs (value gv)
1740 {
1741   CAMLparam1 (gv);
1742   CAMLlocal1 (rv);
1743
1744   guestfs_h *g = Guestfs_val (gv);
1745   if (g == NULL)
1746     caml_failwith ("pvs: used handle after closing it");
1747
1748   int i;
1749   char **r;
1750
1751   caml_enter_blocking_section ();
1752   r = guestfs_pvs (g);
1753   caml_leave_blocking_section ();
1754   if (r == NULL)
1755     ocaml_guestfs_raise_error (g, "pvs");
1756
1757   rv = caml_copy_string_array ((const char **) r);
1758   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1759   free (r);
1760   CAMLreturn (rv);
1761 }
1762
1763 CAMLprim value
1764 ocaml_guestfs_vgs (value gv)
1765 {
1766   CAMLparam1 (gv);
1767   CAMLlocal1 (rv);
1768
1769   guestfs_h *g = Guestfs_val (gv);
1770   if (g == NULL)
1771     caml_failwith ("vgs: used handle after closing it");
1772
1773   int i;
1774   char **r;
1775
1776   caml_enter_blocking_section ();
1777   r = guestfs_vgs (g);
1778   caml_leave_blocking_section ();
1779   if (r == NULL)
1780     ocaml_guestfs_raise_error (g, "vgs");
1781
1782   rv = caml_copy_string_array ((const char **) r);
1783   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1784   free (r);
1785   CAMLreturn (rv);
1786 }
1787
1788 CAMLprim value
1789 ocaml_guestfs_lvs (value gv)
1790 {
1791   CAMLparam1 (gv);
1792   CAMLlocal1 (rv);
1793
1794   guestfs_h *g = Guestfs_val (gv);
1795   if (g == NULL)
1796     caml_failwith ("lvs: used handle after closing it");
1797
1798   int i;
1799   char **r;
1800
1801   caml_enter_blocking_section ();
1802   r = guestfs_lvs (g);
1803   caml_leave_blocking_section ();
1804   if (r == NULL)
1805     ocaml_guestfs_raise_error (g, "lvs");
1806
1807   rv = caml_copy_string_array ((const char **) r);
1808   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1809   free (r);
1810   CAMLreturn (rv);
1811 }
1812
1813 CAMLprim value
1814 ocaml_guestfs_pvs_full (value gv)
1815 {
1816   CAMLparam1 (gv);
1817   CAMLlocal1 (rv);
1818
1819   guestfs_h *g = Guestfs_val (gv);
1820   if (g == NULL)
1821     caml_failwith ("pvs_full: used handle after closing it");
1822
1823   struct guestfs_lvm_pv_list *r;
1824
1825   caml_enter_blocking_section ();
1826   r = guestfs_pvs_full (g);
1827   caml_leave_blocking_section ();
1828   if (r == NULL)
1829     ocaml_guestfs_raise_error (g, "pvs_full");
1830
1831   rv = copy_lvm_pv_list (r);
1832   guestfs_free_lvm_pv_list (r);
1833   CAMLreturn (rv);
1834 }
1835
1836 CAMLprim value
1837 ocaml_guestfs_vgs_full (value gv)
1838 {
1839   CAMLparam1 (gv);
1840   CAMLlocal1 (rv);
1841
1842   guestfs_h *g = Guestfs_val (gv);
1843   if (g == NULL)
1844     caml_failwith ("vgs_full: used handle after closing it");
1845
1846   struct guestfs_lvm_vg_list *r;
1847
1848   caml_enter_blocking_section ();
1849   r = guestfs_vgs_full (g);
1850   caml_leave_blocking_section ();
1851   if (r == NULL)
1852     ocaml_guestfs_raise_error (g, "vgs_full");
1853
1854   rv = copy_lvm_vg_list (r);
1855   guestfs_free_lvm_vg_list (r);
1856   CAMLreturn (rv);
1857 }
1858
1859 CAMLprim value
1860 ocaml_guestfs_lvs_full (value gv)
1861 {
1862   CAMLparam1 (gv);
1863   CAMLlocal1 (rv);
1864
1865   guestfs_h *g = Guestfs_val (gv);
1866   if (g == NULL)
1867     caml_failwith ("lvs_full: used handle after closing it");
1868
1869   struct guestfs_lvm_lv_list *r;
1870
1871   caml_enter_blocking_section ();
1872   r = guestfs_lvs_full (g);
1873   caml_leave_blocking_section ();
1874   if (r == NULL)
1875     ocaml_guestfs_raise_error (g, "lvs_full");
1876
1877   rv = copy_lvm_lv_list (r);
1878   guestfs_free_lvm_lv_list (r);
1879   CAMLreturn (rv);
1880 }
1881
1882 CAMLprim value
1883 ocaml_guestfs_read_lines (value gv, value pathv)
1884 {
1885   CAMLparam2 (gv, pathv);
1886   CAMLlocal1 (rv);
1887
1888   guestfs_h *g = Guestfs_val (gv);
1889   if (g == NULL)
1890     caml_failwith ("read_lines: used handle after closing it");
1891
1892   const char *path = String_val (pathv);
1893   int i;
1894   char **r;
1895
1896   caml_enter_blocking_section ();
1897   r = guestfs_read_lines (g, path);
1898   caml_leave_blocking_section ();
1899   if (r == NULL)
1900     ocaml_guestfs_raise_error (g, "read_lines");
1901
1902   rv = caml_copy_string_array ((const char **) r);
1903   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1904   free (r);
1905   CAMLreturn (rv);
1906 }
1907
1908 CAMLprim value
1909 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
1910 {
1911   CAMLparam3 (gv, rootv, flagsv);
1912   CAMLlocal1 (rv);
1913
1914   guestfs_h *g = Guestfs_val (gv);
1915   if (g == NULL)
1916     caml_failwith ("aug_init: used handle after closing it");
1917
1918   const char *root = String_val (rootv);
1919   int flags = Int_val (flagsv);
1920   int r;
1921
1922   caml_enter_blocking_section ();
1923   r = guestfs_aug_init (g, root, flags);
1924   caml_leave_blocking_section ();
1925   if (r == -1)
1926     ocaml_guestfs_raise_error (g, "aug_init");
1927
1928   rv = Val_unit;
1929   CAMLreturn (rv);
1930 }
1931
1932 CAMLprim value
1933 ocaml_guestfs_aug_close (value gv)
1934 {
1935   CAMLparam1 (gv);
1936   CAMLlocal1 (rv);
1937
1938   guestfs_h *g = Guestfs_val (gv);
1939   if (g == NULL)
1940     caml_failwith ("aug_close: used handle after closing it");
1941
1942   int r;
1943
1944   caml_enter_blocking_section ();
1945   r = guestfs_aug_close (g);
1946   caml_leave_blocking_section ();
1947   if (r == -1)
1948     ocaml_guestfs_raise_error (g, "aug_close");
1949
1950   rv = Val_unit;
1951   CAMLreturn (rv);
1952 }
1953
1954 CAMLprim value
1955 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
1956 {
1957   CAMLparam3 (gv, namev, exprv);
1958   CAMLlocal1 (rv);
1959
1960   guestfs_h *g = Guestfs_val (gv);
1961   if (g == NULL)
1962     caml_failwith ("aug_defvar: used handle after closing it");
1963
1964   const char *name = String_val (namev);
1965   const char *expr =
1966     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
1967   int r;
1968
1969   caml_enter_blocking_section ();
1970   r = guestfs_aug_defvar (g, name, expr);
1971   caml_leave_blocking_section ();
1972   if (r == -1)
1973     ocaml_guestfs_raise_error (g, "aug_defvar");
1974
1975   rv = Val_int (r);
1976   CAMLreturn (rv);
1977 }
1978
1979 CAMLprim value
1980 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1981 {
1982   CAMLparam4 (gv, namev, exprv, valv);
1983   CAMLlocal1 (rv);
1984
1985   guestfs_h *g = Guestfs_val (gv);
1986   if (g == NULL)
1987     caml_failwith ("aug_defnode: used handle after closing it");
1988
1989   const char *name = String_val (namev);
1990   const char *expr = String_val (exprv);
1991   const char *val = String_val (valv);
1992   struct guestfs_int_bool *r;
1993
1994   caml_enter_blocking_section ();
1995   r = guestfs_aug_defnode (g, name, expr, val);
1996   caml_leave_blocking_section ();
1997   if (r == NULL)
1998     ocaml_guestfs_raise_error (g, "aug_defnode");
1999
2000   rv = caml_alloc (2, 0);
2001   Store_field (rv, 0, Val_int (r->i));
2002   Store_field (rv, 1, Val_bool (r->b));
2003   guestfs_free_int_bool (r);
2004   CAMLreturn (rv);
2005 }
2006
2007 CAMLprim value
2008 ocaml_guestfs_aug_get (value gv, value pathv)
2009 {
2010   CAMLparam2 (gv, pathv);
2011   CAMLlocal1 (rv);
2012
2013   guestfs_h *g = Guestfs_val (gv);
2014   if (g == NULL)
2015     caml_failwith ("aug_get: used handle after closing it");
2016
2017   const char *path = String_val (pathv);
2018   char *r;
2019
2020   caml_enter_blocking_section ();
2021   r = guestfs_aug_get (g, path);
2022   caml_leave_blocking_section ();
2023   if (r == NULL)
2024     ocaml_guestfs_raise_error (g, "aug_get");
2025
2026   rv = caml_copy_string (r);
2027   free (r);
2028   CAMLreturn (rv);
2029 }
2030
2031 CAMLprim value
2032 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
2033 {
2034   CAMLparam3 (gv, pathv, valv);
2035   CAMLlocal1 (rv);
2036
2037   guestfs_h *g = Guestfs_val (gv);
2038   if (g == NULL)
2039     caml_failwith ("aug_set: used handle after closing it");
2040
2041   const char *path = String_val (pathv);
2042   const char *val = String_val (valv);
2043   int r;
2044
2045   caml_enter_blocking_section ();
2046   r = guestfs_aug_set (g, path, val);
2047   caml_leave_blocking_section ();
2048   if (r == -1)
2049     ocaml_guestfs_raise_error (g, "aug_set");
2050
2051   rv = Val_unit;
2052   CAMLreturn (rv);
2053 }
2054
2055 CAMLprim value
2056 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
2057 {
2058   CAMLparam4 (gv, pathv, labelv, beforev);
2059   CAMLlocal1 (rv);
2060
2061   guestfs_h *g = Guestfs_val (gv);
2062   if (g == NULL)
2063     caml_failwith ("aug_insert: used handle after closing it");
2064
2065   const char *path = String_val (pathv);
2066   const char *label = String_val (labelv);
2067   int before = Bool_val (beforev);
2068   int r;
2069
2070   caml_enter_blocking_section ();
2071   r = guestfs_aug_insert (g, path, label, before);
2072   caml_leave_blocking_section ();
2073   if (r == -1)
2074     ocaml_guestfs_raise_error (g, "aug_insert");
2075
2076   rv = Val_unit;
2077   CAMLreturn (rv);
2078 }
2079
2080 CAMLprim value
2081 ocaml_guestfs_aug_rm (value gv, value pathv)
2082 {
2083   CAMLparam2 (gv, pathv);
2084   CAMLlocal1 (rv);
2085
2086   guestfs_h *g = Guestfs_val (gv);
2087   if (g == NULL)
2088     caml_failwith ("aug_rm: used handle after closing it");
2089
2090   const char *path = String_val (pathv);
2091   int r;
2092
2093   caml_enter_blocking_section ();
2094   r = guestfs_aug_rm (g, path);
2095   caml_leave_blocking_section ();
2096   if (r == -1)
2097     ocaml_guestfs_raise_error (g, "aug_rm");
2098
2099   rv = Val_int (r);
2100   CAMLreturn (rv);
2101 }
2102
2103 CAMLprim value
2104 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
2105 {
2106   CAMLparam3 (gv, srcv, destv);
2107   CAMLlocal1 (rv);
2108
2109   guestfs_h *g = Guestfs_val (gv);
2110   if (g == NULL)
2111     caml_failwith ("aug_mv: used handle after closing it");
2112
2113   const char *src = String_val (srcv);
2114   const char *dest = String_val (destv);
2115   int r;
2116
2117   caml_enter_blocking_section ();
2118   r = guestfs_aug_mv (g, src, dest);
2119   caml_leave_blocking_section ();
2120   if (r == -1)
2121     ocaml_guestfs_raise_error (g, "aug_mv");
2122
2123   rv = Val_unit;
2124   CAMLreturn (rv);
2125 }
2126
2127 CAMLprim value
2128 ocaml_guestfs_aug_match (value gv, value pathv)
2129 {
2130   CAMLparam2 (gv, pathv);
2131   CAMLlocal1 (rv);
2132
2133   guestfs_h *g = Guestfs_val (gv);
2134   if (g == NULL)
2135     caml_failwith ("aug_match: used handle after closing it");
2136
2137   const char *path = String_val (pathv);
2138   int i;
2139   char **r;
2140
2141   caml_enter_blocking_section ();
2142   r = guestfs_aug_match (g, path);
2143   caml_leave_blocking_section ();
2144   if (r == NULL)
2145     ocaml_guestfs_raise_error (g, "aug_match");
2146
2147   rv = caml_copy_string_array ((const char **) r);
2148   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2149   free (r);
2150   CAMLreturn (rv);
2151 }
2152
2153 CAMLprim value
2154 ocaml_guestfs_aug_save (value gv)
2155 {
2156   CAMLparam1 (gv);
2157   CAMLlocal1 (rv);
2158
2159   guestfs_h *g = Guestfs_val (gv);
2160   if (g == NULL)
2161     caml_failwith ("aug_save: used handle after closing it");
2162
2163   int r;
2164
2165   caml_enter_blocking_section ();
2166   r = guestfs_aug_save (g);
2167   caml_leave_blocking_section ();
2168   if (r == -1)
2169     ocaml_guestfs_raise_error (g, "aug_save");
2170
2171   rv = Val_unit;
2172   CAMLreturn (rv);
2173 }
2174
2175 CAMLprim value
2176 ocaml_guestfs_aug_load (value gv)
2177 {
2178   CAMLparam1 (gv);
2179   CAMLlocal1 (rv);
2180
2181   guestfs_h *g = Guestfs_val (gv);
2182   if (g == NULL)
2183     caml_failwith ("aug_load: used handle after closing it");
2184
2185   int r;
2186
2187   caml_enter_blocking_section ();
2188   r = guestfs_aug_load (g);
2189   caml_leave_blocking_section ();
2190   if (r == -1)
2191     ocaml_guestfs_raise_error (g, "aug_load");
2192
2193   rv = Val_unit;
2194   CAMLreturn (rv);
2195 }
2196
2197 CAMLprim value
2198 ocaml_guestfs_aug_ls (value gv, value pathv)
2199 {
2200   CAMLparam2 (gv, pathv);
2201   CAMLlocal1 (rv);
2202
2203   guestfs_h *g = Guestfs_val (gv);
2204   if (g == NULL)
2205     caml_failwith ("aug_ls: used handle after closing it");
2206
2207   const char *path = String_val (pathv);
2208   int i;
2209   char **r;
2210
2211   caml_enter_blocking_section ();
2212   r = guestfs_aug_ls (g, path);
2213   caml_leave_blocking_section ();
2214   if (r == NULL)
2215     ocaml_guestfs_raise_error (g, "aug_ls");
2216
2217   rv = caml_copy_string_array ((const char **) r);
2218   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2219   free (r);
2220   CAMLreturn (rv);
2221 }
2222
2223 CAMLprim value
2224 ocaml_guestfs_rm (value gv, value pathv)
2225 {
2226   CAMLparam2 (gv, pathv);
2227   CAMLlocal1 (rv);
2228
2229   guestfs_h *g = Guestfs_val (gv);
2230   if (g == NULL)
2231     caml_failwith ("rm: used handle after closing it");
2232
2233   const char *path = String_val (pathv);
2234   int r;
2235
2236   caml_enter_blocking_section ();
2237   r = guestfs_rm (g, path);
2238   caml_leave_blocking_section ();
2239   if (r == -1)
2240     ocaml_guestfs_raise_error (g, "rm");
2241
2242   rv = Val_unit;
2243   CAMLreturn (rv);
2244 }
2245
2246 CAMLprim value
2247 ocaml_guestfs_rmdir (value gv, value pathv)
2248 {
2249   CAMLparam2 (gv, pathv);
2250   CAMLlocal1 (rv);
2251
2252   guestfs_h *g = Guestfs_val (gv);
2253   if (g == NULL)
2254     caml_failwith ("rmdir: used handle after closing it");
2255
2256   const char *path = String_val (pathv);
2257   int r;
2258
2259   caml_enter_blocking_section ();
2260   r = guestfs_rmdir (g, path);
2261   caml_leave_blocking_section ();
2262   if (r == -1)
2263     ocaml_guestfs_raise_error (g, "rmdir");
2264
2265   rv = Val_unit;
2266   CAMLreturn (rv);
2267 }
2268
2269 CAMLprim value
2270 ocaml_guestfs_rm_rf (value gv, value pathv)
2271 {
2272   CAMLparam2 (gv, pathv);
2273   CAMLlocal1 (rv);
2274
2275   guestfs_h *g = Guestfs_val (gv);
2276   if (g == NULL)
2277     caml_failwith ("rm_rf: used handle after closing it");
2278
2279   const char *path = String_val (pathv);
2280   int r;
2281
2282   caml_enter_blocking_section ();
2283   r = guestfs_rm_rf (g, path);
2284   caml_leave_blocking_section ();
2285   if (r == -1)
2286     ocaml_guestfs_raise_error (g, "rm_rf");
2287
2288   rv = Val_unit;
2289   CAMLreturn (rv);
2290 }
2291
2292 CAMLprim value
2293 ocaml_guestfs_mkdir (value gv, value pathv)
2294 {
2295   CAMLparam2 (gv, pathv);
2296   CAMLlocal1 (rv);
2297
2298   guestfs_h *g = Guestfs_val (gv);
2299   if (g == NULL)
2300     caml_failwith ("mkdir: used handle after closing it");
2301
2302   const char *path = String_val (pathv);
2303   int r;
2304
2305   caml_enter_blocking_section ();
2306   r = guestfs_mkdir (g, path);
2307   caml_leave_blocking_section ();
2308   if (r == -1)
2309     ocaml_guestfs_raise_error (g, "mkdir");
2310
2311   rv = Val_unit;
2312   CAMLreturn (rv);
2313 }
2314
2315 CAMLprim value
2316 ocaml_guestfs_mkdir_p (value gv, value pathv)
2317 {
2318   CAMLparam2 (gv, pathv);
2319   CAMLlocal1 (rv);
2320
2321   guestfs_h *g = Guestfs_val (gv);
2322   if (g == NULL)
2323     caml_failwith ("mkdir_p: used handle after closing it");
2324
2325   const char *path = String_val (pathv);
2326   int r;
2327
2328   caml_enter_blocking_section ();
2329   r = guestfs_mkdir_p (g, path);
2330   caml_leave_blocking_section ();
2331   if (r == -1)
2332     ocaml_guestfs_raise_error (g, "mkdir_p");
2333
2334   rv = Val_unit;
2335   CAMLreturn (rv);
2336 }
2337
2338 CAMLprim value
2339 ocaml_guestfs_chmod (value gv, value modev, value pathv)
2340 {
2341   CAMLparam3 (gv, modev, pathv);
2342   CAMLlocal1 (rv);
2343
2344   guestfs_h *g = Guestfs_val (gv);
2345   if (g == NULL)
2346     caml_failwith ("chmod: used handle after closing it");
2347
2348   int mode = Int_val (modev);
2349   const char *path = String_val (pathv);
2350   int r;
2351
2352   caml_enter_blocking_section ();
2353   r = guestfs_chmod (g, mode, path);
2354   caml_leave_blocking_section ();
2355   if (r == -1)
2356     ocaml_guestfs_raise_error (g, "chmod");
2357
2358   rv = Val_unit;
2359   CAMLreturn (rv);
2360 }
2361
2362 CAMLprim value
2363 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
2364 {
2365   CAMLparam4 (gv, ownerv, groupv, pathv);
2366   CAMLlocal1 (rv);
2367
2368   guestfs_h *g = Guestfs_val (gv);
2369   if (g == NULL)
2370     caml_failwith ("chown: used handle after closing it");
2371
2372   int owner = Int_val (ownerv);
2373   int group = Int_val (groupv);
2374   const char *path = String_val (pathv);
2375   int r;
2376
2377   caml_enter_blocking_section ();
2378   r = guestfs_chown (g, owner, group, path);
2379   caml_leave_blocking_section ();
2380   if (r == -1)
2381     ocaml_guestfs_raise_error (g, "chown");
2382
2383   rv = Val_unit;
2384   CAMLreturn (rv);
2385 }
2386
2387 CAMLprim value
2388 ocaml_guestfs_exists (value gv, value pathv)
2389 {
2390   CAMLparam2 (gv, pathv);
2391   CAMLlocal1 (rv);
2392
2393   guestfs_h *g = Guestfs_val (gv);
2394   if (g == NULL)
2395     caml_failwith ("exists: used handle after closing it");
2396
2397   const char *path = String_val (pathv);
2398   int r;
2399
2400   caml_enter_blocking_section ();
2401   r = guestfs_exists (g, path);
2402   caml_leave_blocking_section ();
2403   if (r == -1)
2404     ocaml_guestfs_raise_error (g, "exists");
2405
2406   rv = Val_bool (r);
2407   CAMLreturn (rv);
2408 }
2409
2410 CAMLprim value
2411 ocaml_guestfs_is_file (value gv, value pathv)
2412 {
2413   CAMLparam2 (gv, pathv);
2414   CAMLlocal1 (rv);
2415
2416   guestfs_h *g = Guestfs_val (gv);
2417   if (g == NULL)
2418     caml_failwith ("is_file: used handle after closing it");
2419
2420   const char *path = String_val (pathv);
2421   int r;
2422
2423   caml_enter_blocking_section ();
2424   r = guestfs_is_file (g, path);
2425   caml_leave_blocking_section ();
2426   if (r == -1)
2427     ocaml_guestfs_raise_error (g, "is_file");
2428
2429   rv = Val_bool (r);
2430   CAMLreturn (rv);
2431 }
2432
2433 CAMLprim value
2434 ocaml_guestfs_is_dir (value gv, value pathv)
2435 {
2436   CAMLparam2 (gv, pathv);
2437   CAMLlocal1 (rv);
2438
2439   guestfs_h *g = Guestfs_val (gv);
2440   if (g == NULL)
2441     caml_failwith ("is_dir: used handle after closing it");
2442
2443   const char *path = String_val (pathv);
2444   int r;
2445
2446   caml_enter_blocking_section ();
2447   r = guestfs_is_dir (g, path);
2448   caml_leave_blocking_section ();
2449   if (r == -1)
2450     ocaml_guestfs_raise_error (g, "is_dir");
2451
2452   rv = Val_bool (r);
2453   CAMLreturn (rv);
2454 }
2455
2456 CAMLprim value
2457 ocaml_guestfs_pvcreate (value gv, value devicev)
2458 {
2459   CAMLparam2 (gv, devicev);
2460   CAMLlocal1 (rv);
2461
2462   guestfs_h *g = Guestfs_val (gv);
2463   if (g == NULL)
2464     caml_failwith ("pvcreate: used handle after closing it");
2465
2466   const char *device = String_val (devicev);
2467   int r;
2468
2469   caml_enter_blocking_section ();
2470   r = guestfs_pvcreate (g, device);
2471   caml_leave_blocking_section ();
2472   if (r == -1)
2473     ocaml_guestfs_raise_error (g, "pvcreate");
2474
2475   rv = Val_unit;
2476   CAMLreturn (rv);
2477 }
2478
2479 CAMLprim value
2480 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
2481 {
2482   CAMLparam3 (gv, volgroupv, physvolsv);
2483   CAMLlocal1 (rv);
2484
2485   guestfs_h *g = Guestfs_val (gv);
2486   if (g == NULL)
2487     caml_failwith ("vgcreate: used handle after closing it");
2488
2489   const char *volgroup = String_val (volgroupv);
2490   char **physvols = ocaml_guestfs_strings_val (g, physvolsv);
2491   int r;
2492
2493   caml_enter_blocking_section ();
2494   r = guestfs_vgcreate (g, volgroup, physvols);
2495   caml_leave_blocking_section ();
2496   ocaml_guestfs_free_strings (physvols);
2497   if (r == -1)
2498     ocaml_guestfs_raise_error (g, "vgcreate");
2499
2500   rv = Val_unit;
2501   CAMLreturn (rv);
2502 }
2503
2504 CAMLprim value
2505 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
2506 {
2507   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
2508   CAMLlocal1 (rv);
2509
2510   guestfs_h *g = Guestfs_val (gv);
2511   if (g == NULL)
2512     caml_failwith ("lvcreate: used handle after closing it");
2513
2514   const char *logvol = String_val (logvolv);
2515   const char *volgroup = String_val (volgroupv);
2516   int mbytes = Int_val (mbytesv);
2517   int r;
2518
2519   caml_enter_blocking_section ();
2520   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
2521   caml_leave_blocking_section ();
2522   if (r == -1)
2523     ocaml_guestfs_raise_error (g, "lvcreate");
2524
2525   rv = Val_unit;
2526   CAMLreturn (rv);
2527 }
2528
2529 CAMLprim value
2530 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
2531 {
2532   CAMLparam3 (gv, fstypev, devicev);
2533   CAMLlocal1 (rv);
2534
2535   guestfs_h *g = Guestfs_val (gv);
2536   if (g == NULL)
2537     caml_failwith ("mkfs: used handle after closing it");
2538
2539   const char *fstype = String_val (fstypev);
2540   const char *device = String_val (devicev);
2541   int r;
2542
2543   caml_enter_blocking_section ();
2544   r = guestfs_mkfs (g, fstype, device);
2545   caml_leave_blocking_section ();
2546   if (r == -1)
2547     ocaml_guestfs_raise_error (g, "mkfs");
2548
2549   rv = Val_unit;
2550   CAMLreturn (rv);
2551 }
2552
2553 CAMLprim value
2554 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
2555 {
2556   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
2557   CAMLxparam1 (linesv);
2558   CAMLlocal1 (rv);
2559
2560   guestfs_h *g = Guestfs_val (gv);
2561   if (g == NULL)
2562     caml_failwith ("sfdisk: used handle after closing it");
2563
2564   const char *device = String_val (devicev);
2565   int cyls = Int_val (cylsv);
2566   int heads = Int_val (headsv);
2567   int sectors = Int_val (sectorsv);
2568   char **lines = ocaml_guestfs_strings_val (g, linesv);
2569   int r;
2570
2571   caml_enter_blocking_section ();
2572   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
2573   caml_leave_blocking_section ();
2574   ocaml_guestfs_free_strings (lines);
2575   if (r == -1)
2576     ocaml_guestfs_raise_error (g, "sfdisk");
2577
2578   rv = Val_unit;
2579   CAMLreturn (rv);
2580 }
2581
2582 CAMLprim value
2583 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
2584 {
2585   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
2586 }
2587
2588 CAMLprim value
2589 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
2590 {
2591   CAMLparam4 (gv, pathv, contentv, sizev);
2592   CAMLlocal1 (rv);
2593
2594   guestfs_h *g = Guestfs_val (gv);
2595   if (g == NULL)
2596     caml_failwith ("write_file: used handle after closing it");
2597
2598   const char *path = String_val (pathv);
2599   const char *content = String_val (contentv);
2600   int size = Int_val (sizev);
2601   int r;
2602
2603   caml_enter_blocking_section ();
2604   r = guestfs_write_file (g, path, content, size);
2605   caml_leave_blocking_section ();
2606   if (r == -1)
2607     ocaml_guestfs_raise_error (g, "write_file");
2608
2609   rv = Val_unit;
2610   CAMLreturn (rv);
2611 }
2612
2613 CAMLprim value
2614 ocaml_guestfs_umount (value gv, value pathordevicev)
2615 {
2616   CAMLparam2 (gv, pathordevicev);
2617   CAMLlocal1 (rv);
2618
2619   guestfs_h *g = Guestfs_val (gv);
2620   if (g == NULL)
2621     caml_failwith ("umount: used handle after closing it");
2622
2623   const char *pathordevice = String_val (pathordevicev);
2624   int r;
2625
2626   caml_enter_blocking_section ();
2627   r = guestfs_umount (g, pathordevice);
2628   caml_leave_blocking_section ();
2629   if (r == -1)
2630     ocaml_guestfs_raise_error (g, "umount");
2631
2632   rv = Val_unit;
2633   CAMLreturn (rv);
2634 }
2635
2636 CAMLprim value
2637 ocaml_guestfs_mounts (value gv)
2638 {
2639   CAMLparam1 (gv);
2640   CAMLlocal1 (rv);
2641
2642   guestfs_h *g = Guestfs_val (gv);
2643   if (g == NULL)
2644     caml_failwith ("mounts: used handle after closing it");
2645
2646   int i;
2647   char **r;
2648
2649   caml_enter_blocking_section ();
2650   r = guestfs_mounts (g);
2651   caml_leave_blocking_section ();
2652   if (r == NULL)
2653     ocaml_guestfs_raise_error (g, "mounts");
2654
2655   rv = caml_copy_string_array ((const char **) r);
2656   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2657   free (r);
2658   CAMLreturn (rv);
2659 }
2660
2661 CAMLprim value
2662 ocaml_guestfs_umount_all (value gv)
2663 {
2664   CAMLparam1 (gv);
2665   CAMLlocal1 (rv);
2666
2667   guestfs_h *g = Guestfs_val (gv);
2668   if (g == NULL)
2669     caml_failwith ("umount_all: used handle after closing it");
2670
2671   int r;
2672
2673   caml_enter_blocking_section ();
2674   r = guestfs_umount_all (g);
2675   caml_leave_blocking_section ();
2676   if (r == -1)
2677     ocaml_guestfs_raise_error (g, "umount_all");
2678
2679   rv = Val_unit;
2680   CAMLreturn (rv);
2681 }
2682
2683 CAMLprim value
2684 ocaml_guestfs_lvm_remove_all (value gv)
2685 {
2686   CAMLparam1 (gv);
2687   CAMLlocal1 (rv);
2688
2689   guestfs_h *g = Guestfs_val (gv);
2690   if (g == NULL)
2691     caml_failwith ("lvm_remove_all: used handle after closing it");
2692
2693   int r;
2694
2695   caml_enter_blocking_section ();
2696   r = guestfs_lvm_remove_all (g);
2697   caml_leave_blocking_section ();
2698   if (r == -1)
2699     ocaml_guestfs_raise_error (g, "lvm_remove_all");
2700
2701   rv = Val_unit;
2702   CAMLreturn (rv);
2703 }
2704
2705 CAMLprim value
2706 ocaml_guestfs_file (value gv, value pathv)
2707 {
2708   CAMLparam2 (gv, pathv);
2709   CAMLlocal1 (rv);
2710
2711   guestfs_h *g = Guestfs_val (gv);
2712   if (g == NULL)
2713     caml_failwith ("file: used handle after closing it");
2714
2715   const char *path = String_val (pathv);
2716   char *r;
2717
2718   caml_enter_blocking_section ();
2719   r = guestfs_file (g, path);
2720   caml_leave_blocking_section ();
2721   if (r == NULL)
2722     ocaml_guestfs_raise_error (g, "file");
2723
2724   rv = caml_copy_string (r);
2725   free (r);
2726   CAMLreturn (rv);
2727 }
2728
2729 CAMLprim value
2730 ocaml_guestfs_command (value gv, value argumentsv)
2731 {
2732   CAMLparam2 (gv, argumentsv);
2733   CAMLlocal1 (rv);
2734
2735   guestfs_h *g = Guestfs_val (gv);
2736   if (g == NULL)
2737     caml_failwith ("command: used handle after closing it");
2738
2739   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2740   char *r;
2741
2742   caml_enter_blocking_section ();
2743   r = guestfs_command (g, arguments);
2744   caml_leave_blocking_section ();
2745   ocaml_guestfs_free_strings (arguments);
2746   if (r == NULL)
2747     ocaml_guestfs_raise_error (g, "command");
2748
2749   rv = caml_copy_string (r);
2750   free (r);
2751   CAMLreturn (rv);
2752 }
2753
2754 CAMLprim value
2755 ocaml_guestfs_command_lines (value gv, value argumentsv)
2756 {
2757   CAMLparam2 (gv, argumentsv);
2758   CAMLlocal1 (rv);
2759
2760   guestfs_h *g = Guestfs_val (gv);
2761   if (g == NULL)
2762     caml_failwith ("command_lines: used handle after closing it");
2763
2764   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2765   int i;
2766   char **r;
2767
2768   caml_enter_blocking_section ();
2769   r = guestfs_command_lines (g, arguments);
2770   caml_leave_blocking_section ();
2771   ocaml_guestfs_free_strings (arguments);
2772   if (r == NULL)
2773     ocaml_guestfs_raise_error (g, "command_lines");
2774
2775   rv = caml_copy_string_array ((const char **) r);
2776   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2777   free (r);
2778   CAMLreturn (rv);
2779 }
2780
2781 CAMLprim value
2782 ocaml_guestfs_stat (value gv, value pathv)
2783 {
2784   CAMLparam2 (gv, pathv);
2785   CAMLlocal1 (rv);
2786
2787   guestfs_h *g = Guestfs_val (gv);
2788   if (g == NULL)
2789     caml_failwith ("stat: used handle after closing it");
2790
2791   const char *path = String_val (pathv);
2792   struct guestfs_stat *r;
2793
2794   caml_enter_blocking_section ();
2795   r = guestfs_stat (g, path);
2796   caml_leave_blocking_section ();
2797   if (r == NULL)
2798     ocaml_guestfs_raise_error (g, "stat");
2799
2800   rv = copy_stat (r);
2801   free (r);
2802   CAMLreturn (rv);
2803 }
2804
2805 CAMLprim value
2806 ocaml_guestfs_lstat (value gv, value pathv)
2807 {
2808   CAMLparam2 (gv, pathv);
2809   CAMLlocal1 (rv);
2810
2811   guestfs_h *g = Guestfs_val (gv);
2812   if (g == NULL)
2813     caml_failwith ("lstat: used handle after closing it");
2814
2815   const char *path = String_val (pathv);
2816   struct guestfs_stat *r;
2817
2818   caml_enter_blocking_section ();
2819   r = guestfs_lstat (g, path);
2820   caml_leave_blocking_section ();
2821   if (r == NULL)
2822     ocaml_guestfs_raise_error (g, "lstat");
2823
2824   rv = copy_stat (r);
2825   free (r);
2826   CAMLreturn (rv);
2827 }
2828
2829 CAMLprim value
2830 ocaml_guestfs_statvfs (value gv, value pathv)
2831 {
2832   CAMLparam2 (gv, pathv);
2833   CAMLlocal1 (rv);
2834
2835   guestfs_h *g = Guestfs_val (gv);
2836   if (g == NULL)
2837     caml_failwith ("statvfs: used handle after closing it");
2838
2839   const char *path = String_val (pathv);
2840   struct guestfs_statvfs *r;
2841
2842   caml_enter_blocking_section ();
2843   r = guestfs_statvfs (g, path);
2844   caml_leave_blocking_section ();
2845   if (r == NULL)
2846     ocaml_guestfs_raise_error (g, "statvfs");
2847
2848   rv = copy_statvfs (r);
2849   free (r);
2850   CAMLreturn (rv);
2851 }
2852
2853 CAMLprim value
2854 ocaml_guestfs_tune2fs_l (value gv, value devicev)
2855 {
2856   CAMLparam2 (gv, devicev);
2857   CAMLlocal1 (rv);
2858
2859   guestfs_h *g = Guestfs_val (gv);
2860   if (g == NULL)
2861     caml_failwith ("tune2fs_l: used handle after closing it");
2862
2863   const char *device = String_val (devicev);
2864   int i;
2865   char **r;
2866
2867   caml_enter_blocking_section ();
2868   r = guestfs_tune2fs_l (g, device);
2869   caml_leave_blocking_section ();
2870   if (r == NULL)
2871     ocaml_guestfs_raise_error (g, "tune2fs_l");
2872
2873   rv = copy_table (r);
2874   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2875   free (r);
2876   CAMLreturn (rv);
2877 }
2878
2879 CAMLprim value
2880 ocaml_guestfs_blockdev_setro (value gv, value devicev)
2881 {
2882   CAMLparam2 (gv, devicev);
2883   CAMLlocal1 (rv);
2884
2885   guestfs_h *g = Guestfs_val (gv);
2886   if (g == NULL)
2887     caml_failwith ("blockdev_setro: used handle after closing it");
2888
2889   const char *device = String_val (devicev);
2890   int r;
2891
2892   caml_enter_blocking_section ();
2893   r = guestfs_blockdev_setro (g, device);
2894   caml_leave_blocking_section ();
2895   if (r == -1)
2896     ocaml_guestfs_raise_error (g, "blockdev_setro");
2897
2898   rv = Val_unit;
2899   CAMLreturn (rv);
2900 }
2901
2902 CAMLprim value
2903 ocaml_guestfs_blockdev_setrw (value gv, value devicev)
2904 {
2905   CAMLparam2 (gv, devicev);
2906   CAMLlocal1 (rv);
2907
2908   guestfs_h *g = Guestfs_val (gv);
2909   if (g == NULL)
2910     caml_failwith ("blockdev_setrw: used handle after closing it");
2911
2912   const char *device = String_val (devicev);
2913   int r;
2914
2915   caml_enter_blocking_section ();
2916   r = guestfs_blockdev_setrw (g, device);
2917   caml_leave_blocking_section ();
2918   if (r == -1)
2919     ocaml_guestfs_raise_error (g, "blockdev_setrw");
2920
2921   rv = Val_unit;
2922   CAMLreturn (rv);
2923 }
2924
2925 CAMLprim value
2926 ocaml_guestfs_blockdev_getro (value gv, value devicev)
2927 {
2928   CAMLparam2 (gv, devicev);
2929   CAMLlocal1 (rv);
2930
2931   guestfs_h *g = Guestfs_val (gv);
2932   if (g == NULL)
2933     caml_failwith ("blockdev_getro: used handle after closing it");
2934
2935   const char *device = String_val (devicev);
2936   int r;
2937
2938   caml_enter_blocking_section ();
2939   r = guestfs_blockdev_getro (g, device);
2940   caml_leave_blocking_section ();
2941   if (r == -1)
2942     ocaml_guestfs_raise_error (g, "blockdev_getro");
2943
2944   rv = Val_bool (r);
2945   CAMLreturn (rv);
2946 }
2947
2948 CAMLprim value
2949 ocaml_guestfs_blockdev_getss (value gv, value devicev)
2950 {
2951   CAMLparam2 (gv, devicev);
2952   CAMLlocal1 (rv);
2953
2954   guestfs_h *g = Guestfs_val (gv);
2955   if (g == NULL)
2956     caml_failwith ("blockdev_getss: used handle after closing it");
2957
2958   const char *device = String_val (devicev);
2959   int r;
2960
2961   caml_enter_blocking_section ();
2962   r = guestfs_blockdev_getss (g, device);
2963   caml_leave_blocking_section ();
2964   if (r == -1)
2965     ocaml_guestfs_raise_error (g, "blockdev_getss");
2966
2967   rv = Val_int (r);
2968   CAMLreturn (rv);
2969 }
2970
2971 CAMLprim value
2972 ocaml_guestfs_blockdev_getbsz (value gv, value devicev)
2973 {
2974   CAMLparam2 (gv, devicev);
2975   CAMLlocal1 (rv);
2976
2977   guestfs_h *g = Guestfs_val (gv);
2978   if (g == NULL)
2979     caml_failwith ("blockdev_getbsz: used handle after closing it");
2980
2981   const char *device = String_val (devicev);
2982   int r;
2983
2984   caml_enter_blocking_section ();
2985   r = guestfs_blockdev_getbsz (g, device);
2986   caml_leave_blocking_section ();
2987   if (r == -1)
2988     ocaml_guestfs_raise_error (g, "blockdev_getbsz");
2989
2990   rv = Val_int (r);
2991   CAMLreturn (rv);
2992 }
2993
2994 CAMLprim value
2995 ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev)
2996 {
2997   CAMLparam3 (gv, devicev, blocksizev);
2998   CAMLlocal1 (rv);
2999
3000   guestfs_h *g = Guestfs_val (gv);
3001   if (g == NULL)
3002     caml_failwith ("blockdev_setbsz: used handle after closing it");
3003
3004   const char *device = String_val (devicev);
3005   int blocksize = Int_val (blocksizev);
3006   int r;
3007
3008   caml_enter_blocking_section ();
3009   r = guestfs_blockdev_setbsz (g, device, blocksize);
3010   caml_leave_blocking_section ();
3011   if (r == -1)
3012     ocaml_guestfs_raise_error (g, "blockdev_setbsz");
3013
3014   rv = Val_unit;
3015   CAMLreturn (rv);
3016 }
3017
3018 CAMLprim value
3019 ocaml_guestfs_blockdev_getsz (value gv, value devicev)
3020 {
3021   CAMLparam2 (gv, devicev);
3022   CAMLlocal1 (rv);
3023
3024   guestfs_h *g = Guestfs_val (gv);
3025   if (g == NULL)
3026     caml_failwith ("blockdev_getsz: used handle after closing it");
3027
3028   const char *device = String_val (devicev);
3029   int64_t r;
3030
3031   caml_enter_blocking_section ();
3032   r = guestfs_blockdev_getsz (g, device);
3033   caml_leave_blocking_section ();
3034   if (r == -1)
3035     ocaml_guestfs_raise_error (g, "blockdev_getsz");
3036
3037   rv = caml_copy_int64 (r);
3038   CAMLreturn (rv);
3039 }
3040
3041 CAMLprim value
3042 ocaml_guestfs_blockdev_getsize64 (value gv, value devicev)
3043 {
3044   CAMLparam2 (gv, devicev);
3045   CAMLlocal1 (rv);
3046
3047   guestfs_h *g = Guestfs_val (gv);
3048   if (g == NULL)
3049     caml_failwith ("blockdev_getsize64: used handle after closing it");
3050
3051   const char *device = String_val (devicev);
3052   int64_t r;
3053
3054   caml_enter_blocking_section ();
3055   r = guestfs_blockdev_getsize64 (g, device);
3056   caml_leave_blocking_section ();
3057   if (r == -1)
3058     ocaml_guestfs_raise_error (g, "blockdev_getsize64");
3059
3060   rv = caml_copy_int64 (r);
3061   CAMLreturn (rv);
3062 }
3063
3064 CAMLprim value
3065 ocaml_guestfs_blockdev_flushbufs (value gv, value devicev)
3066 {
3067   CAMLparam2 (gv, devicev);
3068   CAMLlocal1 (rv);
3069
3070   guestfs_h *g = Guestfs_val (gv);
3071   if (g == NULL)
3072     caml_failwith ("blockdev_flushbufs: used handle after closing it");
3073
3074   const char *device = String_val (devicev);
3075   int r;
3076
3077   caml_enter_blocking_section ();
3078   r = guestfs_blockdev_flushbufs (g, device);
3079   caml_leave_blocking_section ();
3080   if (r == -1)
3081     ocaml_guestfs_raise_error (g, "blockdev_flushbufs");
3082
3083   rv = Val_unit;
3084   CAMLreturn (rv);
3085 }
3086
3087 CAMLprim value
3088 ocaml_guestfs_blockdev_rereadpt (value gv, value devicev)
3089 {
3090   CAMLparam2 (gv, devicev);
3091   CAMLlocal1 (rv);
3092
3093   guestfs_h *g = Guestfs_val (gv);
3094   if (g == NULL)
3095     caml_failwith ("blockdev_rereadpt: used handle after closing it");
3096
3097   const char *device = String_val (devicev);
3098   int r;
3099
3100   caml_enter_blocking_section ();
3101   r = guestfs_blockdev_rereadpt (g, device);
3102   caml_leave_blocking_section ();
3103   if (r == -1)
3104     ocaml_guestfs_raise_error (g, "blockdev_rereadpt");
3105
3106   rv = Val_unit;
3107   CAMLreturn (rv);
3108 }
3109
3110 CAMLprim value
3111 ocaml_guestfs_upload (value gv, value filenamev, value remotefilenamev)
3112 {
3113   CAMLparam3 (gv, filenamev, remotefilenamev);
3114   CAMLlocal1 (rv);
3115
3116   guestfs_h *g = Guestfs_val (gv);
3117   if (g == NULL)
3118     caml_failwith ("upload: used handle after closing it");
3119
3120   const char *filename = String_val (filenamev);
3121   const char *remotefilename = String_val (remotefilenamev);
3122   int r;
3123
3124   caml_enter_blocking_section ();
3125   r = guestfs_upload (g, filename, remotefilename);
3126   caml_leave_blocking_section ();
3127   if (r == -1)
3128     ocaml_guestfs_raise_error (g, "upload");
3129
3130   rv = Val_unit;
3131   CAMLreturn (rv);
3132 }
3133
3134 CAMLprim value
3135 ocaml_guestfs_download (value gv, value remotefilenamev, value filenamev)
3136 {
3137   CAMLparam3 (gv, remotefilenamev, filenamev);
3138   CAMLlocal1 (rv);
3139
3140   guestfs_h *g = Guestfs_val (gv);
3141   if (g == NULL)
3142     caml_failwith ("download: used handle after closing it");
3143
3144   const char *remotefilename = String_val (remotefilenamev);
3145   const char *filename = String_val (filenamev);
3146   int r;
3147
3148   caml_enter_blocking_section ();
3149   r = guestfs_download (g, remotefilename, filename);
3150   caml_leave_blocking_section ();
3151   if (r == -1)
3152     ocaml_guestfs_raise_error (g, "download");
3153
3154   rv = Val_unit;
3155   CAMLreturn (rv);
3156 }
3157
3158 CAMLprim value
3159 ocaml_guestfs_checksum (value gv, value csumtypev, value pathv)
3160 {
3161   CAMLparam3 (gv, csumtypev, pathv);
3162   CAMLlocal1 (rv);
3163
3164   guestfs_h *g = Guestfs_val (gv);
3165   if (g == NULL)
3166     caml_failwith ("checksum: used handle after closing it");
3167
3168   const char *csumtype = String_val (csumtypev);
3169   const char *path = String_val (pathv);
3170   char *r;
3171
3172   caml_enter_blocking_section ();
3173   r = guestfs_checksum (g, csumtype, path);
3174   caml_leave_blocking_section ();
3175   if (r == NULL)
3176     ocaml_guestfs_raise_error (g, "checksum");
3177
3178   rv = caml_copy_string (r);
3179   free (r);
3180   CAMLreturn (rv);
3181 }
3182
3183 CAMLprim value
3184 ocaml_guestfs_tar_in (value gv, value tarfilev, value directoryv)
3185 {
3186   CAMLparam3 (gv, tarfilev, directoryv);
3187   CAMLlocal1 (rv);
3188
3189   guestfs_h *g = Guestfs_val (gv);
3190   if (g == NULL)
3191     caml_failwith ("tar_in: used handle after closing it");
3192
3193   const char *tarfile = String_val (tarfilev);
3194   const char *directory = String_val (directoryv);
3195   int r;
3196
3197   caml_enter_blocking_section ();
3198   r = guestfs_tar_in (g, tarfile, directory);
3199   caml_leave_blocking_section ();
3200   if (r == -1)
3201     ocaml_guestfs_raise_error (g, "tar_in");
3202
3203   rv = Val_unit;
3204   CAMLreturn (rv);
3205 }
3206
3207 CAMLprim value
3208 ocaml_guestfs_tar_out (value gv, value directoryv, value tarfilev)
3209 {
3210   CAMLparam3 (gv, directoryv, tarfilev);
3211   CAMLlocal1 (rv);
3212
3213   guestfs_h *g = Guestfs_val (gv);
3214   if (g == NULL)
3215     caml_failwith ("tar_out: used handle after closing it");
3216
3217   const char *directory = String_val (directoryv);
3218   const char *tarfile = String_val (tarfilev);
3219   int r;
3220
3221   caml_enter_blocking_section ();
3222   r = guestfs_tar_out (g, directory, tarfile);
3223   caml_leave_blocking_section ();
3224   if (r == -1)
3225     ocaml_guestfs_raise_error (g, "tar_out");
3226
3227   rv = Val_unit;
3228   CAMLreturn (rv);
3229 }
3230
3231 CAMLprim value
3232 ocaml_guestfs_tgz_in (value gv, value tarballv, value directoryv)
3233 {
3234   CAMLparam3 (gv, tarballv, directoryv);
3235   CAMLlocal1 (rv);
3236
3237   guestfs_h *g = Guestfs_val (gv);
3238   if (g == NULL)
3239     caml_failwith ("tgz_in: used handle after closing it");
3240
3241   const char *tarball = String_val (tarballv);
3242   const char *directory = String_val (directoryv);
3243   int r;
3244
3245   caml_enter_blocking_section ();
3246   r = guestfs_tgz_in (g, tarball, directory);
3247   caml_leave_blocking_section ();
3248   if (r == -1)
3249     ocaml_guestfs_raise_error (g, "tgz_in");
3250
3251   rv = Val_unit;
3252   CAMLreturn (rv);
3253 }
3254
3255 CAMLprim value
3256 ocaml_guestfs_tgz_out (value gv, value directoryv, value tarballv)
3257 {
3258   CAMLparam3 (gv, directoryv, tarballv);
3259   CAMLlocal1 (rv);
3260
3261   guestfs_h *g = Guestfs_val (gv);
3262   if (g == NULL)
3263     caml_failwith ("tgz_out: used handle after closing it");
3264
3265   const char *directory = String_val (directoryv);
3266   const char *tarball = String_val (tarballv);
3267   int r;
3268
3269   caml_enter_blocking_section ();
3270   r = guestfs_tgz_out (g, directory, tarball);
3271   caml_leave_blocking_section ();
3272   if (r == -1)
3273     ocaml_guestfs_raise_error (g, "tgz_out");
3274
3275   rv = Val_unit;
3276   CAMLreturn (rv);
3277 }
3278
3279 CAMLprim value
3280 ocaml_guestfs_mount_ro (value gv, value devicev, value mountpointv)
3281 {
3282   CAMLparam3 (gv, devicev, mountpointv);
3283   CAMLlocal1 (rv);
3284
3285   guestfs_h *g = Guestfs_val (gv);
3286   if (g == NULL)
3287     caml_failwith ("mount_ro: used handle after closing it");
3288
3289   const char *device = String_val (devicev);
3290   const char *mountpoint = String_val (mountpointv);
3291   int r;
3292
3293   caml_enter_blocking_section ();
3294   r = guestfs_mount_ro (g, device, mountpoint);
3295   caml_leave_blocking_section ();
3296   if (r == -1)
3297     ocaml_guestfs_raise_error (g, "mount_ro");
3298
3299   rv = Val_unit;
3300   CAMLreturn (rv);
3301 }
3302
3303 CAMLprim value
3304 ocaml_guestfs_mount_options (value gv, value optionsv, value devicev, value mountpointv)
3305 {
3306   CAMLparam4 (gv, optionsv, devicev, mountpointv);
3307   CAMLlocal1 (rv);
3308
3309   guestfs_h *g = Guestfs_val (gv);
3310   if (g == NULL)
3311     caml_failwith ("mount_options: used handle after closing it");
3312
3313   const char *options = String_val (optionsv);
3314   const char *device = String_val (devicev);
3315   const char *mountpoint = String_val (mountpointv);
3316   int r;
3317
3318   caml_enter_blocking_section ();
3319   r = guestfs_mount_options (g, options, device, mountpoint);
3320   caml_leave_blocking_section ();
3321   if (r == -1)
3322     ocaml_guestfs_raise_error (g, "mount_options");
3323
3324   rv = Val_unit;
3325   CAMLreturn (rv);
3326 }
3327
3328 CAMLprim value
3329 ocaml_guestfs_mount_vfs (value gv, value optionsv, value vfstypev, value devicev, value mountpointv)
3330 {
3331   CAMLparam5 (gv, optionsv, vfstypev, devicev, mountpointv);
3332   CAMLlocal1 (rv);
3333
3334   guestfs_h *g = Guestfs_val (gv);
3335   if (g == NULL)
3336     caml_failwith ("mount_vfs: used handle after closing it");
3337
3338   const char *options = String_val (optionsv);
3339   const char *vfstype = String_val (vfstypev);
3340   const char *device = String_val (devicev);
3341   const char *mountpoint = String_val (mountpointv);
3342   int r;
3343
3344   caml_enter_blocking_section ();
3345   r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
3346   caml_leave_blocking_section ();
3347   if (r == -1)
3348     ocaml_guestfs_raise_error (g, "mount_vfs");
3349
3350   rv = Val_unit;
3351   CAMLreturn (rv);
3352 }
3353
3354 CAMLprim value
3355 ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
3356 {
3357   CAMLparam3 (gv, subcmdv, extraargsv);
3358   CAMLlocal1 (rv);
3359
3360   guestfs_h *g = Guestfs_val (gv);
3361   if (g == NULL)
3362     caml_failwith ("debug: used handle after closing it");
3363
3364   const char *subcmd = String_val (subcmdv);
3365   char **extraargs = ocaml_guestfs_strings_val (g, extraargsv);
3366   char *r;
3367
3368   caml_enter_blocking_section ();
3369   r = guestfs_debug (g, subcmd, extraargs);
3370   caml_leave_blocking_section ();
3371   ocaml_guestfs_free_strings (extraargs);
3372   if (r == NULL)
3373     ocaml_guestfs_raise_error (g, "debug");
3374
3375   rv = caml_copy_string (r);
3376   free (r);
3377   CAMLreturn (rv);
3378 }
3379
3380 CAMLprim value
3381 ocaml_guestfs_lvremove (value gv, value devicev)
3382 {
3383   CAMLparam2 (gv, devicev);
3384   CAMLlocal1 (rv);
3385
3386   guestfs_h *g = Guestfs_val (gv);
3387   if (g == NULL)
3388     caml_failwith ("lvremove: used handle after closing it");
3389
3390   const char *device = String_val (devicev);
3391   int r;
3392
3393   caml_enter_blocking_section ();
3394   r = guestfs_lvremove (g, device);
3395   caml_leave_blocking_section ();
3396   if (r == -1)
3397     ocaml_guestfs_raise_error (g, "lvremove");
3398
3399   rv = Val_unit;
3400   CAMLreturn (rv);
3401 }
3402
3403 CAMLprim value
3404 ocaml_guestfs_vgremove (value gv, value vgnamev)
3405 {
3406   CAMLparam2 (gv, vgnamev);
3407   CAMLlocal1 (rv);
3408
3409   guestfs_h *g = Guestfs_val (gv);
3410   if (g == NULL)
3411     caml_failwith ("vgremove: used handle after closing it");
3412
3413   const char *vgname = String_val (vgnamev);
3414   int r;
3415
3416   caml_enter_blocking_section ();
3417   r = guestfs_vgremove (g, vgname);
3418   caml_leave_blocking_section ();
3419   if (r == -1)
3420     ocaml_guestfs_raise_error (g, "vgremove");
3421
3422   rv = Val_unit;
3423   CAMLreturn (rv);
3424 }
3425
3426 CAMLprim value
3427 ocaml_guestfs_pvremove (value gv, value devicev)
3428 {
3429   CAMLparam2 (gv, devicev);
3430   CAMLlocal1 (rv);
3431
3432   guestfs_h *g = Guestfs_val (gv);
3433   if (g == NULL)
3434     caml_failwith ("pvremove: used handle after closing it");
3435
3436   const char *device = String_val (devicev);
3437   int r;
3438
3439   caml_enter_blocking_section ();
3440   r = guestfs_pvremove (g, device);
3441   caml_leave_blocking_section ();
3442   if (r == -1)
3443     ocaml_guestfs_raise_error (g, "pvremove");
3444
3445   rv = Val_unit;
3446   CAMLreturn (rv);
3447 }
3448
3449 CAMLprim value
3450 ocaml_guestfs_set_e2label (value gv, value devicev, value labelv)
3451 {
3452   CAMLparam3 (gv, devicev, labelv);
3453   CAMLlocal1 (rv);
3454
3455   guestfs_h *g = Guestfs_val (gv);
3456   if (g == NULL)
3457     caml_failwith ("set_e2label: used handle after closing it");
3458
3459   const char *device = String_val (devicev);
3460   const char *label = String_val (labelv);
3461   int r;
3462
3463   caml_enter_blocking_section ();
3464   r = guestfs_set_e2label (g, device, label);
3465   caml_leave_blocking_section ();
3466   if (r == -1)
3467     ocaml_guestfs_raise_error (g, "set_e2label");
3468
3469   rv = Val_unit;
3470   CAMLreturn (rv);
3471 }
3472
3473 CAMLprim value
3474 ocaml_guestfs_get_e2label (value gv, value devicev)
3475 {
3476   CAMLparam2 (gv, devicev);
3477   CAMLlocal1 (rv);
3478
3479   guestfs_h *g = Guestfs_val (gv);
3480   if (g == NULL)
3481     caml_failwith ("get_e2label: used handle after closing it");
3482
3483   const char *device = String_val (devicev);
3484   char *r;
3485
3486   caml_enter_blocking_section ();
3487   r = guestfs_get_e2label (g, device);
3488   caml_leave_blocking_section ();
3489   if (r == NULL)
3490     ocaml_guestfs_raise_error (g, "get_e2label");
3491
3492   rv = caml_copy_string (r);
3493   free (r);
3494   CAMLreturn (rv);
3495 }
3496
3497 CAMLprim value
3498 ocaml_guestfs_set_e2uuid (value gv, value devicev, value uuidv)
3499 {
3500   CAMLparam3 (gv, devicev, uuidv);
3501   CAMLlocal1 (rv);
3502
3503   guestfs_h *g = Guestfs_val (gv);
3504   if (g == NULL)
3505     caml_failwith ("set_e2uuid: used handle after closing it");
3506
3507   const char *device = String_val (devicev);
3508   const char *uuid = String_val (uuidv);
3509   int r;
3510
3511   caml_enter_blocking_section ();
3512   r = guestfs_set_e2uuid (g, device, uuid);
3513   caml_leave_blocking_section ();
3514   if (r == -1)
3515     ocaml_guestfs_raise_error (g, "set_e2uuid");
3516
3517   rv = Val_unit;
3518   CAMLreturn (rv);
3519 }
3520
3521 CAMLprim value
3522 ocaml_guestfs_get_e2uuid (value gv, value devicev)
3523 {
3524   CAMLparam2 (gv, devicev);
3525   CAMLlocal1 (rv);
3526
3527   guestfs_h *g = Guestfs_val (gv);
3528   if (g == NULL)
3529     caml_failwith ("get_e2uuid: used handle after closing it");
3530
3531   const char *device = String_val (devicev);
3532   char *r;
3533
3534   caml_enter_blocking_section ();
3535   r = guestfs_get_e2uuid (g, device);
3536   caml_leave_blocking_section ();
3537   if (r == NULL)
3538     ocaml_guestfs_raise_error (g, "get_e2uuid");
3539
3540   rv = caml_copy_string (r);
3541   free (r);
3542   CAMLreturn (rv);
3543 }
3544
3545 CAMLprim value
3546 ocaml_guestfs_fsck (value gv, value fstypev, value devicev)
3547 {
3548   CAMLparam3 (gv, fstypev, devicev);
3549   CAMLlocal1 (rv);
3550
3551   guestfs_h *g = Guestfs_val (gv);
3552   if (g == NULL)
3553     caml_failwith ("fsck: used handle after closing it");
3554
3555   const char *fstype = String_val (fstypev);
3556   const char *device = String_val (devicev);
3557   int r;
3558
3559   caml_enter_blocking_section ();
3560   r = guestfs_fsck (g, fstype, device);
3561   caml_leave_blocking_section ();
3562   if (r == -1)
3563     ocaml_guestfs_raise_error (g, "fsck");
3564
3565   rv = Val_int (r);
3566   CAMLreturn (rv);
3567 }
3568
3569 CAMLprim value
3570 ocaml_guestfs_zero (value gv, value devicev)
3571 {
3572   CAMLparam2 (gv, devicev);
3573   CAMLlocal1 (rv);
3574
3575   guestfs_h *g = Guestfs_val (gv);
3576   if (g == NULL)
3577     caml_failwith ("zero: used handle after closing it");
3578
3579   const char *device = String_val (devicev);
3580   int r;
3581
3582   caml_enter_blocking_section ();
3583   r = guestfs_zero (g, device);
3584   caml_leave_blocking_section ();
3585   if (r == -1)
3586     ocaml_guestfs_raise_error (g, "zero");
3587
3588   rv = Val_unit;
3589   CAMLreturn (rv);
3590 }
3591
3592 CAMLprim value
3593 ocaml_guestfs_grub_install (value gv, value rootv, value devicev)
3594 {
3595   CAMLparam3 (gv, rootv, devicev);
3596   CAMLlocal1 (rv);
3597
3598   guestfs_h *g = Guestfs_val (gv);
3599   if (g == NULL)
3600     caml_failwith ("grub_install: used handle after closing it");
3601
3602   const char *root = String_val (rootv);
3603   const char *device = String_val (devicev);
3604   int r;
3605
3606   caml_enter_blocking_section ();
3607   r = guestfs_grub_install (g, root, device);
3608   caml_leave_blocking_section ();
3609   if (r == -1)
3610     ocaml_guestfs_raise_error (g, "grub_install");
3611
3612   rv = Val_unit;
3613   CAMLreturn (rv);
3614 }
3615
3616 CAMLprim value
3617 ocaml_guestfs_cp (value gv, value srcv, value destv)
3618 {
3619   CAMLparam3 (gv, srcv, destv);
3620   CAMLlocal1 (rv);
3621
3622   guestfs_h *g = Guestfs_val (gv);
3623   if (g == NULL)
3624     caml_failwith ("cp: used handle after closing it");
3625
3626   const char *src = String_val (srcv);
3627   const char *dest = String_val (destv);
3628   int r;
3629
3630   caml_enter_blocking_section ();
3631   r = guestfs_cp (g, src, dest);
3632   caml_leave_blocking_section ();
3633   if (r == -1)
3634     ocaml_guestfs_raise_error (g, "cp");
3635
3636   rv = Val_unit;
3637   CAMLreturn (rv);
3638 }
3639
3640 CAMLprim value
3641 ocaml_guestfs_cp_a (value gv, value srcv, value destv)
3642 {
3643   CAMLparam3 (gv, srcv, destv);
3644   CAMLlocal1 (rv);
3645
3646   guestfs_h *g = Guestfs_val (gv);
3647   if (g == NULL)
3648     caml_failwith ("cp_a: used handle after closing it");
3649
3650   const char *src = String_val (srcv);
3651   const char *dest = String_val (destv);
3652   int r;
3653
3654   caml_enter_blocking_section ();
3655   r = guestfs_cp_a (g, src, dest);
3656   caml_leave_blocking_section ();
3657   if (r == -1)
3658     ocaml_guestfs_raise_error (g, "cp_a");
3659
3660   rv = Val_unit;
3661   CAMLreturn (rv);
3662 }
3663
3664 CAMLprim value
3665 ocaml_guestfs_mv (value gv, value srcv, value destv)
3666 {
3667   CAMLparam3 (gv, srcv, destv);
3668   CAMLlocal1 (rv);
3669
3670   guestfs_h *g = Guestfs_val (gv);
3671   if (g == NULL)
3672     caml_failwith ("mv: used handle after closing it");
3673
3674   const char *src = String_val (srcv);
3675   const char *dest = String_val (destv);
3676   int r;
3677
3678   caml_enter_blocking_section ();
3679   r = guestfs_mv (g, src, dest);
3680   caml_leave_blocking_section ();
3681   if (r == -1)
3682     ocaml_guestfs_raise_error (g, "mv");
3683
3684   rv = Val_unit;
3685   CAMLreturn (rv);
3686 }
3687
3688 CAMLprim value
3689 ocaml_guestfs_drop_caches (value gv, value whattodropv)
3690 {
3691   CAMLparam2 (gv, whattodropv);
3692   CAMLlocal1 (rv);
3693
3694   guestfs_h *g = Guestfs_val (gv);
3695   if (g == NULL)
3696     caml_failwith ("drop_caches: used handle after closing it");
3697
3698   int whattodrop = Int_val (whattodropv);
3699   int r;
3700
3701   caml_enter_blocking_section ();
3702   r = guestfs_drop_caches (g, whattodrop);
3703   caml_leave_blocking_section ();
3704   if (r == -1)
3705     ocaml_guestfs_raise_error (g, "drop_caches");
3706
3707   rv = Val_unit;
3708   CAMLreturn (rv);
3709 }
3710
3711 CAMLprim value
3712 ocaml_guestfs_dmesg (value gv)
3713 {
3714   CAMLparam1 (gv);
3715   CAMLlocal1 (rv);
3716
3717   guestfs_h *g = Guestfs_val (gv);
3718   if (g == NULL)
3719     caml_failwith ("dmesg: used handle after closing it");
3720
3721   char *r;
3722
3723   caml_enter_blocking_section ();
3724   r = guestfs_dmesg (g);
3725   caml_leave_blocking_section ();
3726   if (r == NULL)
3727     ocaml_guestfs_raise_error (g, "dmesg");
3728
3729   rv = caml_copy_string (r);
3730   free (r);
3731   CAMLreturn (rv);
3732 }
3733
3734 CAMLprim value
3735 ocaml_guestfs_ping_daemon (value gv)
3736 {
3737   CAMLparam1 (gv);
3738   CAMLlocal1 (rv);
3739
3740   guestfs_h *g = Guestfs_val (gv);
3741   if (g == NULL)
3742     caml_failwith ("ping_daemon: used handle after closing it");
3743
3744   int r;
3745
3746   caml_enter_blocking_section ();
3747   r = guestfs_ping_daemon (g);
3748   caml_leave_blocking_section ();
3749   if (r == -1)
3750     ocaml_guestfs_raise_error (g, "ping_daemon");
3751
3752   rv = Val_unit;
3753   CAMLreturn (rv);
3754 }
3755
3756 CAMLprim value
3757 ocaml_guestfs_equal (value gv, value file1v, value file2v)
3758 {
3759   CAMLparam3 (gv, file1v, file2v);
3760   CAMLlocal1 (rv);
3761
3762   guestfs_h *g = Guestfs_val (gv);
3763   if (g == NULL)
3764     caml_failwith ("equal: used handle after closing it");
3765
3766   const char *file1 = String_val (file1v);
3767   const char *file2 = String_val (file2v);
3768   int r;
3769
3770   caml_enter_blocking_section ();
3771   r = guestfs_equal (g, file1, file2);
3772   caml_leave_blocking_section ();
3773   if (r == -1)
3774     ocaml_guestfs_raise_error (g, "equal");
3775
3776   rv = Val_bool (r);
3777   CAMLreturn (rv);
3778 }
3779
3780 CAMLprim value
3781 ocaml_guestfs_strings (value gv, value pathv)
3782 {
3783   CAMLparam2 (gv, pathv);
3784   CAMLlocal1 (rv);
3785
3786   guestfs_h *g = Guestfs_val (gv);
3787   if (g == NULL)
3788     caml_failwith ("strings: used handle after closing it");
3789
3790   const char *path = String_val (pathv);
3791   int i;
3792   char **r;
3793
3794   caml_enter_blocking_section ();
3795   r = guestfs_strings (g, path);
3796   caml_leave_blocking_section ();
3797   if (r == NULL)
3798     ocaml_guestfs_raise_error (g, "strings");
3799
3800   rv = caml_copy_string_array ((const char **) r);
3801   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3802   free (r);
3803   CAMLreturn (rv);
3804 }
3805
3806 CAMLprim value
3807 ocaml_guestfs_strings_e (value gv, value encodingv, value pathv)
3808 {
3809   CAMLparam3 (gv, encodingv, pathv);
3810   CAMLlocal1 (rv);
3811
3812   guestfs_h *g = Guestfs_val (gv);
3813   if (g == NULL)
3814     caml_failwith ("strings_e: used handle after closing it");
3815
3816   const char *encoding = String_val (encodingv);
3817   const char *path = String_val (pathv);
3818   int i;
3819   char **r;
3820
3821   caml_enter_blocking_section ();
3822   r = guestfs_strings_e (g, encoding, path);
3823   caml_leave_blocking_section ();
3824   if (r == NULL)
3825     ocaml_guestfs_raise_error (g, "strings_e");
3826
3827   rv = caml_copy_string_array ((const char **) r);
3828   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3829   free (r);
3830   CAMLreturn (rv);
3831 }
3832
3833 CAMLprim value
3834 ocaml_guestfs_hexdump (value gv, value pathv)
3835 {
3836   CAMLparam2 (gv, pathv);
3837   CAMLlocal1 (rv);
3838
3839   guestfs_h *g = Guestfs_val (gv);
3840   if (g == NULL)
3841     caml_failwith ("hexdump: used handle after closing it");
3842
3843   const char *path = String_val (pathv);
3844   char *r;
3845
3846   caml_enter_blocking_section ();
3847   r = guestfs_hexdump (g, path);
3848   caml_leave_blocking_section ();
3849   if (r == NULL)
3850     ocaml_guestfs_raise_error (g, "hexdump");
3851
3852   rv = caml_copy_string (r);
3853   free (r);
3854   CAMLreturn (rv);
3855 }
3856
3857 CAMLprim value
3858 ocaml_guestfs_zerofree (value gv, value devicev)
3859 {
3860   CAMLparam2 (gv, devicev);
3861   CAMLlocal1 (rv);
3862
3863   guestfs_h *g = Guestfs_val (gv);
3864   if (g == NULL)
3865     caml_failwith ("zerofree: used handle after closing it");
3866
3867   const char *device = String_val (devicev);
3868   int r;
3869
3870   caml_enter_blocking_section ();
3871   r = guestfs_zerofree (g, device);
3872   caml_leave_blocking_section ();
3873   if (r == -1)
3874     ocaml_guestfs_raise_error (g, "zerofree");
3875
3876   rv = Val_unit;
3877   CAMLreturn (rv);
3878 }
3879
3880 CAMLprim value
3881 ocaml_guestfs_pvresize (value gv, value devicev)
3882 {
3883   CAMLparam2 (gv, devicev);
3884   CAMLlocal1 (rv);
3885
3886   guestfs_h *g = Guestfs_val (gv);
3887   if (g == NULL)
3888     caml_failwith ("pvresize: used handle after closing it");
3889
3890   const char *device = String_val (devicev);
3891   int r;
3892
3893   caml_enter_blocking_section ();
3894   r = guestfs_pvresize (g, device);
3895   caml_leave_blocking_section ();
3896   if (r == -1)
3897     ocaml_guestfs_raise_error (g, "pvresize");
3898
3899   rv = Val_unit;
3900   CAMLreturn (rv);
3901 }
3902
3903 CAMLprim value
3904 ocaml_guestfs_sfdisk_N (value gv, value devicev, value nv, value cylsv, value headsv, value sectorsv, value linev)
3905 {
3906   CAMLparam5 (gv, devicev, nv, cylsv, headsv);
3907   CAMLxparam2 (sectorsv, linev);
3908   CAMLlocal1 (rv);
3909
3910   guestfs_h *g = Guestfs_val (gv);
3911   if (g == NULL)
3912     caml_failwith ("sfdisk_N: used handle after closing it");
3913
3914   const char *device = String_val (devicev);
3915   int n = Int_val (nv);
3916   int cyls = Int_val (cylsv);
3917   int heads = Int_val (headsv);
3918   int sectors = Int_val (sectorsv);
3919   const char *line = String_val (linev);
3920   int r;
3921
3922   caml_enter_blocking_section ();
3923   r = guestfs_sfdisk_N (g, device, n, cyls, heads, sectors, line);
3924   caml_leave_blocking_section ();
3925   if (r == -1)
3926     ocaml_guestfs_raise_error (g, "sfdisk_N");
3927
3928   rv = Val_unit;
3929   CAMLreturn (rv);
3930 }
3931
3932 CAMLprim value
3933 ocaml_guestfs_sfdisk_N_byte (value *argv, int argn)
3934 {
3935   return ocaml_guestfs_sfdisk_N (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
3936 }
3937
3938 CAMLprim value
3939 ocaml_guestfs_sfdisk_l (value gv, value devicev)
3940 {
3941   CAMLparam2 (gv, devicev);
3942   CAMLlocal1 (rv);
3943
3944   guestfs_h *g = Guestfs_val (gv);
3945   if (g == NULL)
3946     caml_failwith ("sfdisk_l: used handle after closing it");
3947
3948   const char *device = String_val (devicev);
3949   char *r;
3950
3951   caml_enter_blocking_section ();
3952   r = guestfs_sfdisk_l (g, device);
3953   caml_leave_blocking_section ();
3954   if (r == NULL)
3955     ocaml_guestfs_raise_error (g, "sfdisk_l");
3956
3957   rv = caml_copy_string (r);
3958   free (r);
3959   CAMLreturn (rv);
3960 }
3961
3962 CAMLprim value
3963 ocaml_guestfs_sfdisk_kernel_geometry (value gv, value devicev)
3964 {
3965   CAMLparam2 (gv, devicev);
3966   CAMLlocal1 (rv);
3967
3968   guestfs_h *g = Guestfs_val (gv);
3969   if (g == NULL)
3970     caml_failwith ("sfdisk_kernel_geometry: used handle after closing it");
3971
3972   const char *device = String_val (devicev);
3973   char *r;
3974
3975   caml_enter_blocking_section ();
3976   r = guestfs_sfdisk_kernel_geometry (g, device);
3977   caml_leave_blocking_section ();
3978   if (r == NULL)
3979     ocaml_guestfs_raise_error (g, "sfdisk_kernel_geometry");
3980
3981   rv = caml_copy_string (r);
3982   free (r);
3983   CAMLreturn (rv);
3984 }
3985
3986 CAMLprim value
3987 ocaml_guestfs_sfdisk_disk_geometry (value gv, value devicev)
3988 {
3989   CAMLparam2 (gv, devicev);
3990   CAMLlocal1 (rv);
3991
3992   guestfs_h *g = Guestfs_val (gv);
3993   if (g == NULL)
3994     caml_failwith ("sfdisk_disk_geometry: used handle after closing it");
3995
3996   const char *device = String_val (devicev);
3997   char *r;
3998
3999   caml_enter_blocking_section ();
4000   r = guestfs_sfdisk_disk_geometry (g, device);
4001   caml_leave_blocking_section ();
4002   if (r == NULL)
4003     ocaml_guestfs_raise_error (g, "sfdisk_disk_geometry");
4004
4005   rv = caml_copy_string (r);
4006   free (r);
4007   CAMLreturn (rv);
4008 }
4009
4010 CAMLprim value
4011 ocaml_guestfs_vg_activate_all (value gv, value activatev)
4012 {
4013   CAMLparam2 (gv, activatev);
4014   CAMLlocal1 (rv);
4015
4016   guestfs_h *g = Guestfs_val (gv);
4017   if (g == NULL)
4018     caml_failwith ("vg_activate_all: used handle after closing it");
4019
4020   int activate = Bool_val (activatev);
4021   int r;
4022
4023   caml_enter_blocking_section ();
4024   r = guestfs_vg_activate_all (g, activate);
4025   caml_leave_blocking_section ();
4026   if (r == -1)
4027     ocaml_guestfs_raise_error (g, "vg_activate_all");
4028
4029   rv = Val_unit;
4030   CAMLreturn (rv);
4031 }
4032
4033 CAMLprim value
4034 ocaml_guestfs_vg_activate (value gv, value activatev, value volgroupsv)
4035 {
4036   CAMLparam3 (gv, activatev, volgroupsv);
4037   CAMLlocal1 (rv);
4038
4039   guestfs_h *g = Guestfs_val (gv);
4040   if (g == NULL)
4041     caml_failwith ("vg_activate: used handle after closing it");
4042
4043   int activate = Bool_val (activatev);
4044   char **volgroups = ocaml_guestfs_strings_val (g, volgroupsv);
4045   int r;
4046
4047   caml_enter_blocking_section ();
4048   r = guestfs_vg_activate (g, activate, volgroups);
4049   caml_leave_blocking_section ();
4050   ocaml_guestfs_free_strings (volgroups);
4051   if (r == -1)
4052     ocaml_guestfs_raise_error (g, "vg_activate");
4053
4054   rv = Val_unit;
4055   CAMLreturn (rv);
4056 }
4057
4058 CAMLprim value
4059 ocaml_guestfs_lvresize (value gv, value devicev, value mbytesv)
4060 {
4061   CAMLparam3 (gv, devicev, mbytesv);
4062   CAMLlocal1 (rv);
4063
4064   guestfs_h *g = Guestfs_val (gv);
4065   if (g == NULL)
4066     caml_failwith ("lvresize: used handle after closing it");
4067
4068   const char *device = String_val (devicev);
4069   int mbytes = Int_val (mbytesv);
4070   int r;
4071
4072   caml_enter_blocking_section ();
4073   r = guestfs_lvresize (g, device, mbytes);
4074   caml_leave_blocking_section ();
4075   if (r == -1)
4076     ocaml_guestfs_raise_error (g, "lvresize");
4077
4078   rv = Val_unit;
4079   CAMLreturn (rv);
4080 }
4081
4082 CAMLprim value
4083 ocaml_guestfs_resize2fs (value gv, value devicev)
4084 {
4085   CAMLparam2 (gv, devicev);
4086   CAMLlocal1 (rv);
4087
4088   guestfs_h *g = Guestfs_val (gv);
4089   if (g == NULL)
4090     caml_failwith ("resize2fs: used handle after closing it");
4091
4092   const char *device = String_val (devicev);
4093   int r;
4094
4095   caml_enter_blocking_section ();
4096   r = guestfs_resize2fs (g, device);
4097   caml_leave_blocking_section ();
4098   if (r == -1)
4099     ocaml_guestfs_raise_error (g, "resize2fs");
4100
4101   rv = Val_unit;
4102   CAMLreturn (rv);
4103 }
4104
4105 CAMLprim value
4106 ocaml_guestfs_find (value gv, value directoryv)
4107 {
4108   CAMLparam2 (gv, directoryv);
4109   CAMLlocal1 (rv);
4110
4111   guestfs_h *g = Guestfs_val (gv);
4112   if (g == NULL)
4113     caml_failwith ("find: used handle after closing it");
4114
4115   const char *directory = String_val (directoryv);
4116   int i;
4117   char **r;
4118
4119   caml_enter_blocking_section ();
4120   r = guestfs_find (g, directory);
4121   caml_leave_blocking_section ();
4122   if (r == NULL)
4123     ocaml_guestfs_raise_error (g, "find");
4124
4125   rv = caml_copy_string_array ((const char **) r);
4126   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4127   free (r);
4128   CAMLreturn (rv);
4129 }
4130
4131 CAMLprim value
4132 ocaml_guestfs_e2fsck_f (value gv, value devicev)
4133 {
4134   CAMLparam2 (gv, devicev);
4135   CAMLlocal1 (rv);
4136
4137   guestfs_h *g = Guestfs_val (gv);
4138   if (g == NULL)
4139     caml_failwith ("e2fsck_f: used handle after closing it");
4140
4141   const char *device = String_val (devicev);
4142   int r;
4143
4144   caml_enter_blocking_section ();
4145   r = guestfs_e2fsck_f (g, device);
4146   caml_leave_blocking_section ();
4147   if (r == -1)
4148     ocaml_guestfs_raise_error (g, "e2fsck_f");
4149
4150   rv = Val_unit;
4151   CAMLreturn (rv);
4152 }
4153
4154 CAMLprim value
4155 ocaml_guestfs_sleep (value gv, value secsv)
4156 {
4157   CAMLparam2 (gv, secsv);
4158   CAMLlocal1 (rv);
4159
4160   guestfs_h *g = Guestfs_val (gv);
4161   if (g == NULL)
4162     caml_failwith ("sleep: used handle after closing it");
4163
4164   int secs = Int_val (secsv);
4165   int r;
4166
4167   caml_enter_blocking_section ();
4168   r = guestfs_sleep (g, secs);
4169   caml_leave_blocking_section ();
4170   if (r == -1)
4171     ocaml_guestfs_raise_error (g, "sleep");
4172
4173   rv = Val_unit;
4174   CAMLreturn (rv);
4175 }
4176
4177 CAMLprim value
4178 ocaml_guestfs_ntfs_3g_probe (value gv, value rwv, value devicev)
4179 {
4180   CAMLparam3 (gv, rwv, devicev);
4181   CAMLlocal1 (rv);
4182
4183   guestfs_h *g = Guestfs_val (gv);
4184   if (g == NULL)
4185     caml_failwith ("ntfs_3g_probe: used handle after closing it");
4186
4187   int rw = Bool_val (rwv);
4188   const char *device = String_val (devicev);
4189   int r;
4190
4191   caml_enter_blocking_section ();
4192   r = guestfs_ntfs_3g_probe (g, rw, device);
4193   caml_leave_blocking_section ();
4194   if (r == -1)
4195     ocaml_guestfs_raise_error (g, "ntfs_3g_probe");
4196
4197   rv = Val_int (r);
4198   CAMLreturn (rv);
4199 }
4200
4201 CAMLprim value
4202 ocaml_guestfs_sh (value gv, value commandv)
4203 {
4204   CAMLparam2 (gv, commandv);
4205   CAMLlocal1 (rv);
4206
4207   guestfs_h *g = Guestfs_val (gv);
4208   if (g == NULL)
4209     caml_failwith ("sh: used handle after closing it");
4210
4211   const char *command = String_val (commandv);
4212   char *r;
4213
4214   caml_enter_blocking_section ();
4215   r = guestfs_sh (g, command);
4216   caml_leave_blocking_section ();
4217   if (r == NULL)
4218     ocaml_guestfs_raise_error (g, "sh");
4219
4220   rv = caml_copy_string (r);
4221   free (r);
4222   CAMLreturn (rv);
4223 }
4224
4225 CAMLprim value
4226 ocaml_guestfs_sh_lines (value gv, value commandv)
4227 {
4228   CAMLparam2 (gv, commandv);
4229   CAMLlocal1 (rv);
4230
4231   guestfs_h *g = Guestfs_val (gv);
4232   if (g == NULL)
4233     caml_failwith ("sh_lines: used handle after closing it");
4234
4235   const char *command = String_val (commandv);
4236   int i;
4237   char **r;
4238
4239   caml_enter_blocking_section ();
4240   r = guestfs_sh_lines (g, command);
4241   caml_leave_blocking_section ();
4242   if (r == NULL)
4243     ocaml_guestfs_raise_error (g, "sh_lines");
4244
4245   rv = caml_copy_string_array ((const char **) r);
4246   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4247   free (r);
4248   CAMLreturn (rv);
4249 }
4250
4251 CAMLprim value
4252 ocaml_guestfs_glob_expand (value gv, value patternv)
4253 {
4254   CAMLparam2 (gv, patternv);
4255   CAMLlocal1 (rv);
4256
4257   guestfs_h *g = Guestfs_val (gv);
4258   if (g == NULL)
4259     caml_failwith ("glob_expand: used handle after closing it");
4260
4261   const char *pattern = String_val (patternv);
4262   int i;
4263   char **r;
4264
4265   caml_enter_blocking_section ();
4266   r = guestfs_glob_expand (g, pattern);
4267   caml_leave_blocking_section ();
4268   if (r == NULL)
4269     ocaml_guestfs_raise_error (g, "glob_expand");
4270
4271   rv = caml_copy_string_array ((const char **) r);
4272   for (i = 0; r[i] != NULL; ++i) free (r[i]);
4273   free (r);
4274   CAMLreturn (rv);
4275 }
4276