Generated code for 'find' command.
[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_append (value gv, value appendv)
560 {
561   CAMLparam2 (gv, appendv);
562   CAMLlocal1 (rv);
563
564   guestfs_h *g = Guestfs_val (gv);
565   if (g == NULL)
566     caml_failwith ("set_append: used handle after closing it");
567
568   const char *append = String_val (appendv);
569   int r;
570
571   caml_enter_blocking_section ();
572   r = guestfs_set_append (g, append);
573   caml_leave_blocking_section ();
574   if (r == -1)
575     ocaml_guestfs_raise_error (g, "set_append");
576
577   rv = Val_unit;
578   CAMLreturn (rv);
579 }
580
581 CAMLprim value
582 ocaml_guestfs_get_append (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_append: used handle after closing it");
590
591   const char *r;
592
593   caml_enter_blocking_section ();
594   r = guestfs_get_append (g);
595   caml_leave_blocking_section ();
596   if (r == NULL)
597     ocaml_guestfs_raise_error (g, "get_append");
598
599   rv = caml_copy_string (r);
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_guestfs_set_autosync (value gv, value autosyncv)
605 {
606   CAMLparam2 (gv, autosyncv);
607   CAMLlocal1 (rv);
608
609   guestfs_h *g = Guestfs_val (gv);
610   if (g == NULL)
611     caml_failwith ("set_autosync: used handle after closing it");
612
613   int autosync = Bool_val (autosyncv);
614   int r;
615
616   caml_enter_blocking_section ();
617   r = guestfs_set_autosync (g, autosync);
618   caml_leave_blocking_section ();
619   if (r == -1)
620     ocaml_guestfs_raise_error (g, "set_autosync");
621
622   rv = Val_unit;
623   CAMLreturn (rv);
624 }
625
626 CAMLprim value
627 ocaml_guestfs_get_autosync (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_autosync: used handle after closing it");
635
636   int r;
637
638   caml_enter_blocking_section ();
639   r = guestfs_get_autosync (g);
640   caml_leave_blocking_section ();
641   if (r == -1)
642     ocaml_guestfs_raise_error (g, "get_autosync");
643
644   rv = Val_bool (r);
645   CAMLreturn (rv);
646 }
647
648 CAMLprim value
649 ocaml_guestfs_set_verbose (value gv, value verbosev)
650 {
651   CAMLparam2 (gv, verbosev);
652   CAMLlocal1 (rv);
653
654   guestfs_h *g = Guestfs_val (gv);
655   if (g == NULL)
656     caml_failwith ("set_verbose: used handle after closing it");
657
658   int verbose = Bool_val (verbosev);
659   int r;
660
661   caml_enter_blocking_section ();
662   r = guestfs_set_verbose (g, verbose);
663   caml_leave_blocking_section ();
664   if (r == -1)
665     ocaml_guestfs_raise_error (g, "set_verbose");
666
667   rv = Val_unit;
668   CAMLreturn (rv);
669 }
670
671 CAMLprim value
672 ocaml_guestfs_get_verbose (value gv)
673 {
674   CAMLparam1 (gv);
675   CAMLlocal1 (rv);
676
677   guestfs_h *g = Guestfs_val (gv);
678   if (g == NULL)
679     caml_failwith ("get_verbose: used handle after closing it");
680
681   int r;
682
683   caml_enter_blocking_section ();
684   r = guestfs_get_verbose (g);
685   caml_leave_blocking_section ();
686   if (r == -1)
687     ocaml_guestfs_raise_error (g, "get_verbose");
688
689   rv = Val_bool (r);
690   CAMLreturn (rv);
691 }
692
693 CAMLprim value
694 ocaml_guestfs_is_ready (value gv)
695 {
696   CAMLparam1 (gv);
697   CAMLlocal1 (rv);
698
699   guestfs_h *g = Guestfs_val (gv);
700   if (g == NULL)
701     caml_failwith ("is_ready: used handle after closing it");
702
703   int r;
704
705   caml_enter_blocking_section ();
706   r = guestfs_is_ready (g);
707   caml_leave_blocking_section ();
708   if (r == -1)
709     ocaml_guestfs_raise_error (g, "is_ready");
710
711   rv = Val_bool (r);
712   CAMLreturn (rv);
713 }
714
715 CAMLprim value
716 ocaml_guestfs_is_config (value gv)
717 {
718   CAMLparam1 (gv);
719   CAMLlocal1 (rv);
720
721   guestfs_h *g = Guestfs_val (gv);
722   if (g == NULL)
723     caml_failwith ("is_config: used handle after closing it");
724
725   int r;
726
727   caml_enter_blocking_section ();
728   r = guestfs_is_config (g);
729   caml_leave_blocking_section ();
730   if (r == -1)
731     ocaml_guestfs_raise_error (g, "is_config");
732
733   rv = Val_bool (r);
734   CAMLreturn (rv);
735 }
736
737 CAMLprim value
738 ocaml_guestfs_is_launching (value gv)
739 {
740   CAMLparam1 (gv);
741   CAMLlocal1 (rv);
742
743   guestfs_h *g = Guestfs_val (gv);
744   if (g == NULL)
745     caml_failwith ("is_launching: used handle after closing it");
746
747   int r;
748
749   caml_enter_blocking_section ();
750   r = guestfs_is_launching (g);
751   caml_leave_blocking_section ();
752   if (r == -1)
753     ocaml_guestfs_raise_error (g, "is_launching");
754
755   rv = Val_bool (r);
756   CAMLreturn (rv);
757 }
758
759 CAMLprim value
760 ocaml_guestfs_is_busy (value gv)
761 {
762   CAMLparam1 (gv);
763   CAMLlocal1 (rv);
764
765   guestfs_h *g = Guestfs_val (gv);
766   if (g == NULL)
767     caml_failwith ("is_busy: used handle after closing it");
768
769   int r;
770
771   caml_enter_blocking_section ();
772   r = guestfs_is_busy (g);
773   caml_leave_blocking_section ();
774   if (r == -1)
775     ocaml_guestfs_raise_error (g, "is_busy");
776
777   rv = Val_bool (r);
778   CAMLreturn (rv);
779 }
780
781 CAMLprim value
782 ocaml_guestfs_get_state (value gv)
783 {
784   CAMLparam1 (gv);
785   CAMLlocal1 (rv);
786
787   guestfs_h *g = Guestfs_val (gv);
788   if (g == NULL)
789     caml_failwith ("get_state: used handle after closing it");
790
791   int r;
792
793   caml_enter_blocking_section ();
794   r = guestfs_get_state (g);
795   caml_leave_blocking_section ();
796   if (r == -1)
797     ocaml_guestfs_raise_error (g, "get_state");
798
799   rv = Val_int (r);
800   CAMLreturn (rv);
801 }
802
803 CAMLprim value
804 ocaml_guestfs_set_busy (value gv)
805 {
806   CAMLparam1 (gv);
807   CAMLlocal1 (rv);
808
809   guestfs_h *g = Guestfs_val (gv);
810   if (g == NULL)
811     caml_failwith ("set_busy: used handle after closing it");
812
813   int r;
814
815   caml_enter_blocking_section ();
816   r = guestfs_set_busy (g);
817   caml_leave_blocking_section ();
818   if (r == -1)
819     ocaml_guestfs_raise_error (g, "set_busy");
820
821   rv = Val_unit;
822   CAMLreturn (rv);
823 }
824
825 CAMLprim value
826 ocaml_guestfs_set_ready (value gv)
827 {
828   CAMLparam1 (gv);
829   CAMLlocal1 (rv);
830
831   guestfs_h *g = Guestfs_val (gv);
832   if (g == NULL)
833     caml_failwith ("set_ready: used handle after closing it");
834
835   int r;
836
837   caml_enter_blocking_section ();
838   r = guestfs_set_ready (g);
839   caml_leave_blocking_section ();
840   if (r == -1)
841     ocaml_guestfs_raise_error (g, "set_ready");
842
843   rv = Val_unit;
844   CAMLreturn (rv);
845 }
846
847 CAMLprim value
848 ocaml_guestfs_end_busy (value gv)
849 {
850   CAMLparam1 (gv);
851   CAMLlocal1 (rv);
852
853   guestfs_h *g = Guestfs_val (gv);
854   if (g == NULL)
855     caml_failwith ("end_busy: used handle after closing it");
856
857   int r;
858
859   caml_enter_blocking_section ();
860   r = guestfs_end_busy (g);
861   caml_leave_blocking_section ();
862   if (r == -1)
863     ocaml_guestfs_raise_error (g, "end_busy");
864
865   rv = Val_unit;
866   CAMLreturn (rv);
867 }
868
869 CAMLprim value
870 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
871 {
872   CAMLparam3 (gv, devicev, mountpointv);
873   CAMLlocal1 (rv);
874
875   guestfs_h *g = Guestfs_val (gv);
876   if (g == NULL)
877     caml_failwith ("mount: used handle after closing it");
878
879   const char *device = String_val (devicev);
880   const char *mountpoint = String_val (mountpointv);
881   int r;
882
883   caml_enter_blocking_section ();
884   r = guestfs_mount (g, device, mountpoint);
885   caml_leave_blocking_section ();
886   if (r == -1)
887     ocaml_guestfs_raise_error (g, "mount");
888
889   rv = Val_unit;
890   CAMLreturn (rv);
891 }
892
893 CAMLprim value
894 ocaml_guestfs_sync (value gv)
895 {
896   CAMLparam1 (gv);
897   CAMLlocal1 (rv);
898
899   guestfs_h *g = Guestfs_val (gv);
900   if (g == NULL)
901     caml_failwith ("sync: used handle after closing it");
902
903   int r;
904
905   caml_enter_blocking_section ();
906   r = guestfs_sync (g);
907   caml_leave_blocking_section ();
908   if (r == -1)
909     ocaml_guestfs_raise_error (g, "sync");
910
911   rv = Val_unit;
912   CAMLreturn (rv);
913 }
914
915 CAMLprim value
916 ocaml_guestfs_touch (value gv, value pathv)
917 {
918   CAMLparam2 (gv, pathv);
919   CAMLlocal1 (rv);
920
921   guestfs_h *g = Guestfs_val (gv);
922   if (g == NULL)
923     caml_failwith ("touch: used handle after closing it");
924
925   const char *path = String_val (pathv);
926   int r;
927
928   caml_enter_blocking_section ();
929   r = guestfs_touch (g, path);
930   caml_leave_blocking_section ();
931   if (r == -1)
932     ocaml_guestfs_raise_error (g, "touch");
933
934   rv = Val_unit;
935   CAMLreturn (rv);
936 }
937
938 CAMLprim value
939 ocaml_guestfs_cat (value gv, value pathv)
940 {
941   CAMLparam2 (gv, pathv);
942   CAMLlocal1 (rv);
943
944   guestfs_h *g = Guestfs_val (gv);
945   if (g == NULL)
946     caml_failwith ("cat: used handle after closing it");
947
948   const char *path = String_val (pathv);
949   char *r;
950
951   caml_enter_blocking_section ();
952   r = guestfs_cat (g, path);
953   caml_leave_blocking_section ();
954   if (r == NULL)
955     ocaml_guestfs_raise_error (g, "cat");
956
957   rv = caml_copy_string (r);
958   free (r);
959   CAMLreturn (rv);
960 }
961
962 CAMLprim value
963 ocaml_guestfs_ll (value gv, value directoryv)
964 {
965   CAMLparam2 (gv, directoryv);
966   CAMLlocal1 (rv);
967
968   guestfs_h *g = Guestfs_val (gv);
969   if (g == NULL)
970     caml_failwith ("ll: used handle after closing it");
971
972   const char *directory = String_val (directoryv);
973   char *r;
974
975   caml_enter_blocking_section ();
976   r = guestfs_ll (g, directory);
977   caml_leave_blocking_section ();
978   if (r == NULL)
979     ocaml_guestfs_raise_error (g, "ll");
980
981   rv = caml_copy_string (r);
982   free (r);
983   CAMLreturn (rv);
984 }
985
986 CAMLprim value
987 ocaml_guestfs_ls (value gv, value directoryv)
988 {
989   CAMLparam2 (gv, directoryv);
990   CAMLlocal1 (rv);
991
992   guestfs_h *g = Guestfs_val (gv);
993   if (g == NULL)
994     caml_failwith ("ls: used handle after closing it");
995
996   const char *directory = String_val (directoryv);
997   int i;
998   char **r;
999
1000   caml_enter_blocking_section ();
1001   r = guestfs_ls (g, directory);
1002   caml_leave_blocking_section ();
1003   if (r == NULL)
1004     ocaml_guestfs_raise_error (g, "ls");
1005
1006   rv = caml_copy_string_array ((const char **) r);
1007   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1008   free (r);
1009   CAMLreturn (rv);
1010 }
1011
1012 CAMLprim value
1013 ocaml_guestfs_list_devices (value gv)
1014 {
1015   CAMLparam1 (gv);
1016   CAMLlocal1 (rv);
1017
1018   guestfs_h *g = Guestfs_val (gv);
1019   if (g == NULL)
1020     caml_failwith ("list_devices: used handle after closing it");
1021
1022   int i;
1023   char **r;
1024
1025   caml_enter_blocking_section ();
1026   r = guestfs_list_devices (g);
1027   caml_leave_blocking_section ();
1028   if (r == NULL)
1029     ocaml_guestfs_raise_error (g, "list_devices");
1030
1031   rv = caml_copy_string_array ((const char **) r);
1032   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1033   free (r);
1034   CAMLreturn (rv);
1035 }
1036
1037 CAMLprim value
1038 ocaml_guestfs_list_partitions (value gv)
1039 {
1040   CAMLparam1 (gv);
1041   CAMLlocal1 (rv);
1042
1043   guestfs_h *g = Guestfs_val (gv);
1044   if (g == NULL)
1045     caml_failwith ("list_partitions: used handle after closing it");
1046
1047   int i;
1048   char **r;
1049
1050   caml_enter_blocking_section ();
1051   r = guestfs_list_partitions (g);
1052   caml_leave_blocking_section ();
1053   if (r == NULL)
1054     ocaml_guestfs_raise_error (g, "list_partitions");
1055
1056   rv = caml_copy_string_array ((const char **) r);
1057   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1058   free (r);
1059   CAMLreturn (rv);
1060 }
1061
1062 CAMLprim value
1063 ocaml_guestfs_pvs (value gv)
1064 {
1065   CAMLparam1 (gv);
1066   CAMLlocal1 (rv);
1067
1068   guestfs_h *g = Guestfs_val (gv);
1069   if (g == NULL)
1070     caml_failwith ("pvs: used handle after closing it");
1071
1072   int i;
1073   char **r;
1074
1075   caml_enter_blocking_section ();
1076   r = guestfs_pvs (g);
1077   caml_leave_blocking_section ();
1078   if (r == NULL)
1079     ocaml_guestfs_raise_error (g, "pvs");
1080
1081   rv = caml_copy_string_array ((const char **) r);
1082   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1083   free (r);
1084   CAMLreturn (rv);
1085 }
1086
1087 CAMLprim value
1088 ocaml_guestfs_vgs (value gv)
1089 {
1090   CAMLparam1 (gv);
1091   CAMLlocal1 (rv);
1092
1093   guestfs_h *g = Guestfs_val (gv);
1094   if (g == NULL)
1095     caml_failwith ("vgs: used handle after closing it");
1096
1097   int i;
1098   char **r;
1099
1100   caml_enter_blocking_section ();
1101   r = guestfs_vgs (g);
1102   caml_leave_blocking_section ();
1103   if (r == NULL)
1104     ocaml_guestfs_raise_error (g, "vgs");
1105
1106   rv = caml_copy_string_array ((const char **) r);
1107   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1108   free (r);
1109   CAMLreturn (rv);
1110 }
1111
1112 CAMLprim value
1113 ocaml_guestfs_lvs (value gv)
1114 {
1115   CAMLparam1 (gv);
1116   CAMLlocal1 (rv);
1117
1118   guestfs_h *g = Guestfs_val (gv);
1119   if (g == NULL)
1120     caml_failwith ("lvs: used handle after closing it");
1121
1122   int i;
1123   char **r;
1124
1125   caml_enter_blocking_section ();
1126   r = guestfs_lvs (g);
1127   caml_leave_blocking_section ();
1128   if (r == NULL)
1129     ocaml_guestfs_raise_error (g, "lvs");
1130
1131   rv = caml_copy_string_array ((const char **) r);
1132   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1133   free (r);
1134   CAMLreturn (rv);
1135 }
1136
1137 CAMLprim value
1138 ocaml_guestfs_pvs_full (value gv)
1139 {
1140   CAMLparam1 (gv);
1141   CAMLlocal1 (rv);
1142
1143   guestfs_h *g = Guestfs_val (gv);
1144   if (g == NULL)
1145     caml_failwith ("pvs_full: used handle after closing it");
1146
1147   struct guestfs_lvm_pv_list *r;
1148
1149   caml_enter_blocking_section ();
1150   r = guestfs_pvs_full (g);
1151   caml_leave_blocking_section ();
1152   if (r == NULL)
1153     ocaml_guestfs_raise_error (g, "pvs_full");
1154
1155   rv = copy_lvm_pv_list (r);
1156   guestfs_free_lvm_pv_list (r);
1157   CAMLreturn (rv);
1158 }
1159
1160 CAMLprim value
1161 ocaml_guestfs_vgs_full (value gv)
1162 {
1163   CAMLparam1 (gv);
1164   CAMLlocal1 (rv);
1165
1166   guestfs_h *g = Guestfs_val (gv);
1167   if (g == NULL)
1168     caml_failwith ("vgs_full: used handle after closing it");
1169
1170   struct guestfs_lvm_vg_list *r;
1171
1172   caml_enter_blocking_section ();
1173   r = guestfs_vgs_full (g);
1174   caml_leave_blocking_section ();
1175   if (r == NULL)
1176     ocaml_guestfs_raise_error (g, "vgs_full");
1177
1178   rv = copy_lvm_vg_list (r);
1179   guestfs_free_lvm_vg_list (r);
1180   CAMLreturn (rv);
1181 }
1182
1183 CAMLprim value
1184 ocaml_guestfs_lvs_full (value gv)
1185 {
1186   CAMLparam1 (gv);
1187   CAMLlocal1 (rv);
1188
1189   guestfs_h *g = Guestfs_val (gv);
1190   if (g == NULL)
1191     caml_failwith ("lvs_full: used handle after closing it");
1192
1193   struct guestfs_lvm_lv_list *r;
1194
1195   caml_enter_blocking_section ();
1196   r = guestfs_lvs_full (g);
1197   caml_leave_blocking_section ();
1198   if (r == NULL)
1199     ocaml_guestfs_raise_error (g, "lvs_full");
1200
1201   rv = copy_lvm_lv_list (r);
1202   guestfs_free_lvm_lv_list (r);
1203   CAMLreturn (rv);
1204 }
1205
1206 CAMLprim value
1207 ocaml_guestfs_read_lines (value gv, value pathv)
1208 {
1209   CAMLparam2 (gv, pathv);
1210   CAMLlocal1 (rv);
1211
1212   guestfs_h *g = Guestfs_val (gv);
1213   if (g == NULL)
1214     caml_failwith ("read_lines: used handle after closing it");
1215
1216   const char *path = String_val (pathv);
1217   int i;
1218   char **r;
1219
1220   caml_enter_blocking_section ();
1221   r = guestfs_read_lines (g, path);
1222   caml_leave_blocking_section ();
1223   if (r == NULL)
1224     ocaml_guestfs_raise_error (g, "read_lines");
1225
1226   rv = caml_copy_string_array ((const char **) r);
1227   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1228   free (r);
1229   CAMLreturn (rv);
1230 }
1231
1232 CAMLprim value
1233 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
1234 {
1235   CAMLparam3 (gv, rootv, flagsv);
1236   CAMLlocal1 (rv);
1237
1238   guestfs_h *g = Guestfs_val (gv);
1239   if (g == NULL)
1240     caml_failwith ("aug_init: used handle after closing it");
1241
1242   const char *root = String_val (rootv);
1243   int flags = Int_val (flagsv);
1244   int r;
1245
1246   caml_enter_blocking_section ();
1247   r = guestfs_aug_init (g, root, flags);
1248   caml_leave_blocking_section ();
1249   if (r == -1)
1250     ocaml_guestfs_raise_error (g, "aug_init");
1251
1252   rv = Val_unit;
1253   CAMLreturn (rv);
1254 }
1255
1256 CAMLprim value
1257 ocaml_guestfs_aug_close (value gv)
1258 {
1259   CAMLparam1 (gv);
1260   CAMLlocal1 (rv);
1261
1262   guestfs_h *g = Guestfs_val (gv);
1263   if (g == NULL)
1264     caml_failwith ("aug_close: used handle after closing it");
1265
1266   int r;
1267
1268   caml_enter_blocking_section ();
1269   r = guestfs_aug_close (g);
1270   caml_leave_blocking_section ();
1271   if (r == -1)
1272     ocaml_guestfs_raise_error (g, "aug_close");
1273
1274   rv = Val_unit;
1275   CAMLreturn (rv);
1276 }
1277
1278 CAMLprim value
1279 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
1280 {
1281   CAMLparam3 (gv, namev, exprv);
1282   CAMLlocal1 (rv);
1283
1284   guestfs_h *g = Guestfs_val (gv);
1285   if (g == NULL)
1286     caml_failwith ("aug_defvar: used handle after closing it");
1287
1288   const char *name = String_val (namev);
1289   const char *expr =
1290     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
1291   int r;
1292
1293   caml_enter_blocking_section ();
1294   r = guestfs_aug_defvar (g, name, expr);
1295   caml_leave_blocking_section ();
1296   if (r == -1)
1297     ocaml_guestfs_raise_error (g, "aug_defvar");
1298
1299   rv = Val_int (r);
1300   CAMLreturn (rv);
1301 }
1302
1303 CAMLprim value
1304 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1305 {
1306   CAMLparam4 (gv, namev, exprv, valv);
1307   CAMLlocal1 (rv);
1308
1309   guestfs_h *g = Guestfs_val (gv);
1310   if (g == NULL)
1311     caml_failwith ("aug_defnode: used handle after closing it");
1312
1313   const char *name = String_val (namev);
1314   const char *expr = String_val (exprv);
1315   const char *val = String_val (valv);
1316   struct guestfs_int_bool *r;
1317
1318   caml_enter_blocking_section ();
1319   r = guestfs_aug_defnode (g, name, expr, val);
1320   caml_leave_blocking_section ();
1321   if (r == NULL)
1322     ocaml_guestfs_raise_error (g, "aug_defnode");
1323
1324   rv = caml_alloc (2, 0);
1325   Store_field (rv, 0, Val_int (r->i));
1326   Store_field (rv, 1, Val_bool (r->b));
1327   guestfs_free_int_bool (r);
1328   CAMLreturn (rv);
1329 }
1330
1331 CAMLprim value
1332 ocaml_guestfs_aug_get (value gv, value pathv)
1333 {
1334   CAMLparam2 (gv, pathv);
1335   CAMLlocal1 (rv);
1336
1337   guestfs_h *g = Guestfs_val (gv);
1338   if (g == NULL)
1339     caml_failwith ("aug_get: used handle after closing it");
1340
1341   const char *path = String_val (pathv);
1342   char *r;
1343
1344   caml_enter_blocking_section ();
1345   r = guestfs_aug_get (g, path);
1346   caml_leave_blocking_section ();
1347   if (r == NULL)
1348     ocaml_guestfs_raise_error (g, "aug_get");
1349
1350   rv = caml_copy_string (r);
1351   free (r);
1352   CAMLreturn (rv);
1353 }
1354
1355 CAMLprim value
1356 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
1357 {
1358   CAMLparam3 (gv, pathv, valv);
1359   CAMLlocal1 (rv);
1360
1361   guestfs_h *g = Guestfs_val (gv);
1362   if (g == NULL)
1363     caml_failwith ("aug_set: used handle after closing it");
1364
1365   const char *path = String_val (pathv);
1366   const char *val = String_val (valv);
1367   int r;
1368
1369   caml_enter_blocking_section ();
1370   r = guestfs_aug_set (g, path, val);
1371   caml_leave_blocking_section ();
1372   if (r == -1)
1373     ocaml_guestfs_raise_error (g, "aug_set");
1374
1375   rv = Val_unit;
1376   CAMLreturn (rv);
1377 }
1378
1379 CAMLprim value
1380 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1381 {
1382   CAMLparam4 (gv, pathv, labelv, beforev);
1383   CAMLlocal1 (rv);
1384
1385   guestfs_h *g = Guestfs_val (gv);
1386   if (g == NULL)
1387     caml_failwith ("aug_insert: used handle after closing it");
1388
1389   const char *path = String_val (pathv);
1390   const char *label = String_val (labelv);
1391   int before = Bool_val (beforev);
1392   int r;
1393
1394   caml_enter_blocking_section ();
1395   r = guestfs_aug_insert (g, path, label, before);
1396   caml_leave_blocking_section ();
1397   if (r == -1)
1398     ocaml_guestfs_raise_error (g, "aug_insert");
1399
1400   rv = Val_unit;
1401   CAMLreturn (rv);
1402 }
1403
1404 CAMLprim value
1405 ocaml_guestfs_aug_rm (value gv, value pathv)
1406 {
1407   CAMLparam2 (gv, pathv);
1408   CAMLlocal1 (rv);
1409
1410   guestfs_h *g = Guestfs_val (gv);
1411   if (g == NULL)
1412     caml_failwith ("aug_rm: used handle after closing it");
1413
1414   const char *path = String_val (pathv);
1415   int r;
1416
1417   caml_enter_blocking_section ();
1418   r = guestfs_aug_rm (g, path);
1419   caml_leave_blocking_section ();
1420   if (r == -1)
1421     ocaml_guestfs_raise_error (g, "aug_rm");
1422
1423   rv = Val_int (r);
1424   CAMLreturn (rv);
1425 }
1426
1427 CAMLprim value
1428 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1429 {
1430   CAMLparam3 (gv, srcv, destv);
1431   CAMLlocal1 (rv);
1432
1433   guestfs_h *g = Guestfs_val (gv);
1434   if (g == NULL)
1435     caml_failwith ("aug_mv: used handle after closing it");
1436
1437   const char *src = String_val (srcv);
1438   const char *dest = String_val (destv);
1439   int r;
1440
1441   caml_enter_blocking_section ();
1442   r = guestfs_aug_mv (g, src, dest);
1443   caml_leave_blocking_section ();
1444   if (r == -1)
1445     ocaml_guestfs_raise_error (g, "aug_mv");
1446
1447   rv = Val_unit;
1448   CAMLreturn (rv);
1449 }
1450
1451 CAMLprim value
1452 ocaml_guestfs_aug_match (value gv, value pathv)
1453 {
1454   CAMLparam2 (gv, pathv);
1455   CAMLlocal1 (rv);
1456
1457   guestfs_h *g = Guestfs_val (gv);
1458   if (g == NULL)
1459     caml_failwith ("aug_match: used handle after closing it");
1460
1461   const char *path = String_val (pathv);
1462   int i;
1463   char **r;
1464
1465   caml_enter_blocking_section ();
1466   r = guestfs_aug_match (g, path);
1467   caml_leave_blocking_section ();
1468   if (r == NULL)
1469     ocaml_guestfs_raise_error (g, "aug_match");
1470
1471   rv = caml_copy_string_array ((const char **) r);
1472   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1473   free (r);
1474   CAMLreturn (rv);
1475 }
1476
1477 CAMLprim value
1478 ocaml_guestfs_aug_save (value gv)
1479 {
1480   CAMLparam1 (gv);
1481   CAMLlocal1 (rv);
1482
1483   guestfs_h *g = Guestfs_val (gv);
1484   if (g == NULL)
1485     caml_failwith ("aug_save: used handle after closing it");
1486
1487   int r;
1488
1489   caml_enter_blocking_section ();
1490   r = guestfs_aug_save (g);
1491   caml_leave_blocking_section ();
1492   if (r == -1)
1493     ocaml_guestfs_raise_error (g, "aug_save");
1494
1495   rv = Val_unit;
1496   CAMLreturn (rv);
1497 }
1498
1499 CAMLprim value
1500 ocaml_guestfs_aug_load (value gv)
1501 {
1502   CAMLparam1 (gv);
1503   CAMLlocal1 (rv);
1504
1505   guestfs_h *g = Guestfs_val (gv);
1506   if (g == NULL)
1507     caml_failwith ("aug_load: used handle after closing it");
1508
1509   int r;
1510
1511   caml_enter_blocking_section ();
1512   r = guestfs_aug_load (g);
1513   caml_leave_blocking_section ();
1514   if (r == -1)
1515     ocaml_guestfs_raise_error (g, "aug_load");
1516
1517   rv = Val_unit;
1518   CAMLreturn (rv);
1519 }
1520
1521 CAMLprim value
1522 ocaml_guestfs_aug_ls (value gv, value pathv)
1523 {
1524   CAMLparam2 (gv, pathv);
1525   CAMLlocal1 (rv);
1526
1527   guestfs_h *g = Guestfs_val (gv);
1528   if (g == NULL)
1529     caml_failwith ("aug_ls: used handle after closing it");
1530
1531   const char *path = String_val (pathv);
1532   int i;
1533   char **r;
1534
1535   caml_enter_blocking_section ();
1536   r = guestfs_aug_ls (g, path);
1537   caml_leave_blocking_section ();
1538   if (r == NULL)
1539     ocaml_guestfs_raise_error (g, "aug_ls");
1540
1541   rv = caml_copy_string_array ((const char **) r);
1542   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1543   free (r);
1544   CAMLreturn (rv);
1545 }
1546
1547 CAMLprim value
1548 ocaml_guestfs_rm (value gv, value pathv)
1549 {
1550   CAMLparam2 (gv, pathv);
1551   CAMLlocal1 (rv);
1552
1553   guestfs_h *g = Guestfs_val (gv);
1554   if (g == NULL)
1555     caml_failwith ("rm: used handle after closing it");
1556
1557   const char *path = String_val (pathv);
1558   int r;
1559
1560   caml_enter_blocking_section ();
1561   r = guestfs_rm (g, path);
1562   caml_leave_blocking_section ();
1563   if (r == -1)
1564     ocaml_guestfs_raise_error (g, "rm");
1565
1566   rv = Val_unit;
1567   CAMLreturn (rv);
1568 }
1569
1570 CAMLprim value
1571 ocaml_guestfs_rmdir (value gv, value pathv)
1572 {
1573   CAMLparam2 (gv, pathv);
1574   CAMLlocal1 (rv);
1575
1576   guestfs_h *g = Guestfs_val (gv);
1577   if (g == NULL)
1578     caml_failwith ("rmdir: used handle after closing it");
1579
1580   const char *path = String_val (pathv);
1581   int r;
1582
1583   caml_enter_blocking_section ();
1584   r = guestfs_rmdir (g, path);
1585   caml_leave_blocking_section ();
1586   if (r == -1)
1587     ocaml_guestfs_raise_error (g, "rmdir");
1588
1589   rv = Val_unit;
1590   CAMLreturn (rv);
1591 }
1592
1593 CAMLprim value
1594 ocaml_guestfs_rm_rf (value gv, value pathv)
1595 {
1596   CAMLparam2 (gv, pathv);
1597   CAMLlocal1 (rv);
1598
1599   guestfs_h *g = Guestfs_val (gv);
1600   if (g == NULL)
1601     caml_failwith ("rm_rf: used handle after closing it");
1602
1603   const char *path = String_val (pathv);
1604   int r;
1605
1606   caml_enter_blocking_section ();
1607   r = guestfs_rm_rf (g, path);
1608   caml_leave_blocking_section ();
1609   if (r == -1)
1610     ocaml_guestfs_raise_error (g, "rm_rf");
1611
1612   rv = Val_unit;
1613   CAMLreturn (rv);
1614 }
1615
1616 CAMLprim value
1617 ocaml_guestfs_mkdir (value gv, value pathv)
1618 {
1619   CAMLparam2 (gv, pathv);
1620   CAMLlocal1 (rv);
1621
1622   guestfs_h *g = Guestfs_val (gv);
1623   if (g == NULL)
1624     caml_failwith ("mkdir: used handle after closing it");
1625
1626   const char *path = String_val (pathv);
1627   int r;
1628
1629   caml_enter_blocking_section ();
1630   r = guestfs_mkdir (g, path);
1631   caml_leave_blocking_section ();
1632   if (r == -1)
1633     ocaml_guestfs_raise_error (g, "mkdir");
1634
1635   rv = Val_unit;
1636   CAMLreturn (rv);
1637 }
1638
1639 CAMLprim value
1640 ocaml_guestfs_mkdir_p (value gv, value pathv)
1641 {
1642   CAMLparam2 (gv, pathv);
1643   CAMLlocal1 (rv);
1644
1645   guestfs_h *g = Guestfs_val (gv);
1646   if (g == NULL)
1647     caml_failwith ("mkdir_p: used handle after closing it");
1648
1649   const char *path = String_val (pathv);
1650   int r;
1651
1652   caml_enter_blocking_section ();
1653   r = guestfs_mkdir_p (g, path);
1654   caml_leave_blocking_section ();
1655   if (r == -1)
1656     ocaml_guestfs_raise_error (g, "mkdir_p");
1657
1658   rv = Val_unit;
1659   CAMLreturn (rv);
1660 }
1661
1662 CAMLprim value
1663 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1664 {
1665   CAMLparam3 (gv, modev, pathv);
1666   CAMLlocal1 (rv);
1667
1668   guestfs_h *g = Guestfs_val (gv);
1669   if (g == NULL)
1670     caml_failwith ("chmod: used handle after closing it");
1671
1672   int mode = Int_val (modev);
1673   const char *path = String_val (pathv);
1674   int r;
1675
1676   caml_enter_blocking_section ();
1677   r = guestfs_chmod (g, mode, path);
1678   caml_leave_blocking_section ();
1679   if (r == -1)
1680     ocaml_guestfs_raise_error (g, "chmod");
1681
1682   rv = Val_unit;
1683   CAMLreturn (rv);
1684 }
1685
1686 CAMLprim value
1687 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1688 {
1689   CAMLparam4 (gv, ownerv, groupv, pathv);
1690   CAMLlocal1 (rv);
1691
1692   guestfs_h *g = Guestfs_val (gv);
1693   if (g == NULL)
1694     caml_failwith ("chown: used handle after closing it");
1695
1696   int owner = Int_val (ownerv);
1697   int group = Int_val (groupv);
1698   const char *path = String_val (pathv);
1699   int r;
1700
1701   caml_enter_blocking_section ();
1702   r = guestfs_chown (g, owner, group, path);
1703   caml_leave_blocking_section ();
1704   if (r == -1)
1705     ocaml_guestfs_raise_error (g, "chown");
1706
1707   rv = Val_unit;
1708   CAMLreturn (rv);
1709 }
1710
1711 CAMLprim value
1712 ocaml_guestfs_exists (value gv, value pathv)
1713 {
1714   CAMLparam2 (gv, pathv);
1715   CAMLlocal1 (rv);
1716
1717   guestfs_h *g = Guestfs_val (gv);
1718   if (g == NULL)
1719     caml_failwith ("exists: used handle after closing it");
1720
1721   const char *path = String_val (pathv);
1722   int r;
1723
1724   caml_enter_blocking_section ();
1725   r = guestfs_exists (g, path);
1726   caml_leave_blocking_section ();
1727   if (r == -1)
1728     ocaml_guestfs_raise_error (g, "exists");
1729
1730   rv = Val_bool (r);
1731   CAMLreturn (rv);
1732 }
1733
1734 CAMLprim value
1735 ocaml_guestfs_is_file (value gv, value pathv)
1736 {
1737   CAMLparam2 (gv, pathv);
1738   CAMLlocal1 (rv);
1739
1740   guestfs_h *g = Guestfs_val (gv);
1741   if (g == NULL)
1742     caml_failwith ("is_file: used handle after closing it");
1743
1744   const char *path = String_val (pathv);
1745   int r;
1746
1747   caml_enter_blocking_section ();
1748   r = guestfs_is_file (g, path);
1749   caml_leave_blocking_section ();
1750   if (r == -1)
1751     ocaml_guestfs_raise_error (g, "is_file");
1752
1753   rv = Val_bool (r);
1754   CAMLreturn (rv);
1755 }
1756
1757 CAMLprim value
1758 ocaml_guestfs_is_dir (value gv, value pathv)
1759 {
1760   CAMLparam2 (gv, pathv);
1761   CAMLlocal1 (rv);
1762
1763   guestfs_h *g = Guestfs_val (gv);
1764   if (g == NULL)
1765     caml_failwith ("is_dir: used handle after closing it");
1766
1767   const char *path = String_val (pathv);
1768   int r;
1769
1770   caml_enter_blocking_section ();
1771   r = guestfs_is_dir (g, path);
1772   caml_leave_blocking_section ();
1773   if (r == -1)
1774     ocaml_guestfs_raise_error (g, "is_dir");
1775
1776   rv = Val_bool (r);
1777   CAMLreturn (rv);
1778 }
1779
1780 CAMLprim value
1781 ocaml_guestfs_pvcreate (value gv, value devicev)
1782 {
1783   CAMLparam2 (gv, devicev);
1784   CAMLlocal1 (rv);
1785
1786   guestfs_h *g = Guestfs_val (gv);
1787   if (g == NULL)
1788     caml_failwith ("pvcreate: used handle after closing it");
1789
1790   const char *device = String_val (devicev);
1791   int r;
1792
1793   caml_enter_blocking_section ();
1794   r = guestfs_pvcreate (g, device);
1795   caml_leave_blocking_section ();
1796   if (r == -1)
1797     ocaml_guestfs_raise_error (g, "pvcreate");
1798
1799   rv = Val_unit;
1800   CAMLreturn (rv);
1801 }
1802
1803 CAMLprim value
1804 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
1805 {
1806   CAMLparam3 (gv, volgroupv, physvolsv);
1807   CAMLlocal1 (rv);
1808
1809   guestfs_h *g = Guestfs_val (gv);
1810   if (g == NULL)
1811     caml_failwith ("vgcreate: used handle after closing it");
1812
1813   const char *volgroup = String_val (volgroupv);
1814   char **physvols = ocaml_guestfs_strings_val (g, physvolsv);
1815   int r;
1816
1817   caml_enter_blocking_section ();
1818   r = guestfs_vgcreate (g, volgroup, physvols);
1819   caml_leave_blocking_section ();
1820   ocaml_guestfs_free_strings (physvols);
1821   if (r == -1)
1822     ocaml_guestfs_raise_error (g, "vgcreate");
1823
1824   rv = Val_unit;
1825   CAMLreturn (rv);
1826 }
1827
1828 CAMLprim value
1829 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
1830 {
1831   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
1832   CAMLlocal1 (rv);
1833
1834   guestfs_h *g = Guestfs_val (gv);
1835   if (g == NULL)
1836     caml_failwith ("lvcreate: used handle after closing it");
1837
1838   const char *logvol = String_val (logvolv);
1839   const char *volgroup = String_val (volgroupv);
1840   int mbytes = Int_val (mbytesv);
1841   int r;
1842
1843   caml_enter_blocking_section ();
1844   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
1845   caml_leave_blocking_section ();
1846   if (r == -1)
1847     ocaml_guestfs_raise_error (g, "lvcreate");
1848
1849   rv = Val_unit;
1850   CAMLreturn (rv);
1851 }
1852
1853 CAMLprim value
1854 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
1855 {
1856   CAMLparam3 (gv, fstypev, devicev);
1857   CAMLlocal1 (rv);
1858
1859   guestfs_h *g = Guestfs_val (gv);
1860   if (g == NULL)
1861     caml_failwith ("mkfs: used handle after closing it");
1862
1863   const char *fstype = String_val (fstypev);
1864   const char *device = String_val (devicev);
1865   int r;
1866
1867   caml_enter_blocking_section ();
1868   r = guestfs_mkfs (g, fstype, device);
1869   caml_leave_blocking_section ();
1870   if (r == -1)
1871     ocaml_guestfs_raise_error (g, "mkfs");
1872
1873   rv = Val_unit;
1874   CAMLreturn (rv);
1875 }
1876
1877 CAMLprim value
1878 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
1879 {
1880   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
1881   CAMLxparam1 (linesv);
1882   CAMLlocal1 (rv);
1883
1884   guestfs_h *g = Guestfs_val (gv);
1885   if (g == NULL)
1886     caml_failwith ("sfdisk: used handle after closing it");
1887
1888   const char *device = String_val (devicev);
1889   int cyls = Int_val (cylsv);
1890   int heads = Int_val (headsv);
1891   int sectors = Int_val (sectorsv);
1892   char **lines = ocaml_guestfs_strings_val (g, linesv);
1893   int r;
1894
1895   caml_enter_blocking_section ();
1896   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
1897   caml_leave_blocking_section ();
1898   ocaml_guestfs_free_strings (lines);
1899   if (r == -1)
1900     ocaml_guestfs_raise_error (g, "sfdisk");
1901
1902   rv = Val_unit;
1903   CAMLreturn (rv);
1904 }
1905
1906 CAMLprim value
1907 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
1908 {
1909   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
1910 }
1911
1912 CAMLprim value
1913 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
1914 {
1915   CAMLparam4 (gv, pathv, contentv, sizev);
1916   CAMLlocal1 (rv);
1917
1918   guestfs_h *g = Guestfs_val (gv);
1919   if (g == NULL)
1920     caml_failwith ("write_file: used handle after closing it");
1921
1922   const char *path = String_val (pathv);
1923   const char *content = String_val (contentv);
1924   int size = Int_val (sizev);
1925   int r;
1926
1927   caml_enter_blocking_section ();
1928   r = guestfs_write_file (g, path, content, size);
1929   caml_leave_blocking_section ();
1930   if (r == -1)
1931     ocaml_guestfs_raise_error (g, "write_file");
1932
1933   rv = Val_unit;
1934   CAMLreturn (rv);
1935 }
1936
1937 CAMLprim value
1938 ocaml_guestfs_umount (value gv, value pathordevicev)
1939 {
1940   CAMLparam2 (gv, pathordevicev);
1941   CAMLlocal1 (rv);
1942
1943   guestfs_h *g = Guestfs_val (gv);
1944   if (g == NULL)
1945     caml_failwith ("umount: used handle after closing it");
1946
1947   const char *pathordevice = String_val (pathordevicev);
1948   int r;
1949
1950   caml_enter_blocking_section ();
1951   r = guestfs_umount (g, pathordevice);
1952   caml_leave_blocking_section ();
1953   if (r == -1)
1954     ocaml_guestfs_raise_error (g, "umount");
1955
1956   rv = Val_unit;
1957   CAMLreturn (rv);
1958 }
1959
1960 CAMLprim value
1961 ocaml_guestfs_mounts (value gv)
1962 {
1963   CAMLparam1 (gv);
1964   CAMLlocal1 (rv);
1965
1966   guestfs_h *g = Guestfs_val (gv);
1967   if (g == NULL)
1968     caml_failwith ("mounts: used handle after closing it");
1969
1970   int i;
1971   char **r;
1972
1973   caml_enter_blocking_section ();
1974   r = guestfs_mounts (g);
1975   caml_leave_blocking_section ();
1976   if (r == NULL)
1977     ocaml_guestfs_raise_error (g, "mounts");
1978
1979   rv = caml_copy_string_array ((const char **) r);
1980   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1981   free (r);
1982   CAMLreturn (rv);
1983 }
1984
1985 CAMLprim value
1986 ocaml_guestfs_umount_all (value gv)
1987 {
1988   CAMLparam1 (gv);
1989   CAMLlocal1 (rv);
1990
1991   guestfs_h *g = Guestfs_val (gv);
1992   if (g == NULL)
1993     caml_failwith ("umount_all: used handle after closing it");
1994
1995   int r;
1996
1997   caml_enter_blocking_section ();
1998   r = guestfs_umount_all (g);
1999   caml_leave_blocking_section ();
2000   if (r == -1)
2001     ocaml_guestfs_raise_error (g, "umount_all");
2002
2003   rv = Val_unit;
2004   CAMLreturn (rv);
2005 }
2006
2007 CAMLprim value
2008 ocaml_guestfs_lvm_remove_all (value gv)
2009 {
2010   CAMLparam1 (gv);
2011   CAMLlocal1 (rv);
2012
2013   guestfs_h *g = Guestfs_val (gv);
2014   if (g == NULL)
2015     caml_failwith ("lvm_remove_all: used handle after closing it");
2016
2017   int r;
2018
2019   caml_enter_blocking_section ();
2020   r = guestfs_lvm_remove_all (g);
2021   caml_leave_blocking_section ();
2022   if (r == -1)
2023     ocaml_guestfs_raise_error (g, "lvm_remove_all");
2024
2025   rv = Val_unit;
2026   CAMLreturn (rv);
2027 }
2028
2029 CAMLprim value
2030 ocaml_guestfs_file (value gv, value pathv)
2031 {
2032   CAMLparam2 (gv, pathv);
2033   CAMLlocal1 (rv);
2034
2035   guestfs_h *g = Guestfs_val (gv);
2036   if (g == NULL)
2037     caml_failwith ("file: used handle after closing it");
2038
2039   const char *path = String_val (pathv);
2040   char *r;
2041
2042   caml_enter_blocking_section ();
2043   r = guestfs_file (g, path);
2044   caml_leave_blocking_section ();
2045   if (r == NULL)
2046     ocaml_guestfs_raise_error (g, "file");
2047
2048   rv = caml_copy_string (r);
2049   free (r);
2050   CAMLreturn (rv);
2051 }
2052
2053 CAMLprim value
2054 ocaml_guestfs_command (value gv, value argumentsv)
2055 {
2056   CAMLparam2 (gv, argumentsv);
2057   CAMLlocal1 (rv);
2058
2059   guestfs_h *g = Guestfs_val (gv);
2060   if (g == NULL)
2061     caml_failwith ("command: used handle after closing it");
2062
2063   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2064   char *r;
2065
2066   caml_enter_blocking_section ();
2067   r = guestfs_command (g, arguments);
2068   caml_leave_blocking_section ();
2069   ocaml_guestfs_free_strings (arguments);
2070   if (r == NULL)
2071     ocaml_guestfs_raise_error (g, "command");
2072
2073   rv = caml_copy_string (r);
2074   free (r);
2075   CAMLreturn (rv);
2076 }
2077
2078 CAMLprim value
2079 ocaml_guestfs_command_lines (value gv, value argumentsv)
2080 {
2081   CAMLparam2 (gv, argumentsv);
2082   CAMLlocal1 (rv);
2083
2084   guestfs_h *g = Guestfs_val (gv);
2085   if (g == NULL)
2086     caml_failwith ("command_lines: used handle after closing it");
2087
2088   char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
2089   int i;
2090   char **r;
2091
2092   caml_enter_blocking_section ();
2093   r = guestfs_command_lines (g, arguments);
2094   caml_leave_blocking_section ();
2095   ocaml_guestfs_free_strings (arguments);
2096   if (r == NULL)
2097     ocaml_guestfs_raise_error (g, "command_lines");
2098
2099   rv = caml_copy_string_array ((const char **) r);
2100   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2101   free (r);
2102   CAMLreturn (rv);
2103 }
2104
2105 CAMLprim value
2106 ocaml_guestfs_stat (value gv, value pathv)
2107 {
2108   CAMLparam2 (gv, pathv);
2109   CAMLlocal1 (rv);
2110
2111   guestfs_h *g = Guestfs_val (gv);
2112   if (g == NULL)
2113     caml_failwith ("stat: used handle after closing it");
2114
2115   const char *path = String_val (pathv);
2116   struct guestfs_stat *r;
2117
2118   caml_enter_blocking_section ();
2119   r = guestfs_stat (g, path);
2120   caml_leave_blocking_section ();
2121   if (r == NULL)
2122     ocaml_guestfs_raise_error (g, "stat");
2123
2124   rv = copy_stat (r);
2125   free (r);
2126   CAMLreturn (rv);
2127 }
2128
2129 CAMLprim value
2130 ocaml_guestfs_lstat (value gv, value pathv)
2131 {
2132   CAMLparam2 (gv, pathv);
2133   CAMLlocal1 (rv);
2134
2135   guestfs_h *g = Guestfs_val (gv);
2136   if (g == NULL)
2137     caml_failwith ("lstat: used handle after closing it");
2138
2139   const char *path = String_val (pathv);
2140   struct guestfs_stat *r;
2141
2142   caml_enter_blocking_section ();
2143   r = guestfs_lstat (g, path);
2144   caml_leave_blocking_section ();
2145   if (r == NULL)
2146     ocaml_guestfs_raise_error (g, "lstat");
2147
2148   rv = copy_stat (r);
2149   free (r);
2150   CAMLreturn (rv);
2151 }
2152
2153 CAMLprim value
2154 ocaml_guestfs_statvfs (value gv, value pathv)
2155 {
2156   CAMLparam2 (gv, pathv);
2157   CAMLlocal1 (rv);
2158
2159   guestfs_h *g = Guestfs_val (gv);
2160   if (g == NULL)
2161     caml_failwith ("statvfs: used handle after closing it");
2162
2163   const char *path = String_val (pathv);
2164   struct guestfs_statvfs *r;
2165
2166   caml_enter_blocking_section ();
2167   r = guestfs_statvfs (g, path);
2168   caml_leave_blocking_section ();
2169   if (r == NULL)
2170     ocaml_guestfs_raise_error (g, "statvfs");
2171
2172   rv = copy_statvfs (r);
2173   free (r);
2174   CAMLreturn (rv);
2175 }
2176
2177 CAMLprim value
2178 ocaml_guestfs_tune2fs_l (value gv, value devicev)
2179 {
2180   CAMLparam2 (gv, devicev);
2181   CAMLlocal1 (rv);
2182
2183   guestfs_h *g = Guestfs_val (gv);
2184   if (g == NULL)
2185     caml_failwith ("tune2fs_l: used handle after closing it");
2186
2187   const char *device = String_val (devicev);
2188   int i;
2189   char **r;
2190
2191   caml_enter_blocking_section ();
2192   r = guestfs_tune2fs_l (g, device);
2193   caml_leave_blocking_section ();
2194   if (r == NULL)
2195     ocaml_guestfs_raise_error (g, "tune2fs_l");
2196
2197   rv = copy_table (r);
2198   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2199   free (r);
2200   CAMLreturn (rv);
2201 }
2202
2203 CAMLprim value
2204 ocaml_guestfs_blockdev_setro (value gv, value devicev)
2205 {
2206   CAMLparam2 (gv, devicev);
2207   CAMLlocal1 (rv);
2208
2209   guestfs_h *g = Guestfs_val (gv);
2210   if (g == NULL)
2211     caml_failwith ("blockdev_setro: used handle after closing it");
2212
2213   const char *device = String_val (devicev);
2214   int r;
2215
2216   caml_enter_blocking_section ();
2217   r = guestfs_blockdev_setro (g, device);
2218   caml_leave_blocking_section ();
2219   if (r == -1)
2220     ocaml_guestfs_raise_error (g, "blockdev_setro");
2221
2222   rv = Val_unit;
2223   CAMLreturn (rv);
2224 }
2225
2226 CAMLprim value
2227 ocaml_guestfs_blockdev_setrw (value gv, value devicev)
2228 {
2229   CAMLparam2 (gv, devicev);
2230   CAMLlocal1 (rv);
2231
2232   guestfs_h *g = Guestfs_val (gv);
2233   if (g == NULL)
2234     caml_failwith ("blockdev_setrw: used handle after closing it");
2235
2236   const char *device = String_val (devicev);
2237   int r;
2238
2239   caml_enter_blocking_section ();
2240   r = guestfs_blockdev_setrw (g, device);
2241   caml_leave_blocking_section ();
2242   if (r == -1)
2243     ocaml_guestfs_raise_error (g, "blockdev_setrw");
2244
2245   rv = Val_unit;
2246   CAMLreturn (rv);
2247 }
2248
2249 CAMLprim value
2250 ocaml_guestfs_blockdev_getro (value gv, value devicev)
2251 {
2252   CAMLparam2 (gv, devicev);
2253   CAMLlocal1 (rv);
2254
2255   guestfs_h *g = Guestfs_val (gv);
2256   if (g == NULL)
2257     caml_failwith ("blockdev_getro: used handle after closing it");
2258
2259   const char *device = String_val (devicev);
2260   int r;
2261
2262   caml_enter_blocking_section ();
2263   r = guestfs_blockdev_getro (g, device);
2264   caml_leave_blocking_section ();
2265   if (r == -1)
2266     ocaml_guestfs_raise_error (g, "blockdev_getro");
2267
2268   rv = Val_bool (r);
2269   CAMLreturn (rv);
2270 }
2271
2272 CAMLprim value
2273 ocaml_guestfs_blockdev_getss (value gv, value devicev)
2274 {
2275   CAMLparam2 (gv, devicev);
2276   CAMLlocal1 (rv);
2277
2278   guestfs_h *g = Guestfs_val (gv);
2279   if (g == NULL)
2280     caml_failwith ("blockdev_getss: used handle after closing it");
2281
2282   const char *device = String_val (devicev);
2283   int r;
2284
2285   caml_enter_blocking_section ();
2286   r = guestfs_blockdev_getss (g, device);
2287   caml_leave_blocking_section ();
2288   if (r == -1)
2289     ocaml_guestfs_raise_error (g, "blockdev_getss");
2290
2291   rv = Val_int (r);
2292   CAMLreturn (rv);
2293 }
2294
2295 CAMLprim value
2296 ocaml_guestfs_blockdev_getbsz (value gv, value devicev)
2297 {
2298   CAMLparam2 (gv, devicev);
2299   CAMLlocal1 (rv);
2300
2301   guestfs_h *g = Guestfs_val (gv);
2302   if (g == NULL)
2303     caml_failwith ("blockdev_getbsz: used handle after closing it");
2304
2305   const char *device = String_val (devicev);
2306   int r;
2307
2308   caml_enter_blocking_section ();
2309   r = guestfs_blockdev_getbsz (g, device);
2310   caml_leave_blocking_section ();
2311   if (r == -1)
2312     ocaml_guestfs_raise_error (g, "blockdev_getbsz");
2313
2314   rv = Val_int (r);
2315   CAMLreturn (rv);
2316 }
2317
2318 CAMLprim value
2319 ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev)
2320 {
2321   CAMLparam3 (gv, devicev, blocksizev);
2322   CAMLlocal1 (rv);
2323
2324   guestfs_h *g = Guestfs_val (gv);
2325   if (g == NULL)
2326     caml_failwith ("blockdev_setbsz: used handle after closing it");
2327
2328   const char *device = String_val (devicev);
2329   int blocksize = Int_val (blocksizev);
2330   int r;
2331
2332   caml_enter_blocking_section ();
2333   r = guestfs_blockdev_setbsz (g, device, blocksize);
2334   caml_leave_blocking_section ();
2335   if (r == -1)
2336     ocaml_guestfs_raise_error (g, "blockdev_setbsz");
2337
2338   rv = Val_unit;
2339   CAMLreturn (rv);
2340 }
2341
2342 CAMLprim value
2343 ocaml_guestfs_blockdev_getsz (value gv, value devicev)
2344 {
2345   CAMLparam2 (gv, devicev);
2346   CAMLlocal1 (rv);
2347
2348   guestfs_h *g = Guestfs_val (gv);
2349   if (g == NULL)
2350     caml_failwith ("blockdev_getsz: used handle after closing it");
2351
2352   const char *device = String_val (devicev);
2353   int64_t r;
2354
2355   caml_enter_blocking_section ();
2356   r = guestfs_blockdev_getsz (g, device);
2357   caml_leave_blocking_section ();
2358   if (r == -1)
2359     ocaml_guestfs_raise_error (g, "blockdev_getsz");
2360
2361   rv = caml_copy_int64 (r);
2362   CAMLreturn (rv);
2363 }
2364
2365 CAMLprim value
2366 ocaml_guestfs_blockdev_getsize64 (value gv, value devicev)
2367 {
2368   CAMLparam2 (gv, devicev);
2369   CAMLlocal1 (rv);
2370
2371   guestfs_h *g = Guestfs_val (gv);
2372   if (g == NULL)
2373     caml_failwith ("blockdev_getsize64: used handle after closing it");
2374
2375   const char *device = String_val (devicev);
2376   int64_t r;
2377
2378   caml_enter_blocking_section ();
2379   r = guestfs_blockdev_getsize64 (g, device);
2380   caml_leave_blocking_section ();
2381   if (r == -1)
2382     ocaml_guestfs_raise_error (g, "blockdev_getsize64");
2383
2384   rv = caml_copy_int64 (r);
2385   CAMLreturn (rv);
2386 }
2387
2388 CAMLprim value
2389 ocaml_guestfs_blockdev_flushbufs (value gv, value devicev)
2390 {
2391   CAMLparam2 (gv, devicev);
2392   CAMLlocal1 (rv);
2393
2394   guestfs_h *g = Guestfs_val (gv);
2395   if (g == NULL)
2396     caml_failwith ("blockdev_flushbufs: used handle after closing it");
2397
2398   const char *device = String_val (devicev);
2399   int r;
2400
2401   caml_enter_blocking_section ();
2402   r = guestfs_blockdev_flushbufs (g, device);
2403   caml_leave_blocking_section ();
2404   if (r == -1)
2405     ocaml_guestfs_raise_error (g, "blockdev_flushbufs");
2406
2407   rv = Val_unit;
2408   CAMLreturn (rv);
2409 }
2410
2411 CAMLprim value
2412 ocaml_guestfs_blockdev_rereadpt (value gv, value devicev)
2413 {
2414   CAMLparam2 (gv, devicev);
2415   CAMLlocal1 (rv);
2416
2417   guestfs_h *g = Guestfs_val (gv);
2418   if (g == NULL)
2419     caml_failwith ("blockdev_rereadpt: used handle after closing it");
2420
2421   const char *device = String_val (devicev);
2422   int r;
2423
2424   caml_enter_blocking_section ();
2425   r = guestfs_blockdev_rereadpt (g, device);
2426   caml_leave_blocking_section ();
2427   if (r == -1)
2428     ocaml_guestfs_raise_error (g, "blockdev_rereadpt");
2429
2430   rv = Val_unit;
2431   CAMLreturn (rv);
2432 }
2433
2434 CAMLprim value
2435 ocaml_guestfs_upload (value gv, value filenamev, value remotefilenamev)
2436 {
2437   CAMLparam3 (gv, filenamev, remotefilenamev);
2438   CAMLlocal1 (rv);
2439
2440   guestfs_h *g = Guestfs_val (gv);
2441   if (g == NULL)
2442     caml_failwith ("upload: used handle after closing it");
2443
2444   const char *filename = String_val (filenamev);
2445   const char *remotefilename = String_val (remotefilenamev);
2446   int r;
2447
2448   caml_enter_blocking_section ();
2449   r = guestfs_upload (g, filename, remotefilename);
2450   caml_leave_blocking_section ();
2451   if (r == -1)
2452     ocaml_guestfs_raise_error (g, "upload");
2453
2454   rv = Val_unit;
2455   CAMLreturn (rv);
2456 }
2457
2458 CAMLprim value
2459 ocaml_guestfs_download (value gv, value remotefilenamev, value filenamev)
2460 {
2461   CAMLparam3 (gv, remotefilenamev, filenamev);
2462   CAMLlocal1 (rv);
2463
2464   guestfs_h *g = Guestfs_val (gv);
2465   if (g == NULL)
2466     caml_failwith ("download: used handle after closing it");
2467
2468   const char *remotefilename = String_val (remotefilenamev);
2469   const char *filename = String_val (filenamev);
2470   int r;
2471
2472   caml_enter_blocking_section ();
2473   r = guestfs_download (g, remotefilename, filename);
2474   caml_leave_blocking_section ();
2475   if (r == -1)
2476     ocaml_guestfs_raise_error (g, "download");
2477
2478   rv = Val_unit;
2479   CAMLreturn (rv);
2480 }
2481
2482 CAMLprim value
2483 ocaml_guestfs_checksum (value gv, value csumtypev, value pathv)
2484 {
2485   CAMLparam3 (gv, csumtypev, pathv);
2486   CAMLlocal1 (rv);
2487
2488   guestfs_h *g = Guestfs_val (gv);
2489   if (g == NULL)
2490     caml_failwith ("checksum: used handle after closing it");
2491
2492   const char *csumtype = String_val (csumtypev);
2493   const char *path = String_val (pathv);
2494   char *r;
2495
2496   caml_enter_blocking_section ();
2497   r = guestfs_checksum (g, csumtype, path);
2498   caml_leave_blocking_section ();
2499   if (r == NULL)
2500     ocaml_guestfs_raise_error (g, "checksum");
2501
2502   rv = caml_copy_string (r);
2503   free (r);
2504   CAMLreturn (rv);
2505 }
2506
2507 CAMLprim value
2508 ocaml_guestfs_tar_in (value gv, value tarfilev, value directoryv)
2509 {
2510   CAMLparam3 (gv, tarfilev, directoryv);
2511   CAMLlocal1 (rv);
2512
2513   guestfs_h *g = Guestfs_val (gv);
2514   if (g == NULL)
2515     caml_failwith ("tar_in: used handle after closing it");
2516
2517   const char *tarfile = String_val (tarfilev);
2518   const char *directory = String_val (directoryv);
2519   int r;
2520
2521   caml_enter_blocking_section ();
2522   r = guestfs_tar_in (g, tarfile, directory);
2523   caml_leave_blocking_section ();
2524   if (r == -1)
2525     ocaml_guestfs_raise_error (g, "tar_in");
2526
2527   rv = Val_unit;
2528   CAMLreturn (rv);
2529 }
2530
2531 CAMLprim value
2532 ocaml_guestfs_tar_out (value gv, value directoryv, value tarfilev)
2533 {
2534   CAMLparam3 (gv, directoryv, tarfilev);
2535   CAMLlocal1 (rv);
2536
2537   guestfs_h *g = Guestfs_val (gv);
2538   if (g == NULL)
2539     caml_failwith ("tar_out: used handle after closing it");
2540
2541   const char *directory = String_val (directoryv);
2542   const char *tarfile = String_val (tarfilev);
2543   int r;
2544
2545   caml_enter_blocking_section ();
2546   r = guestfs_tar_out (g, directory, tarfile);
2547   caml_leave_blocking_section ();
2548   if (r == -1)
2549     ocaml_guestfs_raise_error (g, "tar_out");
2550
2551   rv = Val_unit;
2552   CAMLreturn (rv);
2553 }
2554
2555 CAMLprim value
2556 ocaml_guestfs_tgz_in (value gv, value tarballv, value directoryv)
2557 {
2558   CAMLparam3 (gv, tarballv, directoryv);
2559   CAMLlocal1 (rv);
2560
2561   guestfs_h *g = Guestfs_val (gv);
2562   if (g == NULL)
2563     caml_failwith ("tgz_in: used handle after closing it");
2564
2565   const char *tarball = String_val (tarballv);
2566   const char *directory = String_val (directoryv);
2567   int r;
2568
2569   caml_enter_blocking_section ();
2570   r = guestfs_tgz_in (g, tarball, directory);
2571   caml_leave_blocking_section ();
2572   if (r == -1)
2573     ocaml_guestfs_raise_error (g, "tgz_in");
2574
2575   rv = Val_unit;
2576   CAMLreturn (rv);
2577 }
2578
2579 CAMLprim value
2580 ocaml_guestfs_tgz_out (value gv, value directoryv, value tarballv)
2581 {
2582   CAMLparam3 (gv, directoryv, tarballv);
2583   CAMLlocal1 (rv);
2584
2585   guestfs_h *g = Guestfs_val (gv);
2586   if (g == NULL)
2587     caml_failwith ("tgz_out: used handle after closing it");
2588
2589   const char *directory = String_val (directoryv);
2590   const char *tarball = String_val (tarballv);
2591   int r;
2592
2593   caml_enter_blocking_section ();
2594   r = guestfs_tgz_out (g, directory, tarball);
2595   caml_leave_blocking_section ();
2596   if (r == -1)
2597     ocaml_guestfs_raise_error (g, "tgz_out");
2598
2599   rv = Val_unit;
2600   CAMLreturn (rv);
2601 }
2602
2603 CAMLprim value
2604 ocaml_guestfs_mount_ro (value gv, value devicev, value mountpointv)
2605 {
2606   CAMLparam3 (gv, devicev, mountpointv);
2607   CAMLlocal1 (rv);
2608
2609   guestfs_h *g = Guestfs_val (gv);
2610   if (g == NULL)
2611     caml_failwith ("mount_ro: used handle after closing it");
2612
2613   const char *device = String_val (devicev);
2614   const char *mountpoint = String_val (mountpointv);
2615   int r;
2616
2617   caml_enter_blocking_section ();
2618   r = guestfs_mount_ro (g, device, mountpoint);
2619   caml_leave_blocking_section ();
2620   if (r == -1)
2621     ocaml_guestfs_raise_error (g, "mount_ro");
2622
2623   rv = Val_unit;
2624   CAMLreturn (rv);
2625 }
2626
2627 CAMLprim value
2628 ocaml_guestfs_mount_options (value gv, value optionsv, value devicev, value mountpointv)
2629 {
2630   CAMLparam4 (gv, optionsv, devicev, mountpointv);
2631   CAMLlocal1 (rv);
2632
2633   guestfs_h *g = Guestfs_val (gv);
2634   if (g == NULL)
2635     caml_failwith ("mount_options: used handle after closing it");
2636
2637   const char *options = String_val (optionsv);
2638   const char *device = String_val (devicev);
2639   const char *mountpoint = String_val (mountpointv);
2640   int r;
2641
2642   caml_enter_blocking_section ();
2643   r = guestfs_mount_options (g, options, device, mountpoint);
2644   caml_leave_blocking_section ();
2645   if (r == -1)
2646     ocaml_guestfs_raise_error (g, "mount_options");
2647
2648   rv = Val_unit;
2649   CAMLreturn (rv);
2650 }
2651
2652 CAMLprim value
2653 ocaml_guestfs_mount_vfs (value gv, value optionsv, value vfstypev, value devicev, value mountpointv)
2654 {
2655   CAMLparam5 (gv, optionsv, vfstypev, devicev, mountpointv);
2656   CAMLlocal1 (rv);
2657
2658   guestfs_h *g = Guestfs_val (gv);
2659   if (g == NULL)
2660     caml_failwith ("mount_vfs: used handle after closing it");
2661
2662   const char *options = String_val (optionsv);
2663   const char *vfstype = String_val (vfstypev);
2664   const char *device = String_val (devicev);
2665   const char *mountpoint = String_val (mountpointv);
2666   int r;
2667
2668   caml_enter_blocking_section ();
2669   r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint);
2670   caml_leave_blocking_section ();
2671   if (r == -1)
2672     ocaml_guestfs_raise_error (g, "mount_vfs");
2673
2674   rv = Val_unit;
2675   CAMLreturn (rv);
2676 }
2677
2678 CAMLprim value
2679 ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
2680 {
2681   CAMLparam3 (gv, subcmdv, extraargsv);
2682   CAMLlocal1 (rv);
2683
2684   guestfs_h *g = Guestfs_val (gv);
2685   if (g == NULL)
2686     caml_failwith ("debug: used handle after closing it");
2687
2688   const char *subcmd = String_val (subcmdv);
2689   char **extraargs = ocaml_guestfs_strings_val (g, extraargsv);
2690   char *r;
2691
2692   caml_enter_blocking_section ();
2693   r = guestfs_debug (g, subcmd, extraargs);
2694   caml_leave_blocking_section ();
2695   ocaml_guestfs_free_strings (extraargs);
2696   if (r == NULL)
2697     ocaml_guestfs_raise_error (g, "debug");
2698
2699   rv = caml_copy_string (r);
2700   free (r);
2701   CAMLreturn (rv);
2702 }
2703
2704 CAMLprim value
2705 ocaml_guestfs_lvremove (value gv, value devicev)
2706 {
2707   CAMLparam2 (gv, devicev);
2708   CAMLlocal1 (rv);
2709
2710   guestfs_h *g = Guestfs_val (gv);
2711   if (g == NULL)
2712     caml_failwith ("lvremove: used handle after closing it");
2713
2714   const char *device = String_val (devicev);
2715   int r;
2716
2717   caml_enter_blocking_section ();
2718   r = guestfs_lvremove (g, device);
2719   caml_leave_blocking_section ();
2720   if (r == -1)
2721     ocaml_guestfs_raise_error (g, "lvremove");
2722
2723   rv = Val_unit;
2724   CAMLreturn (rv);
2725 }
2726
2727 CAMLprim value
2728 ocaml_guestfs_vgremove (value gv, value vgnamev)
2729 {
2730   CAMLparam2 (gv, vgnamev);
2731   CAMLlocal1 (rv);
2732
2733   guestfs_h *g = Guestfs_val (gv);
2734   if (g == NULL)
2735     caml_failwith ("vgremove: used handle after closing it");
2736
2737   const char *vgname = String_val (vgnamev);
2738   int r;
2739
2740   caml_enter_blocking_section ();
2741   r = guestfs_vgremove (g, vgname);
2742   caml_leave_blocking_section ();
2743   if (r == -1)
2744     ocaml_guestfs_raise_error (g, "vgremove");
2745
2746   rv = Val_unit;
2747   CAMLreturn (rv);
2748 }
2749
2750 CAMLprim value
2751 ocaml_guestfs_pvremove (value gv, value devicev)
2752 {
2753   CAMLparam2 (gv, devicev);
2754   CAMLlocal1 (rv);
2755
2756   guestfs_h *g = Guestfs_val (gv);
2757   if (g == NULL)
2758     caml_failwith ("pvremove: used handle after closing it");
2759
2760   const char *device = String_val (devicev);
2761   int r;
2762
2763   caml_enter_blocking_section ();
2764   r = guestfs_pvremove (g, device);
2765   caml_leave_blocking_section ();
2766   if (r == -1)
2767     ocaml_guestfs_raise_error (g, "pvremove");
2768
2769   rv = Val_unit;
2770   CAMLreturn (rv);
2771 }
2772
2773 CAMLprim value
2774 ocaml_guestfs_set_e2label (value gv, value devicev, value labelv)
2775 {
2776   CAMLparam3 (gv, devicev, labelv);
2777   CAMLlocal1 (rv);
2778
2779   guestfs_h *g = Guestfs_val (gv);
2780   if (g == NULL)
2781     caml_failwith ("set_e2label: used handle after closing it");
2782
2783   const char *device = String_val (devicev);
2784   const char *label = String_val (labelv);
2785   int r;
2786
2787   caml_enter_blocking_section ();
2788   r = guestfs_set_e2label (g, device, label);
2789   caml_leave_blocking_section ();
2790   if (r == -1)
2791     ocaml_guestfs_raise_error (g, "set_e2label");
2792
2793   rv = Val_unit;
2794   CAMLreturn (rv);
2795 }
2796
2797 CAMLprim value
2798 ocaml_guestfs_get_e2label (value gv, value devicev)
2799 {
2800   CAMLparam2 (gv, devicev);
2801   CAMLlocal1 (rv);
2802
2803   guestfs_h *g = Guestfs_val (gv);
2804   if (g == NULL)
2805     caml_failwith ("get_e2label: used handle after closing it");
2806
2807   const char *device = String_val (devicev);
2808   char *r;
2809
2810   caml_enter_blocking_section ();
2811   r = guestfs_get_e2label (g, device);
2812   caml_leave_blocking_section ();
2813   if (r == NULL)
2814     ocaml_guestfs_raise_error (g, "get_e2label");
2815
2816   rv = caml_copy_string (r);
2817   free (r);
2818   CAMLreturn (rv);
2819 }
2820
2821 CAMLprim value
2822 ocaml_guestfs_set_e2uuid (value gv, value devicev, value uuidv)
2823 {
2824   CAMLparam3 (gv, devicev, uuidv);
2825   CAMLlocal1 (rv);
2826
2827   guestfs_h *g = Guestfs_val (gv);
2828   if (g == NULL)
2829     caml_failwith ("set_e2uuid: used handle after closing it");
2830
2831   const char *device = String_val (devicev);
2832   const char *uuid = String_val (uuidv);
2833   int r;
2834
2835   caml_enter_blocking_section ();
2836   r = guestfs_set_e2uuid (g, device, uuid);
2837   caml_leave_blocking_section ();
2838   if (r == -1)
2839     ocaml_guestfs_raise_error (g, "set_e2uuid");
2840
2841   rv = Val_unit;
2842   CAMLreturn (rv);
2843 }
2844
2845 CAMLprim value
2846 ocaml_guestfs_get_e2uuid (value gv, value devicev)
2847 {
2848   CAMLparam2 (gv, devicev);
2849   CAMLlocal1 (rv);
2850
2851   guestfs_h *g = Guestfs_val (gv);
2852   if (g == NULL)
2853     caml_failwith ("get_e2uuid: used handle after closing it");
2854
2855   const char *device = String_val (devicev);
2856   char *r;
2857
2858   caml_enter_blocking_section ();
2859   r = guestfs_get_e2uuid (g, device);
2860   caml_leave_blocking_section ();
2861   if (r == NULL)
2862     ocaml_guestfs_raise_error (g, "get_e2uuid");
2863
2864   rv = caml_copy_string (r);
2865   free (r);
2866   CAMLreturn (rv);
2867 }
2868
2869 CAMLprim value
2870 ocaml_guestfs_fsck (value gv, value fstypev, value devicev)
2871 {
2872   CAMLparam3 (gv, fstypev, devicev);
2873   CAMLlocal1 (rv);
2874
2875   guestfs_h *g = Guestfs_val (gv);
2876   if (g == NULL)
2877     caml_failwith ("fsck: used handle after closing it");
2878
2879   const char *fstype = String_val (fstypev);
2880   const char *device = String_val (devicev);
2881   int r;
2882
2883   caml_enter_blocking_section ();
2884   r = guestfs_fsck (g, fstype, device);
2885   caml_leave_blocking_section ();
2886   if (r == -1)
2887     ocaml_guestfs_raise_error (g, "fsck");
2888
2889   rv = Val_int (r);
2890   CAMLreturn (rv);
2891 }
2892
2893 CAMLprim value
2894 ocaml_guestfs_zero (value gv, value devicev)
2895 {
2896   CAMLparam2 (gv, devicev);
2897   CAMLlocal1 (rv);
2898
2899   guestfs_h *g = Guestfs_val (gv);
2900   if (g == NULL)
2901     caml_failwith ("zero: used handle after closing it");
2902
2903   const char *device = String_val (devicev);
2904   int r;
2905
2906   caml_enter_blocking_section ();
2907   r = guestfs_zero (g, device);
2908   caml_leave_blocking_section ();
2909   if (r == -1)
2910     ocaml_guestfs_raise_error (g, "zero");
2911
2912   rv = Val_unit;
2913   CAMLreturn (rv);
2914 }
2915
2916 CAMLprim value
2917 ocaml_guestfs_grub_install (value gv, value rootv, value devicev)
2918 {
2919   CAMLparam3 (gv, rootv, devicev);
2920   CAMLlocal1 (rv);
2921
2922   guestfs_h *g = Guestfs_val (gv);
2923   if (g == NULL)
2924     caml_failwith ("grub_install: used handle after closing it");
2925
2926   const char *root = String_val (rootv);
2927   const char *device = String_val (devicev);
2928   int r;
2929
2930   caml_enter_blocking_section ();
2931   r = guestfs_grub_install (g, root, device);
2932   caml_leave_blocking_section ();
2933   if (r == -1)
2934     ocaml_guestfs_raise_error (g, "grub_install");
2935
2936   rv = Val_unit;
2937   CAMLreturn (rv);
2938 }
2939
2940 CAMLprim value
2941 ocaml_guestfs_cp (value gv, value srcv, value destv)
2942 {
2943   CAMLparam3 (gv, srcv, destv);
2944   CAMLlocal1 (rv);
2945
2946   guestfs_h *g = Guestfs_val (gv);
2947   if (g == NULL)
2948     caml_failwith ("cp: used handle after closing it");
2949
2950   const char *src = String_val (srcv);
2951   const char *dest = String_val (destv);
2952   int r;
2953
2954   caml_enter_blocking_section ();
2955   r = guestfs_cp (g, src, dest);
2956   caml_leave_blocking_section ();
2957   if (r == -1)
2958     ocaml_guestfs_raise_error (g, "cp");
2959
2960   rv = Val_unit;
2961   CAMLreturn (rv);
2962 }
2963
2964 CAMLprim value
2965 ocaml_guestfs_cp_a (value gv, value srcv, value destv)
2966 {
2967   CAMLparam3 (gv, srcv, destv);
2968   CAMLlocal1 (rv);
2969
2970   guestfs_h *g = Guestfs_val (gv);
2971   if (g == NULL)
2972     caml_failwith ("cp_a: used handle after closing it");
2973
2974   const char *src = String_val (srcv);
2975   const char *dest = String_val (destv);
2976   int r;
2977
2978   caml_enter_blocking_section ();
2979   r = guestfs_cp_a (g, src, dest);
2980   caml_leave_blocking_section ();
2981   if (r == -1)
2982     ocaml_guestfs_raise_error (g, "cp_a");
2983
2984   rv = Val_unit;
2985   CAMLreturn (rv);
2986 }
2987
2988 CAMLprim value
2989 ocaml_guestfs_mv (value gv, value srcv, value destv)
2990 {
2991   CAMLparam3 (gv, srcv, destv);
2992   CAMLlocal1 (rv);
2993
2994   guestfs_h *g = Guestfs_val (gv);
2995   if (g == NULL)
2996     caml_failwith ("mv: used handle after closing it");
2997
2998   const char *src = String_val (srcv);
2999   const char *dest = String_val (destv);
3000   int r;
3001
3002   caml_enter_blocking_section ();
3003   r = guestfs_mv (g, src, dest);
3004   caml_leave_blocking_section ();
3005   if (r == -1)
3006     ocaml_guestfs_raise_error (g, "mv");
3007
3008   rv = Val_unit;
3009   CAMLreturn (rv);
3010 }
3011
3012 CAMLprim value
3013 ocaml_guestfs_drop_caches (value gv, value whattodropv)
3014 {
3015   CAMLparam2 (gv, whattodropv);
3016   CAMLlocal1 (rv);
3017
3018   guestfs_h *g = Guestfs_val (gv);
3019   if (g == NULL)
3020     caml_failwith ("drop_caches: used handle after closing it");
3021
3022   int whattodrop = Int_val (whattodropv);
3023   int r;
3024
3025   caml_enter_blocking_section ();
3026   r = guestfs_drop_caches (g, whattodrop);
3027   caml_leave_blocking_section ();
3028   if (r == -1)
3029     ocaml_guestfs_raise_error (g, "drop_caches");
3030
3031   rv = Val_unit;
3032   CAMLreturn (rv);
3033 }
3034
3035 CAMLprim value
3036 ocaml_guestfs_dmesg (value gv)
3037 {
3038   CAMLparam1 (gv);
3039   CAMLlocal1 (rv);
3040
3041   guestfs_h *g = Guestfs_val (gv);
3042   if (g == NULL)
3043     caml_failwith ("dmesg: used handle after closing it");
3044
3045   char *r;
3046
3047   caml_enter_blocking_section ();
3048   r = guestfs_dmesg (g);
3049   caml_leave_blocking_section ();
3050   if (r == NULL)
3051     ocaml_guestfs_raise_error (g, "dmesg");
3052
3053   rv = caml_copy_string (r);
3054   free (r);
3055   CAMLreturn (rv);
3056 }
3057
3058 CAMLprim value
3059 ocaml_guestfs_ping_daemon (value gv)
3060 {
3061   CAMLparam1 (gv);
3062   CAMLlocal1 (rv);
3063
3064   guestfs_h *g = Guestfs_val (gv);
3065   if (g == NULL)
3066     caml_failwith ("ping_daemon: used handle after closing it");
3067
3068   int r;
3069
3070   caml_enter_blocking_section ();
3071   r = guestfs_ping_daemon (g);
3072   caml_leave_blocking_section ();
3073   if (r == -1)
3074     ocaml_guestfs_raise_error (g, "ping_daemon");
3075
3076   rv = Val_unit;
3077   CAMLreturn (rv);
3078 }
3079
3080 CAMLprim value
3081 ocaml_guestfs_equal (value gv, value file1v, value file2v)
3082 {
3083   CAMLparam3 (gv, file1v, file2v);
3084   CAMLlocal1 (rv);
3085
3086   guestfs_h *g = Guestfs_val (gv);
3087   if (g == NULL)
3088     caml_failwith ("equal: used handle after closing it");
3089
3090   const char *file1 = String_val (file1v);
3091   const char *file2 = String_val (file2v);
3092   int r;
3093
3094   caml_enter_blocking_section ();
3095   r = guestfs_equal (g, file1, file2);
3096   caml_leave_blocking_section ();
3097   if (r == -1)
3098     ocaml_guestfs_raise_error (g, "equal");
3099
3100   rv = Val_bool (r);
3101   CAMLreturn (rv);
3102 }
3103
3104 CAMLprim value
3105 ocaml_guestfs_strings (value gv, value pathv)
3106 {
3107   CAMLparam2 (gv, pathv);
3108   CAMLlocal1 (rv);
3109
3110   guestfs_h *g = Guestfs_val (gv);
3111   if (g == NULL)
3112     caml_failwith ("strings: used handle after closing it");
3113
3114   const char *path = String_val (pathv);
3115   int i;
3116   char **r;
3117
3118   caml_enter_blocking_section ();
3119   r = guestfs_strings (g, path);
3120   caml_leave_blocking_section ();
3121   if (r == NULL)
3122     ocaml_guestfs_raise_error (g, "strings");
3123
3124   rv = caml_copy_string_array ((const char **) r);
3125   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3126   free (r);
3127   CAMLreturn (rv);
3128 }
3129
3130 CAMLprim value
3131 ocaml_guestfs_strings_e (value gv, value encodingv, value pathv)
3132 {
3133   CAMLparam3 (gv, encodingv, pathv);
3134   CAMLlocal1 (rv);
3135
3136   guestfs_h *g = Guestfs_val (gv);
3137   if (g == NULL)
3138     caml_failwith ("strings_e: used handle after closing it");
3139
3140   const char *encoding = String_val (encodingv);
3141   const char *path = String_val (pathv);
3142   int i;
3143   char **r;
3144
3145   caml_enter_blocking_section ();
3146   r = guestfs_strings_e (g, encoding, path);
3147   caml_leave_blocking_section ();
3148   if (r == NULL)
3149     ocaml_guestfs_raise_error (g, "strings_e");
3150
3151   rv = caml_copy_string_array ((const char **) r);
3152   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3153   free (r);
3154   CAMLreturn (rv);
3155 }
3156
3157 CAMLprim value
3158 ocaml_guestfs_hexdump (value gv, value pathv)
3159 {
3160   CAMLparam2 (gv, pathv);
3161   CAMLlocal1 (rv);
3162
3163   guestfs_h *g = Guestfs_val (gv);
3164   if (g == NULL)
3165     caml_failwith ("hexdump: used handle after closing it");
3166
3167   const char *path = String_val (pathv);
3168   char *r;
3169
3170   caml_enter_blocking_section ();
3171   r = guestfs_hexdump (g, path);
3172   caml_leave_blocking_section ();
3173   if (r == NULL)
3174     ocaml_guestfs_raise_error (g, "hexdump");
3175
3176   rv = caml_copy_string (r);
3177   free (r);
3178   CAMLreturn (rv);
3179 }
3180
3181 CAMLprim value
3182 ocaml_guestfs_zerofree (value gv, value devicev)
3183 {
3184   CAMLparam2 (gv, devicev);
3185   CAMLlocal1 (rv);
3186
3187   guestfs_h *g = Guestfs_val (gv);
3188   if (g == NULL)
3189     caml_failwith ("zerofree: used handle after closing it");
3190
3191   const char *device = String_val (devicev);
3192   int r;
3193
3194   caml_enter_blocking_section ();
3195   r = guestfs_zerofree (g, device);
3196   caml_leave_blocking_section ();
3197   if (r == -1)
3198     ocaml_guestfs_raise_error (g, "zerofree");
3199
3200   rv = Val_unit;
3201   CAMLreturn (rv);
3202 }
3203
3204 CAMLprim value
3205 ocaml_guestfs_pvresize (value gv, value devicev)
3206 {
3207   CAMLparam2 (gv, devicev);
3208   CAMLlocal1 (rv);
3209
3210   guestfs_h *g = Guestfs_val (gv);
3211   if (g == NULL)
3212     caml_failwith ("pvresize: used handle after closing it");
3213
3214   const char *device = String_val (devicev);
3215   int r;
3216
3217   caml_enter_blocking_section ();
3218   r = guestfs_pvresize (g, device);
3219   caml_leave_blocking_section ();
3220   if (r == -1)
3221     ocaml_guestfs_raise_error (g, "pvresize");
3222
3223   rv = Val_unit;
3224   CAMLreturn (rv);
3225 }
3226
3227 CAMLprim value
3228 ocaml_guestfs_sfdisk_N (value gv, value devicev, value nv, value cylsv, value headsv, value sectorsv, value linev)
3229 {
3230   CAMLparam5 (gv, devicev, nv, cylsv, headsv);
3231   CAMLxparam2 (sectorsv, linev);
3232   CAMLlocal1 (rv);
3233
3234   guestfs_h *g = Guestfs_val (gv);
3235   if (g == NULL)
3236     caml_failwith ("sfdisk_N: used handle after closing it");
3237
3238   const char *device = String_val (devicev);
3239   int n = Int_val (nv);
3240   int cyls = Int_val (cylsv);
3241   int heads = Int_val (headsv);
3242   int sectors = Int_val (sectorsv);
3243   const char *line = String_val (linev);
3244   int r;
3245
3246   caml_enter_blocking_section ();
3247   r = guestfs_sfdisk_N (g, device, n, cyls, heads, sectors, line);
3248   caml_leave_blocking_section ();
3249   if (r == -1)
3250     ocaml_guestfs_raise_error (g, "sfdisk_N");
3251
3252   rv = Val_unit;
3253   CAMLreturn (rv);
3254 }
3255
3256 CAMLprim value
3257 ocaml_guestfs_sfdisk_N_byte (value *argv, int argn)
3258 {
3259   return ocaml_guestfs_sfdisk_N (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
3260 }
3261
3262 CAMLprim value
3263 ocaml_guestfs_sfdisk_l (value gv, value devicev)
3264 {
3265   CAMLparam2 (gv, devicev);
3266   CAMLlocal1 (rv);
3267
3268   guestfs_h *g = Guestfs_val (gv);
3269   if (g == NULL)
3270     caml_failwith ("sfdisk_l: used handle after closing it");
3271
3272   const char *device = String_val (devicev);
3273   char *r;
3274
3275   caml_enter_blocking_section ();
3276   r = guestfs_sfdisk_l (g, device);
3277   caml_leave_blocking_section ();
3278   if (r == NULL)
3279     ocaml_guestfs_raise_error (g, "sfdisk_l");
3280
3281   rv = caml_copy_string (r);
3282   free (r);
3283   CAMLreturn (rv);
3284 }
3285
3286 CAMLprim value
3287 ocaml_guestfs_sfdisk_kernel_geometry (value gv, value devicev)
3288 {
3289   CAMLparam2 (gv, devicev);
3290   CAMLlocal1 (rv);
3291
3292   guestfs_h *g = Guestfs_val (gv);
3293   if (g == NULL)
3294     caml_failwith ("sfdisk_kernel_geometry: used handle after closing it");
3295
3296   const char *device = String_val (devicev);
3297   char *r;
3298
3299   caml_enter_blocking_section ();
3300   r = guestfs_sfdisk_kernel_geometry (g, device);
3301   caml_leave_blocking_section ();
3302   if (r == NULL)
3303     ocaml_guestfs_raise_error (g, "sfdisk_kernel_geometry");
3304
3305   rv = caml_copy_string (r);
3306   free (r);
3307   CAMLreturn (rv);
3308 }
3309
3310 CAMLprim value
3311 ocaml_guestfs_sfdisk_disk_geometry (value gv, value devicev)
3312 {
3313   CAMLparam2 (gv, devicev);
3314   CAMLlocal1 (rv);
3315
3316   guestfs_h *g = Guestfs_val (gv);
3317   if (g == NULL)
3318     caml_failwith ("sfdisk_disk_geometry: used handle after closing it");
3319
3320   const char *device = String_val (devicev);
3321   char *r;
3322
3323   caml_enter_blocking_section ();
3324   r = guestfs_sfdisk_disk_geometry (g, device);
3325   caml_leave_blocking_section ();
3326   if (r == NULL)
3327     ocaml_guestfs_raise_error (g, "sfdisk_disk_geometry");
3328
3329   rv = caml_copy_string (r);
3330   free (r);
3331   CAMLreturn (rv);
3332 }
3333
3334 CAMLprim value
3335 ocaml_guestfs_vg_activate_all (value gv, value activatev)
3336 {
3337   CAMLparam2 (gv, activatev);
3338   CAMLlocal1 (rv);
3339
3340   guestfs_h *g = Guestfs_val (gv);
3341   if (g == NULL)
3342     caml_failwith ("vg_activate_all: used handle after closing it");
3343
3344   int activate = Bool_val (activatev);
3345   int r;
3346
3347   caml_enter_blocking_section ();
3348   r = guestfs_vg_activate_all (g, activate);
3349   caml_leave_blocking_section ();
3350   if (r == -1)
3351     ocaml_guestfs_raise_error (g, "vg_activate_all");
3352
3353   rv = Val_unit;
3354   CAMLreturn (rv);
3355 }
3356
3357 CAMLprim value
3358 ocaml_guestfs_vg_activate (value gv, value activatev, value volgroupsv)
3359 {
3360   CAMLparam3 (gv, activatev, volgroupsv);
3361   CAMLlocal1 (rv);
3362
3363   guestfs_h *g = Guestfs_val (gv);
3364   if (g == NULL)
3365     caml_failwith ("vg_activate: used handle after closing it");
3366
3367   int activate = Bool_val (activatev);
3368   char **volgroups = ocaml_guestfs_strings_val (g, volgroupsv);
3369   int r;
3370
3371   caml_enter_blocking_section ();
3372   r = guestfs_vg_activate (g, activate, volgroups);
3373   caml_leave_blocking_section ();
3374   ocaml_guestfs_free_strings (volgroups);
3375   if (r == -1)
3376     ocaml_guestfs_raise_error (g, "vg_activate");
3377
3378   rv = Val_unit;
3379   CAMLreturn (rv);
3380 }
3381
3382 CAMLprim value
3383 ocaml_guestfs_lvresize (value gv, value devicev, value mbytesv)
3384 {
3385   CAMLparam3 (gv, devicev, mbytesv);
3386   CAMLlocal1 (rv);
3387
3388   guestfs_h *g = Guestfs_val (gv);
3389   if (g == NULL)
3390     caml_failwith ("lvresize: used handle after closing it");
3391
3392   const char *device = String_val (devicev);
3393   int mbytes = Int_val (mbytesv);
3394   int r;
3395
3396   caml_enter_blocking_section ();
3397   r = guestfs_lvresize (g, device, mbytes);
3398   caml_leave_blocking_section ();
3399   if (r == -1)
3400     ocaml_guestfs_raise_error (g, "lvresize");
3401
3402   rv = Val_unit;
3403   CAMLreturn (rv);
3404 }
3405
3406 CAMLprim value
3407 ocaml_guestfs_resize2fs (value gv, value devicev)
3408 {
3409   CAMLparam2 (gv, devicev);
3410   CAMLlocal1 (rv);
3411
3412   guestfs_h *g = Guestfs_val (gv);
3413   if (g == NULL)
3414     caml_failwith ("resize2fs: used handle after closing it");
3415
3416   const char *device = String_val (devicev);
3417   int r;
3418
3419   caml_enter_blocking_section ();
3420   r = guestfs_resize2fs (g, device);
3421   caml_leave_blocking_section ();
3422   if (r == -1)
3423     ocaml_guestfs_raise_error (g, "resize2fs");
3424
3425   rv = Val_unit;
3426   CAMLreturn (rv);
3427 }
3428
3429 CAMLprim value
3430 ocaml_guestfs_find (value gv, value directoryv)
3431 {
3432   CAMLparam2 (gv, directoryv);
3433   CAMLlocal1 (rv);
3434
3435   guestfs_h *g = Guestfs_val (gv);
3436   if (g == NULL)
3437     caml_failwith ("find: used handle after closing it");
3438
3439   const char *directory = String_val (directoryv);
3440   int i;
3441   char **r;
3442
3443   caml_enter_blocking_section ();
3444   r = guestfs_find (g, directory);
3445   caml_leave_blocking_section ();
3446   if (r == NULL)
3447     ocaml_guestfs_raise_error (g, "find");
3448
3449   rv = caml_copy_string_array ((const char **) r);
3450   for (i = 0; r[i] != NULL; ++i) free (r[i]);
3451   free (r);
3452   CAMLreturn (rv);
3453 }
3454