Add 'make valgrind' target to run tests under valgrind.
[libguestfs.git] / ocaml / guestfs_c_actions.c
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <caml/config.h>
27 #include <caml/alloc.h>
28 #include <caml/callback.h>
29 #include <caml/fail.h>
30 #include <caml/memory.h>
31 #include <caml/mlvalues.h>
32 #include <caml/signals.h>
33
34 #include <guestfs.h>
35
36 #include "guestfs_c.h"
37
38 /* Copy a hashtable of string pairs into an assoc-list.  We return
39  * the list in reverse order, but hashtables aren't supposed to be
40  * ordered anyway.
41  */
42 static CAMLprim value
43 copy_table (char * const * argv)
44 {
45   CAMLparam0 ();
46   CAMLlocal5 (rv, pairv, kv, vv, cons);
47   int i;
48
49   rv = Val_int (0);
50   for (i = 0; argv[i] != NULL; i += 2) {
51     kv = caml_copy_string (argv[i]);
52     vv = caml_copy_string (argv[i+1]);
53     pairv = caml_alloc (2, 0);
54     Store_field (pairv, 0, kv);
55     Store_field (pairv, 1, vv);
56     cons = caml_alloc (2, 0);
57     Store_field (cons, 1, rv);
58     rv = cons;
59     Store_field (cons, 0, pairv);
60   }
61
62   CAMLreturn (rv);
63 }
64
65 static CAMLprim value
66 copy_lvm_pv (const struct guestfs_lvm_pv *pv)
67 {
68   CAMLparam0 ();
69   CAMLlocal2 (rv, v);
70
71   rv = caml_alloc (14, 0);
72   v = caml_copy_string (pv->pv_name);
73   Store_field (rv, 0, v);
74   v = caml_alloc_string (32);
75   memcpy (String_val (v), pv->pv_uuid, 32);
76   Store_field (rv, 1, v);
77   v = caml_copy_string (pv->pv_fmt);
78   Store_field (rv, 2, v);
79   v = caml_copy_int64 (pv->pv_size);
80   Store_field (rv, 3, v);
81   v = caml_copy_int64 (pv->dev_size);
82   Store_field (rv, 4, v);
83   v = caml_copy_int64 (pv->pv_free);
84   Store_field (rv, 5, v);
85   v = caml_copy_int64 (pv->pv_used);
86   Store_field (rv, 6, v);
87   v = caml_copy_string (pv->pv_attr);
88   Store_field (rv, 7, v);
89   v = caml_copy_int64 (pv->pv_pe_count);
90   Store_field (rv, 8, v);
91   v = caml_copy_int64 (pv->pv_pe_alloc_count);
92   Store_field (rv, 9, v);
93   v = caml_copy_string (pv->pv_tags);
94   Store_field (rv, 10, v);
95   v = caml_copy_int64 (pv->pe_start);
96   Store_field (rv, 11, v);
97   v = caml_copy_int64 (pv->pv_mda_count);
98   Store_field (rv, 12, v);
99   v = caml_copy_int64 (pv->pv_mda_free);
100   Store_field (rv, 13, v);
101   CAMLreturn (rv);
102 }
103
104 static CAMLprim value
105 copy_lvm_pv_list (const struct guestfs_lvm_pv_list *pvs)
106 {
107   CAMLparam0 ();
108   CAMLlocal2 (rv, v);
109   int i;
110
111   if (pvs->len == 0)
112     CAMLreturn (Atom (0));
113   else {
114     rv = caml_alloc (pvs->len, 0);
115     for (i = 0; i < pvs->len; ++i) {
116       v = copy_lvm_pv (&pvs->val[i]);
117       caml_modify (&Field (rv, i), v);
118     }
119     CAMLreturn (rv);
120   }
121 }
122
123 static CAMLprim value
124 copy_lvm_vg (const struct guestfs_lvm_vg *vg)
125 {
126   CAMLparam0 ();
127   CAMLlocal2 (rv, v);
128
129   rv = caml_alloc (19, 0);
130   v = caml_copy_string (vg->vg_name);
131   Store_field (rv, 0, v);
132   v = caml_alloc_string (32);
133   memcpy (String_val (v), vg->vg_uuid, 32);
134   Store_field (rv, 1, v);
135   v = caml_copy_string (vg->vg_fmt);
136   Store_field (rv, 2, v);
137   v = caml_copy_string (vg->vg_attr);
138   Store_field (rv, 3, v);
139   v = caml_copy_int64 (vg->vg_size);
140   Store_field (rv, 4, v);
141   v = caml_copy_int64 (vg->vg_free);
142   Store_field (rv, 5, v);
143   v = caml_copy_string (vg->vg_sysid);
144   Store_field (rv, 6, v);
145   v = caml_copy_int64 (vg->vg_extent_size);
146   Store_field (rv, 7, v);
147   v = caml_copy_int64 (vg->vg_extent_count);
148   Store_field (rv, 8, v);
149   v = caml_copy_int64 (vg->vg_free_count);
150   Store_field (rv, 9, v);
151   v = caml_copy_int64 (vg->max_lv);
152   Store_field (rv, 10, v);
153   v = caml_copy_int64 (vg->max_pv);
154   Store_field (rv, 11, v);
155   v = caml_copy_int64 (vg->pv_count);
156   Store_field (rv, 12, v);
157   v = caml_copy_int64 (vg->lv_count);
158   Store_field (rv, 13, v);
159   v = caml_copy_int64 (vg->snap_count);
160   Store_field (rv, 14, v);
161   v = caml_copy_int64 (vg->vg_seqno);
162   Store_field (rv, 15, v);
163   v = caml_copy_string (vg->vg_tags);
164   Store_field (rv, 16, v);
165   v = caml_copy_int64 (vg->vg_mda_count);
166   Store_field (rv, 17, v);
167   v = caml_copy_int64 (vg->vg_mda_free);
168   Store_field (rv, 18, v);
169   CAMLreturn (rv);
170 }
171
172 static CAMLprim value
173 copy_lvm_vg_list (const struct guestfs_lvm_vg_list *vgs)
174 {
175   CAMLparam0 ();
176   CAMLlocal2 (rv, v);
177   int i;
178
179   if (vgs->len == 0)
180     CAMLreturn (Atom (0));
181   else {
182     rv = caml_alloc (vgs->len, 0);
183     for (i = 0; i < vgs->len; ++i) {
184       v = copy_lvm_vg (&vgs->val[i]);
185       caml_modify (&Field (rv, i), v);
186     }
187     CAMLreturn (rv);
188   }
189 }
190
191 static CAMLprim value
192 copy_lvm_lv (const struct guestfs_lvm_lv *lv)
193 {
194   CAMLparam0 ();
195   CAMLlocal3 (rv, v, v2);
196
197   rv = caml_alloc (16, 0);
198   v = caml_copy_string (lv->lv_name);
199   Store_field (rv, 0, v);
200   v = caml_alloc_string (32);
201   memcpy (String_val (v), lv->lv_uuid, 32);
202   Store_field (rv, 1, v);
203   v = caml_copy_string (lv->lv_attr);
204   Store_field (rv, 2, v);
205   v = caml_copy_int64 (lv->lv_major);
206   Store_field (rv, 3, v);
207   v = caml_copy_int64 (lv->lv_minor);
208   Store_field (rv, 4, v);
209   v = caml_copy_int64 (lv->lv_kernel_major);
210   Store_field (rv, 5, v);
211   v = caml_copy_int64 (lv->lv_kernel_minor);
212   Store_field (rv, 6, v);
213   v = caml_copy_int64 (lv->lv_size);
214   Store_field (rv, 7, v);
215   v = caml_copy_int64 (lv->seg_count);
216   Store_field (rv, 8, v);
217   v = caml_copy_string (lv->origin);
218   Store_field (rv, 9, v);
219   if (lv->snap_percent >= 0) { /* Some snap_percent */
220     v2 = caml_copy_double (lv->snap_percent);
221     v = caml_alloc (1, 0);
222     Store_field (v, 0, v2);
223   } else /* None */
224     v = Val_int (0);
225   Store_field (rv, 10, v);
226   if (lv->copy_percent >= 0) { /* Some copy_percent */
227     v2 = caml_copy_double (lv->copy_percent);
228     v = caml_alloc (1, 0);
229     Store_field (v, 0, v2);
230   } else /* None */
231     v = Val_int (0);
232   Store_field (rv, 11, v);
233   v = caml_copy_string (lv->move_pv);
234   Store_field (rv, 12, v);
235   v = caml_copy_string (lv->lv_tags);
236   Store_field (rv, 13, v);
237   v = caml_copy_string (lv->mirror_log);
238   Store_field (rv, 14, v);
239   v = caml_copy_string (lv->modules);
240   Store_field (rv, 15, v);
241   CAMLreturn (rv);
242 }
243
244 static CAMLprim value
245 copy_lvm_lv_list (const struct guestfs_lvm_lv_list *lvs)
246 {
247   CAMLparam0 ();
248   CAMLlocal2 (rv, v);
249   int i;
250
251   if (lvs->len == 0)
252     CAMLreturn (Atom (0));
253   else {
254     rv = caml_alloc (lvs->len, 0);
255     for (i = 0; i < lvs->len; ++i) {
256       v = copy_lvm_lv (&lvs->val[i]);
257       caml_modify (&Field (rv, i), v);
258     }
259     CAMLreturn (rv);
260   }
261 }
262
263 static CAMLprim value
264 copy_stat (const struct guestfs_stat *stat)
265 {
266   CAMLparam0 ();
267   CAMLlocal2 (rv, v);
268
269   rv = caml_alloc (13, 0);
270   v = caml_copy_int64 (stat->dev);
271   Store_field (rv, 0, v);
272   v = caml_copy_int64 (stat->ino);
273   Store_field (rv, 1, v);
274   v = caml_copy_int64 (stat->mode);
275   Store_field (rv, 2, v);
276   v = caml_copy_int64 (stat->nlink);
277   Store_field (rv, 3, v);
278   v = caml_copy_int64 (stat->uid);
279   Store_field (rv, 4, v);
280   v = caml_copy_int64 (stat->gid);
281   Store_field (rv, 5, v);
282   v = caml_copy_int64 (stat->rdev);
283   Store_field (rv, 6, v);
284   v = caml_copy_int64 (stat->size);
285   Store_field (rv, 7, v);
286   v = caml_copy_int64 (stat->blksize);
287   Store_field (rv, 8, v);
288   v = caml_copy_int64 (stat->blocks);
289   Store_field (rv, 9, v);
290   v = caml_copy_int64 (stat->atime);
291   Store_field (rv, 10, v);
292   v = caml_copy_int64 (stat->mtime);
293   Store_field (rv, 11, v);
294   v = caml_copy_int64 (stat->ctime);
295   Store_field (rv, 12, v);
296   CAMLreturn (rv);
297 }
298
299 static CAMLprim value
300 copy_statvfs (const struct guestfs_statvfs *statvfs)
301 {
302   CAMLparam0 ();
303   CAMLlocal2 (rv, v);
304
305   rv = caml_alloc (11, 0);
306   v = caml_copy_int64 (statvfs->bsize);
307   Store_field (rv, 0, v);
308   v = caml_copy_int64 (statvfs->frsize);
309   Store_field (rv, 1, v);
310   v = caml_copy_int64 (statvfs->blocks);
311   Store_field (rv, 2, v);
312   v = caml_copy_int64 (statvfs->bfree);
313   Store_field (rv, 3, v);
314   v = caml_copy_int64 (statvfs->bavail);
315   Store_field (rv, 4, v);
316   v = caml_copy_int64 (statvfs->files);
317   Store_field (rv, 5, v);
318   v = caml_copy_int64 (statvfs->ffree);
319   Store_field (rv, 6, v);
320   v = caml_copy_int64 (statvfs->favail);
321   Store_field (rv, 7, v);
322   v = caml_copy_int64 (statvfs->fsid);
323   Store_field (rv, 8, v);
324   v = caml_copy_int64 (statvfs->flag);
325   Store_field (rv, 9, v);
326   v = caml_copy_int64 (statvfs->namemax);
327   Store_field (rv, 10, v);
328   CAMLreturn (rv);
329 }
330
331 CAMLprim value
332 ocaml_guestfs_launch (value gv)
333 {
334   CAMLparam1 (gv);
335   CAMLlocal1 (rv);
336
337   guestfs_h *g = Guestfs_val (gv);
338   if (g == NULL)
339     caml_failwith ("launch: used handle after closing it");
340
341   int r;
342
343   caml_enter_blocking_section ();
344   r = guestfs_launch (g);
345   caml_leave_blocking_section ();
346   if (r == -1)
347     ocaml_guestfs_raise_error (g, "launch");
348
349   rv = Val_unit;
350   CAMLreturn (rv);
351 }
352
353 CAMLprim value
354 ocaml_guestfs_wait_ready (value gv)
355 {
356   CAMLparam1 (gv);
357   CAMLlocal1 (rv);
358
359   guestfs_h *g = Guestfs_val (gv);
360   if (g == NULL)
361     caml_failwith ("wait_ready: used handle after closing it");
362
363   int r;
364
365   caml_enter_blocking_section ();
366   r = guestfs_wait_ready (g);
367   caml_leave_blocking_section ();
368   if (r == -1)
369     ocaml_guestfs_raise_error (g, "wait_ready");
370
371   rv = Val_unit;
372   CAMLreturn (rv);
373 }
374
375 CAMLprim value
376 ocaml_guestfs_kill_subprocess (value gv)
377 {
378   CAMLparam1 (gv);
379   CAMLlocal1 (rv);
380
381   guestfs_h *g = Guestfs_val (gv);
382   if (g == NULL)
383     caml_failwith ("kill_subprocess: used handle after closing it");
384
385   int r;
386
387   caml_enter_blocking_section ();
388   r = guestfs_kill_subprocess (g);
389   caml_leave_blocking_section ();
390   if (r == -1)
391     ocaml_guestfs_raise_error (g, "kill_subprocess");
392
393   rv = Val_unit;
394   CAMLreturn (rv);
395 }
396
397 CAMLprim value
398 ocaml_guestfs_add_drive (value gv, value filenamev)
399 {
400   CAMLparam2 (gv, filenamev);
401   CAMLlocal1 (rv);
402
403   guestfs_h *g = Guestfs_val (gv);
404   if (g == NULL)
405     caml_failwith ("add_drive: used handle after closing it");
406
407   const char *filename = String_val (filenamev);
408   int r;
409
410   caml_enter_blocking_section ();
411   r = guestfs_add_drive (g, filename);
412   caml_leave_blocking_section ();
413   if (r == -1)
414     ocaml_guestfs_raise_error (g, "add_drive");
415
416   rv = Val_unit;
417   CAMLreturn (rv);
418 }
419
420 CAMLprim value
421 ocaml_guestfs_add_cdrom (value gv, value filenamev)
422 {
423   CAMLparam2 (gv, filenamev);
424   CAMLlocal1 (rv);
425
426   guestfs_h *g = Guestfs_val (gv);
427   if (g == NULL)
428     caml_failwith ("add_cdrom: used handle after closing it");
429
430   const char *filename = String_val (filenamev);
431   int r;
432
433   caml_enter_blocking_section ();
434   r = guestfs_add_cdrom (g, filename);
435   caml_leave_blocking_section ();
436   if (r == -1)
437     ocaml_guestfs_raise_error (g, "add_cdrom");
438
439   rv = Val_unit;
440   CAMLreturn (rv);
441 }
442
443 CAMLprim value
444 ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
445 {
446   CAMLparam3 (gv, qemuparamv, qemuvaluev);
447   CAMLlocal1 (rv);
448
449   guestfs_h *g = Guestfs_val (gv);
450   if (g == NULL)
451     caml_failwith ("config: used handle after closing it");
452
453   const char *qemuparam = String_val (qemuparamv);
454   const char *qemuvalue =
455     qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
456   int r;
457
458   caml_enter_blocking_section ();
459   r = guestfs_config (g, qemuparam, qemuvalue);
460   caml_leave_blocking_section ();
461   if (r == -1)
462     ocaml_guestfs_raise_error (g, "config");
463
464   rv = Val_unit;
465   CAMLreturn (rv);
466 }
467
468 CAMLprim value
469 ocaml_guestfs_set_qemu (value gv, value qemuv)
470 {
471   CAMLparam2 (gv, qemuv);
472   CAMLlocal1 (rv);
473
474   guestfs_h *g = Guestfs_val (gv);
475   if (g == NULL)
476     caml_failwith ("set_qemu: used handle after closing it");
477
478   const char *qemu = String_val (qemuv);
479   int r;
480
481   caml_enter_blocking_section ();
482   r = guestfs_set_qemu (g, qemu);
483   caml_leave_blocking_section ();
484   if (r == -1)
485     ocaml_guestfs_raise_error (g, "set_qemu");
486
487   rv = Val_unit;
488   CAMLreturn (rv);
489 }
490
491 CAMLprim value
492 ocaml_guestfs_get_qemu (value gv)
493 {
494   CAMLparam1 (gv);
495   CAMLlocal1 (rv);
496
497   guestfs_h *g = Guestfs_val (gv);
498   if (g == NULL)
499     caml_failwith ("get_qemu: used handle after closing it");
500
501   const char *r;
502
503   caml_enter_blocking_section ();
504   r = guestfs_get_qemu (g);
505   caml_leave_blocking_section ();
506   if (r == NULL)
507     ocaml_guestfs_raise_error (g, "get_qemu");
508
509   rv = caml_copy_string (r);
510   CAMLreturn (rv);
511 }
512
513 CAMLprim value
514 ocaml_guestfs_set_path (value gv, value pathv)
515 {
516   CAMLparam2 (gv, pathv);
517   CAMLlocal1 (rv);
518
519   guestfs_h *g = Guestfs_val (gv);
520   if (g == NULL)
521     caml_failwith ("set_path: used handle after closing it");
522
523   const char *path = String_val (pathv);
524   int r;
525
526   caml_enter_blocking_section ();
527   r = guestfs_set_path (g, path);
528   caml_leave_blocking_section ();
529   if (r == -1)
530     ocaml_guestfs_raise_error (g, "set_path");
531
532   rv = Val_unit;
533   CAMLreturn (rv);
534 }
535
536 CAMLprim value
537 ocaml_guestfs_get_path (value gv)
538 {
539   CAMLparam1 (gv);
540   CAMLlocal1 (rv);
541
542   guestfs_h *g = Guestfs_val (gv);
543   if (g == NULL)
544     caml_failwith ("get_path: used handle after closing it");
545
546   const char *r;
547
548   caml_enter_blocking_section ();
549   r = guestfs_get_path (g);
550   caml_leave_blocking_section ();
551   if (r == NULL)
552     ocaml_guestfs_raise_error (g, "get_path");
553
554   rv = caml_copy_string (r);
555   CAMLreturn (rv);
556 }
557
558 CAMLprim value
559 ocaml_guestfs_set_autosync (value gv, value autosyncv)
560 {
561   CAMLparam2 (gv, autosyncv);
562   CAMLlocal1 (rv);
563
564   guestfs_h *g = Guestfs_val (gv);
565   if (g == NULL)
566     caml_failwith ("set_autosync: used handle after closing it");
567
568   int autosync = Bool_val (autosyncv);
569   int r;
570
571   caml_enter_blocking_section ();
572   r = guestfs_set_autosync (g, autosync);
573   caml_leave_blocking_section ();
574   if (r == -1)
575     ocaml_guestfs_raise_error (g, "set_autosync");
576
577   rv = Val_unit;
578   CAMLreturn (rv);
579 }
580
581 CAMLprim value
582 ocaml_guestfs_get_autosync (value gv)
583 {
584   CAMLparam1 (gv);
585   CAMLlocal1 (rv);
586
587   guestfs_h *g = Guestfs_val (gv);
588   if (g == NULL)
589     caml_failwith ("get_autosync: used handle after closing it");
590
591   int r;
592
593   caml_enter_blocking_section ();
594   r = guestfs_get_autosync (g);
595   caml_leave_blocking_section ();
596   if (r == -1)
597     ocaml_guestfs_raise_error (g, "get_autosync");
598
599   rv = Val_bool (r);
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_guestfs_set_verbose (value gv, value verbosev)
605 {
606   CAMLparam2 (gv, verbosev);
607   CAMLlocal1 (rv);
608
609   guestfs_h *g = Guestfs_val (gv);
610   if (g == NULL)
611     caml_failwith ("set_verbose: used handle after closing it");
612
613   int verbose = Bool_val (verbosev);
614   int r;
615
616   caml_enter_blocking_section ();
617   r = guestfs_set_verbose (g, verbose);
618   caml_leave_blocking_section ();
619   if (r == -1)
620     ocaml_guestfs_raise_error (g, "set_verbose");
621
622   rv = Val_unit;
623   CAMLreturn (rv);
624 }
625
626 CAMLprim value
627 ocaml_guestfs_get_verbose (value gv)
628 {
629   CAMLparam1 (gv);
630   CAMLlocal1 (rv);
631
632   guestfs_h *g = Guestfs_val (gv);
633   if (g == NULL)
634     caml_failwith ("get_verbose: used handle after closing it");
635
636   int r;
637
638   caml_enter_blocking_section ();
639   r = guestfs_get_verbose (g);
640   caml_leave_blocking_section ();
641   if (r == -1)
642     ocaml_guestfs_raise_error (g, "get_verbose");
643
644   rv = Val_bool (r);
645   CAMLreturn (rv);
646 }
647
648 CAMLprim value
649 ocaml_guestfs_is_ready (value gv)
650 {
651   CAMLparam1 (gv);
652   CAMLlocal1 (rv);
653
654   guestfs_h *g = Guestfs_val (gv);
655   if (g == NULL)
656     caml_failwith ("is_ready: used handle after closing it");
657
658   int r;
659
660   caml_enter_blocking_section ();
661   r = guestfs_is_ready (g);
662   caml_leave_blocking_section ();
663   if (r == -1)
664     ocaml_guestfs_raise_error (g, "is_ready");
665
666   rv = Val_bool (r);
667   CAMLreturn (rv);
668 }
669
670 CAMLprim value
671 ocaml_guestfs_is_config (value gv)
672 {
673   CAMLparam1 (gv);
674   CAMLlocal1 (rv);
675
676   guestfs_h *g = Guestfs_val (gv);
677   if (g == NULL)
678     caml_failwith ("is_config: used handle after closing it");
679
680   int r;
681
682   caml_enter_blocking_section ();
683   r = guestfs_is_config (g);
684   caml_leave_blocking_section ();
685   if (r == -1)
686     ocaml_guestfs_raise_error (g, "is_config");
687
688   rv = Val_bool (r);
689   CAMLreturn (rv);
690 }
691
692 CAMLprim value
693 ocaml_guestfs_is_launching (value gv)
694 {
695   CAMLparam1 (gv);
696   CAMLlocal1 (rv);
697
698   guestfs_h *g = Guestfs_val (gv);
699   if (g == NULL)
700     caml_failwith ("is_launching: used handle after closing it");
701
702   int r;
703
704   caml_enter_blocking_section ();
705   r = guestfs_is_launching (g);
706   caml_leave_blocking_section ();
707   if (r == -1)
708     ocaml_guestfs_raise_error (g, "is_launching");
709
710   rv = Val_bool (r);
711   CAMLreturn (rv);
712 }
713
714 CAMLprim value
715 ocaml_guestfs_is_busy (value gv)
716 {
717   CAMLparam1 (gv);
718   CAMLlocal1 (rv);
719
720   guestfs_h *g = Guestfs_val (gv);
721   if (g == NULL)
722     caml_failwith ("is_busy: used handle after closing it");
723
724   int r;
725
726   caml_enter_blocking_section ();
727   r = guestfs_is_busy (g);
728   caml_leave_blocking_section ();
729   if (r == -1)
730     ocaml_guestfs_raise_error (g, "is_busy");
731
732   rv = Val_bool (r);
733   CAMLreturn (rv);
734 }
735
736 CAMLprim value
737 ocaml_guestfs_get_state (value gv)
738 {
739   CAMLparam1 (gv);
740   CAMLlocal1 (rv);
741
742   guestfs_h *g = Guestfs_val (gv);
743   if (g == NULL)
744     caml_failwith ("get_state: used handle after closing it");
745
746   int r;
747
748   caml_enter_blocking_section ();
749   r = guestfs_get_state (g);
750   caml_leave_blocking_section ();
751   if (r == -1)
752     ocaml_guestfs_raise_error (g, "get_state");
753
754   rv = Val_int (r);
755   CAMLreturn (rv);
756 }
757
758 CAMLprim value
759 ocaml_guestfs_set_busy (value gv)
760 {
761   CAMLparam1 (gv);
762   CAMLlocal1 (rv);
763
764   guestfs_h *g = Guestfs_val (gv);
765   if (g == NULL)
766     caml_failwith ("set_busy: used handle after closing it");
767
768   int r;
769
770   caml_enter_blocking_section ();
771   r = guestfs_set_busy (g);
772   caml_leave_blocking_section ();
773   if (r == -1)
774     ocaml_guestfs_raise_error (g, "set_busy");
775
776   rv = Val_unit;
777   CAMLreturn (rv);
778 }
779
780 CAMLprim value
781 ocaml_guestfs_set_ready (value gv)
782 {
783   CAMLparam1 (gv);
784   CAMLlocal1 (rv);
785
786   guestfs_h *g = Guestfs_val (gv);
787   if (g == NULL)
788     caml_failwith ("set_ready: used handle after closing it");
789
790   int r;
791
792   caml_enter_blocking_section ();
793   r = guestfs_set_ready (g);
794   caml_leave_blocking_section ();
795   if (r == -1)
796     ocaml_guestfs_raise_error (g, "set_ready");
797
798   rv = Val_unit;
799   CAMLreturn (rv);
800 }
801
802 CAMLprim value
803 ocaml_guestfs_end_busy (value gv)
804 {
805   CAMLparam1 (gv);
806   CAMLlocal1 (rv);
807
808   guestfs_h *g = Guestfs_val (gv);
809   if (g == NULL)
810     caml_failwith ("end_busy: used handle after closing it");
811
812   int r;
813
814   caml_enter_blocking_section ();
815   r = guestfs_end_busy (g);
816   caml_leave_blocking_section ();
817   if (r == -1)
818     ocaml_guestfs_raise_error (g, "end_busy");
819
820   rv = Val_unit;
821   CAMLreturn (rv);
822 }
823
824 CAMLprim value
825 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
826 {
827   CAMLparam3 (gv, devicev, mountpointv);
828   CAMLlocal1 (rv);
829
830   guestfs_h *g = Guestfs_val (gv);
831   if (g == NULL)
832     caml_failwith ("mount: used handle after closing it");
833
834   const char *device = String_val (devicev);
835   const char *mountpoint = String_val (mountpointv);
836   int r;
837
838   caml_enter_blocking_section ();
839   r = guestfs_mount (g, device, mountpoint);
840   caml_leave_blocking_section ();
841   if (r == -1)
842     ocaml_guestfs_raise_error (g, "mount");
843
844   rv = Val_unit;
845   CAMLreturn (rv);
846 }
847
848 CAMLprim value
849 ocaml_guestfs_sync (value gv)
850 {
851   CAMLparam1 (gv);
852   CAMLlocal1 (rv);
853
854   guestfs_h *g = Guestfs_val (gv);
855   if (g == NULL)
856     caml_failwith ("sync: used handle after closing it");
857
858   int r;
859
860   caml_enter_blocking_section ();
861   r = guestfs_sync (g);
862   caml_leave_blocking_section ();
863   if (r == -1)
864     ocaml_guestfs_raise_error (g, "sync");
865
866   rv = Val_unit;
867   CAMLreturn (rv);
868 }
869
870 CAMLprim value
871 ocaml_guestfs_touch (value gv, value pathv)
872 {
873   CAMLparam2 (gv, pathv);
874   CAMLlocal1 (rv);
875
876   guestfs_h *g = Guestfs_val (gv);
877   if (g == NULL)
878     caml_failwith ("touch: used handle after closing it");
879
880   const char *path = String_val (pathv);
881   int r;
882
883   caml_enter_blocking_section ();
884   r = guestfs_touch (g, path);
885   caml_leave_blocking_section ();
886   if (r == -1)
887     ocaml_guestfs_raise_error (g, "touch");
888
889   rv = Val_unit;
890   CAMLreturn (rv);
891 }
892
893 CAMLprim value
894 ocaml_guestfs_cat (value gv, value pathv)
895 {
896   CAMLparam2 (gv, pathv);
897   CAMLlocal1 (rv);
898
899   guestfs_h *g = Guestfs_val (gv);
900   if (g == NULL)
901     caml_failwith ("cat: used handle after closing it");
902
903   const char *path = String_val (pathv);
904   char *r;
905
906   caml_enter_blocking_section ();
907   r = guestfs_cat (g, path);
908   caml_leave_blocking_section ();
909   if (r == NULL)
910     ocaml_guestfs_raise_error (g, "cat");
911
912   rv = caml_copy_string (r);
913   free (r);
914   CAMLreturn (rv);
915 }
916
917 CAMLprim value
918 ocaml_guestfs_ll (value gv, value directoryv)
919 {
920   CAMLparam2 (gv, directoryv);
921   CAMLlocal1 (rv);
922
923   guestfs_h *g = Guestfs_val (gv);
924   if (g == NULL)
925     caml_failwith ("ll: used handle after closing it");
926
927   const char *directory = String_val (directoryv);
928   char *r;
929
930   caml_enter_blocking_section ();
931   r = guestfs_ll (g, directory);
932   caml_leave_blocking_section ();
933   if (r == NULL)
934     ocaml_guestfs_raise_error (g, "ll");
935
936   rv = caml_copy_string (r);
937   free (r);
938   CAMLreturn (rv);
939 }
940
941 CAMLprim value
942 ocaml_guestfs_ls (value gv, value directoryv)
943 {
944   CAMLparam2 (gv, directoryv);
945   CAMLlocal1 (rv);
946
947   guestfs_h *g = Guestfs_val (gv);
948   if (g == NULL)
949     caml_failwith ("ls: used handle after closing it");
950
951   const char *directory = String_val (directoryv);
952   int i;
953   char **r;
954
955   caml_enter_blocking_section ();
956   r = guestfs_ls (g, directory);
957   caml_leave_blocking_section ();
958   if (r == NULL)
959     ocaml_guestfs_raise_error (g, "ls");
960
961   rv = caml_copy_string_array ((const char **) r);
962   for (i = 0; r[i] != NULL; ++i) free (r[i]);
963   free (r);
964   CAMLreturn (rv);
965 }
966
967 CAMLprim value
968 ocaml_guestfs_list_devices (value gv)
969 {
970   CAMLparam1 (gv);
971   CAMLlocal1 (rv);
972
973   guestfs_h *g = Guestfs_val (gv);
974   if (g == NULL)
975     caml_failwith ("list_devices: used handle after closing it");
976
977   int i;
978   char **r;
979
980   caml_enter_blocking_section ();
981   r = guestfs_list_devices (g);
982   caml_leave_blocking_section ();
983   if (r == NULL)
984     ocaml_guestfs_raise_error (g, "list_devices");
985
986   rv = caml_copy_string_array ((const char **) r);
987   for (i = 0; r[i] != NULL; ++i) free (r[i]);
988   free (r);
989   CAMLreturn (rv);
990 }
991
992 CAMLprim value
993 ocaml_guestfs_list_partitions (value gv)
994 {
995   CAMLparam1 (gv);
996   CAMLlocal1 (rv);
997
998   guestfs_h *g = Guestfs_val (gv);
999   if (g == NULL)
1000     caml_failwith ("list_partitions: used handle after closing it");
1001
1002   int i;
1003   char **r;
1004
1005   caml_enter_blocking_section ();
1006   r = guestfs_list_partitions (g);
1007   caml_leave_blocking_section ();
1008   if (r == NULL)
1009     ocaml_guestfs_raise_error (g, "list_partitions");
1010
1011   rv = caml_copy_string_array ((const char **) r);
1012   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1013   free (r);
1014   CAMLreturn (rv);
1015 }
1016
1017 CAMLprim value
1018 ocaml_guestfs_pvs (value gv)
1019 {
1020   CAMLparam1 (gv);
1021   CAMLlocal1 (rv);
1022
1023   guestfs_h *g = Guestfs_val (gv);
1024   if (g == NULL)
1025     caml_failwith ("pvs: used handle after closing it");
1026
1027   int i;
1028   char **r;
1029
1030   caml_enter_blocking_section ();
1031   r = guestfs_pvs (g);
1032   caml_leave_blocking_section ();
1033   if (r == NULL)
1034     ocaml_guestfs_raise_error (g, "pvs");
1035
1036   rv = caml_copy_string_array ((const char **) r);
1037   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1038   free (r);
1039   CAMLreturn (rv);
1040 }
1041
1042 CAMLprim value
1043 ocaml_guestfs_vgs (value gv)
1044 {
1045   CAMLparam1 (gv);
1046   CAMLlocal1 (rv);
1047
1048   guestfs_h *g = Guestfs_val (gv);
1049   if (g == NULL)
1050     caml_failwith ("vgs: used handle after closing it");
1051
1052   int i;
1053   char **r;
1054
1055   caml_enter_blocking_section ();
1056   r = guestfs_vgs (g);
1057   caml_leave_blocking_section ();
1058   if (r == NULL)
1059     ocaml_guestfs_raise_error (g, "vgs");
1060
1061   rv = caml_copy_string_array ((const char **) r);
1062   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1063   free (r);
1064   CAMLreturn (rv);
1065 }
1066
1067 CAMLprim value
1068 ocaml_guestfs_lvs (value gv)
1069 {
1070   CAMLparam1 (gv);
1071   CAMLlocal1 (rv);
1072
1073   guestfs_h *g = Guestfs_val (gv);
1074   if (g == NULL)
1075     caml_failwith ("lvs: used handle after closing it");
1076
1077   int i;
1078   char **r;
1079
1080   caml_enter_blocking_section ();
1081   r = guestfs_lvs (g);
1082   caml_leave_blocking_section ();
1083   if (r == NULL)
1084     ocaml_guestfs_raise_error (g, "lvs");
1085
1086   rv = caml_copy_string_array ((const char **) r);
1087   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1088   free (r);
1089   CAMLreturn (rv);
1090 }
1091
1092 CAMLprim value
1093 ocaml_guestfs_pvs_full (value gv)
1094 {
1095   CAMLparam1 (gv);
1096   CAMLlocal1 (rv);
1097
1098   guestfs_h *g = Guestfs_val (gv);
1099   if (g == NULL)
1100     caml_failwith ("pvs_full: used handle after closing it");
1101
1102   struct guestfs_lvm_pv_list *r;
1103
1104   caml_enter_blocking_section ();
1105   r = guestfs_pvs_full (g);
1106   caml_leave_blocking_section ();
1107   if (r == NULL)
1108     ocaml_guestfs_raise_error (g, "pvs_full");
1109
1110   rv = copy_lvm_pv_list (r);
1111   guestfs_free_lvm_pv_list (r);
1112   CAMLreturn (rv);
1113 }
1114
1115 CAMLprim value
1116 ocaml_guestfs_vgs_full (value gv)
1117 {
1118   CAMLparam1 (gv);
1119   CAMLlocal1 (rv);
1120
1121   guestfs_h *g = Guestfs_val (gv);
1122   if (g == NULL)
1123     caml_failwith ("vgs_full: used handle after closing it");
1124
1125   struct guestfs_lvm_vg_list *r;
1126
1127   caml_enter_blocking_section ();
1128   r = guestfs_vgs_full (g);
1129   caml_leave_blocking_section ();
1130   if (r == NULL)
1131     ocaml_guestfs_raise_error (g, "vgs_full");
1132
1133   rv = copy_lvm_vg_list (r);
1134   guestfs_free_lvm_vg_list (r);
1135   CAMLreturn (rv);
1136 }
1137
1138 CAMLprim value
1139 ocaml_guestfs_lvs_full (value gv)
1140 {
1141   CAMLparam1 (gv);
1142   CAMLlocal1 (rv);
1143
1144   guestfs_h *g = Guestfs_val (gv);
1145   if (g == NULL)
1146     caml_failwith ("lvs_full: used handle after closing it");
1147
1148   struct guestfs_lvm_lv_list *r;
1149
1150   caml_enter_blocking_section ();
1151   r = guestfs_lvs_full (g);
1152   caml_leave_blocking_section ();
1153   if (r == NULL)
1154     ocaml_guestfs_raise_error (g, "lvs_full");
1155
1156   rv = copy_lvm_lv_list (r);
1157   guestfs_free_lvm_lv_list (r);
1158   CAMLreturn (rv);
1159 }
1160
1161 CAMLprim value
1162 ocaml_guestfs_read_lines (value gv, value pathv)
1163 {
1164   CAMLparam2 (gv, pathv);
1165   CAMLlocal1 (rv);
1166
1167   guestfs_h *g = Guestfs_val (gv);
1168   if (g == NULL)
1169     caml_failwith ("read_lines: used handle after closing it");
1170
1171   const char *path = String_val (pathv);
1172   int i;
1173   char **r;
1174
1175   caml_enter_blocking_section ();
1176   r = guestfs_read_lines (g, path);
1177   caml_leave_blocking_section ();
1178   if (r == NULL)
1179     ocaml_guestfs_raise_error (g, "read_lines");
1180
1181   rv = caml_copy_string_array ((const char **) r);
1182   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1183   free (r);
1184   CAMLreturn (rv);
1185 }
1186
1187 CAMLprim value
1188 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
1189 {
1190   CAMLparam3 (gv, rootv, flagsv);
1191   CAMLlocal1 (rv);
1192
1193   guestfs_h *g = Guestfs_val (gv);
1194   if (g == NULL)
1195     caml_failwith ("aug_init: used handle after closing it");
1196
1197   const char *root = String_val (rootv);
1198   int flags = Int_val (flagsv);
1199   int r;
1200
1201   caml_enter_blocking_section ();
1202   r = guestfs_aug_init (g, root, flags);
1203   caml_leave_blocking_section ();
1204   if (r == -1)
1205     ocaml_guestfs_raise_error (g, "aug_init");
1206
1207   rv = Val_unit;
1208   CAMLreturn (rv);
1209 }
1210
1211 CAMLprim value
1212 ocaml_guestfs_aug_close (value gv)
1213 {
1214   CAMLparam1 (gv);
1215   CAMLlocal1 (rv);
1216
1217   guestfs_h *g = Guestfs_val (gv);
1218   if (g == NULL)
1219     caml_failwith ("aug_close: used handle after closing it");
1220
1221   int r;
1222
1223   caml_enter_blocking_section ();
1224   r = guestfs_aug_close (g);
1225   caml_leave_blocking_section ();
1226   if (r == -1)
1227     ocaml_guestfs_raise_error (g, "aug_close");
1228
1229   rv = Val_unit;
1230   CAMLreturn (rv);
1231 }
1232
1233 CAMLprim value
1234 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
1235 {
1236   CAMLparam3 (gv, namev, exprv);
1237   CAMLlocal1 (rv);
1238
1239   guestfs_h *g = Guestfs_val (gv);
1240   if (g == NULL)
1241     caml_failwith ("aug_defvar: used handle after closing it");
1242
1243   const char *name = String_val (namev);
1244   const char *expr =
1245     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
1246   int r;
1247
1248   caml_enter_blocking_section ();
1249   r = guestfs_aug_defvar (g, name, expr);
1250   caml_leave_blocking_section ();
1251   if (r == -1)
1252     ocaml_guestfs_raise_error (g, "aug_defvar");
1253
1254   rv = Val_int (r);
1255   CAMLreturn (rv);
1256 }
1257
1258 CAMLprim value
1259 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1260 {
1261   CAMLparam4 (gv, namev, exprv, valv);
1262   CAMLlocal1 (rv);
1263
1264   guestfs_h *g = Guestfs_val (gv);
1265   if (g == NULL)
1266     caml_failwith ("aug_defnode: used handle after closing it");
1267
1268   const char *name = String_val (namev);
1269   const char *expr = String_val (exprv);
1270   const char *val = String_val (valv);
1271   struct guestfs_int_bool *r;
1272
1273   caml_enter_blocking_section ();
1274   r = guestfs_aug_defnode (g, name, expr, val);
1275   caml_leave_blocking_section ();
1276   if (r == NULL)
1277     ocaml_guestfs_raise_error (g, "aug_defnode");
1278
1279   rv = caml_alloc (2, 0);
1280   Store_field (rv, 0, Val_int (r->i));
1281   Store_field (rv, 1, Val_bool (r->b));
1282   guestfs_free_int_bool (r);
1283   CAMLreturn (rv);
1284 }
1285
1286 CAMLprim value
1287 ocaml_guestfs_aug_get (value gv, value pathv)
1288 {
1289   CAMLparam2 (gv, pathv);
1290   CAMLlocal1 (rv);
1291
1292   guestfs_h *g = Guestfs_val (gv);
1293   if (g == NULL)
1294     caml_failwith ("aug_get: used handle after closing it");
1295
1296   const char *path = String_val (pathv);
1297   char *r;
1298
1299   caml_enter_blocking_section ();
1300   r = guestfs_aug_get (g, path);
1301   caml_leave_blocking_section ();
1302   if (r == NULL)
1303     ocaml_guestfs_raise_error (g, "aug_get");
1304
1305   rv = caml_copy_string (r);
1306   free (r);
1307   CAMLreturn (rv);
1308 }
1309
1310 CAMLprim value
1311 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
1312 {
1313   CAMLparam3 (gv, pathv, valv);
1314   CAMLlocal1 (rv);
1315
1316   guestfs_h *g = Guestfs_val (gv);
1317   if (g == NULL)
1318     caml_failwith ("aug_set: used handle after closing it");
1319
1320   const char *path = String_val (pathv);
1321   const char *val = String_val (valv);
1322   int r;
1323
1324   caml_enter_blocking_section ();
1325   r = guestfs_aug_set (g, path, val);
1326   caml_leave_blocking_section ();
1327   if (r == -1)
1328     ocaml_guestfs_raise_error (g, "aug_set");
1329
1330   rv = Val_unit;
1331   CAMLreturn (rv);
1332 }
1333
1334 CAMLprim value
1335 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1336 {
1337   CAMLparam4 (gv, pathv, labelv, beforev);
1338   CAMLlocal1 (rv);
1339
1340   guestfs_h *g = Guestfs_val (gv);
1341   if (g == NULL)
1342     caml_failwith ("aug_insert: used handle after closing it");
1343
1344   const char *path = String_val (pathv);
1345   const char *label = String_val (labelv);
1346   int before = Bool_val (beforev);
1347   int r;
1348
1349   caml_enter_blocking_section ();
1350   r = guestfs_aug_insert (g, path, label, before);
1351   caml_leave_blocking_section ();
1352   if (r == -1)
1353     ocaml_guestfs_raise_error (g, "aug_insert");
1354
1355   rv = Val_unit;
1356   CAMLreturn (rv);
1357 }
1358
1359 CAMLprim value
1360 ocaml_guestfs_aug_rm (value gv, value pathv)
1361 {
1362   CAMLparam2 (gv, pathv);
1363   CAMLlocal1 (rv);
1364
1365   guestfs_h *g = Guestfs_val (gv);
1366   if (g == NULL)
1367     caml_failwith ("aug_rm: used handle after closing it");
1368
1369   const char *path = String_val (pathv);
1370   int r;
1371
1372   caml_enter_blocking_section ();
1373   r = guestfs_aug_rm (g, path);
1374   caml_leave_blocking_section ();
1375   if (r == -1)
1376     ocaml_guestfs_raise_error (g, "aug_rm");
1377
1378   rv = Val_int (r);
1379   CAMLreturn (rv);
1380 }
1381
1382 CAMLprim value
1383 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1384 {
1385   CAMLparam3 (gv, srcv, destv);
1386   CAMLlocal1 (rv);
1387
1388   guestfs_h *g = Guestfs_val (gv);
1389   if (g == NULL)
1390     caml_failwith ("aug_mv: used handle after closing it");
1391
1392   const char *src = String_val (srcv);
1393   const char *dest = String_val (destv);
1394   int r;
1395
1396   caml_enter_blocking_section ();
1397   r = guestfs_aug_mv (g, src, dest);
1398   caml_leave_blocking_section ();
1399   if (r == -1)
1400     ocaml_guestfs_raise_error (g, "aug_mv");
1401
1402   rv = Val_unit;
1403   CAMLreturn (rv);
1404 }
1405
1406 CAMLprim value
1407 ocaml_guestfs_aug_match (value gv, value pathv)
1408 {
1409   CAMLparam2 (gv, pathv);
1410   CAMLlocal1 (rv);
1411
1412   guestfs_h *g = Guestfs_val (gv);
1413   if (g == NULL)
1414     caml_failwith ("aug_match: used handle after closing it");
1415
1416   const char *path = String_val (pathv);
1417   int i;
1418   char **r;
1419
1420   caml_enter_blocking_section ();
1421   r = guestfs_aug_match (g, path);
1422   caml_leave_blocking_section ();
1423   if (r == NULL)
1424     ocaml_guestfs_raise_error (g, "aug_match");
1425
1426   rv = caml_copy_string_array ((const char **) r);
1427   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1428   free (r);
1429   CAMLreturn (rv);
1430 }
1431
1432 CAMLprim value
1433 ocaml_guestfs_aug_save (value gv)
1434 {
1435   CAMLparam1 (gv);
1436   CAMLlocal1 (rv);
1437
1438   guestfs_h *g = Guestfs_val (gv);
1439   if (g == NULL)
1440     caml_failwith ("aug_save: used handle after closing it");
1441
1442   int r;
1443
1444   caml_enter_blocking_section ();
1445   r = guestfs_aug_save (g);
1446   caml_leave_blocking_section ();
1447   if (r == -1)
1448     ocaml_guestfs_raise_error (g, "aug_save");
1449
1450   rv = Val_unit;
1451   CAMLreturn (rv);
1452 }
1453
1454 CAMLprim value
1455 ocaml_guestfs_aug_load (value gv)
1456 {
1457   CAMLparam1 (gv);
1458   CAMLlocal1 (rv);
1459
1460   guestfs_h *g = Guestfs_val (gv);
1461   if (g == NULL)
1462     caml_failwith ("aug_load: used handle after closing it");
1463
1464   int r;
1465
1466   caml_enter_blocking_section ();
1467   r = guestfs_aug_load (g);
1468   caml_leave_blocking_section ();
1469   if (r == -1)
1470     ocaml_guestfs_raise_error (g, "aug_load");
1471
1472   rv = Val_unit;
1473   CAMLreturn (rv);
1474 }
1475
1476 CAMLprim value
1477 ocaml_guestfs_aug_ls (value gv, value pathv)
1478 {
1479   CAMLparam2 (gv, pathv);
1480   CAMLlocal1 (rv);
1481
1482   guestfs_h *g = Guestfs_val (gv);
1483   if (g == NULL)
1484     caml_failwith ("aug_ls: used handle after closing it");
1485
1486   const char *path = String_val (pathv);
1487   int i;
1488   char **r;
1489
1490   caml_enter_blocking_section ();
1491   r = guestfs_aug_ls (g, path);
1492   caml_leave_blocking_section ();
1493   if (r == NULL)
1494     ocaml_guestfs_raise_error (g, "aug_ls");
1495
1496   rv = caml_copy_string_array ((const char **) r);
1497   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1498   free (r);
1499   CAMLreturn (rv);
1500 }
1501
1502 CAMLprim value
1503 ocaml_guestfs_rm (value gv, value pathv)
1504 {
1505   CAMLparam2 (gv, pathv);
1506   CAMLlocal1 (rv);
1507
1508   guestfs_h *g = Guestfs_val (gv);
1509   if (g == NULL)
1510     caml_failwith ("rm: used handle after closing it");
1511
1512   const char *path = String_val (pathv);
1513   int r;
1514
1515   caml_enter_blocking_section ();
1516   r = guestfs_rm (g, path);
1517   caml_leave_blocking_section ();
1518   if (r == -1)
1519     ocaml_guestfs_raise_error (g, "rm");
1520
1521   rv = Val_unit;
1522   CAMLreturn (rv);
1523 }
1524
1525 CAMLprim value
1526 ocaml_guestfs_rmdir (value gv, value pathv)
1527 {
1528   CAMLparam2 (gv, pathv);
1529   CAMLlocal1 (rv);
1530
1531   guestfs_h *g = Guestfs_val (gv);
1532   if (g == NULL)
1533     caml_failwith ("rmdir: used handle after closing it");
1534
1535   const char *path = String_val (pathv);
1536   int r;
1537
1538   caml_enter_blocking_section ();
1539   r = guestfs_rmdir (g, path);
1540   caml_leave_blocking_section ();
1541   if (r == -1)
1542     ocaml_guestfs_raise_error (g, "rmdir");
1543
1544   rv = Val_unit;
1545   CAMLreturn (rv);
1546 }
1547
1548 CAMLprim value
1549 ocaml_guestfs_rm_rf (value gv, value pathv)
1550 {
1551   CAMLparam2 (gv, pathv);
1552   CAMLlocal1 (rv);
1553
1554   guestfs_h *g = Guestfs_val (gv);
1555   if (g == NULL)
1556     caml_failwith ("rm_rf: used handle after closing it");
1557
1558   const char *path = String_val (pathv);
1559   int r;
1560
1561   caml_enter_blocking_section ();
1562   r = guestfs_rm_rf (g, path);
1563   caml_leave_blocking_section ();
1564   if (r == -1)
1565     ocaml_guestfs_raise_error (g, "rm_rf");
1566
1567   rv = Val_unit;
1568   CAMLreturn (rv);
1569 }
1570
1571 CAMLprim value
1572 ocaml_guestfs_mkdir (value gv, value pathv)
1573 {
1574   CAMLparam2 (gv, pathv);
1575   CAMLlocal1 (rv);
1576
1577   guestfs_h *g = Guestfs_val (gv);
1578   if (g == NULL)
1579     caml_failwith ("mkdir: used handle after closing it");
1580
1581   const char *path = String_val (pathv);
1582   int r;
1583
1584   caml_enter_blocking_section ();
1585   r = guestfs_mkdir (g, path);
1586   caml_leave_blocking_section ();
1587   if (r == -1)
1588     ocaml_guestfs_raise_error (g, "mkdir");
1589
1590   rv = Val_unit;
1591   CAMLreturn (rv);
1592 }
1593
1594 CAMLprim value
1595 ocaml_guestfs_mkdir_p (value gv, value pathv)
1596 {
1597   CAMLparam2 (gv, pathv);
1598   CAMLlocal1 (rv);
1599
1600   guestfs_h *g = Guestfs_val (gv);
1601   if (g == NULL)
1602     caml_failwith ("mkdir_p: used handle after closing it");
1603
1604   const char *path = String_val (pathv);
1605   int r;
1606
1607   caml_enter_blocking_section ();
1608   r = guestfs_mkdir_p (g, path);
1609   caml_leave_blocking_section ();
1610   if (r == -1)
1611     ocaml_guestfs_raise_error (g, "mkdir_p");
1612
1613   rv = Val_unit;
1614   CAMLreturn (rv);
1615 }
1616
1617 CAMLprim value
1618 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1619 {
1620   CAMLparam3 (gv, modev, pathv);
1621   CAMLlocal1 (rv);
1622
1623   guestfs_h *g = Guestfs_val (gv);
1624   if (g == NULL)
1625     caml_failwith ("chmod: used handle after closing it");
1626
1627   int mode = Int_val (modev);
1628   const char *path = String_val (pathv);
1629   int r;
1630
1631   caml_enter_blocking_section ();
1632   r = guestfs_chmod (g, mode, path);
1633   caml_leave_blocking_section ();
1634   if (r == -1)
1635     ocaml_guestfs_raise_error (g, "chmod");
1636
1637   rv = Val_unit;
1638   CAMLreturn (rv);
1639 }
1640
1641 CAMLprim value
1642 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1643 {
1644   CAMLparam4 (gv, ownerv, groupv, pathv);
1645   CAMLlocal1 (rv);
1646
1647   guestfs_h *g = Guestfs_val (gv);
1648   if (g == NULL)
1649     caml_failwith ("chown: used handle after closing it");
1650
1651   int owner = Int_val (ownerv);
1652   int group = Int_val (groupv);
1653   const char *path = String_val (pathv);
1654   int r;
1655
1656   caml_enter_blocking_section ();
1657   r = guestfs_chown (g, owner, group, path);
1658   caml_leave_blocking_section ();
1659   if (r == -1)
1660     ocaml_guestfs_raise_error (g, "chown");
1661
1662   rv = Val_unit;
1663   CAMLreturn (rv);
1664 }
1665
1666 CAMLprim value
1667 ocaml_guestfs_exists (value gv, value pathv)
1668 {
1669   CAMLparam2 (gv, pathv);
1670   CAMLlocal1 (rv);
1671
1672   guestfs_h *g = Guestfs_val (gv);
1673   if (g == NULL)
1674     caml_failwith ("exists: used handle after closing it");
1675
1676   const char *path = String_val (pathv);
1677   int r;
1678
1679   caml_enter_blocking_section ();
1680   r = guestfs_exists (g, path);
1681   caml_leave_blocking_section ();
1682   if (r == -1)
1683     ocaml_guestfs_raise_error (g, "exists");
1684
1685   rv = Val_bool (r);
1686   CAMLreturn (rv);
1687 }
1688
1689 CAMLprim value
1690 ocaml_guestfs_is_file (value gv, value pathv)
1691 {
1692   CAMLparam2 (gv, pathv);
1693   CAMLlocal1 (rv);
1694
1695   guestfs_h *g = Guestfs_val (gv);
1696   if (g == NULL)
1697     caml_failwith ("is_file: used handle after closing it");
1698
1699   const char *path = String_val (pathv);
1700   int r;
1701
1702   caml_enter_blocking_section ();
1703   r = guestfs_is_file (g, path);
1704   caml_leave_blocking_section ();
1705   if (r == -1)
1706     ocaml_guestfs_raise_error (g, "is_file");
1707
1708   rv = Val_bool (r);
1709   CAMLreturn (rv);
1710 }
1711
1712 CAMLprim value
1713 ocaml_guestfs_is_dir (value gv, value pathv)
1714 {
1715   CAMLparam2 (gv, pathv);
1716   CAMLlocal1 (rv);
1717
1718   guestfs_h *g = Guestfs_val (gv);
1719   if (g == NULL)
1720     caml_failwith ("is_dir: used handle after closing it");
1721
1722   const char *path = String_val (pathv);
1723   int r;
1724
1725   caml_enter_blocking_section ();
1726   r = guestfs_is_dir (g, path);
1727   caml_leave_blocking_section ();
1728   if (r == -1)
1729     ocaml_guestfs_raise_error (g, "is_dir");
1730
1731   rv = Val_bool (r);
1732   CAMLreturn (rv);
1733 }
1734
1735 CAMLprim value
1736 ocaml_guestfs_pvcreate (value gv, value devicev)
1737 {
1738   CAMLparam2 (gv, devicev);
1739   CAMLlocal1 (rv);
1740
1741   guestfs_h *g = Guestfs_val (gv);
1742   if (g == NULL)
1743     caml_failwith ("pvcreate: used handle after closing it");
1744
1745   const char *device = String_val (devicev);
1746   int r;
1747
1748   caml_enter_blocking_section ();
1749   r = guestfs_pvcreate (g, device);
1750   caml_leave_blocking_section ();
1751   if (r == -1)
1752     ocaml_guestfs_raise_error (g, "pvcreate");
1753
1754   rv = Val_unit;
1755   CAMLreturn (rv);
1756 }
1757
1758 CAMLprim value
1759 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
1760 {
1761   CAMLparam3 (gv, volgroupv, physvolsv);
1762   CAMLlocal1 (rv);
1763
1764   guestfs_h *g = Guestfs_val (gv);
1765   if (g == NULL)
1766     caml_failwith ("vgcreate: used handle after closing it");
1767
1768   const char *volgroup = String_val (volgroupv);
1769   char **physvols = ocaml_guestfs_strings_val (g, physvolsv);
1770   int r;
1771
1772   caml_enter_blocking_section ();
1773   r = guestfs_vgcreate (g, volgroup, physvols);
1774   caml_leave_blocking_section ();
1775   ocaml_guestfs_free_strings (physvols);
1776   if (r == -1)
1777     ocaml_guestfs_raise_error (g, "vgcreate");
1778
1779   rv = Val_unit;
1780   CAMLreturn (rv);
1781 }
1782
1783 CAMLprim value
1784 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
1785 {
1786   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
1787   CAMLlocal1 (rv);
1788
1789   guestfs_h *g = Guestfs_val (gv);
1790   if (g == NULL)
1791     caml_failwith ("lvcreate: used handle after closing it");
1792
1793   const char *logvol = String_val (logvolv);
1794   const char *volgroup = String_val (volgroupv);
1795   int mbytes = Int_val (mbytesv);
1796   int r;
1797
1798   caml_enter_blocking_section ();
1799   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
1800   caml_leave_blocking_section ();
1801   if (r == -1)
1802     ocaml_guestfs_raise_error (g, "lvcreate");
1803
1804   rv = Val_unit;
1805   CAMLreturn (rv);
1806 }
1807
1808 CAMLprim value
1809 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
1810 {
1811   CAMLparam3 (gv, fstypev, devicev);
1812   CAMLlocal1 (rv);
1813
1814   guestfs_h *g = Guestfs_val (gv);
1815   if (g == NULL)
1816     caml_failwith ("mkfs: used handle after closing it");
1817
1818   const char *fstype = String_val (fstypev);
1819   const char *device = String_val (devicev);
1820   int r;
1821
1822   caml_enter_blocking_section ();
1823   r = guestfs_mkfs (g, fstype, device);
1824   caml_leave_blocking_section ();
1825   if (r == -1)
1826     ocaml_guestfs_raise_error (g, "mkfs");
1827
1828   rv = Val_unit;
1829   CAMLreturn (rv);
1830 }
1831
1832 CAMLprim value
1833 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
1834 {
1835   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
1836   CAMLxparam1 (linesv);
1837   CAMLlocal1 (rv);
1838
1839   guestfs_h *g = Guestfs_val (gv);
1840   if (g == NULL)
1841     caml_failwith ("sfdisk: used handle after closing it");
1842
1843   const char *device = String_val (devicev);
1844   int cyls = Int_val (cylsv);
1845   int heads = Int_val (headsv);
1846   int sectors = Int_val (sectorsv);
1847   char **lines = ocaml_guestfs_strings_val (g, linesv);
1848   int r;
1849
1850   caml_enter_blocking_section ();
1851   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
1852   caml_leave_blocking_section ();
1853   ocaml_guestfs_free_strings (lines);
1854   if (r == -1)
1855     ocaml_guestfs_raise_error (g, "sfdisk");
1856
1857   rv = Val_unit;
1858   CAMLreturn (rv);
1859 }
1860
1861 CAMLprim value
1862 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
1863 {
1864   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
1865 }
1866
1867 CAMLprim value
1868 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
1869 {
1870   CAMLparam4 (gv, pathv, contentv, sizev);
1871   CAMLlocal1 (rv);
1872
1873   guestfs_h *g = Guestfs_val (gv);
1874   if (g == NULL)
1875     caml_failwith ("write_file: used handle after closing it");
1876
1877   const char *path = String_val (pathv);
1878   const char *content = String_val (contentv);
1879   int size = Int_val (sizev);
1880   int r;
1881
1882   caml_enter_blocking_section ();
1883   r = guestfs_write_file (g, path, content, size);
1884   caml_leave_blocking_section ();
1885   if (r == -1)
1886     ocaml_guestfs_raise_error (g, "write_file");
1887
1888   rv = Val_unit;
1889   CAMLreturn (rv);
1890 }
1891
1892 CAMLprim value
1893 ocaml_guestfs_umount (value gv, value pathordevicev)
1894 {
1895   CAMLparam2 (gv, pathordevicev);
1896   CAMLlocal1 (rv);
1897
1898   guestfs_h *g = Guestfs_val (gv);
1899   if (g == NULL)
1900     caml_failwith ("umount: used handle after closing it");
1901
1902   const char *pathordevice = String_val (pathordevicev);
1903   int r;
1904
1905   caml_enter_blocking_section ();
1906   r = guestfs_umount (g, pathordevice);
1907   caml_leave_blocking_section ();
1908   if (r == -1)
1909     ocaml_guestfs_raise_error (g, "umount");
1910
1911   rv = Val_unit;
1912   CAMLreturn (rv);
1913 }
1914
1915 CAMLprim value
1916 ocaml_guestfs_mounts (value gv)
1917 {
1918   CAMLparam1 (gv);
1919   CAMLlocal1 (rv);
1920
1921   guestfs_h *g = Guestfs_val (gv);
1922   if (g == NULL)
1923     caml_failwith ("mounts: used handle after closing it");
1924
1925   int i;
1926   char **r;
1927
1928   caml_enter_blocking_section ();
1929   r = guestfs_mounts (g);
1930   caml_leave_blocking_section ();
1931   if (r == NULL)
1932     ocaml_guestfs_raise_error (g, "mounts");
1933
1934   rv = caml_copy_string_array ((const char **) r);
1935   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1936   free (r);
1937   CAMLreturn (rv);
1938 }
1939
1940 CAMLprim value
1941 ocaml_guestfs_umount_all (value gv)
1942 {
1943   CAMLparam1 (gv);
1944   CAMLlocal1 (rv);
1945
1946   guestfs_h *g = Guestfs_val (gv);
1947   if (g == NULL)
1948     caml_failwith ("umount_all: used handle after closing it");
1949
1950   int r;
1951
1952   caml_enter_blocking_section ();
1953   r = guestfs_umount_all (g);
1954   caml_leave_blocking_section ();
1955   if (r == -1)
1956     ocaml_guestfs_raise_error (g, "umount_all");
1957
1958   rv = Val_unit;
1959   CAMLreturn (rv);
1960 }
1961
1962 CAMLprim value
1963 ocaml_guestfs_lvm_remove_all (value gv)
1964 {
1965   CAMLparam1 (gv);
1966   CAMLlocal1 (rv);
1967
1968   guestfs_h *g = Guestfs_val (gv);
1969   if (g == NULL)
1970     caml_failwith ("lvm_remove_all: used handle after closing it");
1971
1972   int r;
1973
1974   caml_enter_blocking_section ();
1975   r = guestfs_lvm_remove_all (g);
1976   caml_leave_blocking_section ();
1977   if (r == -1)
1978     ocaml_guestfs_raise_error (g, "lvm_remove_all");
1979
1980   rv = Val_unit;
1981   CAMLreturn (rv);
1982 }
1983
1984 CAMLprim value
1985 ocaml_guestfs_file (value gv, value pathv)
1986 {
1987   CAMLparam2 (gv, pathv);
1988   CAMLlocal1 (rv);
1989
1990   guestfs_h *g = Guestfs_val (gv);
1991   if (g == NULL)
1992     caml_failwith ("file: used handle after closing it");
1993
1994   const char *path = String_val (pathv);
1995   char *r;
1996
1997   caml_enter_blocking_section ();
1998   r = guestfs_file (g, path);
1999   caml_leave_blocking_section ();
2000   if (r == NULL)
2001     ocaml_guestfs_raise_error (g, "file");
2002
2003   rv = caml_copy_string (r);
2004   free (r);
2005   CAMLreturn (rv);
2006 }
2007
2008 CAMLprim value
2009 ocaml_guestfs_command (value gv, value argumentsv)
2010 {
2011   CAMLparam2 (gv, argumentsv);
2012   CAMLlocal1 (rv);
2013
2014   guestfs_h *g = Guestfs_val (gv);
2015   if (g == NULL)
2016     caml_failwith ("command: used handle after closing it");
2017
2018   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2019   char *r;
2020
2021   caml_enter_blocking_section ();
2022   r = guestfs_command (g, arguments);
2023   caml_leave_blocking_section ();
2024   ocaml_guestfs_free_strings (arguments);
2025   if (r == NULL)
2026     ocaml_guestfs_raise_error (g, "command");
2027
2028   rv = caml_copy_string (r);
2029   free (r);
2030   CAMLreturn (rv);
2031 }
2032
2033 CAMLprim value
2034 ocaml_guestfs_command_lines (value gv, value argumentsv)
2035 {
2036   CAMLparam2 (gv, argumentsv);
2037   CAMLlocal1 (rv);
2038
2039   guestfs_h *g = Guestfs_val (gv);
2040   if (g == NULL)
2041     caml_failwith ("command_lines: used handle after closing it");
2042
2043   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2044   int i;
2045   char **r;
2046
2047   caml_enter_blocking_section ();
2048   r = guestfs_command_lines (g, arguments);
2049   caml_leave_blocking_section ();
2050   ocaml_guestfs_free_strings (arguments);
2051   if (r == NULL)
2052     ocaml_guestfs_raise_error (g, "command_lines");
2053
2054   rv = caml_copy_string_array ((const char **) r);
2055   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2056   free (r);
2057   CAMLreturn (rv);
2058 }
2059
2060 CAMLprim value
2061 ocaml_guestfs_stat (value gv, value pathv)
2062 {
2063   CAMLparam2 (gv, pathv);
2064   CAMLlocal1 (rv);
2065
2066   guestfs_h *g = Guestfs_val (gv);
2067   if (g == NULL)
2068     caml_failwith ("stat: used handle after closing it");
2069
2070   const char *path = String_val (pathv);
2071   struct guestfs_stat *r;
2072
2073   caml_enter_blocking_section ();
2074   r = guestfs_stat (g, path);
2075   caml_leave_blocking_section ();
2076   if (r == NULL)
2077     ocaml_guestfs_raise_error (g, "stat");
2078
2079   rv = copy_stat (r);
2080   free (r);
2081   CAMLreturn (rv);
2082 }
2083
2084 CAMLprim value
2085 ocaml_guestfs_lstat (value gv, value pathv)
2086 {
2087   CAMLparam2 (gv, pathv);
2088   CAMLlocal1 (rv);
2089
2090   guestfs_h *g = Guestfs_val (gv);
2091   if (g == NULL)
2092     caml_failwith ("lstat: used handle after closing it");
2093
2094   const char *path = String_val (pathv);
2095   struct guestfs_stat *r;
2096
2097   caml_enter_blocking_section ();
2098   r = guestfs_lstat (g, path);
2099   caml_leave_blocking_section ();
2100   if (r == NULL)
2101     ocaml_guestfs_raise_error (g, "lstat");
2102
2103   rv = copy_stat (r);
2104   free (r);
2105   CAMLreturn (rv);
2106 }
2107
2108 CAMLprim value
2109 ocaml_guestfs_statvfs (value gv, value pathv)
2110 {
2111   CAMLparam2 (gv, pathv);
2112   CAMLlocal1 (rv);
2113
2114   guestfs_h *g = Guestfs_val (gv);
2115   if (g == NULL)
2116     caml_failwith ("statvfs: used handle after closing it");
2117
2118   const char *path = String_val (pathv);
2119   struct guestfs_statvfs *r;
2120
2121   caml_enter_blocking_section ();
2122   r = guestfs_statvfs (g, path);
2123   caml_leave_blocking_section ();
2124   if (r == NULL)
2125     ocaml_guestfs_raise_error (g, "statvfs");
2126
2127   rv = copy_statvfs (r);
2128   free (r);
2129   CAMLreturn (rv);
2130 }
2131
2132 CAMLprim value
2133 ocaml_guestfs_tune2fs_l (value gv, value devicev)
2134 {
2135   CAMLparam2 (gv, devicev);
2136   CAMLlocal1 (rv);
2137
2138   guestfs_h *g = Guestfs_val (gv);
2139   if (g == NULL)
2140     caml_failwith ("tune2fs_l: used handle after closing it");
2141
2142   const char *device = String_val (devicev);
2143   int i;
2144   char **r;
2145
2146   caml_enter_blocking_section ();
2147   r = guestfs_tune2fs_l (g, device);
2148   caml_leave_blocking_section ();
2149   if (r == NULL)
2150     ocaml_guestfs_raise_error (g, "tune2fs_l");
2151
2152   rv = copy_table (r);
2153   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2154   free (r);
2155   CAMLreturn (rv);
2156 }
2157
2158 CAMLprim value
2159 ocaml_guestfs_blockdev_setro (value gv, value devicev)
2160 {
2161   CAMLparam2 (gv, devicev);
2162   CAMLlocal1 (rv);
2163
2164   guestfs_h *g = Guestfs_val (gv);
2165   if (g == NULL)
2166     caml_failwith ("blockdev_setro: used handle after closing it");
2167
2168   const char *device = String_val (devicev);
2169   int r;
2170
2171   caml_enter_blocking_section ();
2172   r = guestfs_blockdev_setro (g, device);
2173   caml_leave_blocking_section ();
2174   if (r == -1)
2175     ocaml_guestfs_raise_error (g, "blockdev_setro");
2176
2177   rv = Val_unit;
2178   CAMLreturn (rv);
2179 }
2180
2181 CAMLprim value
2182 ocaml_guestfs_blockdev_setrw (value gv, value devicev)
2183 {
2184   CAMLparam2 (gv, devicev);
2185   CAMLlocal1 (rv);
2186
2187   guestfs_h *g = Guestfs_val (gv);
2188   if (g == NULL)
2189     caml_failwith ("blockdev_setrw: used handle after closing it");
2190
2191   const char *device = String_val (devicev);
2192   int r;
2193
2194   caml_enter_blocking_section ();
2195   r = guestfs_blockdev_setrw (g, device);
2196   caml_leave_blocking_section ();
2197   if (r == -1)
2198     ocaml_guestfs_raise_error (g, "blockdev_setrw");
2199
2200   rv = Val_unit;
2201   CAMLreturn (rv);
2202 }
2203
2204 CAMLprim value
2205 ocaml_guestfs_blockdev_getro (value gv, value devicev)
2206 {
2207   CAMLparam2 (gv, devicev);
2208   CAMLlocal1 (rv);
2209
2210   guestfs_h *g = Guestfs_val (gv);
2211   if (g == NULL)
2212     caml_failwith ("blockdev_getro: used handle after closing it");
2213
2214   const char *device = String_val (devicev);
2215   int r;
2216
2217   caml_enter_blocking_section ();
2218   r = guestfs_blockdev_getro (g, device);
2219   caml_leave_blocking_section ();
2220   if (r == -1)
2221     ocaml_guestfs_raise_error (g, "blockdev_getro");
2222
2223   rv = Val_bool (r);
2224   CAMLreturn (rv);
2225 }
2226
2227 CAMLprim value
2228 ocaml_guestfs_blockdev_getss (value gv, value devicev)
2229 {
2230   CAMLparam2 (gv, devicev);
2231   CAMLlocal1 (rv);
2232
2233   guestfs_h *g = Guestfs_val (gv);
2234   if (g == NULL)
2235     caml_failwith ("blockdev_getss: used handle after closing it");
2236
2237   const char *device = String_val (devicev);
2238   int r;
2239
2240   caml_enter_blocking_section ();
2241   r = guestfs_blockdev_getss (g, device);
2242   caml_leave_blocking_section ();
2243   if (r == -1)
2244     ocaml_guestfs_raise_error (g, "blockdev_getss");
2245
2246   rv = Val_int (r);
2247   CAMLreturn (rv);
2248 }
2249
2250 CAMLprim value
2251 ocaml_guestfs_blockdev_getbsz (value gv, value devicev)
2252 {
2253   CAMLparam2 (gv, devicev);
2254   CAMLlocal1 (rv);
2255
2256   guestfs_h *g = Guestfs_val (gv);
2257   if (g == NULL)
2258     caml_failwith ("blockdev_getbsz: used handle after closing it");
2259
2260   const char *device = String_val (devicev);
2261   int r;
2262
2263   caml_enter_blocking_section ();
2264   r = guestfs_blockdev_getbsz (g, device);
2265   caml_leave_blocking_section ();
2266   if (r == -1)
2267     ocaml_guestfs_raise_error (g, "blockdev_getbsz");
2268
2269   rv = Val_int (r);
2270   CAMLreturn (rv);
2271 }
2272
2273 CAMLprim value
2274 ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev)
2275 {
2276   CAMLparam3 (gv, devicev, blocksizev);
2277   CAMLlocal1 (rv);
2278
2279   guestfs_h *g = Guestfs_val (gv);
2280   if (g == NULL)
2281     caml_failwith ("blockdev_setbsz: used handle after closing it");
2282
2283   const char *device = String_val (devicev);
2284   int blocksize = Int_val (blocksizev);
2285   int r;
2286
2287   caml_enter_blocking_section ();
2288   r = guestfs_blockdev_setbsz (g, device, blocksize);
2289   caml_leave_blocking_section ();
2290   if (r == -1)
2291     ocaml_guestfs_raise_error (g, "blockdev_setbsz");
2292
2293   rv = Val_unit;
2294   CAMLreturn (rv);
2295 }
2296
2297 CAMLprim value
2298 ocaml_guestfs_blockdev_getsz (value gv, value devicev)
2299 {
2300   CAMLparam2 (gv, devicev);
2301   CAMLlocal1 (rv);
2302
2303   guestfs_h *g = Guestfs_val (gv);
2304   if (g == NULL)
2305     caml_failwith ("blockdev_getsz: used handle after closing it");
2306
2307   const char *device = String_val (devicev);
2308   int64_t r;
2309
2310   caml_enter_blocking_section ();
2311   r = guestfs_blockdev_getsz (g, device);
2312   caml_leave_blocking_section ();
2313   if (r == -1)
2314     ocaml_guestfs_raise_error (g, "blockdev_getsz");
2315
2316   rv = caml_copy_int64 (r);
2317   CAMLreturn (rv);
2318 }
2319
2320 CAMLprim value
2321 ocaml_guestfs_blockdev_getsize64 (value gv, value devicev)
2322 {
2323   CAMLparam2 (gv, devicev);
2324   CAMLlocal1 (rv);
2325
2326   guestfs_h *g = Guestfs_val (gv);
2327   if (g == NULL)
2328     caml_failwith ("blockdev_getsize64: used handle after closing it");
2329
2330   const char *device = String_val (devicev);
2331   int64_t r;
2332
2333   caml_enter_blocking_section ();
2334   r = guestfs_blockdev_getsize64 (g, device);
2335   caml_leave_blocking_section ();
2336   if (r == -1)
2337     ocaml_guestfs_raise_error (g, "blockdev_getsize64");
2338
2339   rv = caml_copy_int64 (r);
2340   CAMLreturn (rv);
2341 }
2342
2343 CAMLprim value
2344 ocaml_guestfs_blockdev_flushbufs (value gv, value devicev)
2345 {
2346   CAMLparam2 (gv, devicev);
2347   CAMLlocal1 (rv);
2348
2349   guestfs_h *g = Guestfs_val (gv);
2350   if (g == NULL)
2351     caml_failwith ("blockdev_flushbufs: used handle after closing it");
2352
2353   const char *device = String_val (devicev);
2354   int r;
2355
2356   caml_enter_blocking_section ();
2357   r = guestfs_blockdev_flushbufs (g, device);
2358   caml_leave_blocking_section ();
2359   if (r == -1)
2360     ocaml_guestfs_raise_error (g, "blockdev_flushbufs");
2361
2362   rv = Val_unit;
2363   CAMLreturn (rv);
2364 }
2365
2366 CAMLprim value
2367 ocaml_guestfs_blockdev_rereadpt (value gv, value devicev)
2368 {
2369   CAMLparam2 (gv, devicev);
2370   CAMLlocal1 (rv);
2371
2372   guestfs_h *g = Guestfs_val (gv);
2373   if (g == NULL)
2374     caml_failwith ("blockdev_rereadpt: used handle after closing it");
2375
2376   const char *device = String_val (devicev);
2377   int r;
2378
2379   caml_enter_blocking_section ();
2380   r = guestfs_blockdev_rereadpt (g, device);
2381   caml_leave_blocking_section ();
2382   if (r == -1)
2383     ocaml_guestfs_raise_error (g, "blockdev_rereadpt");
2384
2385   rv = Val_unit;
2386   CAMLreturn (rv);
2387 }
2388
2389 CAMLprim value
2390 ocaml_guestfs_upload (value gv, value filenamev, value remotefilenamev)
2391 {
2392   CAMLparam3 (gv, filenamev, remotefilenamev);
2393   CAMLlocal1 (rv);
2394
2395   guestfs_h *g = Guestfs_val (gv);
2396   if (g == NULL)
2397     caml_failwith ("upload: used handle after closing it");
2398
2399   const char *filename = String_val (filenamev);
2400   const char *remotefilename = String_val (remotefilenamev);
2401   int r;
2402
2403   caml_enter_blocking_section ();
2404   r = guestfs_upload (g, filename, remotefilename);
2405   caml_leave_blocking_section ();
2406   if (r == -1)
2407     ocaml_guestfs_raise_error (g, "upload");
2408
2409   rv = Val_unit;
2410   CAMLreturn (rv);
2411 }
2412
2413 CAMLprim value
2414 ocaml_guestfs_download (value gv, value remotefilenamev, value filenamev)
2415 {
2416   CAMLparam3 (gv, remotefilenamev, filenamev);
2417   CAMLlocal1 (rv);
2418
2419   guestfs_h *g = Guestfs_val (gv);
2420   if (g == NULL)
2421     caml_failwith ("download: used handle after closing it");
2422
2423   const char *remotefilename = String_val (remotefilenamev);
2424   const char *filename = String_val (filenamev);
2425   int r;
2426
2427   caml_enter_blocking_section ();
2428   r = guestfs_download (g, remotefilename, filename);
2429   caml_leave_blocking_section ();
2430   if (r == -1)
2431     ocaml_guestfs_raise_error (g, "download");
2432
2433   rv = Val_unit;
2434   CAMLreturn (rv);
2435 }
2436
2437 CAMLprim value
2438 ocaml_guestfs_checksum (value gv, value csumtypev, value pathv)
2439 {
2440   CAMLparam3 (gv, csumtypev, pathv);
2441   CAMLlocal1 (rv);
2442
2443   guestfs_h *g = Guestfs_val (gv);
2444   if (g == NULL)
2445     caml_failwith ("checksum: used handle after closing it");
2446
2447   const char *csumtype = String_val (csumtypev);
2448   const char *path = String_val (pathv);
2449   char *r;
2450
2451   caml_enter_blocking_section ();
2452   r = guestfs_checksum (g, csumtype, path);
2453   caml_leave_blocking_section ();
2454   if (r == NULL)
2455     ocaml_guestfs_raise_error (g, "checksum");
2456
2457   rv = caml_copy_string (r);
2458   free (r);
2459   CAMLreturn (rv);
2460 }
2461
2462 CAMLprim value
2463 ocaml_guestfs_tar_in (value gv, value tarfilev, value directoryv)
2464 {
2465   CAMLparam3 (gv, tarfilev, directoryv);
2466   CAMLlocal1 (rv);
2467
2468   guestfs_h *g = Guestfs_val (gv);
2469   if (g == NULL)
2470     caml_failwith ("tar_in: used handle after closing it");
2471
2472   const char *tarfile = String_val (tarfilev);
2473   const char *directory = String_val (directoryv);
2474   int r;
2475
2476   caml_enter_blocking_section ();
2477   r = guestfs_tar_in (g, tarfile, directory);
2478   caml_leave_blocking_section ();
2479   if (r == -1)
2480     ocaml_guestfs_raise_error (g, "tar_in");
2481
2482   rv = Val_unit;
2483   CAMLreturn (rv);
2484 }
2485
2486 CAMLprim value
2487 ocaml_guestfs_tar_out (value gv, value directoryv, value tarfilev)
2488 {
2489   CAMLparam3 (gv, directoryv, tarfilev);
2490   CAMLlocal1 (rv);
2491
2492   guestfs_h *g = Guestfs_val (gv);
2493   if (g == NULL)
2494     caml_failwith ("tar_out: used handle after closing it");
2495
2496   const char *directory = String_val (directoryv);
2497   const char *tarfile = String_val (tarfilev);
2498   int r;
2499
2500   caml_enter_blocking_section ();
2501   r = guestfs_tar_out (g, directory, tarfile);
2502   caml_leave_blocking_section ();
2503   if (r == -1)
2504     ocaml_guestfs_raise_error (g, "tar_out");
2505
2506   rv = Val_unit;
2507   CAMLreturn (rv);
2508 }
2509
2510 CAMLprim value
2511 ocaml_guestfs_tgz_in (value gv, value tarballv, value directoryv)
2512 {
2513   CAMLparam3 (gv, tarballv, directoryv);
2514   CAMLlocal1 (rv);
2515
2516   guestfs_h *g = Guestfs_val (gv);
2517   if (g == NULL)
2518     caml_failwith ("tgz_in: used handle after closing it");
2519
2520   const char *tarball = String_val (tarballv);
2521   const char *directory = String_val (directoryv);
2522   int r;
2523
2524   caml_enter_blocking_section ();
2525   r = guestfs_tgz_in (g, tarball, directory);
2526   caml_leave_blocking_section ();
2527   if (r == -1)
2528     ocaml_guestfs_raise_error (g, "tgz_in");
2529
2530   rv = Val_unit;
2531   CAMLreturn (rv);
2532 }
2533
2534 CAMLprim value
2535 ocaml_guestfs_tgz_out (value gv, value directoryv, value tarballv)
2536 {
2537   CAMLparam3 (gv, directoryv, tarballv);
2538   CAMLlocal1 (rv);
2539
2540   guestfs_h *g = Guestfs_val (gv);
2541   if (g == NULL)
2542     caml_failwith ("tgz_out: used handle after closing it");
2543
2544   const char *directory = String_val (directoryv);
2545   const char *tarball = String_val (tarballv);
2546   int r;
2547
2548   caml_enter_blocking_section ();
2549   r = guestfs_tgz_out (g, directory, tarball);
2550   caml_leave_blocking_section ();
2551   if (r == -1)
2552     ocaml_guestfs_raise_error (g, "tgz_out");
2553
2554   rv = Val_unit;
2555   CAMLreturn (rv);
2556 }
2557
2558 CAMLprim value
2559 ocaml_guestfs_mount_ro (value gv, value devicev, value mountpointv)
2560 {
2561   CAMLparam3 (gv, devicev, mountpointv);
2562   CAMLlocal1 (rv);
2563
2564   guestfs_h *g = Guestfs_val (gv);
2565   if (g == NULL)
2566     caml_failwith ("mount_ro: used handle after closing it");
2567
2568   const char *device = String_val (devicev);
2569   const char *mountpoint = String_val (mountpointv);
2570   int r;
2571
2572   caml_enter_blocking_section ();
2573   r = guestfs_mount_ro (g, device, mountpoint);
2574   caml_leave_blocking_section ();
2575   if (r == -1)
2576     ocaml_guestfs_raise_error (g, "mount_ro");
2577
2578   rv = Val_unit;
2579   CAMLreturn (rv);
2580 }
2581
2582 CAMLprim value
2583 ocaml_guestfs_mount_options (value gv, value optionsv, value devicev, value mountpointv)
2584 {
2585   CAMLparam4 (gv, optionsv, devicev, mountpointv);
2586   CAMLlocal1 (rv);
2587
2588   guestfs_h *g = Guestfs_val (gv);
2589   if (g == NULL)
2590     caml_failwith ("mount_options: used handle after closing it");
2591
2592   const char *options = String_val (optionsv);
2593   const char *device = String_val (devicev);
2594   const char *mountpoint = String_val (mountpointv);
2595   int r;
2596
2597   caml_enter_blocking_section ();
2598   r = guestfs_mount_options (g, options, device, mountpoint);
2599   caml_leave_blocking_section ();
2600   if (r == -1)
2601     ocaml_guestfs_raise_error (g, "mount_options");
2602
2603   rv = Val_unit;
2604   CAMLreturn (rv);
2605 }
2606
2607 CAMLprim value
2608 ocaml_guestfs_mount_vfs (value gv, value optionsv, value vfstypev, value devicev, value mountpointv)
2609 {
2610   CAMLparam5 (gv, optionsv, vfstypev, devicev, mountpointv);
2611   CAMLlocal1 (rv);
2612
2613   guestfs_h *g = Guestfs_val (gv);
2614   if (g == NULL)
2615     caml_failwith ("mount_vfs: used handle after closing it");
2616
2617   const char *options = String_val (optionsv);
2618   const char *vfstype = String_val (vfstypev);
2619   const char *device = String_val (devicev);
2620   const char *mountpoint = String_val (mountpointv);
2621   int r;
2622
2623   caml_enter_blocking_section ();
2624   r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
2625   caml_leave_blocking_section ();
2626   if (r == -1)
2627     ocaml_guestfs_raise_error (g, "mount_vfs");
2628
2629   rv = Val_unit;
2630   CAMLreturn (rv);
2631 }
2632
2633 CAMLprim value
2634 ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
2635 {
2636   CAMLparam3 (gv, subcmdv, extraargsv);
2637   CAMLlocal1 (rv);
2638
2639   guestfs_h *g = Guestfs_val (gv);
2640   if (g == NULL)
2641     caml_failwith ("debug: used handle after closing it");
2642
2643   const char *subcmd = String_val (subcmdv);
2644   char **extraargs = ocaml_guestfs_strings_val (g, extraargsv);
2645   char *r;
2646
2647   caml_enter_blocking_section ();
2648   r = guestfs_debug (g, subcmd, extraargs);
2649   caml_leave_blocking_section ();
2650   ocaml_guestfs_free_strings (extraargs);
2651   if (r == NULL)
2652     ocaml_guestfs_raise_error (g, "debug");
2653
2654   rv = caml_copy_string (r);
2655   free (r);
2656   CAMLreturn (rv);
2657 }
2658
2659 CAMLprim value
2660 ocaml_guestfs_lvremove (value gv, value devicev)
2661 {
2662   CAMLparam2 (gv, devicev);
2663   CAMLlocal1 (rv);
2664
2665   guestfs_h *g = Guestfs_val (gv);
2666   if (g == NULL)
2667     caml_failwith ("lvremove: used handle after closing it");
2668
2669   const char *device = String_val (devicev);
2670   int r;
2671
2672   caml_enter_blocking_section ();
2673   r = guestfs_lvremove (g, device);
2674   caml_leave_blocking_section ();
2675   if (r == -1)
2676     ocaml_guestfs_raise_error (g, "lvremove");
2677
2678   rv = Val_unit;
2679   CAMLreturn (rv);
2680 }
2681
2682 CAMLprim value
2683 ocaml_guestfs_vgremove (value gv, value vgnamev)
2684 {
2685   CAMLparam2 (gv, vgnamev);
2686   CAMLlocal1 (rv);
2687
2688   guestfs_h *g = Guestfs_val (gv);
2689   if (g == NULL)
2690     caml_failwith ("vgremove: used handle after closing it");
2691
2692   const char *vgname = String_val (vgnamev);
2693   int r;
2694
2695   caml_enter_blocking_section ();
2696   r = guestfs_vgremove (g, vgname);
2697   caml_leave_blocking_section ();
2698   if (r == -1)
2699     ocaml_guestfs_raise_error (g, "vgremove");
2700
2701   rv = Val_unit;
2702   CAMLreturn (rv);
2703 }
2704
2705 CAMLprim value
2706 ocaml_guestfs_pvremove (value gv, value devicev)
2707 {
2708   CAMLparam2 (gv, devicev);
2709   CAMLlocal1 (rv);
2710
2711   guestfs_h *g = Guestfs_val (gv);
2712   if (g == NULL)
2713     caml_failwith ("pvremove: used handle after closing it");
2714
2715   const char *device = String_val (devicev);
2716   int r;
2717
2718   caml_enter_blocking_section ();
2719   r = guestfs_pvremove (g, device);
2720   caml_leave_blocking_section ();
2721   if (r == -1)
2722     ocaml_guestfs_raise_error (g, "pvremove");
2723
2724   rv = Val_unit;
2725   CAMLreturn (rv);
2726 }
2727
2728 CAMLprim value
2729 ocaml_guestfs_set_e2label (value gv, value devicev, value labelv)
2730 {
2731   CAMLparam3 (gv, devicev, labelv);
2732   CAMLlocal1 (rv);
2733
2734   guestfs_h *g = Guestfs_val (gv);
2735   if (g == NULL)
2736     caml_failwith ("set_e2label: used handle after closing it");
2737
2738   const char *device = String_val (devicev);
2739   const char *label = String_val (labelv);
2740   int r;
2741
2742   caml_enter_blocking_section ();
2743   r = guestfs_set_e2label (g, device, label);
2744   caml_leave_blocking_section ();
2745   if (r == -1)
2746     ocaml_guestfs_raise_error (g, "set_e2label");
2747
2748   rv = Val_unit;
2749   CAMLreturn (rv);
2750 }
2751
2752 CAMLprim value
2753 ocaml_guestfs_get_e2label (value gv, value devicev)
2754 {
2755   CAMLparam2 (gv, devicev);
2756   CAMLlocal1 (rv);
2757
2758   guestfs_h *g = Guestfs_val (gv);
2759   if (g == NULL)
2760     caml_failwith ("get_e2label: used handle after closing it");
2761
2762   const char *device = String_val (devicev);
2763   char *r;
2764
2765   caml_enter_blocking_section ();
2766   r = guestfs_get_e2label (g, device);
2767   caml_leave_blocking_section ();
2768   if (r == NULL)
2769     ocaml_guestfs_raise_error (g, "get_e2label");
2770
2771   rv = caml_copy_string (r);
2772   free (r);
2773   CAMLreturn (rv);
2774 }
2775
2776 CAMLprim value
2777 ocaml_guestfs_set_e2uuid (value gv, value devicev, value uuidv)
2778 {
2779   CAMLparam3 (gv, devicev, uuidv);
2780   CAMLlocal1 (rv);
2781
2782   guestfs_h *g = Guestfs_val (gv);
2783   if (g == NULL)
2784     caml_failwith ("set_e2uuid: used handle after closing it");
2785
2786   const char *device = String_val (devicev);
2787   const char *uuid = String_val (uuidv);
2788   int r;
2789
2790   caml_enter_blocking_section ();
2791   r = guestfs_set_e2uuid (g, device, uuid);
2792   caml_leave_blocking_section ();
2793   if (r == -1)
2794     ocaml_guestfs_raise_error (g, "set_e2uuid");
2795
2796   rv = Val_unit;
2797   CAMLreturn (rv);
2798 }
2799
2800 CAMLprim value
2801 ocaml_guestfs_get_e2uuid (value gv, value devicev)
2802 {
2803   CAMLparam2 (gv, devicev);
2804   CAMLlocal1 (rv);
2805
2806   guestfs_h *g = Guestfs_val (gv);
2807   if (g == NULL)
2808     caml_failwith ("get_e2uuid: used handle after closing it");
2809
2810   const char *device = String_val (devicev);
2811   char *r;
2812
2813   caml_enter_blocking_section ();
2814   r = guestfs_get_e2uuid (g, device);
2815   caml_leave_blocking_section ();
2816   if (r == NULL)
2817     ocaml_guestfs_raise_error (g, "get_e2uuid");
2818
2819   rv = caml_copy_string (r);
2820   free (r);
2821   CAMLreturn (rv);
2822 }
2823
2824 CAMLprim value
2825 ocaml_guestfs_fsck (value gv, value fstypev, value devicev)
2826 {
2827   CAMLparam3 (gv, fstypev, devicev);
2828   CAMLlocal1 (rv);
2829
2830   guestfs_h *g = Guestfs_val (gv);
2831   if (g == NULL)
2832     caml_failwith ("fsck: used handle after closing it");
2833
2834   const char *fstype = String_val (fstypev);
2835   const char *device = String_val (devicev);
2836   int r;
2837
2838   caml_enter_blocking_section ();
2839   r = guestfs_fsck (g, fstype, device);
2840   caml_leave_blocking_section ();
2841   if (r == -1)
2842     ocaml_guestfs_raise_error (g, "fsck");
2843
2844   rv = Val_int (r);
2845   CAMLreturn (rv);
2846 }
2847
2848 CAMLprim value
2849 ocaml_guestfs_zero (value gv, value devicev)
2850 {
2851   CAMLparam2 (gv, devicev);
2852   CAMLlocal1 (rv);
2853
2854   guestfs_h *g = Guestfs_val (gv);
2855   if (g == NULL)
2856     caml_failwith ("zero: used handle after closing it");
2857
2858   const char *device = String_val (devicev);
2859   int r;
2860
2861   caml_enter_blocking_section ();
2862   r = guestfs_zero (g, device);
2863   caml_leave_blocking_section ();
2864   if (r == -1)
2865     ocaml_guestfs_raise_error (g, "zero");
2866
2867   rv = Val_unit;
2868   CAMLreturn (rv);
2869 }
2870
2871 CAMLprim value
2872 ocaml_guestfs_grub_install (value gv, value rootv, value devicev)
2873 {
2874   CAMLparam3 (gv, rootv, devicev);
2875   CAMLlocal1 (rv);
2876
2877   guestfs_h *g = Guestfs_val (gv);
2878   if (g == NULL)
2879     caml_failwith ("grub_install: used handle after closing it");
2880
2881   const char *root = String_val (rootv);
2882   const char *device = String_val (devicev);
2883   int r;
2884
2885   caml_enter_blocking_section ();
2886   r = guestfs_grub_install (g, root, device);
2887   caml_leave_blocking_section ();
2888   if (r == -1)
2889     ocaml_guestfs_raise_error (g, "grub_install");
2890
2891   rv = Val_unit;
2892   CAMLreturn (rv);
2893 }
2894
2895 CAMLprim value
2896 ocaml_guestfs_cp (value gv, value srcv, value destv)
2897 {
2898   CAMLparam3 (gv, srcv, destv);
2899   CAMLlocal1 (rv);
2900
2901   guestfs_h *g = Guestfs_val (gv);
2902   if (g == NULL)
2903     caml_failwith ("cp: used handle after closing it");
2904
2905   const char *src = String_val (srcv);
2906   const char *dest = String_val (destv);
2907   int r;
2908
2909   caml_enter_blocking_section ();
2910   r = guestfs_cp (g, src, dest);
2911   caml_leave_blocking_section ();
2912   if (r == -1)
2913     ocaml_guestfs_raise_error (g, "cp");
2914
2915   rv = Val_unit;
2916   CAMLreturn (rv);
2917 }
2918
2919 CAMLprim value
2920 ocaml_guestfs_cp_a (value gv, value srcv, value destv)
2921 {
2922   CAMLparam3 (gv, srcv, destv);
2923   CAMLlocal1 (rv);
2924
2925   guestfs_h *g = Guestfs_val (gv);
2926   if (g == NULL)
2927     caml_failwith ("cp_a: used handle after closing it");
2928
2929   const char *src = String_val (srcv);
2930   const char *dest = String_val (destv);
2931   int r;
2932
2933   caml_enter_blocking_section ();
2934   r = guestfs_cp_a (g, src, dest);
2935   caml_leave_blocking_section ();
2936   if (r == -1)
2937     ocaml_guestfs_raise_error (g, "cp_a");
2938
2939   rv = Val_unit;
2940   CAMLreturn (rv);
2941 }
2942
2943 CAMLprim value
2944 ocaml_guestfs_mv (value gv, value srcv, value destv)
2945 {
2946   CAMLparam3 (gv, srcv, destv);
2947   CAMLlocal1 (rv);
2948
2949   guestfs_h *g = Guestfs_val (gv);
2950   if (g == NULL)
2951     caml_failwith ("mv: used handle after closing it");
2952
2953   const char *src = String_val (srcv);
2954   const char *dest = String_val (destv);
2955   int r;
2956
2957   caml_enter_blocking_section ();
2958   r = guestfs_mv (g, src, dest);
2959   caml_leave_blocking_section ();
2960   if (r == -1)
2961     ocaml_guestfs_raise_error (g, "mv");
2962
2963   rv = Val_unit;
2964   CAMLreturn (rv);
2965 }
2966
2967 CAMLprim value
2968 ocaml_guestfs_drop_caches (value gv, value whattodropv)
2969 {
2970   CAMLparam2 (gv, whattodropv);
2971   CAMLlocal1 (rv);
2972
2973   guestfs_h *g = Guestfs_val (gv);
2974   if (g == NULL)
2975     caml_failwith ("drop_caches: used handle after closing it");
2976
2977   int whattodrop = Int_val (whattodropv);
2978   int r;
2979
2980   caml_enter_blocking_section ();
2981   r = guestfs_drop_caches (g, whattodrop);
2982   caml_leave_blocking_section ();
2983   if (r == -1)
2984     ocaml_guestfs_raise_error (g, "drop_caches");
2985
2986   rv = Val_unit;
2987   CAMLreturn (rv);
2988 }
2989
2990 CAMLprim value
2991 ocaml_guestfs_dmesg (value gv)
2992 {
2993   CAMLparam1 (gv);
2994   CAMLlocal1 (rv);
2995
2996   guestfs_h *g = Guestfs_val (gv);
2997   if (g == NULL)
2998     caml_failwith ("dmesg: used handle after closing it");
2999
3000   char *r;
3001
3002   caml_enter_blocking_section ();
3003   r = guestfs_dmesg (g);
3004   caml_leave_blocking_section ();
3005   if (r == NULL)
3006     ocaml_guestfs_raise_error (g, "dmesg");
3007
3008   rv = caml_copy_string (r);
3009   free (r);
3010   CAMLreturn (rv);
3011 }
3012
3013 CAMLprim value
3014 ocaml_guestfs_ping_daemon (value gv)
3015 {
3016   CAMLparam1 (gv);
3017   CAMLlocal1 (rv);
3018
3019   guestfs_h *g = Guestfs_val (gv);
3020   if (g == NULL)
3021     caml_failwith ("ping_daemon: used handle after closing it");
3022
3023   int r;
3024
3025   caml_enter_blocking_section ();
3026   r = guestfs_ping_daemon (g);
3027   caml_leave_blocking_section ();
3028   if (r == -1)
3029     ocaml_guestfs_raise_error (g, "ping_daemon");
3030
3031   rv = Val_unit;
3032   CAMLreturn (rv);
3033 }
3034
3035 CAMLprim value
3036 ocaml_guestfs_equal (value gv, value file1v, value file2v)
3037 {
3038   CAMLparam3 (gv, file1v, file2v);
3039   CAMLlocal1 (rv);
3040
3041   guestfs_h *g = Guestfs_val (gv);
3042   if (g == NULL)
3043     caml_failwith ("equal: used handle after closing it");
3044
3045   const char *file1 = String_val (file1v);
3046   const char *file2 = String_val (file2v);
3047   int r;
3048
3049   caml_enter_blocking_section ();
3050   r = guestfs_equal (g, file1, file2);
3051   caml_leave_blocking_section ();
3052   if (r == -1)
3053     ocaml_guestfs_raise_error (g, "equal");
3054
3055   rv = Val_bool (r);
3056   CAMLreturn (rv);
3057 }
3058
3059 CAMLprim value
3060 ocaml_guestfs_strings (value gv, value pathv)
3061 {
3062   CAMLparam2 (gv, pathv);
3063   CAMLlocal1 (rv);
3064
3065   guestfs_h *g = Guestfs_val (gv);
3066   if (g == NULL)
3067     caml_failwith ("strings: used handle after closing it");
3068
3069   const char *path = String_val (pathv);
3070   int i;
3071   char **r;
3072
3073   caml_enter_blocking_section ();
3074   r = guestfs_strings (g, path);
3075   caml_leave_blocking_section ();
3076   if (r == NULL)
3077     ocaml_guestfs_raise_error (g, "strings");
3078
3079   rv = caml_copy_string_array ((const char **) r);
3080   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3081   free (r);
3082   CAMLreturn (rv);
3083 }
3084
3085 CAMLprim value
3086 ocaml_guestfs_strings_e (value gv, value encodingv, value pathv)
3087 {
3088   CAMLparam3 (gv, encodingv, pathv);
3089   CAMLlocal1 (rv);
3090
3091   guestfs_h *g = Guestfs_val (gv);
3092   if (g == NULL)
3093     caml_failwith ("strings_e: used handle after closing it");
3094
3095   const char *encoding = String_val (encodingv);
3096   const char *path = String_val (pathv);
3097   int i;
3098   char **r;
3099
3100   caml_enter_blocking_section ();
3101   r = guestfs_strings_e (g, encoding, path);
3102   caml_leave_blocking_section ();
3103   if (r == NULL)
3104     ocaml_guestfs_raise_error (g, "strings_e");
3105
3106   rv = caml_copy_string_array ((const char **) r);
3107   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3108   free (r);
3109   CAMLreturn (rv);
3110 }
3111
3112 CAMLprim value
3113 ocaml_guestfs_hexdump (value gv, value pathv)
3114 {
3115   CAMLparam2 (gv, pathv);
3116   CAMLlocal1 (rv);
3117
3118   guestfs_h *g = Guestfs_val (gv);
3119   if (g == NULL)
3120     caml_failwith ("hexdump: used handle after closing it");
3121
3122   const char *path = String_val (pathv);
3123   char *r;
3124
3125   caml_enter_blocking_section ();
3126   r = guestfs_hexdump (g, path);
3127   caml_leave_blocking_section ();
3128   if (r == NULL)
3129     ocaml_guestfs_raise_error (g, "hexdump");
3130
3131   rv = caml_copy_string (r);
3132   free (r);
3133   CAMLreturn (rv);
3134 }
3135