Generated code for 'checksum' 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_path (value gv, value pathv)
470 {
471   CAMLparam2 (gv, pathv);
472   CAMLlocal1 (rv);
473
474   guestfs_h *g = Guestfs_val (gv);
475   if (g == NULL)
476     caml_failwith ("set_path: used handle after closing it");
477
478   const char *path = String_val (pathv);
479   int r;
480
481   caml_enter_blocking_section ();
482   r = guestfs_set_path (g, path);
483   caml_leave_blocking_section ();
484   if (r == -1)
485     ocaml_guestfs_raise_error (g, "set_path");
486
487   rv = Val_unit;
488   CAMLreturn (rv);
489 }
490
491 CAMLprim value
492 ocaml_guestfs_get_path (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_path: used handle after closing it");
500
501   const char *r;
502
503   caml_enter_blocking_section ();
504   r = guestfs_get_path (g);
505   caml_leave_blocking_section ();
506   if (r == NULL)
507     ocaml_guestfs_raise_error (g, "get_path");
508
509   rv = caml_copy_string (r);
510   CAMLreturn (rv);
511 }
512
513 CAMLprim value
514 ocaml_guestfs_set_autosync (value gv, value autosyncv)
515 {
516   CAMLparam2 (gv, autosyncv);
517   CAMLlocal1 (rv);
518
519   guestfs_h *g = Guestfs_val (gv);
520   if (g == NULL)
521     caml_failwith ("set_autosync: used handle after closing it");
522
523   int autosync = Bool_val (autosyncv);
524   int r;
525
526   caml_enter_blocking_section ();
527   r = guestfs_set_autosync (g, autosync);
528   caml_leave_blocking_section ();
529   if (r == -1)
530     ocaml_guestfs_raise_error (g, "set_autosync");
531
532   rv = Val_unit;
533   CAMLreturn (rv);
534 }
535
536 CAMLprim value
537 ocaml_guestfs_get_autosync (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_autosync: used handle after closing it");
545
546   int r;
547
548   caml_enter_blocking_section ();
549   r = guestfs_get_autosync (g);
550   caml_leave_blocking_section ();
551   if (r == -1)
552     ocaml_guestfs_raise_error (g, "get_autosync");
553
554   rv = Val_bool (r);
555   CAMLreturn (rv);
556 }
557
558 CAMLprim value
559 ocaml_guestfs_set_verbose (value gv, value verbosev)
560 {
561   CAMLparam2 (gv, verbosev);
562   CAMLlocal1 (rv);
563
564   guestfs_h *g = Guestfs_val (gv);
565   if (g == NULL)
566     caml_failwith ("set_verbose: used handle after closing it");
567
568   int verbose = Bool_val (verbosev);
569   int r;
570
571   caml_enter_blocking_section ();
572   r = guestfs_set_verbose (g, verbose);
573   caml_leave_blocking_section ();
574   if (r == -1)
575     ocaml_guestfs_raise_error (g, "set_verbose");
576
577   rv = Val_unit;
578   CAMLreturn (rv);
579 }
580
581 CAMLprim value
582 ocaml_guestfs_get_verbose (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_verbose: used handle after closing it");
590
591   int r;
592
593   caml_enter_blocking_section ();
594   r = guestfs_get_verbose (g);
595   caml_leave_blocking_section ();
596   if (r == -1)
597     ocaml_guestfs_raise_error (g, "get_verbose");
598
599   rv = Val_bool (r);
600   CAMLreturn (rv);
601 }
602
603 CAMLprim value
604 ocaml_guestfs_is_ready (value gv)
605 {
606   CAMLparam1 (gv);
607   CAMLlocal1 (rv);
608
609   guestfs_h *g = Guestfs_val (gv);
610   if (g == NULL)
611     caml_failwith ("is_ready: used handle after closing it");
612
613   int r;
614
615   caml_enter_blocking_section ();
616   r = guestfs_is_ready (g);
617   caml_leave_blocking_section ();
618   if (r == -1)
619     ocaml_guestfs_raise_error (g, "is_ready");
620
621   rv = Val_bool (r);
622   CAMLreturn (rv);
623 }
624
625 CAMLprim value
626 ocaml_guestfs_is_config (value gv)
627 {
628   CAMLparam1 (gv);
629   CAMLlocal1 (rv);
630
631   guestfs_h *g = Guestfs_val (gv);
632   if (g == NULL)
633     caml_failwith ("is_config: used handle after closing it");
634
635   int r;
636
637   caml_enter_blocking_section ();
638   r = guestfs_is_config (g);
639   caml_leave_blocking_section ();
640   if (r == -1)
641     ocaml_guestfs_raise_error (g, "is_config");
642
643   rv = Val_bool (r);
644   CAMLreturn (rv);
645 }
646
647 CAMLprim value
648 ocaml_guestfs_is_launching (value gv)
649 {
650   CAMLparam1 (gv);
651   CAMLlocal1 (rv);
652
653   guestfs_h *g = Guestfs_val (gv);
654   if (g == NULL)
655     caml_failwith ("is_launching: used handle after closing it");
656
657   int r;
658
659   caml_enter_blocking_section ();
660   r = guestfs_is_launching (g);
661   caml_leave_blocking_section ();
662   if (r == -1)
663     ocaml_guestfs_raise_error (g, "is_launching");
664
665   rv = Val_bool (r);
666   CAMLreturn (rv);
667 }
668
669 CAMLprim value
670 ocaml_guestfs_is_busy (value gv)
671 {
672   CAMLparam1 (gv);
673   CAMLlocal1 (rv);
674
675   guestfs_h *g = Guestfs_val (gv);
676   if (g == NULL)
677     caml_failwith ("is_busy: used handle after closing it");
678
679   int r;
680
681   caml_enter_blocking_section ();
682   r = guestfs_is_busy (g);
683   caml_leave_blocking_section ();
684   if (r == -1)
685     ocaml_guestfs_raise_error (g, "is_busy");
686
687   rv = Val_bool (r);
688   CAMLreturn (rv);
689 }
690
691 CAMLprim value
692 ocaml_guestfs_get_state (value gv)
693 {
694   CAMLparam1 (gv);
695   CAMLlocal1 (rv);
696
697   guestfs_h *g = Guestfs_val (gv);
698   if (g == NULL)
699     caml_failwith ("get_state: used handle after closing it");
700
701   int r;
702
703   caml_enter_blocking_section ();
704   r = guestfs_get_state (g);
705   caml_leave_blocking_section ();
706   if (r == -1)
707     ocaml_guestfs_raise_error (g, "get_state");
708
709   rv = Val_int (r);
710   CAMLreturn (rv);
711 }
712
713 CAMLprim value
714 ocaml_guestfs_set_busy (value gv)
715 {
716   CAMLparam1 (gv);
717   CAMLlocal1 (rv);
718
719   guestfs_h *g = Guestfs_val (gv);
720   if (g == NULL)
721     caml_failwith ("set_busy: used handle after closing it");
722
723   int r;
724
725   caml_enter_blocking_section ();
726   r = guestfs_set_busy (g);
727   caml_leave_blocking_section ();
728   if (r == -1)
729     ocaml_guestfs_raise_error (g, "set_busy");
730
731   rv = Val_unit;
732   CAMLreturn (rv);
733 }
734
735 CAMLprim value
736 ocaml_guestfs_set_ready (value gv)
737 {
738   CAMLparam1 (gv);
739   CAMLlocal1 (rv);
740
741   guestfs_h *g = Guestfs_val (gv);
742   if (g == NULL)
743     caml_failwith ("set_ready: used handle after closing it");
744
745   int r;
746
747   caml_enter_blocking_section ();
748   r = guestfs_set_ready (g);
749   caml_leave_blocking_section ();
750   if (r == -1)
751     ocaml_guestfs_raise_error (g, "set_ready");
752
753   rv = Val_unit;
754   CAMLreturn (rv);
755 }
756
757 CAMLprim value
758 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
759 {
760   CAMLparam3 (gv, devicev, mountpointv);
761   CAMLlocal1 (rv);
762
763   guestfs_h *g = Guestfs_val (gv);
764   if (g == NULL)
765     caml_failwith ("mount: used handle after closing it");
766
767   const char *device = String_val (devicev);
768   const char *mountpoint = String_val (mountpointv);
769   int r;
770
771   caml_enter_blocking_section ();
772   r = guestfs_mount (g, device, mountpoint);
773   caml_leave_blocking_section ();
774   if (r == -1)
775     ocaml_guestfs_raise_error (g, "mount");
776
777   rv = Val_unit;
778   CAMLreturn (rv);
779 }
780
781 CAMLprim value
782 ocaml_guestfs_sync (value gv)
783 {
784   CAMLparam1 (gv);
785   CAMLlocal1 (rv);
786
787   guestfs_h *g = Guestfs_val (gv);
788   if (g == NULL)
789     caml_failwith ("sync: used handle after closing it");
790
791   int r;
792
793   caml_enter_blocking_section ();
794   r = guestfs_sync (g);
795   caml_leave_blocking_section ();
796   if (r == -1)
797     ocaml_guestfs_raise_error (g, "sync");
798
799   rv = Val_unit;
800   CAMLreturn (rv);
801 }
802
803 CAMLprim value
804 ocaml_guestfs_touch (value gv, value pathv)
805 {
806   CAMLparam2 (gv, pathv);
807   CAMLlocal1 (rv);
808
809   guestfs_h *g = Guestfs_val (gv);
810   if (g == NULL)
811     caml_failwith ("touch: used handle after closing it");
812
813   const char *path = String_val (pathv);
814   int r;
815
816   caml_enter_blocking_section ();
817   r = guestfs_touch (g, path);
818   caml_leave_blocking_section ();
819   if (r == -1)
820     ocaml_guestfs_raise_error (g, "touch");
821
822   rv = Val_unit;
823   CAMLreturn (rv);
824 }
825
826 CAMLprim value
827 ocaml_guestfs_cat (value gv, value pathv)
828 {
829   CAMLparam2 (gv, pathv);
830   CAMLlocal1 (rv);
831
832   guestfs_h *g = Guestfs_val (gv);
833   if (g == NULL)
834     caml_failwith ("cat: used handle after closing it");
835
836   const char *path = String_val (pathv);
837   char *r;
838
839   caml_enter_blocking_section ();
840   r = guestfs_cat (g, path);
841   caml_leave_blocking_section ();
842   if (r == NULL)
843     ocaml_guestfs_raise_error (g, "cat");
844
845   rv = caml_copy_string (r);
846   free (r);
847   CAMLreturn (rv);
848 }
849
850 CAMLprim value
851 ocaml_guestfs_ll (value gv, value directoryv)
852 {
853   CAMLparam2 (gv, directoryv);
854   CAMLlocal1 (rv);
855
856   guestfs_h *g = Guestfs_val (gv);
857   if (g == NULL)
858     caml_failwith ("ll: used handle after closing it");
859
860   const char *directory = String_val (directoryv);
861   char *r;
862
863   caml_enter_blocking_section ();
864   r = guestfs_ll (g, directory);
865   caml_leave_blocking_section ();
866   if (r == NULL)
867     ocaml_guestfs_raise_error (g, "ll");
868
869   rv = caml_copy_string (r);
870   free (r);
871   CAMLreturn (rv);
872 }
873
874 CAMLprim value
875 ocaml_guestfs_ls (value gv, value directoryv)
876 {
877   CAMLparam2 (gv, directoryv);
878   CAMLlocal1 (rv);
879
880   guestfs_h *g = Guestfs_val (gv);
881   if (g == NULL)
882     caml_failwith ("ls: used handle after closing it");
883
884   const char *directory = String_val (directoryv);
885   int i;
886   char **r;
887
888   caml_enter_blocking_section ();
889   r = guestfs_ls (g, directory);
890   caml_leave_blocking_section ();
891   if (r == NULL)
892     ocaml_guestfs_raise_error (g, "ls");
893
894   rv = caml_copy_string_array ((const char **) r);
895   for (i = 0; r[i] != NULL; ++i) free (r[i]);
896   free (r);
897   CAMLreturn (rv);
898 }
899
900 CAMLprim value
901 ocaml_guestfs_list_devices (value gv)
902 {
903   CAMLparam1 (gv);
904   CAMLlocal1 (rv);
905
906   guestfs_h *g = Guestfs_val (gv);
907   if (g == NULL)
908     caml_failwith ("list_devices: used handle after closing it");
909
910   int i;
911   char **r;
912
913   caml_enter_blocking_section ();
914   r = guestfs_list_devices (g);
915   caml_leave_blocking_section ();
916   if (r == NULL)
917     ocaml_guestfs_raise_error (g, "list_devices");
918
919   rv = caml_copy_string_array ((const char **) r);
920   for (i = 0; r[i] != NULL; ++i) free (r[i]);
921   free (r);
922   CAMLreturn (rv);
923 }
924
925 CAMLprim value
926 ocaml_guestfs_list_partitions (value gv)
927 {
928   CAMLparam1 (gv);
929   CAMLlocal1 (rv);
930
931   guestfs_h *g = Guestfs_val (gv);
932   if (g == NULL)
933     caml_failwith ("list_partitions: used handle after closing it");
934
935   int i;
936   char **r;
937
938   caml_enter_blocking_section ();
939   r = guestfs_list_partitions (g);
940   caml_leave_blocking_section ();
941   if (r == NULL)
942     ocaml_guestfs_raise_error (g, "list_partitions");
943
944   rv = caml_copy_string_array ((const char **) r);
945   for (i = 0; r[i] != NULL; ++i) free (r[i]);
946   free (r);
947   CAMLreturn (rv);
948 }
949
950 CAMLprim value
951 ocaml_guestfs_pvs (value gv)
952 {
953   CAMLparam1 (gv);
954   CAMLlocal1 (rv);
955
956   guestfs_h *g = Guestfs_val (gv);
957   if (g == NULL)
958     caml_failwith ("pvs: used handle after closing it");
959
960   int i;
961   char **r;
962
963   caml_enter_blocking_section ();
964   r = guestfs_pvs (g);
965   caml_leave_blocking_section ();
966   if (r == NULL)
967     ocaml_guestfs_raise_error (g, "pvs");
968
969   rv = caml_copy_string_array ((const char **) r);
970   for (i = 0; r[i] != NULL; ++i) free (r[i]);
971   free (r);
972   CAMLreturn (rv);
973 }
974
975 CAMLprim value
976 ocaml_guestfs_vgs (value gv)
977 {
978   CAMLparam1 (gv);
979   CAMLlocal1 (rv);
980
981   guestfs_h *g = Guestfs_val (gv);
982   if (g == NULL)
983     caml_failwith ("vgs: used handle after closing it");
984
985   int i;
986   char **r;
987
988   caml_enter_blocking_section ();
989   r = guestfs_vgs (g);
990   caml_leave_blocking_section ();
991   if (r == NULL)
992     ocaml_guestfs_raise_error (g, "vgs");
993
994   rv = caml_copy_string_array ((const char **) r);
995   for (i = 0; r[i] != NULL; ++i) free (r[i]);
996   free (r);
997   CAMLreturn (rv);
998 }
999
1000 CAMLprim value
1001 ocaml_guestfs_lvs (value gv)
1002 {
1003   CAMLparam1 (gv);
1004   CAMLlocal1 (rv);
1005
1006   guestfs_h *g = Guestfs_val (gv);
1007   if (g == NULL)
1008     caml_failwith ("lvs: used handle after closing it");
1009
1010   int i;
1011   char **r;
1012
1013   caml_enter_blocking_section ();
1014   r = guestfs_lvs (g);
1015   caml_leave_blocking_section ();
1016   if (r == NULL)
1017     ocaml_guestfs_raise_error (g, "lvs");
1018
1019   rv = caml_copy_string_array ((const char **) r);
1020   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1021   free (r);
1022   CAMLreturn (rv);
1023 }
1024
1025 CAMLprim value
1026 ocaml_guestfs_pvs_full (value gv)
1027 {
1028   CAMLparam1 (gv);
1029   CAMLlocal1 (rv);
1030
1031   guestfs_h *g = Guestfs_val (gv);
1032   if (g == NULL)
1033     caml_failwith ("pvs_full: used handle after closing it");
1034
1035   struct guestfs_lvm_pv_list *r;
1036
1037   caml_enter_blocking_section ();
1038   r = guestfs_pvs_full (g);
1039   caml_leave_blocking_section ();
1040   if (r == NULL)
1041     ocaml_guestfs_raise_error (g, "pvs_full");
1042
1043   rv = copy_lvm_pv_list (r);
1044   guestfs_free_lvm_pv_list (r);
1045   CAMLreturn (rv);
1046 }
1047
1048 CAMLprim value
1049 ocaml_guestfs_vgs_full (value gv)
1050 {
1051   CAMLparam1 (gv);
1052   CAMLlocal1 (rv);
1053
1054   guestfs_h *g = Guestfs_val (gv);
1055   if (g == NULL)
1056     caml_failwith ("vgs_full: used handle after closing it");
1057
1058   struct guestfs_lvm_vg_list *r;
1059
1060   caml_enter_blocking_section ();
1061   r = guestfs_vgs_full (g);
1062   caml_leave_blocking_section ();
1063   if (r == NULL)
1064     ocaml_guestfs_raise_error (g, "vgs_full");
1065
1066   rv = copy_lvm_vg_list (r);
1067   guestfs_free_lvm_vg_list (r);
1068   CAMLreturn (rv);
1069 }
1070
1071 CAMLprim value
1072 ocaml_guestfs_lvs_full (value gv)
1073 {
1074   CAMLparam1 (gv);
1075   CAMLlocal1 (rv);
1076
1077   guestfs_h *g = Guestfs_val (gv);
1078   if (g == NULL)
1079     caml_failwith ("lvs_full: used handle after closing it");
1080
1081   struct guestfs_lvm_lv_list *r;
1082
1083   caml_enter_blocking_section ();
1084   r = guestfs_lvs_full (g);
1085   caml_leave_blocking_section ();
1086   if (r == NULL)
1087     ocaml_guestfs_raise_error (g, "lvs_full");
1088
1089   rv = copy_lvm_lv_list (r);
1090   guestfs_free_lvm_lv_list (r);
1091   CAMLreturn (rv);
1092 }
1093
1094 CAMLprim value
1095 ocaml_guestfs_read_lines (value gv, value pathv)
1096 {
1097   CAMLparam2 (gv, pathv);
1098   CAMLlocal1 (rv);
1099
1100   guestfs_h *g = Guestfs_val (gv);
1101   if (g == NULL)
1102     caml_failwith ("read_lines: used handle after closing it");
1103
1104   const char *path = String_val (pathv);
1105   int i;
1106   char **r;
1107
1108   caml_enter_blocking_section ();
1109   r = guestfs_read_lines (g, path);
1110   caml_leave_blocking_section ();
1111   if (r == NULL)
1112     ocaml_guestfs_raise_error (g, "read_lines");
1113
1114   rv = caml_copy_string_array ((const char **) r);
1115   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1116   free (r);
1117   CAMLreturn (rv);
1118 }
1119
1120 CAMLprim value
1121 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
1122 {
1123   CAMLparam3 (gv, rootv, flagsv);
1124   CAMLlocal1 (rv);
1125
1126   guestfs_h *g = Guestfs_val (gv);
1127   if (g == NULL)
1128     caml_failwith ("aug_init: used handle after closing it");
1129
1130   const char *root = String_val (rootv);
1131   int flags = Int_val (flagsv);
1132   int r;
1133
1134   caml_enter_blocking_section ();
1135   r = guestfs_aug_init (g, root, flags);
1136   caml_leave_blocking_section ();
1137   if (r == -1)
1138     ocaml_guestfs_raise_error (g, "aug_init");
1139
1140   rv = Val_unit;
1141   CAMLreturn (rv);
1142 }
1143
1144 CAMLprim value
1145 ocaml_guestfs_aug_close (value gv)
1146 {
1147   CAMLparam1 (gv);
1148   CAMLlocal1 (rv);
1149
1150   guestfs_h *g = Guestfs_val (gv);
1151   if (g == NULL)
1152     caml_failwith ("aug_close: used handle after closing it");
1153
1154   int r;
1155
1156   caml_enter_blocking_section ();
1157   r = guestfs_aug_close (g);
1158   caml_leave_blocking_section ();
1159   if (r == -1)
1160     ocaml_guestfs_raise_error (g, "aug_close");
1161
1162   rv = Val_unit;
1163   CAMLreturn (rv);
1164 }
1165
1166 CAMLprim value
1167 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
1168 {
1169   CAMLparam3 (gv, namev, exprv);
1170   CAMLlocal1 (rv);
1171
1172   guestfs_h *g = Guestfs_val (gv);
1173   if (g == NULL)
1174     caml_failwith ("aug_defvar: used handle after closing it");
1175
1176   const char *name = String_val (namev);
1177   const char *expr =
1178     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
1179   int r;
1180
1181   caml_enter_blocking_section ();
1182   r = guestfs_aug_defvar (g, name, expr);
1183   caml_leave_blocking_section ();
1184   if (r == -1)
1185     ocaml_guestfs_raise_error (g, "aug_defvar");
1186
1187   rv = Val_int (r);
1188   CAMLreturn (rv);
1189 }
1190
1191 CAMLprim value
1192 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1193 {
1194   CAMLparam4 (gv, namev, exprv, valv);
1195   CAMLlocal1 (rv);
1196
1197   guestfs_h *g = Guestfs_val (gv);
1198   if (g == NULL)
1199     caml_failwith ("aug_defnode: used handle after closing it");
1200
1201   const char *name = String_val (namev);
1202   const char *expr = String_val (exprv);
1203   const char *val = String_val (valv);
1204   struct guestfs_int_bool *r;
1205
1206   caml_enter_blocking_section ();
1207   r = guestfs_aug_defnode (g, name, expr, val);
1208   caml_leave_blocking_section ();
1209   if (r == NULL)
1210     ocaml_guestfs_raise_error (g, "aug_defnode");
1211
1212   rv = caml_alloc (2, 0);
1213   Store_field (rv, 0, Val_int (r->i));
1214   Store_field (rv, 1, Val_bool (r->b));
1215   guestfs_free_int_bool (r);
1216   CAMLreturn (rv);
1217 }
1218
1219 CAMLprim value
1220 ocaml_guestfs_aug_get (value gv, value pathv)
1221 {
1222   CAMLparam2 (gv, pathv);
1223   CAMLlocal1 (rv);
1224
1225   guestfs_h *g = Guestfs_val (gv);
1226   if (g == NULL)
1227     caml_failwith ("aug_get: used handle after closing it");
1228
1229   const char *path = String_val (pathv);
1230   char *r;
1231
1232   caml_enter_blocking_section ();
1233   r = guestfs_aug_get (g, path);
1234   caml_leave_blocking_section ();
1235   if (r == NULL)
1236     ocaml_guestfs_raise_error (g, "aug_get");
1237
1238   rv = caml_copy_string (r);
1239   free (r);
1240   CAMLreturn (rv);
1241 }
1242
1243 CAMLprim value
1244 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
1245 {
1246   CAMLparam3 (gv, pathv, valv);
1247   CAMLlocal1 (rv);
1248
1249   guestfs_h *g = Guestfs_val (gv);
1250   if (g == NULL)
1251     caml_failwith ("aug_set: used handle after closing it");
1252
1253   const char *path = String_val (pathv);
1254   const char *val = String_val (valv);
1255   int r;
1256
1257   caml_enter_blocking_section ();
1258   r = guestfs_aug_set (g, path, val);
1259   caml_leave_blocking_section ();
1260   if (r == -1)
1261     ocaml_guestfs_raise_error (g, "aug_set");
1262
1263   rv = Val_unit;
1264   CAMLreturn (rv);
1265 }
1266
1267 CAMLprim value
1268 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1269 {
1270   CAMLparam4 (gv, pathv, labelv, beforev);
1271   CAMLlocal1 (rv);
1272
1273   guestfs_h *g = Guestfs_val (gv);
1274   if (g == NULL)
1275     caml_failwith ("aug_insert: used handle after closing it");
1276
1277   const char *path = String_val (pathv);
1278   const char *label = String_val (labelv);
1279   int before = Bool_val (beforev);
1280   int r;
1281
1282   caml_enter_blocking_section ();
1283   r = guestfs_aug_insert (g, path, label, before);
1284   caml_leave_blocking_section ();
1285   if (r == -1)
1286     ocaml_guestfs_raise_error (g, "aug_insert");
1287
1288   rv = Val_unit;
1289   CAMLreturn (rv);
1290 }
1291
1292 CAMLprim value
1293 ocaml_guestfs_aug_rm (value gv, value pathv)
1294 {
1295   CAMLparam2 (gv, pathv);
1296   CAMLlocal1 (rv);
1297
1298   guestfs_h *g = Guestfs_val (gv);
1299   if (g == NULL)
1300     caml_failwith ("aug_rm: used handle after closing it");
1301
1302   const char *path = String_val (pathv);
1303   int r;
1304
1305   caml_enter_blocking_section ();
1306   r = guestfs_aug_rm (g, path);
1307   caml_leave_blocking_section ();
1308   if (r == -1)
1309     ocaml_guestfs_raise_error (g, "aug_rm");
1310
1311   rv = Val_int (r);
1312   CAMLreturn (rv);
1313 }
1314
1315 CAMLprim value
1316 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1317 {
1318   CAMLparam3 (gv, srcv, destv);
1319   CAMLlocal1 (rv);
1320
1321   guestfs_h *g = Guestfs_val (gv);
1322   if (g == NULL)
1323     caml_failwith ("aug_mv: used handle after closing it");
1324
1325   const char *src = String_val (srcv);
1326   const char *dest = String_val (destv);
1327   int r;
1328
1329   caml_enter_blocking_section ();
1330   r = guestfs_aug_mv (g, src, dest);
1331   caml_leave_blocking_section ();
1332   if (r == -1)
1333     ocaml_guestfs_raise_error (g, "aug_mv");
1334
1335   rv = Val_unit;
1336   CAMLreturn (rv);
1337 }
1338
1339 CAMLprim value
1340 ocaml_guestfs_aug_match (value gv, value pathv)
1341 {
1342   CAMLparam2 (gv, pathv);
1343   CAMLlocal1 (rv);
1344
1345   guestfs_h *g = Guestfs_val (gv);
1346   if (g == NULL)
1347     caml_failwith ("aug_match: used handle after closing it");
1348
1349   const char *path = String_val (pathv);
1350   int i;
1351   char **r;
1352
1353   caml_enter_blocking_section ();
1354   r = guestfs_aug_match (g, path);
1355   caml_leave_blocking_section ();
1356   if (r == NULL)
1357     ocaml_guestfs_raise_error (g, "aug_match");
1358
1359   rv = caml_copy_string_array ((const char **) r);
1360   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1361   free (r);
1362   CAMLreturn (rv);
1363 }
1364
1365 CAMLprim value
1366 ocaml_guestfs_aug_save (value gv)
1367 {
1368   CAMLparam1 (gv);
1369   CAMLlocal1 (rv);
1370
1371   guestfs_h *g = Guestfs_val (gv);
1372   if (g == NULL)
1373     caml_failwith ("aug_save: used handle after closing it");
1374
1375   int r;
1376
1377   caml_enter_blocking_section ();
1378   r = guestfs_aug_save (g);
1379   caml_leave_blocking_section ();
1380   if (r == -1)
1381     ocaml_guestfs_raise_error (g, "aug_save");
1382
1383   rv = Val_unit;
1384   CAMLreturn (rv);
1385 }
1386
1387 CAMLprim value
1388 ocaml_guestfs_aug_load (value gv)
1389 {
1390   CAMLparam1 (gv);
1391   CAMLlocal1 (rv);
1392
1393   guestfs_h *g = Guestfs_val (gv);
1394   if (g == NULL)
1395     caml_failwith ("aug_load: used handle after closing it");
1396
1397   int r;
1398
1399   caml_enter_blocking_section ();
1400   r = guestfs_aug_load (g);
1401   caml_leave_blocking_section ();
1402   if (r == -1)
1403     ocaml_guestfs_raise_error (g, "aug_load");
1404
1405   rv = Val_unit;
1406   CAMLreturn (rv);
1407 }
1408
1409 CAMLprim value
1410 ocaml_guestfs_aug_ls (value gv, value pathv)
1411 {
1412   CAMLparam2 (gv, pathv);
1413   CAMLlocal1 (rv);
1414
1415   guestfs_h *g = Guestfs_val (gv);
1416   if (g == NULL)
1417     caml_failwith ("aug_ls: used handle after closing it");
1418
1419   const char *path = String_val (pathv);
1420   int i;
1421   char **r;
1422
1423   caml_enter_blocking_section ();
1424   r = guestfs_aug_ls (g, path);
1425   caml_leave_blocking_section ();
1426   if (r == NULL)
1427     ocaml_guestfs_raise_error (g, "aug_ls");
1428
1429   rv = caml_copy_string_array ((const char **) r);
1430   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1431   free (r);
1432   CAMLreturn (rv);
1433 }
1434
1435 CAMLprim value
1436 ocaml_guestfs_rm (value gv, value pathv)
1437 {
1438   CAMLparam2 (gv, pathv);
1439   CAMLlocal1 (rv);
1440
1441   guestfs_h *g = Guestfs_val (gv);
1442   if (g == NULL)
1443     caml_failwith ("rm: used handle after closing it");
1444
1445   const char *path = String_val (pathv);
1446   int r;
1447
1448   caml_enter_blocking_section ();
1449   r = guestfs_rm (g, path);
1450   caml_leave_blocking_section ();
1451   if (r == -1)
1452     ocaml_guestfs_raise_error (g, "rm");
1453
1454   rv = Val_unit;
1455   CAMLreturn (rv);
1456 }
1457
1458 CAMLprim value
1459 ocaml_guestfs_rmdir (value gv, value pathv)
1460 {
1461   CAMLparam2 (gv, pathv);
1462   CAMLlocal1 (rv);
1463
1464   guestfs_h *g = Guestfs_val (gv);
1465   if (g == NULL)
1466     caml_failwith ("rmdir: used handle after closing it");
1467
1468   const char *path = String_val (pathv);
1469   int r;
1470
1471   caml_enter_blocking_section ();
1472   r = guestfs_rmdir (g, path);
1473   caml_leave_blocking_section ();
1474   if (r == -1)
1475     ocaml_guestfs_raise_error (g, "rmdir");
1476
1477   rv = Val_unit;
1478   CAMLreturn (rv);
1479 }
1480
1481 CAMLprim value
1482 ocaml_guestfs_rm_rf (value gv, value pathv)
1483 {
1484   CAMLparam2 (gv, pathv);
1485   CAMLlocal1 (rv);
1486
1487   guestfs_h *g = Guestfs_val (gv);
1488   if (g == NULL)
1489     caml_failwith ("rm_rf: used handle after closing it");
1490
1491   const char *path = String_val (pathv);
1492   int r;
1493
1494   caml_enter_blocking_section ();
1495   r = guestfs_rm_rf (g, path);
1496   caml_leave_blocking_section ();
1497   if (r == -1)
1498     ocaml_guestfs_raise_error (g, "rm_rf");
1499
1500   rv = Val_unit;
1501   CAMLreturn (rv);
1502 }
1503
1504 CAMLprim value
1505 ocaml_guestfs_mkdir (value gv, value pathv)
1506 {
1507   CAMLparam2 (gv, pathv);
1508   CAMLlocal1 (rv);
1509
1510   guestfs_h *g = Guestfs_val (gv);
1511   if (g == NULL)
1512     caml_failwith ("mkdir: used handle after closing it");
1513
1514   const char *path = String_val (pathv);
1515   int r;
1516
1517   caml_enter_blocking_section ();
1518   r = guestfs_mkdir (g, path);
1519   caml_leave_blocking_section ();
1520   if (r == -1)
1521     ocaml_guestfs_raise_error (g, "mkdir");
1522
1523   rv = Val_unit;
1524   CAMLreturn (rv);
1525 }
1526
1527 CAMLprim value
1528 ocaml_guestfs_mkdir_p (value gv, value pathv)
1529 {
1530   CAMLparam2 (gv, pathv);
1531   CAMLlocal1 (rv);
1532
1533   guestfs_h *g = Guestfs_val (gv);
1534   if (g == NULL)
1535     caml_failwith ("mkdir_p: used handle after closing it");
1536
1537   const char *path = String_val (pathv);
1538   int r;
1539
1540   caml_enter_blocking_section ();
1541   r = guestfs_mkdir_p (g, path);
1542   caml_leave_blocking_section ();
1543   if (r == -1)
1544     ocaml_guestfs_raise_error (g, "mkdir_p");
1545
1546   rv = Val_unit;
1547   CAMLreturn (rv);
1548 }
1549
1550 CAMLprim value
1551 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1552 {
1553   CAMLparam3 (gv, modev, pathv);
1554   CAMLlocal1 (rv);
1555
1556   guestfs_h *g = Guestfs_val (gv);
1557   if (g == NULL)
1558     caml_failwith ("chmod: used handle after closing it");
1559
1560   int mode = Int_val (modev);
1561   const char *path = String_val (pathv);
1562   int r;
1563
1564   caml_enter_blocking_section ();
1565   r = guestfs_chmod (g, mode, path);
1566   caml_leave_blocking_section ();
1567   if (r == -1)
1568     ocaml_guestfs_raise_error (g, "chmod");
1569
1570   rv = Val_unit;
1571   CAMLreturn (rv);
1572 }
1573
1574 CAMLprim value
1575 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1576 {
1577   CAMLparam4 (gv, ownerv, groupv, pathv);
1578   CAMLlocal1 (rv);
1579
1580   guestfs_h *g = Guestfs_val (gv);
1581   if (g == NULL)
1582     caml_failwith ("chown: used handle after closing it");
1583
1584   int owner = Int_val (ownerv);
1585   int group = Int_val (groupv);
1586   const char *path = String_val (pathv);
1587   int r;
1588
1589   caml_enter_blocking_section ();
1590   r = guestfs_chown (g, owner, group, path);
1591   caml_leave_blocking_section ();
1592   if (r == -1)
1593     ocaml_guestfs_raise_error (g, "chown");
1594
1595   rv = Val_unit;
1596   CAMLreturn (rv);
1597 }
1598
1599 CAMLprim value
1600 ocaml_guestfs_exists (value gv, value pathv)
1601 {
1602   CAMLparam2 (gv, pathv);
1603   CAMLlocal1 (rv);
1604
1605   guestfs_h *g = Guestfs_val (gv);
1606   if (g == NULL)
1607     caml_failwith ("exists: used handle after closing it");
1608
1609   const char *path = String_val (pathv);
1610   int r;
1611
1612   caml_enter_blocking_section ();
1613   r = guestfs_exists (g, path);
1614   caml_leave_blocking_section ();
1615   if (r == -1)
1616     ocaml_guestfs_raise_error (g, "exists");
1617
1618   rv = Val_bool (r);
1619   CAMLreturn (rv);
1620 }
1621
1622 CAMLprim value
1623 ocaml_guestfs_is_file (value gv, value pathv)
1624 {
1625   CAMLparam2 (gv, pathv);
1626   CAMLlocal1 (rv);
1627
1628   guestfs_h *g = Guestfs_val (gv);
1629   if (g == NULL)
1630     caml_failwith ("is_file: used handle after closing it");
1631
1632   const char *path = String_val (pathv);
1633   int r;
1634
1635   caml_enter_blocking_section ();
1636   r = guestfs_is_file (g, path);
1637   caml_leave_blocking_section ();
1638   if (r == -1)
1639     ocaml_guestfs_raise_error (g, "is_file");
1640
1641   rv = Val_bool (r);
1642   CAMLreturn (rv);
1643 }
1644
1645 CAMLprim value
1646 ocaml_guestfs_is_dir (value gv, value pathv)
1647 {
1648   CAMLparam2 (gv, pathv);
1649   CAMLlocal1 (rv);
1650
1651   guestfs_h *g = Guestfs_val (gv);
1652   if (g == NULL)
1653     caml_failwith ("is_dir: used handle after closing it");
1654
1655   const char *path = String_val (pathv);
1656   int r;
1657
1658   caml_enter_blocking_section ();
1659   r = guestfs_is_dir (g, path);
1660   caml_leave_blocking_section ();
1661   if (r == -1)
1662     ocaml_guestfs_raise_error (g, "is_dir");
1663
1664   rv = Val_bool (r);
1665   CAMLreturn (rv);
1666 }
1667
1668 CAMLprim value
1669 ocaml_guestfs_pvcreate (value gv, value devicev)
1670 {
1671   CAMLparam2 (gv, devicev);
1672   CAMLlocal1 (rv);
1673
1674   guestfs_h *g = Guestfs_val (gv);
1675   if (g == NULL)
1676     caml_failwith ("pvcreate: used handle after closing it");
1677
1678   const char *device = String_val (devicev);
1679   int r;
1680
1681   caml_enter_blocking_section ();
1682   r = guestfs_pvcreate (g, device);
1683   caml_leave_blocking_section ();
1684   if (r == -1)
1685     ocaml_guestfs_raise_error (g, "pvcreate");
1686
1687   rv = Val_unit;
1688   CAMLreturn (rv);
1689 }
1690
1691 CAMLprim value
1692 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
1693 {
1694   CAMLparam3 (gv, volgroupv, physvolsv);
1695   CAMLlocal1 (rv);
1696
1697   guestfs_h *g = Guestfs_val (gv);
1698   if (g == NULL)
1699     caml_failwith ("vgcreate: used handle after closing it");
1700
1701   const char *volgroup = String_val (volgroupv);
1702   char **physvols = ocaml_guestfs_strings_val (physvolsv);
1703   int r;
1704
1705   caml_enter_blocking_section ();
1706   r = guestfs_vgcreate (g, volgroup, physvols);
1707   caml_leave_blocking_section ();
1708   ocaml_guestfs_free_strings (physvols);
1709   if (r == -1)
1710     ocaml_guestfs_raise_error (g, "vgcreate");
1711
1712   rv = Val_unit;
1713   CAMLreturn (rv);
1714 }
1715
1716 CAMLprim value
1717 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
1718 {
1719   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
1720   CAMLlocal1 (rv);
1721
1722   guestfs_h *g = Guestfs_val (gv);
1723   if (g == NULL)
1724     caml_failwith ("lvcreate: used handle after closing it");
1725
1726   const char *logvol = String_val (logvolv);
1727   const char *volgroup = String_val (volgroupv);
1728   int mbytes = Int_val (mbytesv);
1729   int r;
1730
1731   caml_enter_blocking_section ();
1732   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
1733   caml_leave_blocking_section ();
1734   if (r == -1)
1735     ocaml_guestfs_raise_error (g, "lvcreate");
1736
1737   rv = Val_unit;
1738   CAMLreturn (rv);
1739 }
1740
1741 CAMLprim value
1742 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
1743 {
1744   CAMLparam3 (gv, fstypev, devicev);
1745   CAMLlocal1 (rv);
1746
1747   guestfs_h *g = Guestfs_val (gv);
1748   if (g == NULL)
1749     caml_failwith ("mkfs: used handle after closing it");
1750
1751   const char *fstype = String_val (fstypev);
1752   const char *device = String_val (devicev);
1753   int r;
1754
1755   caml_enter_blocking_section ();
1756   r = guestfs_mkfs (g, fstype, device);
1757   caml_leave_blocking_section ();
1758   if (r == -1)
1759     ocaml_guestfs_raise_error (g, "mkfs");
1760
1761   rv = Val_unit;
1762   CAMLreturn (rv);
1763 }
1764
1765 CAMLprim value
1766 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
1767 {
1768   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
1769   CAMLxparam1 (linesv);
1770   CAMLlocal1 (rv);
1771
1772   guestfs_h *g = Guestfs_val (gv);
1773   if (g == NULL)
1774     caml_failwith ("sfdisk: used handle after closing it");
1775
1776   const char *device = String_val (devicev);
1777   int cyls = Int_val (cylsv);
1778   int heads = Int_val (headsv);
1779   int sectors = Int_val (sectorsv);
1780   char **lines = ocaml_guestfs_strings_val (linesv);
1781   int r;
1782
1783   caml_enter_blocking_section ();
1784   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
1785   caml_leave_blocking_section ();
1786   ocaml_guestfs_free_strings (lines);
1787   if (r == -1)
1788     ocaml_guestfs_raise_error (g, "sfdisk");
1789
1790   rv = Val_unit;
1791   CAMLreturn (rv);
1792 }
1793
1794 CAMLprim value
1795 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
1796 {
1797   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
1798 }
1799
1800 CAMLprim value
1801 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
1802 {
1803   CAMLparam4 (gv, pathv, contentv, sizev);
1804   CAMLlocal1 (rv);
1805
1806   guestfs_h *g = Guestfs_val (gv);
1807   if (g == NULL)
1808     caml_failwith ("write_file: used handle after closing it");
1809
1810   const char *path = String_val (pathv);
1811   const char *content = String_val (contentv);
1812   int size = Int_val (sizev);
1813   int r;
1814
1815   caml_enter_blocking_section ();
1816   r = guestfs_write_file (g, path, content, size);
1817   caml_leave_blocking_section ();
1818   if (r == -1)
1819     ocaml_guestfs_raise_error (g, "write_file");
1820
1821   rv = Val_unit;
1822   CAMLreturn (rv);
1823 }
1824
1825 CAMLprim value
1826 ocaml_guestfs_umount (value gv, value pathordevicev)
1827 {
1828   CAMLparam2 (gv, pathordevicev);
1829   CAMLlocal1 (rv);
1830
1831   guestfs_h *g = Guestfs_val (gv);
1832   if (g == NULL)
1833     caml_failwith ("umount: used handle after closing it");
1834
1835   const char *pathordevice = String_val (pathordevicev);
1836   int r;
1837
1838   caml_enter_blocking_section ();
1839   r = guestfs_umount (g, pathordevice);
1840   caml_leave_blocking_section ();
1841   if (r == -1)
1842     ocaml_guestfs_raise_error (g, "umount");
1843
1844   rv = Val_unit;
1845   CAMLreturn (rv);
1846 }
1847
1848 CAMLprim value
1849 ocaml_guestfs_mounts (value gv)
1850 {
1851   CAMLparam1 (gv);
1852   CAMLlocal1 (rv);
1853
1854   guestfs_h *g = Guestfs_val (gv);
1855   if (g == NULL)
1856     caml_failwith ("mounts: used handle after closing it");
1857
1858   int i;
1859   char **r;
1860
1861   caml_enter_blocking_section ();
1862   r = guestfs_mounts (g);
1863   caml_leave_blocking_section ();
1864   if (r == NULL)
1865     ocaml_guestfs_raise_error (g, "mounts");
1866
1867   rv = caml_copy_string_array ((const char **) r);
1868   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1869   free (r);
1870   CAMLreturn (rv);
1871 }
1872
1873 CAMLprim value
1874 ocaml_guestfs_umount_all (value gv)
1875 {
1876   CAMLparam1 (gv);
1877   CAMLlocal1 (rv);
1878
1879   guestfs_h *g = Guestfs_val (gv);
1880   if (g == NULL)
1881     caml_failwith ("umount_all: used handle after closing it");
1882
1883   int r;
1884
1885   caml_enter_blocking_section ();
1886   r = guestfs_umount_all (g);
1887   caml_leave_blocking_section ();
1888   if (r == -1)
1889     ocaml_guestfs_raise_error (g, "umount_all");
1890
1891   rv = Val_unit;
1892   CAMLreturn (rv);
1893 }
1894
1895 CAMLprim value
1896 ocaml_guestfs_lvm_remove_all (value gv)
1897 {
1898   CAMLparam1 (gv);
1899   CAMLlocal1 (rv);
1900
1901   guestfs_h *g = Guestfs_val (gv);
1902   if (g == NULL)
1903     caml_failwith ("lvm_remove_all: used handle after closing it");
1904
1905   int r;
1906
1907   caml_enter_blocking_section ();
1908   r = guestfs_lvm_remove_all (g);
1909   caml_leave_blocking_section ();
1910   if (r == -1)
1911     ocaml_guestfs_raise_error (g, "lvm_remove_all");
1912
1913   rv = Val_unit;
1914   CAMLreturn (rv);
1915 }
1916
1917 CAMLprim value
1918 ocaml_guestfs_file (value gv, value pathv)
1919 {
1920   CAMLparam2 (gv, pathv);
1921   CAMLlocal1 (rv);
1922
1923   guestfs_h *g = Guestfs_val (gv);
1924   if (g == NULL)
1925     caml_failwith ("file: used handle after closing it");
1926
1927   const char *path = String_val (pathv);
1928   char *r;
1929
1930   caml_enter_blocking_section ();
1931   r = guestfs_file (g, path);
1932   caml_leave_blocking_section ();
1933   if (r == NULL)
1934     ocaml_guestfs_raise_error (g, "file");
1935
1936   rv = caml_copy_string (r);
1937   free (r);
1938   CAMLreturn (rv);
1939 }
1940
1941 CAMLprim value
1942 ocaml_guestfs_command (value gv, value argumentsv)
1943 {
1944   CAMLparam2 (gv, argumentsv);
1945   CAMLlocal1 (rv);
1946
1947   guestfs_h *g = Guestfs_val (gv);
1948   if (g == NULL)
1949     caml_failwith ("command: used handle after closing it");
1950
1951   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1952   char *r;
1953
1954   caml_enter_blocking_section ();
1955   r = guestfs_command (g, arguments);
1956   caml_leave_blocking_section ();
1957   ocaml_guestfs_free_strings (arguments);
1958   if (r == NULL)
1959     ocaml_guestfs_raise_error (g, "command");
1960
1961   rv = caml_copy_string (r);
1962   free (r);
1963   CAMLreturn (rv);
1964 }
1965
1966 CAMLprim value
1967 ocaml_guestfs_command_lines (value gv, value argumentsv)
1968 {
1969   CAMLparam2 (gv, argumentsv);
1970   CAMLlocal1 (rv);
1971
1972   guestfs_h *g = Guestfs_val (gv);
1973   if (g == NULL)
1974     caml_failwith ("command_lines: used handle after closing it");
1975
1976   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1977   int i;
1978   char **r;
1979
1980   caml_enter_blocking_section ();
1981   r = guestfs_command_lines (g, arguments);
1982   caml_leave_blocking_section ();
1983   ocaml_guestfs_free_strings (arguments);
1984   if (r == NULL)
1985     ocaml_guestfs_raise_error (g, "command_lines");
1986
1987   rv = caml_copy_string_array ((const char **) r);
1988   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1989   free (r);
1990   CAMLreturn (rv);
1991 }
1992
1993 CAMLprim value
1994 ocaml_guestfs_stat (value gv, value pathv)
1995 {
1996   CAMLparam2 (gv, pathv);
1997   CAMLlocal1 (rv);
1998
1999   guestfs_h *g = Guestfs_val (gv);
2000   if (g == NULL)
2001     caml_failwith ("stat: used handle after closing it");
2002
2003   const char *path = String_val (pathv);
2004   struct guestfs_stat *r;
2005
2006   caml_enter_blocking_section ();
2007   r = guestfs_stat (g, path);
2008   caml_leave_blocking_section ();
2009   if (r == NULL)
2010     ocaml_guestfs_raise_error (g, "stat");
2011
2012   rv = copy_stat (r);
2013   free (r);
2014   CAMLreturn (rv);
2015 }
2016
2017 CAMLprim value
2018 ocaml_guestfs_lstat (value gv, value pathv)
2019 {
2020   CAMLparam2 (gv, pathv);
2021   CAMLlocal1 (rv);
2022
2023   guestfs_h *g = Guestfs_val (gv);
2024   if (g == NULL)
2025     caml_failwith ("lstat: used handle after closing it");
2026
2027   const char *path = String_val (pathv);
2028   struct guestfs_stat *r;
2029
2030   caml_enter_blocking_section ();
2031   r = guestfs_lstat (g, path);
2032   caml_leave_blocking_section ();
2033   if (r == NULL)
2034     ocaml_guestfs_raise_error (g, "lstat");
2035
2036   rv = copy_stat (r);
2037   free (r);
2038   CAMLreturn (rv);
2039 }
2040
2041 CAMLprim value
2042 ocaml_guestfs_statvfs (value gv, value pathv)
2043 {
2044   CAMLparam2 (gv, pathv);
2045   CAMLlocal1 (rv);
2046
2047   guestfs_h *g = Guestfs_val (gv);
2048   if (g == NULL)
2049     caml_failwith ("statvfs: used handle after closing it");
2050
2051   const char *path = String_val (pathv);
2052   struct guestfs_statvfs *r;
2053
2054   caml_enter_blocking_section ();
2055   r = guestfs_statvfs (g, path);
2056   caml_leave_blocking_section ();
2057   if (r == NULL)
2058     ocaml_guestfs_raise_error (g, "statvfs");
2059
2060   rv = copy_statvfs (r);
2061   free (r);
2062   CAMLreturn (rv);
2063 }
2064
2065 CAMLprim value
2066 ocaml_guestfs_tune2fs_l (value gv, value devicev)
2067 {
2068   CAMLparam2 (gv, devicev);
2069   CAMLlocal1 (rv);
2070
2071   guestfs_h *g = Guestfs_val (gv);
2072   if (g == NULL)
2073     caml_failwith ("tune2fs_l: used handle after closing it");
2074
2075   const char *device = String_val (devicev);
2076   int i;
2077   char **r;
2078
2079   caml_enter_blocking_section ();
2080   r = guestfs_tune2fs_l (g, device);
2081   caml_leave_blocking_section ();
2082   if (r == NULL)
2083     ocaml_guestfs_raise_error (g, "tune2fs_l");
2084
2085   rv = copy_table (r);
2086   for (i = 0; r[i] != NULL; ++i) free (r[i]);
2087   free (r);
2088   CAMLreturn (rv);
2089 }
2090
2091 CAMLprim value
2092 ocaml_guestfs_blockdev_setro (value gv, value devicev)
2093 {
2094   CAMLparam2 (gv, devicev);
2095   CAMLlocal1 (rv);
2096
2097   guestfs_h *g = Guestfs_val (gv);
2098   if (g == NULL)
2099     caml_failwith ("blockdev_setro: used handle after closing it");
2100
2101   const char *device = String_val (devicev);
2102   int r;
2103
2104   caml_enter_blocking_section ();
2105   r = guestfs_blockdev_setro (g, device);
2106   caml_leave_blocking_section ();
2107   if (r == -1)
2108     ocaml_guestfs_raise_error (g, "blockdev_setro");
2109
2110   rv = Val_unit;
2111   CAMLreturn (rv);
2112 }
2113
2114 CAMLprim value
2115 ocaml_guestfs_blockdev_setrw (value gv, value devicev)
2116 {
2117   CAMLparam2 (gv, devicev);
2118   CAMLlocal1 (rv);
2119
2120   guestfs_h *g = Guestfs_val (gv);
2121   if (g == NULL)
2122     caml_failwith ("blockdev_setrw: used handle after closing it");
2123
2124   const char *device = String_val (devicev);
2125   int r;
2126
2127   caml_enter_blocking_section ();
2128   r = guestfs_blockdev_setrw (g, device);
2129   caml_leave_blocking_section ();
2130   if (r == -1)
2131     ocaml_guestfs_raise_error (g, "blockdev_setrw");
2132
2133   rv = Val_unit;
2134   CAMLreturn (rv);
2135 }
2136
2137 CAMLprim value
2138 ocaml_guestfs_blockdev_getro (value gv, value devicev)
2139 {
2140   CAMLparam2 (gv, devicev);
2141   CAMLlocal1 (rv);
2142
2143   guestfs_h *g = Guestfs_val (gv);
2144   if (g == NULL)
2145     caml_failwith ("blockdev_getro: used handle after closing it");
2146
2147   const char *device = String_val (devicev);
2148   int r;
2149
2150   caml_enter_blocking_section ();
2151   r = guestfs_blockdev_getro (g, device);
2152   caml_leave_blocking_section ();
2153   if (r == -1)
2154     ocaml_guestfs_raise_error (g, "blockdev_getro");
2155
2156   rv = Val_bool (r);
2157   CAMLreturn (rv);
2158 }
2159
2160 CAMLprim value
2161 ocaml_guestfs_blockdev_getss (value gv, value devicev)
2162 {
2163   CAMLparam2 (gv, devicev);
2164   CAMLlocal1 (rv);
2165
2166   guestfs_h *g = Guestfs_val (gv);
2167   if (g == NULL)
2168     caml_failwith ("blockdev_getss: used handle after closing it");
2169
2170   const char *device = String_val (devicev);
2171   int r;
2172
2173   caml_enter_blocking_section ();
2174   r = guestfs_blockdev_getss (g, device);
2175   caml_leave_blocking_section ();
2176   if (r == -1)
2177     ocaml_guestfs_raise_error (g, "blockdev_getss");
2178
2179   rv = Val_int (r);
2180   CAMLreturn (rv);
2181 }
2182
2183 CAMLprim value
2184 ocaml_guestfs_blockdev_getbsz (value gv, value devicev)
2185 {
2186   CAMLparam2 (gv, devicev);
2187   CAMLlocal1 (rv);
2188
2189   guestfs_h *g = Guestfs_val (gv);
2190   if (g == NULL)
2191     caml_failwith ("blockdev_getbsz: used handle after closing it");
2192
2193   const char *device = String_val (devicev);
2194   int r;
2195
2196   caml_enter_blocking_section ();
2197   r = guestfs_blockdev_getbsz (g, device);
2198   caml_leave_blocking_section ();
2199   if (r == -1)
2200     ocaml_guestfs_raise_error (g, "blockdev_getbsz");
2201
2202   rv = Val_int (r);
2203   CAMLreturn (rv);
2204 }
2205
2206 CAMLprim value
2207 ocaml_guestfs_blockdev_setbsz (value gv, value devicev, value blocksizev)
2208 {
2209   CAMLparam3 (gv, devicev, blocksizev);
2210   CAMLlocal1 (rv);
2211
2212   guestfs_h *g = Guestfs_val (gv);
2213   if (g == NULL)
2214     caml_failwith ("blockdev_setbsz: used handle after closing it");
2215
2216   const char *device = String_val (devicev);
2217   int blocksize = Int_val (blocksizev);
2218   int r;
2219
2220   caml_enter_blocking_section ();
2221   r = guestfs_blockdev_setbsz (g, device, blocksize);
2222   caml_leave_blocking_section ();
2223   if (r == -1)
2224     ocaml_guestfs_raise_error (g, "blockdev_setbsz");
2225
2226   rv = Val_unit;
2227   CAMLreturn (rv);
2228 }
2229
2230 CAMLprim value
2231 ocaml_guestfs_blockdev_getsz (value gv, value devicev)
2232 {
2233   CAMLparam2 (gv, devicev);
2234   CAMLlocal1 (rv);
2235
2236   guestfs_h *g = Guestfs_val (gv);
2237   if (g == NULL)
2238     caml_failwith ("blockdev_getsz: used handle after closing it");
2239
2240   const char *device = String_val (devicev);
2241   int64_t r;
2242
2243   caml_enter_blocking_section ();
2244   r = guestfs_blockdev_getsz (g, device);
2245   caml_leave_blocking_section ();
2246   if (r == -1)
2247     ocaml_guestfs_raise_error (g, "blockdev_getsz");
2248
2249   rv = caml_copy_int64 (r);
2250   CAMLreturn (rv);
2251 }
2252
2253 CAMLprim value
2254 ocaml_guestfs_blockdev_getsize64 (value gv, value devicev)
2255 {
2256   CAMLparam2 (gv, devicev);
2257   CAMLlocal1 (rv);
2258
2259   guestfs_h *g = Guestfs_val (gv);
2260   if (g == NULL)
2261     caml_failwith ("blockdev_getsize64: used handle after closing it");
2262
2263   const char *device = String_val (devicev);
2264   int64_t r;
2265
2266   caml_enter_blocking_section ();
2267   r = guestfs_blockdev_getsize64 (g, device);
2268   caml_leave_blocking_section ();
2269   if (r == -1)
2270     ocaml_guestfs_raise_error (g, "blockdev_getsize64");
2271
2272   rv = caml_copy_int64 (r);
2273   CAMLreturn (rv);
2274 }
2275
2276 CAMLprim value
2277 ocaml_guestfs_blockdev_flushbufs (value gv, value devicev)
2278 {
2279   CAMLparam2 (gv, devicev);
2280   CAMLlocal1 (rv);
2281
2282   guestfs_h *g = Guestfs_val (gv);
2283   if (g == NULL)
2284     caml_failwith ("blockdev_flushbufs: used handle after closing it");
2285
2286   const char *device = String_val (devicev);
2287   int r;
2288
2289   caml_enter_blocking_section ();
2290   r = guestfs_blockdev_flushbufs (g, device);
2291   caml_leave_blocking_section ();
2292   if (r == -1)
2293     ocaml_guestfs_raise_error (g, "blockdev_flushbufs");
2294
2295   rv = Val_unit;
2296   CAMLreturn (rv);
2297 }
2298
2299 CAMLprim value
2300 ocaml_guestfs_blockdev_rereadpt (value gv, value devicev)
2301 {
2302   CAMLparam2 (gv, devicev);
2303   CAMLlocal1 (rv);
2304
2305   guestfs_h *g = Guestfs_val (gv);
2306   if (g == NULL)
2307     caml_failwith ("blockdev_rereadpt: used handle after closing it");
2308
2309   const char *device = String_val (devicev);
2310   int r;
2311
2312   caml_enter_blocking_section ();
2313   r = guestfs_blockdev_rereadpt (g, device);
2314   caml_leave_blocking_section ();
2315   if (r == -1)
2316     ocaml_guestfs_raise_error (g, "blockdev_rereadpt");
2317
2318   rv = Val_unit;
2319   CAMLreturn (rv);
2320 }
2321
2322 CAMLprim value
2323 ocaml_guestfs_upload (value gv, value filenamev, value remotefilenamev)
2324 {
2325   CAMLparam3 (gv, filenamev, remotefilenamev);
2326   CAMLlocal1 (rv);
2327
2328   guestfs_h *g = Guestfs_val (gv);
2329   if (g == NULL)
2330     caml_failwith ("upload: used handle after closing it");
2331
2332   const char *filename = String_val (filenamev);
2333   const char *remotefilename = String_val (remotefilenamev);
2334   int r;
2335
2336   caml_enter_blocking_section ();
2337   r = guestfs_upload (g, filename, remotefilename);
2338   caml_leave_blocking_section ();
2339   if (r == -1)
2340     ocaml_guestfs_raise_error (g, "upload");
2341
2342   rv = Val_unit;
2343   CAMLreturn (rv);
2344 }
2345
2346 CAMLprim value
2347 ocaml_guestfs_download (value gv, value remotefilenamev, value filenamev)
2348 {
2349   CAMLparam3 (gv, remotefilenamev, filenamev);
2350   CAMLlocal1 (rv);
2351
2352   guestfs_h *g = Guestfs_val (gv);
2353   if (g == NULL)
2354     caml_failwith ("download: used handle after closing it");
2355
2356   const char *remotefilename = String_val (remotefilenamev);
2357   const char *filename = String_val (filenamev);
2358   int r;
2359
2360   caml_enter_blocking_section ();
2361   r = guestfs_download (g, remotefilename, filename);
2362   caml_leave_blocking_section ();
2363   if (r == -1)
2364     ocaml_guestfs_raise_error (g, "download");
2365
2366   rv = Val_unit;
2367   CAMLreturn (rv);
2368 }
2369
2370 CAMLprim value
2371 ocaml_guestfs_checksum (value gv, value csumtypev, value pathv)
2372 {
2373   CAMLparam3 (gv, csumtypev, pathv);
2374   CAMLlocal1 (rv);
2375
2376   guestfs_h *g = Guestfs_val (gv);
2377   if (g == NULL)
2378     caml_failwith ("checksum: used handle after closing it");
2379
2380   const char *csumtype = String_val (csumtypev);
2381   const char *path = String_val (pathv);
2382   char *r;
2383
2384   caml_enter_blocking_section ();
2385   r = guestfs_checksum (g, csumtype, path);
2386   caml_leave_blocking_section ();
2387   if (r == NULL)
2388     ocaml_guestfs_raise_error (g, "checksum");
2389
2390   rv = caml_copy_string (r);
2391   free (r);
2392   CAMLreturn (rv);
2393 }
2394