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