Generated code for stat/lstat/statvfs changes.
[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 static CAMLprim value
39 copy_lvm_pv (const struct guestfs_lvm_pv *pv)
40 {
41   CAMLparam0 ();
42   CAMLlocal2 (rv, v);
43
44   rv = caml_alloc (14, 0);
45   v = caml_copy_string (pv->pv_name);
46   Store_field (rv, 0, v);
47   v = caml_alloc_string (32);
48   memcpy (String_val (v), pv->pv_uuid, 32);
49   Store_field (rv, 1, v);
50   v = caml_copy_string (pv->pv_fmt);
51   Store_field (rv, 2, v);
52   v = caml_copy_int64 (pv->pv_size);
53   Store_field (rv, 3, v);
54   v = caml_copy_int64 (pv->dev_size);
55   Store_field (rv, 4, v);
56   v = caml_copy_int64 (pv->pv_free);
57   Store_field (rv, 5, v);
58   v = caml_copy_int64 (pv->pv_used);
59   Store_field (rv, 6, v);
60   v = caml_copy_string (pv->pv_attr);
61   Store_field (rv, 7, v);
62   v = caml_copy_int64 (pv->pv_pe_count);
63   Store_field (rv, 8, v);
64   v = caml_copy_int64 (pv->pv_pe_alloc_count);
65   Store_field (rv, 9, v);
66   v = caml_copy_string (pv->pv_tags);
67   Store_field (rv, 10, v);
68   v = caml_copy_int64 (pv->pe_start);
69   Store_field (rv, 11, v);
70   v = caml_copy_int64 (pv->pv_mda_count);
71   Store_field (rv, 12, v);
72   v = caml_copy_int64 (pv->pv_mda_free);
73   Store_field (rv, 13, v);
74   CAMLreturn (rv);
75 }
76
77 static CAMLprim value
78 copy_lvm_pv_list (const struct guestfs_lvm_pv_list *pvs)
79 {
80   CAMLparam0 ();
81   CAMLlocal2 (rv, v);
82   int i;
83
84   if (pvs->len == 0)
85     CAMLreturn (Atom (0));
86   else {
87     rv = caml_alloc (pvs->len, 0);
88     for (i = 0; i < pvs->len; ++i) {
89       v = copy_lvm_pv (&pvs->val[i]);
90       caml_modify (&Field (rv, i), v);
91     }
92     CAMLreturn (rv);
93   }
94 }
95
96 static CAMLprim value
97 copy_lvm_vg (const struct guestfs_lvm_vg *vg)
98 {
99   CAMLparam0 ();
100   CAMLlocal2 (rv, v);
101
102   rv = caml_alloc (19, 0);
103   v = caml_copy_string (vg->vg_name);
104   Store_field (rv, 0, v);
105   v = caml_alloc_string (32);
106   memcpy (String_val (v), vg->vg_uuid, 32);
107   Store_field (rv, 1, v);
108   v = caml_copy_string (vg->vg_fmt);
109   Store_field (rv, 2, v);
110   v = caml_copy_string (vg->vg_attr);
111   Store_field (rv, 3, v);
112   v = caml_copy_int64 (vg->vg_size);
113   Store_field (rv, 4, v);
114   v = caml_copy_int64 (vg->vg_free);
115   Store_field (rv, 5, v);
116   v = caml_copy_string (vg->vg_sysid);
117   Store_field (rv, 6, v);
118   v = caml_copy_int64 (vg->vg_extent_size);
119   Store_field (rv, 7, v);
120   v = caml_copy_int64 (vg->vg_extent_count);
121   Store_field (rv, 8, v);
122   v = caml_copy_int64 (vg->vg_free_count);
123   Store_field (rv, 9, v);
124   v = caml_copy_int64 (vg->max_lv);
125   Store_field (rv, 10, v);
126   v = caml_copy_int64 (vg->max_pv);
127   Store_field (rv, 11, v);
128   v = caml_copy_int64 (vg->pv_count);
129   Store_field (rv, 12, v);
130   v = caml_copy_int64 (vg->lv_count);
131   Store_field (rv, 13, v);
132   v = caml_copy_int64 (vg->snap_count);
133   Store_field (rv, 14, v);
134   v = caml_copy_int64 (vg->vg_seqno);
135   Store_field (rv, 15, v);
136   v = caml_copy_string (vg->vg_tags);
137   Store_field (rv, 16, v);
138   v = caml_copy_int64 (vg->vg_mda_count);
139   Store_field (rv, 17, v);
140   v = caml_copy_int64 (vg->vg_mda_free);
141   Store_field (rv, 18, v);
142   CAMLreturn (rv);
143 }
144
145 static CAMLprim value
146 copy_lvm_vg_list (const struct guestfs_lvm_vg_list *vgs)
147 {
148   CAMLparam0 ();
149   CAMLlocal2 (rv, v);
150   int i;
151
152   if (vgs->len == 0)
153     CAMLreturn (Atom (0));
154   else {
155     rv = caml_alloc (vgs->len, 0);
156     for (i = 0; i < vgs->len; ++i) {
157       v = copy_lvm_vg (&vgs->val[i]);
158       caml_modify (&Field (rv, i), v);
159     }
160     CAMLreturn (rv);
161   }
162 }
163
164 static CAMLprim value
165 copy_lvm_lv (const struct guestfs_lvm_lv *lv)
166 {
167   CAMLparam0 ();
168   CAMLlocal3 (rv, v, v2);
169
170   rv = caml_alloc (16, 0);
171   v = caml_copy_string (lv->lv_name);
172   Store_field (rv, 0, v);
173   v = caml_alloc_string (32);
174   memcpy (String_val (v), lv->lv_uuid, 32);
175   Store_field (rv, 1, v);
176   v = caml_copy_string (lv->lv_attr);
177   Store_field (rv, 2, v);
178   v = caml_copy_int64 (lv->lv_major);
179   Store_field (rv, 3, v);
180   v = caml_copy_int64 (lv->lv_minor);
181   Store_field (rv, 4, v);
182   v = caml_copy_int64 (lv->lv_kernel_major);
183   Store_field (rv, 5, v);
184   v = caml_copy_int64 (lv->lv_kernel_minor);
185   Store_field (rv, 6, v);
186   v = caml_copy_int64 (lv->lv_size);
187   Store_field (rv, 7, v);
188   v = caml_copy_int64 (lv->seg_count);
189   Store_field (rv, 8, v);
190   v = caml_copy_string (lv->origin);
191   Store_field (rv, 9, v);
192   if (lv->snap_percent >= 0) { /* Some snap_percent */
193     v2 = caml_copy_double (lv->snap_percent);
194     v = caml_alloc (1, 0);
195     Store_field (v, 0, v2);
196   } else /* None */
197     v = Val_int (0);
198   Store_field (rv, 10, v);
199   if (lv->copy_percent >= 0) { /* Some copy_percent */
200     v2 = caml_copy_double (lv->copy_percent);
201     v = caml_alloc (1, 0);
202     Store_field (v, 0, v2);
203   } else /* None */
204     v = Val_int (0);
205   Store_field (rv, 11, v);
206   v = caml_copy_string (lv->move_pv);
207   Store_field (rv, 12, v);
208   v = caml_copy_string (lv->lv_tags);
209   Store_field (rv, 13, v);
210   v = caml_copy_string (lv->mirror_log);
211   Store_field (rv, 14, v);
212   v = caml_copy_string (lv->modules);
213   Store_field (rv, 15, v);
214   CAMLreturn (rv);
215 }
216
217 static CAMLprim value
218 copy_lvm_lv_list (const struct guestfs_lvm_lv_list *lvs)
219 {
220   CAMLparam0 ();
221   CAMLlocal2 (rv, v);
222   int i;
223
224   if (lvs->len == 0)
225     CAMLreturn (Atom (0));
226   else {
227     rv = caml_alloc (lvs->len, 0);
228     for (i = 0; i < lvs->len; ++i) {
229       v = copy_lvm_lv (&lvs->val[i]);
230       caml_modify (&Field (rv, i), v);
231     }
232     CAMLreturn (rv);
233   }
234 }
235
236 static CAMLprim value
237 copy_stat (const struct guestfs_stat *stat)
238 {
239   CAMLparam0 ();
240   CAMLlocal2 (rv, v);
241
242   rv = caml_alloc (13, 0);
243   v = caml_copy_int64 (stat->dev);
244   Store_field (rv, 0, v);
245   v = caml_copy_int64 (stat->ino);
246   Store_field (rv, 1, v);
247   v = caml_copy_int64 (stat->mode);
248   Store_field (rv, 2, v);
249   v = caml_copy_int64 (stat->nlink);
250   Store_field (rv, 3, v);
251   v = caml_copy_int64 (stat->uid);
252   Store_field (rv, 4, v);
253   v = caml_copy_int64 (stat->gid);
254   Store_field (rv, 5, v);
255   v = caml_copy_int64 (stat->rdev);
256   Store_field (rv, 6, v);
257   v = caml_copy_int64 (stat->size);
258   Store_field (rv, 7, v);
259   v = caml_copy_int64 (stat->blksize);
260   Store_field (rv, 8, v);
261   v = caml_copy_int64 (stat->blocks);
262   Store_field (rv, 9, v);
263   v = caml_copy_int64 (stat->atime);
264   Store_field (rv, 10, v);
265   v = caml_copy_int64 (stat->mtime);
266   Store_field (rv, 11, v);
267   v = caml_copy_int64 (stat->ctime);
268   Store_field (rv, 12, v);
269   CAMLreturn (rv);
270 }
271
272 static CAMLprim value
273 copy_statvfs (const struct guestfs_statvfs *statvfs)
274 {
275   CAMLparam0 ();
276   CAMLlocal2 (rv, v);
277
278   rv = caml_alloc (11, 0);
279   v = caml_copy_int64 (statvfs->bsize);
280   Store_field (rv, 0, v);
281   v = caml_copy_int64 (statvfs->frsize);
282   Store_field (rv, 1, v);
283   v = caml_copy_int64 (statvfs->blocks);
284   Store_field (rv, 2, v);
285   v = caml_copy_int64 (statvfs->bfree);
286   Store_field (rv, 3, v);
287   v = caml_copy_int64 (statvfs->bavail);
288   Store_field (rv, 4, v);
289   v = caml_copy_int64 (statvfs->files);
290   Store_field (rv, 5, v);
291   v = caml_copy_int64 (statvfs->ffree);
292   Store_field (rv, 6, v);
293   v = caml_copy_int64 (statvfs->favail);
294   Store_field (rv, 7, v);
295   v = caml_copy_int64 (statvfs->fsid);
296   Store_field (rv, 8, v);
297   v = caml_copy_int64 (statvfs->flag);
298   Store_field (rv, 9, v);
299   v = caml_copy_int64 (statvfs->namemax);
300   Store_field (rv, 10, v);
301   CAMLreturn (rv);
302 }
303
304 CAMLprim value
305 ocaml_guestfs_launch (value gv)
306 {
307   CAMLparam1 (gv);
308   CAMLlocal1 (rv);
309
310   guestfs_h *g = Guestfs_val (gv);
311   if (g == NULL)
312     caml_failwith ("launch: used handle after closing it");
313
314   int r;
315
316   caml_enter_blocking_section ();
317   r = guestfs_launch (g);
318   caml_leave_blocking_section ();
319   if (r == -1)
320     ocaml_guestfs_raise_error (g, "launch");
321
322   rv = Val_unit;
323   CAMLreturn (rv);
324 }
325
326 CAMLprim value
327 ocaml_guestfs_wait_ready (value gv)
328 {
329   CAMLparam1 (gv);
330   CAMLlocal1 (rv);
331
332   guestfs_h *g = Guestfs_val (gv);
333   if (g == NULL)
334     caml_failwith ("wait_ready: used handle after closing it");
335
336   int r;
337
338   caml_enter_blocking_section ();
339   r = guestfs_wait_ready (g);
340   caml_leave_blocking_section ();
341   if (r == -1)
342     ocaml_guestfs_raise_error (g, "wait_ready");
343
344   rv = Val_unit;
345   CAMLreturn (rv);
346 }
347
348 CAMLprim value
349 ocaml_guestfs_kill_subprocess (value gv)
350 {
351   CAMLparam1 (gv);
352   CAMLlocal1 (rv);
353
354   guestfs_h *g = Guestfs_val (gv);
355   if (g == NULL)
356     caml_failwith ("kill_subprocess: used handle after closing it");
357
358   int r;
359
360   caml_enter_blocking_section ();
361   r = guestfs_kill_subprocess (g);
362   caml_leave_blocking_section ();
363   if (r == -1)
364     ocaml_guestfs_raise_error (g, "kill_subprocess");
365
366   rv = Val_unit;
367   CAMLreturn (rv);
368 }
369
370 CAMLprim value
371 ocaml_guestfs_add_drive (value gv, value filenamev)
372 {
373   CAMLparam2 (gv, filenamev);
374   CAMLlocal1 (rv);
375
376   guestfs_h *g = Guestfs_val (gv);
377   if (g == NULL)
378     caml_failwith ("add_drive: used handle after closing it");
379
380   const char *filename = String_val (filenamev);
381   int r;
382
383   caml_enter_blocking_section ();
384   r = guestfs_add_drive (g, filename);
385   caml_leave_blocking_section ();
386   if (r == -1)
387     ocaml_guestfs_raise_error (g, "add_drive");
388
389   rv = Val_unit;
390   CAMLreturn (rv);
391 }
392
393 CAMLprim value
394 ocaml_guestfs_add_cdrom (value gv, value filenamev)
395 {
396   CAMLparam2 (gv, filenamev);
397   CAMLlocal1 (rv);
398
399   guestfs_h *g = Guestfs_val (gv);
400   if (g == NULL)
401     caml_failwith ("add_cdrom: used handle after closing it");
402
403   const char *filename = String_val (filenamev);
404   int r;
405
406   caml_enter_blocking_section ();
407   r = guestfs_add_cdrom (g, filename);
408   caml_leave_blocking_section ();
409   if (r == -1)
410     ocaml_guestfs_raise_error (g, "add_cdrom");
411
412   rv = Val_unit;
413   CAMLreturn (rv);
414 }
415
416 CAMLprim value
417 ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
418 {
419   CAMLparam3 (gv, qemuparamv, qemuvaluev);
420   CAMLlocal1 (rv);
421
422   guestfs_h *g = Guestfs_val (gv);
423   if (g == NULL)
424     caml_failwith ("config: used handle after closing it");
425
426   const char *qemuparam = String_val (qemuparamv);
427   const char *qemuvalue =
428     qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
429   int r;
430
431   caml_enter_blocking_section ();
432   r = guestfs_config (g, qemuparam, qemuvalue);
433   caml_leave_blocking_section ();
434   if (r == -1)
435     ocaml_guestfs_raise_error (g, "config");
436
437   rv = Val_unit;
438   CAMLreturn (rv);
439 }
440
441 CAMLprim value
442 ocaml_guestfs_set_path (value gv, value pathv)
443 {
444   CAMLparam2 (gv, pathv);
445   CAMLlocal1 (rv);
446
447   guestfs_h *g = Guestfs_val (gv);
448   if (g == NULL)
449     caml_failwith ("set_path: used handle after closing it");
450
451   const char *path = String_val (pathv);
452   int r;
453
454   caml_enter_blocking_section ();
455   r = guestfs_set_path (g, path);
456   caml_leave_blocking_section ();
457   if (r == -1)
458     ocaml_guestfs_raise_error (g, "set_path");
459
460   rv = Val_unit;
461   CAMLreturn (rv);
462 }
463
464 CAMLprim value
465 ocaml_guestfs_get_path (value gv)
466 {
467   CAMLparam1 (gv);
468   CAMLlocal1 (rv);
469
470   guestfs_h *g = Guestfs_val (gv);
471   if (g == NULL)
472     caml_failwith ("get_path: used handle after closing it");
473
474   const char *r;
475
476   caml_enter_blocking_section ();
477   r = guestfs_get_path (g);
478   caml_leave_blocking_section ();
479   if (r == NULL)
480     ocaml_guestfs_raise_error (g, "get_path");
481
482   rv = caml_copy_string (r);
483   CAMLreturn (rv);
484 }
485
486 CAMLprim value
487 ocaml_guestfs_set_autosync (value gv, value autosyncv)
488 {
489   CAMLparam2 (gv, autosyncv);
490   CAMLlocal1 (rv);
491
492   guestfs_h *g = Guestfs_val (gv);
493   if (g == NULL)
494     caml_failwith ("set_autosync: used handle after closing it");
495
496   int autosync = Bool_val (autosyncv);
497   int r;
498
499   caml_enter_blocking_section ();
500   r = guestfs_set_autosync (g, autosync);
501   caml_leave_blocking_section ();
502   if (r == -1)
503     ocaml_guestfs_raise_error (g, "set_autosync");
504
505   rv = Val_unit;
506   CAMLreturn (rv);
507 }
508
509 CAMLprim value
510 ocaml_guestfs_get_autosync (value gv)
511 {
512   CAMLparam1 (gv);
513   CAMLlocal1 (rv);
514
515   guestfs_h *g = Guestfs_val (gv);
516   if (g == NULL)
517     caml_failwith ("get_autosync: used handle after closing it");
518
519   int r;
520
521   caml_enter_blocking_section ();
522   r = guestfs_get_autosync (g);
523   caml_leave_blocking_section ();
524   if (r == -1)
525     ocaml_guestfs_raise_error (g, "get_autosync");
526
527   rv = Val_bool (r);
528   CAMLreturn (rv);
529 }
530
531 CAMLprim value
532 ocaml_guestfs_set_verbose (value gv, value verbosev)
533 {
534   CAMLparam2 (gv, verbosev);
535   CAMLlocal1 (rv);
536
537   guestfs_h *g = Guestfs_val (gv);
538   if (g == NULL)
539     caml_failwith ("set_verbose: used handle after closing it");
540
541   int verbose = Bool_val (verbosev);
542   int r;
543
544   caml_enter_blocking_section ();
545   r = guestfs_set_verbose (g, verbose);
546   caml_leave_blocking_section ();
547   if (r == -1)
548     ocaml_guestfs_raise_error (g, "set_verbose");
549
550   rv = Val_unit;
551   CAMLreturn (rv);
552 }
553
554 CAMLprim value
555 ocaml_guestfs_get_verbose (value gv)
556 {
557   CAMLparam1 (gv);
558   CAMLlocal1 (rv);
559
560   guestfs_h *g = Guestfs_val (gv);
561   if (g == NULL)
562     caml_failwith ("get_verbose: used handle after closing it");
563
564   int r;
565
566   caml_enter_blocking_section ();
567   r = guestfs_get_verbose (g);
568   caml_leave_blocking_section ();
569   if (r == -1)
570     ocaml_guestfs_raise_error (g, "get_verbose");
571
572   rv = Val_bool (r);
573   CAMLreturn (rv);
574 }
575
576 CAMLprim value
577 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
578 {
579   CAMLparam3 (gv, devicev, mountpointv);
580   CAMLlocal1 (rv);
581
582   guestfs_h *g = Guestfs_val (gv);
583   if (g == NULL)
584     caml_failwith ("mount: used handle after closing it");
585
586   const char *device = String_val (devicev);
587   const char *mountpoint = String_val (mountpointv);
588   int r;
589
590   caml_enter_blocking_section ();
591   r = guestfs_mount (g, device, mountpoint);
592   caml_leave_blocking_section ();
593   if (r == -1)
594     ocaml_guestfs_raise_error (g, "mount");
595
596   rv = Val_unit;
597   CAMLreturn (rv);
598 }
599
600 CAMLprim value
601 ocaml_guestfs_sync (value gv)
602 {
603   CAMLparam1 (gv);
604   CAMLlocal1 (rv);
605
606   guestfs_h *g = Guestfs_val (gv);
607   if (g == NULL)
608     caml_failwith ("sync: used handle after closing it");
609
610   int r;
611
612   caml_enter_blocking_section ();
613   r = guestfs_sync (g);
614   caml_leave_blocking_section ();
615   if (r == -1)
616     ocaml_guestfs_raise_error (g, "sync");
617
618   rv = Val_unit;
619   CAMLreturn (rv);
620 }
621
622 CAMLprim value
623 ocaml_guestfs_touch (value gv, value pathv)
624 {
625   CAMLparam2 (gv, pathv);
626   CAMLlocal1 (rv);
627
628   guestfs_h *g = Guestfs_val (gv);
629   if (g == NULL)
630     caml_failwith ("touch: used handle after closing it");
631
632   const char *path = String_val (pathv);
633   int r;
634
635   caml_enter_blocking_section ();
636   r = guestfs_touch (g, path);
637   caml_leave_blocking_section ();
638   if (r == -1)
639     ocaml_guestfs_raise_error (g, "touch");
640
641   rv = Val_unit;
642   CAMLreturn (rv);
643 }
644
645 CAMLprim value
646 ocaml_guestfs_cat (value gv, value pathv)
647 {
648   CAMLparam2 (gv, pathv);
649   CAMLlocal1 (rv);
650
651   guestfs_h *g = Guestfs_val (gv);
652   if (g == NULL)
653     caml_failwith ("cat: used handle after closing it");
654
655   const char *path = String_val (pathv);
656   char *r;
657
658   caml_enter_blocking_section ();
659   r = guestfs_cat (g, path);
660   caml_leave_blocking_section ();
661   if (r == NULL)
662     ocaml_guestfs_raise_error (g, "cat");
663
664   rv = caml_copy_string (r);
665   free (r);
666   CAMLreturn (rv);
667 }
668
669 CAMLprim value
670 ocaml_guestfs_ll (value gv, value directoryv)
671 {
672   CAMLparam2 (gv, directoryv);
673   CAMLlocal1 (rv);
674
675   guestfs_h *g = Guestfs_val (gv);
676   if (g == NULL)
677     caml_failwith ("ll: used handle after closing it");
678
679   const char *directory = String_val (directoryv);
680   char *r;
681
682   caml_enter_blocking_section ();
683   r = guestfs_ll (g, directory);
684   caml_leave_blocking_section ();
685   if (r == NULL)
686     ocaml_guestfs_raise_error (g, "ll");
687
688   rv = caml_copy_string (r);
689   free (r);
690   CAMLreturn (rv);
691 }
692
693 CAMLprim value
694 ocaml_guestfs_ls (value gv, value directoryv)
695 {
696   CAMLparam2 (gv, directoryv);
697   CAMLlocal1 (rv);
698
699   guestfs_h *g = Guestfs_val (gv);
700   if (g == NULL)
701     caml_failwith ("ls: used handle after closing it");
702
703   const char *directory = String_val (directoryv);
704   int i;
705   char **r;
706
707   caml_enter_blocking_section ();
708   r = guestfs_ls (g, directory);
709   caml_leave_blocking_section ();
710   if (r == NULL)
711     ocaml_guestfs_raise_error (g, "ls");
712
713   rv = caml_copy_string_array ((const char **) r);
714   for (i = 0; r[i] != NULL; ++i) free (r[i]);
715   free (r);
716   CAMLreturn (rv);
717 }
718
719 CAMLprim value
720 ocaml_guestfs_list_devices (value gv)
721 {
722   CAMLparam1 (gv);
723   CAMLlocal1 (rv);
724
725   guestfs_h *g = Guestfs_val (gv);
726   if (g == NULL)
727     caml_failwith ("list_devices: used handle after closing it");
728
729   int i;
730   char **r;
731
732   caml_enter_blocking_section ();
733   r = guestfs_list_devices (g);
734   caml_leave_blocking_section ();
735   if (r == NULL)
736     ocaml_guestfs_raise_error (g, "list_devices");
737
738   rv = caml_copy_string_array ((const char **) r);
739   for (i = 0; r[i] != NULL; ++i) free (r[i]);
740   free (r);
741   CAMLreturn (rv);
742 }
743
744 CAMLprim value
745 ocaml_guestfs_list_partitions (value gv)
746 {
747   CAMLparam1 (gv);
748   CAMLlocal1 (rv);
749
750   guestfs_h *g = Guestfs_val (gv);
751   if (g == NULL)
752     caml_failwith ("list_partitions: used handle after closing it");
753
754   int i;
755   char **r;
756
757   caml_enter_blocking_section ();
758   r = guestfs_list_partitions (g);
759   caml_leave_blocking_section ();
760   if (r == NULL)
761     ocaml_guestfs_raise_error (g, "list_partitions");
762
763   rv = caml_copy_string_array ((const char **) r);
764   for (i = 0; r[i] != NULL; ++i) free (r[i]);
765   free (r);
766   CAMLreturn (rv);
767 }
768
769 CAMLprim value
770 ocaml_guestfs_pvs (value gv)
771 {
772   CAMLparam1 (gv);
773   CAMLlocal1 (rv);
774
775   guestfs_h *g = Guestfs_val (gv);
776   if (g == NULL)
777     caml_failwith ("pvs: used handle after closing it");
778
779   int i;
780   char **r;
781
782   caml_enter_blocking_section ();
783   r = guestfs_pvs (g);
784   caml_leave_blocking_section ();
785   if (r == NULL)
786     ocaml_guestfs_raise_error (g, "pvs");
787
788   rv = caml_copy_string_array ((const char **) r);
789   for (i = 0; r[i] != NULL; ++i) free (r[i]);
790   free (r);
791   CAMLreturn (rv);
792 }
793
794 CAMLprim value
795 ocaml_guestfs_vgs (value gv)
796 {
797   CAMLparam1 (gv);
798   CAMLlocal1 (rv);
799
800   guestfs_h *g = Guestfs_val (gv);
801   if (g == NULL)
802     caml_failwith ("vgs: used handle after closing it");
803
804   int i;
805   char **r;
806
807   caml_enter_blocking_section ();
808   r = guestfs_vgs (g);
809   caml_leave_blocking_section ();
810   if (r == NULL)
811     ocaml_guestfs_raise_error (g, "vgs");
812
813   rv = caml_copy_string_array ((const char **) r);
814   for (i = 0; r[i] != NULL; ++i) free (r[i]);
815   free (r);
816   CAMLreturn (rv);
817 }
818
819 CAMLprim value
820 ocaml_guestfs_lvs (value gv)
821 {
822   CAMLparam1 (gv);
823   CAMLlocal1 (rv);
824
825   guestfs_h *g = Guestfs_val (gv);
826   if (g == NULL)
827     caml_failwith ("lvs: used handle after closing it");
828
829   int i;
830   char **r;
831
832   caml_enter_blocking_section ();
833   r = guestfs_lvs (g);
834   caml_leave_blocking_section ();
835   if (r == NULL)
836     ocaml_guestfs_raise_error (g, "lvs");
837
838   rv = caml_copy_string_array ((const char **) r);
839   for (i = 0; r[i] != NULL; ++i) free (r[i]);
840   free (r);
841   CAMLreturn (rv);
842 }
843
844 CAMLprim value
845 ocaml_guestfs_pvs_full (value gv)
846 {
847   CAMLparam1 (gv);
848   CAMLlocal1 (rv);
849
850   guestfs_h *g = Guestfs_val (gv);
851   if (g == NULL)
852     caml_failwith ("pvs_full: used handle after closing it");
853
854   struct guestfs_lvm_pv_list *r;
855
856   caml_enter_blocking_section ();
857   r = guestfs_pvs_full (g);
858   caml_leave_blocking_section ();
859   if (r == NULL)
860     ocaml_guestfs_raise_error (g, "pvs_full");
861
862   rv = copy_lvm_pv_list (r);
863   guestfs_free_lvm_pv_list (r);
864   CAMLreturn (rv);
865 }
866
867 CAMLprim value
868 ocaml_guestfs_vgs_full (value gv)
869 {
870   CAMLparam1 (gv);
871   CAMLlocal1 (rv);
872
873   guestfs_h *g = Guestfs_val (gv);
874   if (g == NULL)
875     caml_failwith ("vgs_full: used handle after closing it");
876
877   struct guestfs_lvm_vg_list *r;
878
879   caml_enter_blocking_section ();
880   r = guestfs_vgs_full (g);
881   caml_leave_blocking_section ();
882   if (r == NULL)
883     ocaml_guestfs_raise_error (g, "vgs_full");
884
885   rv = copy_lvm_vg_list (r);
886   guestfs_free_lvm_vg_list (r);
887   CAMLreturn (rv);
888 }
889
890 CAMLprim value
891 ocaml_guestfs_lvs_full (value gv)
892 {
893   CAMLparam1 (gv);
894   CAMLlocal1 (rv);
895
896   guestfs_h *g = Guestfs_val (gv);
897   if (g == NULL)
898     caml_failwith ("lvs_full: used handle after closing it");
899
900   struct guestfs_lvm_lv_list *r;
901
902   caml_enter_blocking_section ();
903   r = guestfs_lvs_full (g);
904   caml_leave_blocking_section ();
905   if (r == NULL)
906     ocaml_guestfs_raise_error (g, "lvs_full");
907
908   rv = copy_lvm_lv_list (r);
909   guestfs_free_lvm_lv_list (r);
910   CAMLreturn (rv);
911 }
912
913 CAMLprim value
914 ocaml_guestfs_read_lines (value gv, value pathv)
915 {
916   CAMLparam2 (gv, pathv);
917   CAMLlocal1 (rv);
918
919   guestfs_h *g = Guestfs_val (gv);
920   if (g == NULL)
921     caml_failwith ("read_lines: used handle after closing it");
922
923   const char *path = String_val (pathv);
924   int i;
925   char **r;
926
927   caml_enter_blocking_section ();
928   r = guestfs_read_lines (g, path);
929   caml_leave_blocking_section ();
930   if (r == NULL)
931     ocaml_guestfs_raise_error (g, "read_lines");
932
933   rv = caml_copy_string_array ((const char **) r);
934   for (i = 0; r[i] != NULL; ++i) free (r[i]);
935   free (r);
936   CAMLreturn (rv);
937 }
938
939 CAMLprim value
940 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
941 {
942   CAMLparam3 (gv, rootv, flagsv);
943   CAMLlocal1 (rv);
944
945   guestfs_h *g = Guestfs_val (gv);
946   if (g == NULL)
947     caml_failwith ("aug_init: used handle after closing it");
948
949   const char *root = String_val (rootv);
950   int flags = Int_val (flagsv);
951   int r;
952
953   caml_enter_blocking_section ();
954   r = guestfs_aug_init (g, root, flags);
955   caml_leave_blocking_section ();
956   if (r == -1)
957     ocaml_guestfs_raise_error (g, "aug_init");
958
959   rv = Val_unit;
960   CAMLreturn (rv);
961 }
962
963 CAMLprim value
964 ocaml_guestfs_aug_close (value gv)
965 {
966   CAMLparam1 (gv);
967   CAMLlocal1 (rv);
968
969   guestfs_h *g = Guestfs_val (gv);
970   if (g == NULL)
971     caml_failwith ("aug_close: used handle after closing it");
972
973   int r;
974
975   caml_enter_blocking_section ();
976   r = guestfs_aug_close (g);
977   caml_leave_blocking_section ();
978   if (r == -1)
979     ocaml_guestfs_raise_error (g, "aug_close");
980
981   rv = Val_unit;
982   CAMLreturn (rv);
983 }
984
985 CAMLprim value
986 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
987 {
988   CAMLparam3 (gv, namev, exprv);
989   CAMLlocal1 (rv);
990
991   guestfs_h *g = Guestfs_val (gv);
992   if (g == NULL)
993     caml_failwith ("aug_defvar: used handle after closing it");
994
995   const char *name = String_val (namev);
996   const char *expr =
997     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
998   int r;
999
1000   caml_enter_blocking_section ();
1001   r = guestfs_aug_defvar (g, name, expr);
1002   caml_leave_blocking_section ();
1003   if (r == -1)
1004     ocaml_guestfs_raise_error (g, "aug_defvar");
1005
1006   rv = Val_int (r);
1007   CAMLreturn (rv);
1008 }
1009
1010 CAMLprim value
1011 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
1012 {
1013   CAMLparam4 (gv, namev, exprv, valv);
1014   CAMLlocal1 (rv);
1015
1016   guestfs_h *g = Guestfs_val (gv);
1017   if (g == NULL)
1018     caml_failwith ("aug_defnode: used handle after closing it");
1019
1020   const char *name = String_val (namev);
1021   const char *expr = String_val (exprv);
1022   const char *val = String_val (valv);
1023   struct guestfs_int_bool *r;
1024
1025   caml_enter_blocking_section ();
1026   r = guestfs_aug_defnode (g, name, expr, val);
1027   caml_leave_blocking_section ();
1028   if (r == NULL)
1029     ocaml_guestfs_raise_error (g, "aug_defnode");
1030
1031   rv = caml_alloc (2, 0);
1032   Store_field (rv, 0, Val_int (r->i));
1033   Store_field (rv, 1, Val_bool (r->b));
1034   guestfs_free_int_bool (r);
1035   CAMLreturn (rv);
1036 }
1037
1038 CAMLprim value
1039 ocaml_guestfs_aug_get (value gv, value pathv)
1040 {
1041   CAMLparam2 (gv, pathv);
1042   CAMLlocal1 (rv);
1043
1044   guestfs_h *g = Guestfs_val (gv);
1045   if (g == NULL)
1046     caml_failwith ("aug_get: used handle after closing it");
1047
1048   const char *path = String_val (pathv);
1049   char *r;
1050
1051   caml_enter_blocking_section ();
1052   r = guestfs_aug_get (g, path);
1053   caml_leave_blocking_section ();
1054   if (r == NULL)
1055     ocaml_guestfs_raise_error (g, "aug_get");
1056
1057   rv = caml_copy_string (r);
1058   free (r);
1059   CAMLreturn (rv);
1060 }
1061
1062 CAMLprim value
1063 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
1064 {
1065   CAMLparam3 (gv, pathv, valv);
1066   CAMLlocal1 (rv);
1067
1068   guestfs_h *g = Guestfs_val (gv);
1069   if (g == NULL)
1070     caml_failwith ("aug_set: used handle after closing it");
1071
1072   const char *path = String_val (pathv);
1073   const char *val = String_val (valv);
1074   int r;
1075
1076   caml_enter_blocking_section ();
1077   r = guestfs_aug_set (g, path, val);
1078   caml_leave_blocking_section ();
1079   if (r == -1)
1080     ocaml_guestfs_raise_error (g, "aug_set");
1081
1082   rv = Val_unit;
1083   CAMLreturn (rv);
1084 }
1085
1086 CAMLprim value
1087 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1088 {
1089   CAMLparam4 (gv, pathv, labelv, beforev);
1090   CAMLlocal1 (rv);
1091
1092   guestfs_h *g = Guestfs_val (gv);
1093   if (g == NULL)
1094     caml_failwith ("aug_insert: used handle after closing it");
1095
1096   const char *path = String_val (pathv);
1097   const char *label = String_val (labelv);
1098   int before = Bool_val (beforev);
1099   int r;
1100
1101   caml_enter_blocking_section ();
1102   r = guestfs_aug_insert (g, path, label, before);
1103   caml_leave_blocking_section ();
1104   if (r == -1)
1105     ocaml_guestfs_raise_error (g, "aug_insert");
1106
1107   rv = Val_unit;
1108   CAMLreturn (rv);
1109 }
1110
1111 CAMLprim value
1112 ocaml_guestfs_aug_rm (value gv, value pathv)
1113 {
1114   CAMLparam2 (gv, pathv);
1115   CAMLlocal1 (rv);
1116
1117   guestfs_h *g = Guestfs_val (gv);
1118   if (g == NULL)
1119     caml_failwith ("aug_rm: used handle after closing it");
1120
1121   const char *path = String_val (pathv);
1122   int r;
1123
1124   caml_enter_blocking_section ();
1125   r = guestfs_aug_rm (g, path);
1126   caml_leave_blocking_section ();
1127   if (r == -1)
1128     ocaml_guestfs_raise_error (g, "aug_rm");
1129
1130   rv = Val_int (r);
1131   CAMLreturn (rv);
1132 }
1133
1134 CAMLprim value
1135 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1136 {
1137   CAMLparam3 (gv, srcv, destv);
1138   CAMLlocal1 (rv);
1139
1140   guestfs_h *g = Guestfs_val (gv);
1141   if (g == NULL)
1142     caml_failwith ("aug_mv: used handle after closing it");
1143
1144   const char *src = String_val (srcv);
1145   const char *dest = String_val (destv);
1146   int r;
1147
1148   caml_enter_blocking_section ();
1149   r = guestfs_aug_mv (g, src, dest);
1150   caml_leave_blocking_section ();
1151   if (r == -1)
1152     ocaml_guestfs_raise_error (g, "aug_mv");
1153
1154   rv = Val_unit;
1155   CAMLreturn (rv);
1156 }
1157
1158 CAMLprim value
1159 ocaml_guestfs_aug_match (value gv, value pathv)
1160 {
1161   CAMLparam2 (gv, pathv);
1162   CAMLlocal1 (rv);
1163
1164   guestfs_h *g = Guestfs_val (gv);
1165   if (g == NULL)
1166     caml_failwith ("aug_match: used handle after closing it");
1167
1168   const char *path = String_val (pathv);
1169   int i;
1170   char **r;
1171
1172   caml_enter_blocking_section ();
1173   r = guestfs_aug_match (g, path);
1174   caml_leave_blocking_section ();
1175   if (r == NULL)
1176     ocaml_guestfs_raise_error (g, "aug_match");
1177
1178   rv = caml_copy_string_array ((const char **) r);
1179   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1180   free (r);
1181   CAMLreturn (rv);
1182 }
1183
1184 CAMLprim value
1185 ocaml_guestfs_aug_save (value gv)
1186 {
1187   CAMLparam1 (gv);
1188   CAMLlocal1 (rv);
1189
1190   guestfs_h *g = Guestfs_val (gv);
1191   if (g == NULL)
1192     caml_failwith ("aug_save: used handle after closing it");
1193
1194   int r;
1195
1196   caml_enter_blocking_section ();
1197   r = guestfs_aug_save (g);
1198   caml_leave_blocking_section ();
1199   if (r == -1)
1200     ocaml_guestfs_raise_error (g, "aug_save");
1201
1202   rv = Val_unit;
1203   CAMLreturn (rv);
1204 }
1205
1206 CAMLprim value
1207 ocaml_guestfs_aug_load (value gv)
1208 {
1209   CAMLparam1 (gv);
1210   CAMLlocal1 (rv);
1211
1212   guestfs_h *g = Guestfs_val (gv);
1213   if (g == NULL)
1214     caml_failwith ("aug_load: used handle after closing it");
1215
1216   int r;
1217
1218   caml_enter_blocking_section ();
1219   r = guestfs_aug_load (g);
1220   caml_leave_blocking_section ();
1221   if (r == -1)
1222     ocaml_guestfs_raise_error (g, "aug_load");
1223
1224   rv = Val_unit;
1225   CAMLreturn (rv);
1226 }
1227
1228 CAMLprim value
1229 ocaml_guestfs_aug_ls (value gv, value pathv)
1230 {
1231   CAMLparam2 (gv, pathv);
1232   CAMLlocal1 (rv);
1233
1234   guestfs_h *g = Guestfs_val (gv);
1235   if (g == NULL)
1236     caml_failwith ("aug_ls: used handle after closing it");
1237
1238   const char *path = String_val (pathv);
1239   int i;
1240   char **r;
1241
1242   caml_enter_blocking_section ();
1243   r = guestfs_aug_ls (g, path);
1244   caml_leave_blocking_section ();
1245   if (r == NULL)
1246     ocaml_guestfs_raise_error (g, "aug_ls");
1247
1248   rv = caml_copy_string_array ((const char **) r);
1249   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1250   free (r);
1251   CAMLreturn (rv);
1252 }
1253
1254 CAMLprim value
1255 ocaml_guestfs_rm (value gv, value pathv)
1256 {
1257   CAMLparam2 (gv, pathv);
1258   CAMLlocal1 (rv);
1259
1260   guestfs_h *g = Guestfs_val (gv);
1261   if (g == NULL)
1262     caml_failwith ("rm: used handle after closing it");
1263
1264   const char *path = String_val (pathv);
1265   int r;
1266
1267   caml_enter_blocking_section ();
1268   r = guestfs_rm (g, path);
1269   caml_leave_blocking_section ();
1270   if (r == -1)
1271     ocaml_guestfs_raise_error (g, "rm");
1272
1273   rv = Val_unit;
1274   CAMLreturn (rv);
1275 }
1276
1277 CAMLprim value
1278 ocaml_guestfs_rmdir (value gv, value pathv)
1279 {
1280   CAMLparam2 (gv, pathv);
1281   CAMLlocal1 (rv);
1282
1283   guestfs_h *g = Guestfs_val (gv);
1284   if (g == NULL)
1285     caml_failwith ("rmdir: used handle after closing it");
1286
1287   const char *path = String_val (pathv);
1288   int r;
1289
1290   caml_enter_blocking_section ();
1291   r = guestfs_rmdir (g, path);
1292   caml_leave_blocking_section ();
1293   if (r == -1)
1294     ocaml_guestfs_raise_error (g, "rmdir");
1295
1296   rv = Val_unit;
1297   CAMLreturn (rv);
1298 }
1299
1300 CAMLprim value
1301 ocaml_guestfs_rm_rf (value gv, value pathv)
1302 {
1303   CAMLparam2 (gv, pathv);
1304   CAMLlocal1 (rv);
1305
1306   guestfs_h *g = Guestfs_val (gv);
1307   if (g == NULL)
1308     caml_failwith ("rm_rf: used handle after closing it");
1309
1310   const char *path = String_val (pathv);
1311   int r;
1312
1313   caml_enter_blocking_section ();
1314   r = guestfs_rm_rf (g, path);
1315   caml_leave_blocking_section ();
1316   if (r == -1)
1317     ocaml_guestfs_raise_error (g, "rm_rf");
1318
1319   rv = Val_unit;
1320   CAMLreturn (rv);
1321 }
1322
1323 CAMLprim value
1324 ocaml_guestfs_mkdir (value gv, value pathv)
1325 {
1326   CAMLparam2 (gv, pathv);
1327   CAMLlocal1 (rv);
1328
1329   guestfs_h *g = Guestfs_val (gv);
1330   if (g == NULL)
1331     caml_failwith ("mkdir: used handle after closing it");
1332
1333   const char *path = String_val (pathv);
1334   int r;
1335
1336   caml_enter_blocking_section ();
1337   r = guestfs_mkdir (g, path);
1338   caml_leave_blocking_section ();
1339   if (r == -1)
1340     ocaml_guestfs_raise_error (g, "mkdir");
1341
1342   rv = Val_unit;
1343   CAMLreturn (rv);
1344 }
1345
1346 CAMLprim value
1347 ocaml_guestfs_mkdir_p (value gv, value pathv)
1348 {
1349   CAMLparam2 (gv, pathv);
1350   CAMLlocal1 (rv);
1351
1352   guestfs_h *g = Guestfs_val (gv);
1353   if (g == NULL)
1354     caml_failwith ("mkdir_p: used handle after closing it");
1355
1356   const char *path = String_val (pathv);
1357   int r;
1358
1359   caml_enter_blocking_section ();
1360   r = guestfs_mkdir_p (g, path);
1361   caml_leave_blocking_section ();
1362   if (r == -1)
1363     ocaml_guestfs_raise_error (g, "mkdir_p");
1364
1365   rv = Val_unit;
1366   CAMLreturn (rv);
1367 }
1368
1369 CAMLprim value
1370 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1371 {
1372   CAMLparam3 (gv, modev, pathv);
1373   CAMLlocal1 (rv);
1374
1375   guestfs_h *g = Guestfs_val (gv);
1376   if (g == NULL)
1377     caml_failwith ("chmod: used handle after closing it");
1378
1379   int mode = Int_val (modev);
1380   const char *path = String_val (pathv);
1381   int r;
1382
1383   caml_enter_blocking_section ();
1384   r = guestfs_chmod (g, mode, path);
1385   caml_leave_blocking_section ();
1386   if (r == -1)
1387     ocaml_guestfs_raise_error (g, "chmod");
1388
1389   rv = Val_unit;
1390   CAMLreturn (rv);
1391 }
1392
1393 CAMLprim value
1394 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1395 {
1396   CAMLparam4 (gv, ownerv, groupv, pathv);
1397   CAMLlocal1 (rv);
1398
1399   guestfs_h *g = Guestfs_val (gv);
1400   if (g == NULL)
1401     caml_failwith ("chown: used handle after closing it");
1402
1403   int owner = Int_val (ownerv);
1404   int group = Int_val (groupv);
1405   const char *path = String_val (pathv);
1406   int r;
1407
1408   caml_enter_blocking_section ();
1409   r = guestfs_chown (g, owner, group, path);
1410   caml_leave_blocking_section ();
1411   if (r == -1)
1412     ocaml_guestfs_raise_error (g, "chown");
1413
1414   rv = Val_unit;
1415   CAMLreturn (rv);
1416 }
1417
1418 CAMLprim value
1419 ocaml_guestfs_exists (value gv, value pathv)
1420 {
1421   CAMLparam2 (gv, pathv);
1422   CAMLlocal1 (rv);
1423
1424   guestfs_h *g = Guestfs_val (gv);
1425   if (g == NULL)
1426     caml_failwith ("exists: used handle after closing it");
1427
1428   const char *path = String_val (pathv);
1429   int r;
1430
1431   caml_enter_blocking_section ();
1432   r = guestfs_exists (g, path);
1433   caml_leave_blocking_section ();
1434   if (r == -1)
1435     ocaml_guestfs_raise_error (g, "exists");
1436
1437   rv = Val_bool (r);
1438   CAMLreturn (rv);
1439 }
1440
1441 CAMLprim value
1442 ocaml_guestfs_is_file (value gv, value pathv)
1443 {
1444   CAMLparam2 (gv, pathv);
1445   CAMLlocal1 (rv);
1446
1447   guestfs_h *g = Guestfs_val (gv);
1448   if (g == NULL)
1449     caml_failwith ("is_file: used handle after closing it");
1450
1451   const char *path = String_val (pathv);
1452   int r;
1453
1454   caml_enter_blocking_section ();
1455   r = guestfs_is_file (g, path);
1456   caml_leave_blocking_section ();
1457   if (r == -1)
1458     ocaml_guestfs_raise_error (g, "is_file");
1459
1460   rv = Val_bool (r);
1461   CAMLreturn (rv);
1462 }
1463
1464 CAMLprim value
1465 ocaml_guestfs_is_dir (value gv, value pathv)
1466 {
1467   CAMLparam2 (gv, pathv);
1468   CAMLlocal1 (rv);
1469
1470   guestfs_h *g = Guestfs_val (gv);
1471   if (g == NULL)
1472     caml_failwith ("is_dir: used handle after closing it");
1473
1474   const char *path = String_val (pathv);
1475   int r;
1476
1477   caml_enter_blocking_section ();
1478   r = guestfs_is_dir (g, path);
1479   caml_leave_blocking_section ();
1480   if (r == -1)
1481     ocaml_guestfs_raise_error (g, "is_dir");
1482
1483   rv = Val_bool (r);
1484   CAMLreturn (rv);
1485 }
1486
1487 CAMLprim value
1488 ocaml_guestfs_pvcreate (value gv, value devicev)
1489 {
1490   CAMLparam2 (gv, devicev);
1491   CAMLlocal1 (rv);
1492
1493   guestfs_h *g = Guestfs_val (gv);
1494   if (g == NULL)
1495     caml_failwith ("pvcreate: used handle after closing it");
1496
1497   const char *device = String_val (devicev);
1498   int r;
1499
1500   caml_enter_blocking_section ();
1501   r = guestfs_pvcreate (g, device);
1502   caml_leave_blocking_section ();
1503   if (r == -1)
1504     ocaml_guestfs_raise_error (g, "pvcreate");
1505
1506   rv = Val_unit;
1507   CAMLreturn (rv);
1508 }
1509
1510 CAMLprim value
1511 ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
1512 {
1513   CAMLparam3 (gv, volgroupv, physvolsv);
1514   CAMLlocal1 (rv);
1515
1516   guestfs_h *g = Guestfs_val (gv);
1517   if (g == NULL)
1518     caml_failwith ("vgcreate: used handle after closing it");
1519
1520   const char *volgroup = String_val (volgroupv);
1521   char **physvols = ocaml_guestfs_strings_val (physvolsv);
1522   int r;
1523
1524   caml_enter_blocking_section ();
1525   r = guestfs_vgcreate (g, volgroup, physvols);
1526   caml_leave_blocking_section ();
1527   ocaml_guestfs_free_strings (physvols);
1528   if (r == -1)
1529     ocaml_guestfs_raise_error (g, "vgcreate");
1530
1531   rv = Val_unit;
1532   CAMLreturn (rv);
1533 }
1534
1535 CAMLprim value
1536 ocaml_guestfs_lvcreate (value gv, value logvolv, value volgroupv, value mbytesv)
1537 {
1538   CAMLparam4 (gv, logvolv, volgroupv, mbytesv);
1539   CAMLlocal1 (rv);
1540
1541   guestfs_h *g = Guestfs_val (gv);
1542   if (g == NULL)
1543     caml_failwith ("lvcreate: used handle after closing it");
1544
1545   const char *logvol = String_val (logvolv);
1546   const char *volgroup = String_val (volgroupv);
1547   int mbytes = Int_val (mbytesv);
1548   int r;
1549
1550   caml_enter_blocking_section ();
1551   r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
1552   caml_leave_blocking_section ();
1553   if (r == -1)
1554     ocaml_guestfs_raise_error (g, "lvcreate");
1555
1556   rv = Val_unit;
1557   CAMLreturn (rv);
1558 }
1559
1560 CAMLprim value
1561 ocaml_guestfs_mkfs (value gv, value fstypev, value devicev)
1562 {
1563   CAMLparam3 (gv, fstypev, devicev);
1564   CAMLlocal1 (rv);
1565
1566   guestfs_h *g = Guestfs_val (gv);
1567   if (g == NULL)
1568     caml_failwith ("mkfs: used handle after closing it");
1569
1570   const char *fstype = String_val (fstypev);
1571   const char *device = String_val (devicev);
1572   int r;
1573
1574   caml_enter_blocking_section ();
1575   r = guestfs_mkfs (g, fstype, device);
1576   caml_leave_blocking_section ();
1577   if (r == -1)
1578     ocaml_guestfs_raise_error (g, "mkfs");
1579
1580   rv = Val_unit;
1581   CAMLreturn (rv);
1582 }
1583
1584 CAMLprim value
1585 ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value sectorsv, value linesv)
1586 {
1587   CAMLparam5 (gv, devicev, cylsv, headsv, sectorsv);
1588   CAMLxparam1 (linesv);
1589   CAMLlocal1 (rv);
1590
1591   guestfs_h *g = Guestfs_val (gv);
1592   if (g == NULL)
1593     caml_failwith ("sfdisk: used handle after closing it");
1594
1595   const char *device = String_val (devicev);
1596   int cyls = Int_val (cylsv);
1597   int heads = Int_val (headsv);
1598   int sectors = Int_val (sectorsv);
1599   char **lines = ocaml_guestfs_strings_val (linesv);
1600   int r;
1601
1602   caml_enter_blocking_section ();
1603   r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
1604   caml_leave_blocking_section ();
1605   ocaml_guestfs_free_strings (lines);
1606   if (r == -1)
1607     ocaml_guestfs_raise_error (g, "sfdisk");
1608
1609   rv = Val_unit;
1610   CAMLreturn (rv);
1611 }
1612
1613 CAMLprim value
1614 ocaml_guestfs_sfdisk_byte (value *argv, int argn)
1615 {
1616   return ocaml_guestfs_sfdisk (argv[0], argv[0], argv[1], argv[2], argv[3], argv[4]);
1617 }
1618
1619 CAMLprim value
1620 ocaml_guestfs_write_file (value gv, value pathv, value contentv, value sizev)
1621 {
1622   CAMLparam4 (gv, pathv, contentv, sizev);
1623   CAMLlocal1 (rv);
1624
1625   guestfs_h *g = Guestfs_val (gv);
1626   if (g == NULL)
1627     caml_failwith ("write_file: used handle after closing it");
1628
1629   const char *path = String_val (pathv);
1630   const char *content = String_val (contentv);
1631   int size = Int_val (sizev);
1632   int r;
1633
1634   caml_enter_blocking_section ();
1635   r = guestfs_write_file (g, path, content, size);
1636   caml_leave_blocking_section ();
1637   if (r == -1)
1638     ocaml_guestfs_raise_error (g, "write_file");
1639
1640   rv = Val_unit;
1641   CAMLreturn (rv);
1642 }
1643
1644 CAMLprim value
1645 ocaml_guestfs_umount (value gv, value pathordevicev)
1646 {
1647   CAMLparam2 (gv, pathordevicev);
1648   CAMLlocal1 (rv);
1649
1650   guestfs_h *g = Guestfs_val (gv);
1651   if (g == NULL)
1652     caml_failwith ("umount: used handle after closing it");
1653
1654   const char *pathordevice = String_val (pathordevicev);
1655   int r;
1656
1657   caml_enter_blocking_section ();
1658   r = guestfs_umount (g, pathordevice);
1659   caml_leave_blocking_section ();
1660   if (r == -1)
1661     ocaml_guestfs_raise_error (g, "umount");
1662
1663   rv = Val_unit;
1664   CAMLreturn (rv);
1665 }
1666
1667 CAMLprim value
1668 ocaml_guestfs_mounts (value gv)
1669 {
1670   CAMLparam1 (gv);
1671   CAMLlocal1 (rv);
1672
1673   guestfs_h *g = Guestfs_val (gv);
1674   if (g == NULL)
1675     caml_failwith ("mounts: used handle after closing it");
1676
1677   int i;
1678   char **r;
1679
1680   caml_enter_blocking_section ();
1681   r = guestfs_mounts (g);
1682   caml_leave_blocking_section ();
1683   if (r == NULL)
1684     ocaml_guestfs_raise_error (g, "mounts");
1685
1686   rv = caml_copy_string_array ((const char **) r);
1687   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1688   free (r);
1689   CAMLreturn (rv);
1690 }
1691
1692 CAMLprim value
1693 ocaml_guestfs_umount_all (value gv)
1694 {
1695   CAMLparam1 (gv);
1696   CAMLlocal1 (rv);
1697
1698   guestfs_h *g = Guestfs_val (gv);
1699   if (g == NULL)
1700     caml_failwith ("umount_all: used handle after closing it");
1701
1702   int r;
1703
1704   caml_enter_blocking_section ();
1705   r = guestfs_umount_all (g);
1706   caml_leave_blocking_section ();
1707   if (r == -1)
1708     ocaml_guestfs_raise_error (g, "umount_all");
1709
1710   rv = Val_unit;
1711   CAMLreturn (rv);
1712 }
1713
1714 CAMLprim value
1715 ocaml_guestfs_lvm_remove_all (value gv)
1716 {
1717   CAMLparam1 (gv);
1718   CAMLlocal1 (rv);
1719
1720   guestfs_h *g = Guestfs_val (gv);
1721   if (g == NULL)
1722     caml_failwith ("lvm_remove_all: used handle after closing it");
1723
1724   int r;
1725
1726   caml_enter_blocking_section ();
1727   r = guestfs_lvm_remove_all (g);
1728   caml_leave_blocking_section ();
1729   if (r == -1)
1730     ocaml_guestfs_raise_error (g, "lvm_remove_all");
1731
1732   rv = Val_unit;
1733   CAMLreturn (rv);
1734 }
1735
1736 CAMLprim value
1737 ocaml_guestfs_file (value gv, value pathv)
1738 {
1739   CAMLparam2 (gv, pathv);
1740   CAMLlocal1 (rv);
1741
1742   guestfs_h *g = Guestfs_val (gv);
1743   if (g == NULL)
1744     caml_failwith ("file: used handle after closing it");
1745
1746   const char *path = String_val (pathv);
1747   char *r;
1748
1749   caml_enter_blocking_section ();
1750   r = guestfs_file (g, path);
1751   caml_leave_blocking_section ();
1752   if (r == NULL)
1753     ocaml_guestfs_raise_error (g, "file");
1754
1755   rv = caml_copy_string (r);
1756   free (r);
1757   CAMLreturn (rv);
1758 }
1759
1760 CAMLprim value
1761 ocaml_guestfs_command (value gv, value argumentsv)
1762 {
1763   CAMLparam2 (gv, argumentsv);
1764   CAMLlocal1 (rv);
1765
1766   guestfs_h *g = Guestfs_val (gv);
1767   if (g == NULL)
1768     caml_failwith ("command: used handle after closing it");
1769
1770   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1771   char *r;
1772
1773   caml_enter_blocking_section ();
1774   r = guestfs_command (g, arguments);
1775   caml_leave_blocking_section ();
1776   ocaml_guestfs_free_strings (arguments);
1777   if (r == NULL)
1778     ocaml_guestfs_raise_error (g, "command");
1779
1780   rv = caml_copy_string (r);
1781   free (r);
1782   CAMLreturn (rv);
1783 }
1784
1785 CAMLprim value
1786 ocaml_guestfs_command_lines (value gv, value argumentsv)
1787 {
1788   CAMLparam2 (gv, argumentsv);
1789   CAMLlocal1 (rv);
1790
1791   guestfs_h *g = Guestfs_val (gv);
1792   if (g == NULL)
1793     caml_failwith ("command_lines: used handle after closing it");
1794
1795   char **arguments = ocaml_guestfs_strings_val (argumentsv);
1796   int i;
1797   char **r;
1798
1799   caml_enter_blocking_section ();
1800   r = guestfs_command_lines (g, arguments);
1801   caml_leave_blocking_section ();
1802   ocaml_guestfs_free_strings (arguments);
1803   if (r == NULL)
1804     ocaml_guestfs_raise_error (g, "command_lines");
1805
1806   rv = caml_copy_string_array ((const char **) r);
1807   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1808   free (r);
1809   CAMLreturn (rv);
1810 }
1811
1812 CAMLprim value
1813 ocaml_guestfs_stat (value gv, value pathv)
1814 {
1815   CAMLparam2 (gv, pathv);
1816   CAMLlocal1 (rv);
1817
1818   guestfs_h *g = Guestfs_val (gv);
1819   if (g == NULL)
1820     caml_failwith ("stat: used handle after closing it");
1821
1822   const char *path = String_val (pathv);
1823   struct guestfs_stat *r;
1824
1825   caml_enter_blocking_section ();
1826   r = guestfs_stat (g, path);
1827   caml_leave_blocking_section ();
1828   if (r == NULL)
1829     ocaml_guestfs_raise_error (g, "stat");
1830
1831   rv = copy_stat (r);
1832   free (r);
1833   CAMLreturn (rv);
1834 }
1835
1836 CAMLprim value
1837 ocaml_guestfs_lstat (value gv, value pathv)
1838 {
1839   CAMLparam2 (gv, pathv);
1840   CAMLlocal1 (rv);
1841
1842   guestfs_h *g = Guestfs_val (gv);
1843   if (g == NULL)
1844     caml_failwith ("lstat: used handle after closing it");
1845
1846   const char *path = String_val (pathv);
1847   struct guestfs_stat *r;
1848
1849   caml_enter_blocking_section ();
1850   r = guestfs_lstat (g, path);
1851   caml_leave_blocking_section ();
1852   if (r == NULL)
1853     ocaml_guestfs_raise_error (g, "lstat");
1854
1855   rv = copy_stat (r);
1856   free (r);
1857   CAMLreturn (rv);
1858 }
1859
1860 CAMLprim value
1861 ocaml_guestfs_statvfs (value gv, value pathv)
1862 {
1863   CAMLparam2 (gv, pathv);
1864   CAMLlocal1 (rv);
1865
1866   guestfs_h *g = Guestfs_val (gv);
1867   if (g == NULL)
1868     caml_failwith ("statvfs: used handle after closing it");
1869
1870   const char *path = String_val (pathv);
1871   struct guestfs_statvfs *r;
1872
1873   caml_enter_blocking_section ();
1874   r = guestfs_statvfs (g, path);
1875   caml_leave_blocking_section ();
1876   if (r == NULL)
1877     ocaml_guestfs_raise_error (g, "statvfs");
1878
1879   rv = copy_statvfs (r);
1880   free (r);
1881   CAMLreturn (rv);
1882 }
1883