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