Generated files for previous commands.
[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 CAMLprim value
237 ocaml_guestfs_launch (value gv)
238 {
239   CAMLparam1 (gv);
240   CAMLlocal1 (rv);
241
242   guestfs_h *g = Guestfs_val (gv);
243   if (g == NULL)
244     caml_failwith ("launch: used handle after closing it");
245
246   int r;
247
248   caml_enter_blocking_section ();
249   r = guestfs_launch (g);
250   caml_leave_blocking_section ();
251   if (r == -1)
252     ocaml_guestfs_raise_error (g, "launch");
253
254   rv = Val_unit;
255   CAMLreturn (rv);
256 }
257
258 CAMLprim value
259 ocaml_guestfs_wait_ready (value gv)
260 {
261   CAMLparam1 (gv);
262   CAMLlocal1 (rv);
263
264   guestfs_h *g = Guestfs_val (gv);
265   if (g == NULL)
266     caml_failwith ("wait_ready: used handle after closing it");
267
268   int r;
269
270   caml_enter_blocking_section ();
271   r = guestfs_wait_ready (g);
272   caml_leave_blocking_section ();
273   if (r == -1)
274     ocaml_guestfs_raise_error (g, "wait_ready");
275
276   rv = Val_unit;
277   CAMLreturn (rv);
278 }
279
280 CAMLprim value
281 ocaml_guestfs_kill_subprocess (value gv)
282 {
283   CAMLparam1 (gv);
284   CAMLlocal1 (rv);
285
286   guestfs_h *g = Guestfs_val (gv);
287   if (g == NULL)
288     caml_failwith ("kill_subprocess: used handle after closing it");
289
290   int r;
291
292   caml_enter_blocking_section ();
293   r = guestfs_kill_subprocess (g);
294   caml_leave_blocking_section ();
295   if (r == -1)
296     ocaml_guestfs_raise_error (g, "kill_subprocess");
297
298   rv = Val_unit;
299   CAMLreturn (rv);
300 }
301
302 CAMLprim value
303 ocaml_guestfs_add_drive (value gv, value filenamev)
304 {
305   CAMLparam2 (gv, filenamev);
306   CAMLlocal1 (rv);
307
308   guestfs_h *g = Guestfs_val (gv);
309   if (g == NULL)
310     caml_failwith ("add_drive: used handle after closing it");
311
312   const char *filename = String_val (filenamev);
313   int r;
314
315   caml_enter_blocking_section ();
316   r = guestfs_add_drive (g, filename);
317   caml_leave_blocking_section ();
318   if (r == -1)
319     ocaml_guestfs_raise_error (g, "add_drive");
320
321   rv = Val_unit;
322   CAMLreturn (rv);
323 }
324
325 CAMLprim value
326 ocaml_guestfs_add_cdrom (value gv, value filenamev)
327 {
328   CAMLparam2 (gv, filenamev);
329   CAMLlocal1 (rv);
330
331   guestfs_h *g = Guestfs_val (gv);
332   if (g == NULL)
333     caml_failwith ("add_cdrom: used handle after closing it");
334
335   const char *filename = String_val (filenamev);
336   int r;
337
338   caml_enter_blocking_section ();
339   r = guestfs_add_cdrom (g, filename);
340   caml_leave_blocking_section ();
341   if (r == -1)
342     ocaml_guestfs_raise_error (g, "add_cdrom");
343
344   rv = Val_unit;
345   CAMLreturn (rv);
346 }
347
348 CAMLprim value
349 ocaml_guestfs_config (value gv, value qemuparamv, value qemuvaluev)
350 {
351   CAMLparam3 (gv, qemuparamv, qemuvaluev);
352   CAMLlocal1 (rv);
353
354   guestfs_h *g = Guestfs_val (gv);
355   if (g == NULL)
356     caml_failwith ("config: used handle after closing it");
357
358   const char *qemuparam = String_val (qemuparamv);
359   const char *qemuvalue =
360     qemuvaluev != Val_int (0) ? String_val (Field (qemuvaluev, 0)) : NULL;
361   int r;
362
363   caml_enter_blocking_section ();
364   r = guestfs_config (g, qemuparam, qemuvalue);
365   caml_leave_blocking_section ();
366   if (r == -1)
367     ocaml_guestfs_raise_error (g, "config");
368
369   rv = Val_unit;
370   CAMLreturn (rv);
371 }
372
373 CAMLprim value
374 ocaml_guestfs_set_path (value gv, value pathv)
375 {
376   CAMLparam2 (gv, pathv);
377   CAMLlocal1 (rv);
378
379   guestfs_h *g = Guestfs_val (gv);
380   if (g == NULL)
381     caml_failwith ("set_path: used handle after closing it");
382
383   const char *path = String_val (pathv);
384   int r;
385
386   caml_enter_blocking_section ();
387   r = guestfs_set_path (g, path);
388   caml_leave_blocking_section ();
389   if (r == -1)
390     ocaml_guestfs_raise_error (g, "set_path");
391
392   rv = Val_unit;
393   CAMLreturn (rv);
394 }
395
396 CAMLprim value
397 ocaml_guestfs_get_path (value gv)
398 {
399   CAMLparam1 (gv);
400   CAMLlocal1 (rv);
401
402   guestfs_h *g = Guestfs_val (gv);
403   if (g == NULL)
404     caml_failwith ("get_path: used handle after closing it");
405
406   const char *r;
407
408   caml_enter_blocking_section ();
409   r = guestfs_get_path (g);
410   caml_leave_blocking_section ();
411   if (r == NULL)
412     ocaml_guestfs_raise_error (g, "get_path");
413
414   rv = caml_copy_string (r);
415   CAMLreturn (rv);
416 }
417
418 CAMLprim value
419 ocaml_guestfs_set_autosync (value gv, value autosyncv)
420 {
421   CAMLparam2 (gv, autosyncv);
422   CAMLlocal1 (rv);
423
424   guestfs_h *g = Guestfs_val (gv);
425   if (g == NULL)
426     caml_failwith ("set_autosync: used handle after closing it");
427
428   int autosync = Bool_val (autosyncv);
429   int r;
430
431   caml_enter_blocking_section ();
432   r = guestfs_set_autosync (g, autosync);
433   caml_leave_blocking_section ();
434   if (r == -1)
435     ocaml_guestfs_raise_error (g, "set_autosync");
436
437   rv = Val_unit;
438   CAMLreturn (rv);
439 }
440
441 CAMLprim value
442 ocaml_guestfs_get_autosync (value gv)
443 {
444   CAMLparam1 (gv);
445   CAMLlocal1 (rv);
446
447   guestfs_h *g = Guestfs_val (gv);
448   if (g == NULL)
449     caml_failwith ("get_autosync: used handle after closing it");
450
451   int r;
452
453   caml_enter_blocking_section ();
454   r = guestfs_get_autosync (g);
455   caml_leave_blocking_section ();
456   if (r == -1)
457     ocaml_guestfs_raise_error (g, "get_autosync");
458
459   rv = Val_bool (r);
460   CAMLreturn (rv);
461 }
462
463 CAMLprim value
464 ocaml_guestfs_set_verbose (value gv, value verbosev)
465 {
466   CAMLparam2 (gv, verbosev);
467   CAMLlocal1 (rv);
468
469   guestfs_h *g = Guestfs_val (gv);
470   if (g == NULL)
471     caml_failwith ("set_verbose: used handle after closing it");
472
473   int verbose = Bool_val (verbosev);
474   int r;
475
476   caml_enter_blocking_section ();
477   r = guestfs_set_verbose (g, verbose);
478   caml_leave_blocking_section ();
479   if (r == -1)
480     ocaml_guestfs_raise_error (g, "set_verbose");
481
482   rv = Val_unit;
483   CAMLreturn (rv);
484 }
485
486 CAMLprim value
487 ocaml_guestfs_get_verbose (value gv)
488 {
489   CAMLparam1 (gv);
490   CAMLlocal1 (rv);
491
492   guestfs_h *g = Guestfs_val (gv);
493   if (g == NULL)
494     caml_failwith ("get_verbose: used handle after closing it");
495
496   int r;
497
498   caml_enter_blocking_section ();
499   r = guestfs_get_verbose (g);
500   caml_leave_blocking_section ();
501   if (r == -1)
502     ocaml_guestfs_raise_error (g, "get_verbose");
503
504   rv = Val_bool (r);
505   CAMLreturn (rv);
506 }
507
508 CAMLprim value
509 ocaml_guestfs_mount (value gv, value devicev, value mountpointv)
510 {
511   CAMLparam3 (gv, devicev, mountpointv);
512   CAMLlocal1 (rv);
513
514   guestfs_h *g = Guestfs_val (gv);
515   if (g == NULL)
516     caml_failwith ("mount: used handle after closing it");
517
518   const char *device = String_val (devicev);
519   const char *mountpoint = String_val (mountpointv);
520   int r;
521
522   caml_enter_blocking_section ();
523   r = guestfs_mount (g, device, mountpoint);
524   caml_leave_blocking_section ();
525   if (r == -1)
526     ocaml_guestfs_raise_error (g, "mount");
527
528   rv = Val_unit;
529   CAMLreturn (rv);
530 }
531
532 CAMLprim value
533 ocaml_guestfs_sync (value gv)
534 {
535   CAMLparam1 (gv);
536   CAMLlocal1 (rv);
537
538   guestfs_h *g = Guestfs_val (gv);
539   if (g == NULL)
540     caml_failwith ("sync: used handle after closing it");
541
542   int r;
543
544   caml_enter_blocking_section ();
545   r = guestfs_sync (g);
546   caml_leave_blocking_section ();
547   if (r == -1)
548     ocaml_guestfs_raise_error (g, "sync");
549
550   rv = Val_unit;
551   CAMLreturn (rv);
552 }
553
554 CAMLprim value
555 ocaml_guestfs_touch (value gv, value pathv)
556 {
557   CAMLparam2 (gv, pathv);
558   CAMLlocal1 (rv);
559
560   guestfs_h *g = Guestfs_val (gv);
561   if (g == NULL)
562     caml_failwith ("touch: used handle after closing it");
563
564   const char *path = String_val (pathv);
565   int r;
566
567   caml_enter_blocking_section ();
568   r = guestfs_touch (g, path);
569   caml_leave_blocking_section ();
570   if (r == -1)
571     ocaml_guestfs_raise_error (g, "touch");
572
573   rv = Val_unit;
574   CAMLreturn (rv);
575 }
576
577 CAMLprim value
578 ocaml_guestfs_cat (value gv, value pathv)
579 {
580   CAMLparam2 (gv, pathv);
581   CAMLlocal1 (rv);
582
583   guestfs_h *g = Guestfs_val (gv);
584   if (g == NULL)
585     caml_failwith ("cat: used handle after closing it");
586
587   const char *path = String_val (pathv);
588   char *r;
589
590   caml_enter_blocking_section ();
591   r = guestfs_cat (g, path);
592   caml_leave_blocking_section ();
593   if (r == NULL)
594     ocaml_guestfs_raise_error (g, "cat");
595
596   rv = caml_copy_string (r);
597   free (r);
598   CAMLreturn (rv);
599 }
600
601 CAMLprim value
602 ocaml_guestfs_ll (value gv, value directoryv)
603 {
604   CAMLparam2 (gv, directoryv);
605   CAMLlocal1 (rv);
606
607   guestfs_h *g = Guestfs_val (gv);
608   if (g == NULL)
609     caml_failwith ("ll: used handle after closing it");
610
611   const char *directory = String_val (directoryv);
612   char *r;
613
614   caml_enter_blocking_section ();
615   r = guestfs_ll (g, directory);
616   caml_leave_blocking_section ();
617   if (r == NULL)
618     ocaml_guestfs_raise_error (g, "ll");
619
620   rv = caml_copy_string (r);
621   free (r);
622   CAMLreturn (rv);
623 }
624
625 CAMLprim value
626 ocaml_guestfs_ls (value gv, value directoryv)
627 {
628   CAMLparam2 (gv, directoryv);
629   CAMLlocal1 (rv);
630
631   guestfs_h *g = Guestfs_val (gv);
632   if (g == NULL)
633     caml_failwith ("ls: used handle after closing it");
634
635   const char *directory = String_val (directoryv);
636   int i;
637   char **r;
638
639   caml_enter_blocking_section ();
640   r = guestfs_ls (g, directory);
641   caml_leave_blocking_section ();
642   if (r == NULL)
643     ocaml_guestfs_raise_error (g, "ls");
644
645   rv = caml_copy_string_array ((const char **) r);
646   for (i = 0; r[i] != NULL; ++i) free (r[i]);
647   free (r);
648   CAMLreturn (rv);
649 }
650
651 CAMLprim value
652 ocaml_guestfs_list_devices (value gv)
653 {
654   CAMLparam1 (gv);
655   CAMLlocal1 (rv);
656
657   guestfs_h *g = Guestfs_val (gv);
658   if (g == NULL)
659     caml_failwith ("list_devices: used handle after closing it");
660
661   int i;
662   char **r;
663
664   caml_enter_blocking_section ();
665   r = guestfs_list_devices (g);
666   caml_leave_blocking_section ();
667   if (r == NULL)
668     ocaml_guestfs_raise_error (g, "list_devices");
669
670   rv = caml_copy_string_array ((const char **) r);
671   for (i = 0; r[i] != NULL; ++i) free (r[i]);
672   free (r);
673   CAMLreturn (rv);
674 }
675
676 CAMLprim value
677 ocaml_guestfs_list_partitions (value gv)
678 {
679   CAMLparam1 (gv);
680   CAMLlocal1 (rv);
681
682   guestfs_h *g = Guestfs_val (gv);
683   if (g == NULL)
684     caml_failwith ("list_partitions: used handle after closing it");
685
686   int i;
687   char **r;
688
689   caml_enter_blocking_section ();
690   r = guestfs_list_partitions (g);
691   caml_leave_blocking_section ();
692   if (r == NULL)
693     ocaml_guestfs_raise_error (g, "list_partitions");
694
695   rv = caml_copy_string_array ((const char **) r);
696   for (i = 0; r[i] != NULL; ++i) free (r[i]);
697   free (r);
698   CAMLreturn (rv);
699 }
700
701 CAMLprim value
702 ocaml_guestfs_pvs (value gv)
703 {
704   CAMLparam1 (gv);
705   CAMLlocal1 (rv);
706
707   guestfs_h *g = Guestfs_val (gv);
708   if (g == NULL)
709     caml_failwith ("pvs: used handle after closing it");
710
711   int i;
712   char **r;
713
714   caml_enter_blocking_section ();
715   r = guestfs_pvs (g);
716   caml_leave_blocking_section ();
717   if (r == NULL)
718     ocaml_guestfs_raise_error (g, "pvs");
719
720   rv = caml_copy_string_array ((const char **) r);
721   for (i = 0; r[i] != NULL; ++i) free (r[i]);
722   free (r);
723   CAMLreturn (rv);
724 }
725
726 CAMLprim value
727 ocaml_guestfs_vgs (value gv)
728 {
729   CAMLparam1 (gv);
730   CAMLlocal1 (rv);
731
732   guestfs_h *g = Guestfs_val (gv);
733   if (g == NULL)
734     caml_failwith ("vgs: used handle after closing it");
735
736   int i;
737   char **r;
738
739   caml_enter_blocking_section ();
740   r = guestfs_vgs (g);
741   caml_leave_blocking_section ();
742   if (r == NULL)
743     ocaml_guestfs_raise_error (g, "vgs");
744
745   rv = caml_copy_string_array ((const char **) r);
746   for (i = 0; r[i] != NULL; ++i) free (r[i]);
747   free (r);
748   CAMLreturn (rv);
749 }
750
751 CAMLprim value
752 ocaml_guestfs_lvs (value gv)
753 {
754   CAMLparam1 (gv);
755   CAMLlocal1 (rv);
756
757   guestfs_h *g = Guestfs_val (gv);
758   if (g == NULL)
759     caml_failwith ("lvs: used handle after closing it");
760
761   int i;
762   char **r;
763
764   caml_enter_blocking_section ();
765   r = guestfs_lvs (g);
766   caml_leave_blocking_section ();
767   if (r == NULL)
768     ocaml_guestfs_raise_error (g, "lvs");
769
770   rv = caml_copy_string_array ((const char **) r);
771   for (i = 0; r[i] != NULL; ++i) free (r[i]);
772   free (r);
773   CAMLreturn (rv);
774 }
775
776 CAMLprim value
777 ocaml_guestfs_pvs_full (value gv)
778 {
779   CAMLparam1 (gv);
780   CAMLlocal1 (rv);
781
782   guestfs_h *g = Guestfs_val (gv);
783   if (g == NULL)
784     caml_failwith ("pvs_full: used handle after closing it");
785
786   struct guestfs_lvm_pv_list *r;
787
788   caml_enter_blocking_section ();
789   r = guestfs_pvs_full (g);
790   caml_leave_blocking_section ();
791   if (r == NULL)
792     ocaml_guestfs_raise_error (g, "pvs_full");
793
794   rv = copy_lvm_pv_list (r);
795   guestfs_free_lvm_pv_list (r);
796   CAMLreturn (rv);
797 }
798
799 CAMLprim value
800 ocaml_guestfs_vgs_full (value gv)
801 {
802   CAMLparam1 (gv);
803   CAMLlocal1 (rv);
804
805   guestfs_h *g = Guestfs_val (gv);
806   if (g == NULL)
807     caml_failwith ("vgs_full: used handle after closing it");
808
809   struct guestfs_lvm_vg_list *r;
810
811   caml_enter_blocking_section ();
812   r = guestfs_vgs_full (g);
813   caml_leave_blocking_section ();
814   if (r == NULL)
815     ocaml_guestfs_raise_error (g, "vgs_full");
816
817   rv = copy_lvm_vg_list (r);
818   guestfs_free_lvm_vg_list (r);
819   CAMLreturn (rv);
820 }
821
822 CAMLprim value
823 ocaml_guestfs_lvs_full (value gv)
824 {
825   CAMLparam1 (gv);
826   CAMLlocal1 (rv);
827
828   guestfs_h *g = Guestfs_val (gv);
829   if (g == NULL)
830     caml_failwith ("lvs_full: used handle after closing it");
831
832   struct guestfs_lvm_lv_list *r;
833
834   caml_enter_blocking_section ();
835   r = guestfs_lvs_full (g);
836   caml_leave_blocking_section ();
837   if (r == NULL)
838     ocaml_guestfs_raise_error (g, "lvs_full");
839
840   rv = copy_lvm_lv_list (r);
841   guestfs_free_lvm_lv_list (r);
842   CAMLreturn (rv);
843 }
844
845 CAMLprim value
846 ocaml_guestfs_read_lines (value gv, value pathv)
847 {
848   CAMLparam2 (gv, pathv);
849   CAMLlocal1 (rv);
850
851   guestfs_h *g = Guestfs_val (gv);
852   if (g == NULL)
853     caml_failwith ("read_lines: used handle after closing it");
854
855   const char *path = String_val (pathv);
856   int i;
857   char **r;
858
859   caml_enter_blocking_section ();
860   r = guestfs_read_lines (g, path);
861   caml_leave_blocking_section ();
862   if (r == NULL)
863     ocaml_guestfs_raise_error (g, "read_lines");
864
865   rv = caml_copy_string_array ((const char **) r);
866   for (i = 0; r[i] != NULL; ++i) free (r[i]);
867   free (r);
868   CAMLreturn (rv);
869 }
870
871 CAMLprim value
872 ocaml_guestfs_aug_init (value gv, value rootv, value flagsv)
873 {
874   CAMLparam3 (gv, rootv, flagsv);
875   CAMLlocal1 (rv);
876
877   guestfs_h *g = Guestfs_val (gv);
878   if (g == NULL)
879     caml_failwith ("aug_init: used handle after closing it");
880
881   const char *root = String_val (rootv);
882   int flags = Int_val (flagsv);
883   int r;
884
885   caml_enter_blocking_section ();
886   r = guestfs_aug_init (g, root, flags);
887   caml_leave_blocking_section ();
888   if (r == -1)
889     ocaml_guestfs_raise_error (g, "aug_init");
890
891   rv = Val_unit;
892   CAMLreturn (rv);
893 }
894
895 CAMLprim value
896 ocaml_guestfs_aug_close (value gv)
897 {
898   CAMLparam1 (gv);
899   CAMLlocal1 (rv);
900
901   guestfs_h *g = Guestfs_val (gv);
902   if (g == NULL)
903     caml_failwith ("aug_close: used handle after closing it");
904
905   int r;
906
907   caml_enter_blocking_section ();
908   r = guestfs_aug_close (g);
909   caml_leave_blocking_section ();
910   if (r == -1)
911     ocaml_guestfs_raise_error (g, "aug_close");
912
913   rv = Val_unit;
914   CAMLreturn (rv);
915 }
916
917 CAMLprim value
918 ocaml_guestfs_aug_defvar (value gv, value namev, value exprv)
919 {
920   CAMLparam3 (gv, namev, exprv);
921   CAMLlocal1 (rv);
922
923   guestfs_h *g = Guestfs_val (gv);
924   if (g == NULL)
925     caml_failwith ("aug_defvar: used handle after closing it");
926
927   const char *name = String_val (namev);
928   const char *expr =
929     exprv != Val_int (0) ? String_val (Field (exprv, 0)) : NULL;
930   int r;
931
932   caml_enter_blocking_section ();
933   r = guestfs_aug_defvar (g, name, expr);
934   caml_leave_blocking_section ();
935   if (r == -1)
936     ocaml_guestfs_raise_error (g, "aug_defvar");
937
938   rv = Val_int (r);
939   CAMLreturn (rv);
940 }
941
942 CAMLprim value
943 ocaml_guestfs_aug_defnode (value gv, value namev, value exprv, value valv)
944 {
945   CAMLparam4 (gv, namev, exprv, valv);
946   CAMLlocal1 (rv);
947
948   guestfs_h *g = Guestfs_val (gv);
949   if (g == NULL)
950     caml_failwith ("aug_defnode: used handle after closing it");
951
952   const char *name = String_val (namev);
953   const char *expr = String_val (exprv);
954   const char *val = String_val (valv);
955   struct guestfs_int_bool *r;
956
957   caml_enter_blocking_section ();
958   r = guestfs_aug_defnode (g, name, expr, val);
959   caml_leave_blocking_section ();
960   if (r == NULL)
961     ocaml_guestfs_raise_error (g, "aug_defnode");
962
963   rv = caml_alloc (2, 0);
964   Store_field (rv, 0, Val_int (r->i));
965   Store_field (rv, 1, Val_bool (r->b));
966   guestfs_free_int_bool (r);
967   CAMLreturn (rv);
968 }
969
970 CAMLprim value
971 ocaml_guestfs_aug_get (value gv, value pathv)
972 {
973   CAMLparam2 (gv, pathv);
974   CAMLlocal1 (rv);
975
976   guestfs_h *g = Guestfs_val (gv);
977   if (g == NULL)
978     caml_failwith ("aug_get: used handle after closing it");
979
980   const char *path = String_val (pathv);
981   char *r;
982
983   caml_enter_blocking_section ();
984   r = guestfs_aug_get (g, path);
985   caml_leave_blocking_section ();
986   if (r == NULL)
987     ocaml_guestfs_raise_error (g, "aug_get");
988
989   rv = caml_copy_string (r);
990   free (r);
991   CAMLreturn (rv);
992 }
993
994 CAMLprim value
995 ocaml_guestfs_aug_set (value gv, value pathv, value valv)
996 {
997   CAMLparam3 (gv, pathv, valv);
998   CAMLlocal1 (rv);
999
1000   guestfs_h *g = Guestfs_val (gv);
1001   if (g == NULL)
1002     caml_failwith ("aug_set: used handle after closing it");
1003
1004   const char *path = String_val (pathv);
1005   const char *val = String_val (valv);
1006   int r;
1007
1008   caml_enter_blocking_section ();
1009   r = guestfs_aug_set (g, path, val);
1010   caml_leave_blocking_section ();
1011   if (r == -1)
1012     ocaml_guestfs_raise_error (g, "aug_set");
1013
1014   rv = Val_unit;
1015   CAMLreturn (rv);
1016 }
1017
1018 CAMLprim value
1019 ocaml_guestfs_aug_insert (value gv, value pathv, value labelv, value beforev)
1020 {
1021   CAMLparam4 (gv, pathv, labelv, beforev);
1022   CAMLlocal1 (rv);
1023
1024   guestfs_h *g = Guestfs_val (gv);
1025   if (g == NULL)
1026     caml_failwith ("aug_insert: used handle after closing it");
1027
1028   const char *path = String_val (pathv);
1029   const char *label = String_val (labelv);
1030   int before = Bool_val (beforev);
1031   int r;
1032
1033   caml_enter_blocking_section ();
1034   r = guestfs_aug_insert (g, path, label, before);
1035   caml_leave_blocking_section ();
1036   if (r == -1)
1037     ocaml_guestfs_raise_error (g, "aug_insert");
1038
1039   rv = Val_unit;
1040   CAMLreturn (rv);
1041 }
1042
1043 CAMLprim value
1044 ocaml_guestfs_aug_rm (value gv, value pathv)
1045 {
1046   CAMLparam2 (gv, pathv);
1047   CAMLlocal1 (rv);
1048
1049   guestfs_h *g = Guestfs_val (gv);
1050   if (g == NULL)
1051     caml_failwith ("aug_rm: used handle after closing it");
1052
1053   const char *path = String_val (pathv);
1054   int r;
1055
1056   caml_enter_blocking_section ();
1057   r = guestfs_aug_rm (g, path);
1058   caml_leave_blocking_section ();
1059   if (r == -1)
1060     ocaml_guestfs_raise_error (g, "aug_rm");
1061
1062   rv = Val_int (r);
1063   CAMLreturn (rv);
1064 }
1065
1066 CAMLprim value
1067 ocaml_guestfs_aug_mv (value gv, value srcv, value destv)
1068 {
1069   CAMLparam3 (gv, srcv, destv);
1070   CAMLlocal1 (rv);
1071
1072   guestfs_h *g = Guestfs_val (gv);
1073   if (g == NULL)
1074     caml_failwith ("aug_mv: used handle after closing it");
1075
1076   const char *src = String_val (srcv);
1077   const char *dest = String_val (destv);
1078   int r;
1079
1080   caml_enter_blocking_section ();
1081   r = guestfs_aug_mv (g, src, dest);
1082   caml_leave_blocking_section ();
1083   if (r == -1)
1084     ocaml_guestfs_raise_error (g, "aug_mv");
1085
1086   rv = Val_unit;
1087   CAMLreturn (rv);
1088 }
1089
1090 CAMLprim value
1091 ocaml_guestfs_aug_match (value gv, value pathv)
1092 {
1093   CAMLparam2 (gv, pathv);
1094   CAMLlocal1 (rv);
1095
1096   guestfs_h *g = Guestfs_val (gv);
1097   if (g == NULL)
1098     caml_failwith ("aug_match: used handle after closing it");
1099
1100   const char *path = String_val (pathv);
1101   int i;
1102   char **r;
1103
1104   caml_enter_blocking_section ();
1105   r = guestfs_aug_match (g, path);
1106   caml_leave_blocking_section ();
1107   if (r == NULL)
1108     ocaml_guestfs_raise_error (g, "aug_match");
1109
1110   rv = caml_copy_string_array ((const char **) r);
1111   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1112   free (r);
1113   CAMLreturn (rv);
1114 }
1115
1116 CAMLprim value
1117 ocaml_guestfs_aug_save (value gv)
1118 {
1119   CAMLparam1 (gv);
1120   CAMLlocal1 (rv);
1121
1122   guestfs_h *g = Guestfs_val (gv);
1123   if (g == NULL)
1124     caml_failwith ("aug_save: used handle after closing it");
1125
1126   int r;
1127
1128   caml_enter_blocking_section ();
1129   r = guestfs_aug_save (g);
1130   caml_leave_blocking_section ();
1131   if (r == -1)
1132     ocaml_guestfs_raise_error (g, "aug_save");
1133
1134   rv = Val_unit;
1135   CAMLreturn (rv);
1136 }
1137
1138 CAMLprim value
1139 ocaml_guestfs_aug_load (value gv)
1140 {
1141   CAMLparam1 (gv);
1142   CAMLlocal1 (rv);
1143
1144   guestfs_h *g = Guestfs_val (gv);
1145   if (g == NULL)
1146     caml_failwith ("aug_load: used handle after closing it");
1147
1148   int r;
1149
1150   caml_enter_blocking_section ();
1151   r = guestfs_aug_load (g);
1152   caml_leave_blocking_section ();
1153   if (r == -1)
1154     ocaml_guestfs_raise_error (g, "aug_load");
1155
1156   rv = Val_unit;
1157   CAMLreturn (rv);
1158 }
1159
1160 CAMLprim value
1161 ocaml_guestfs_aug_ls (value gv, value pathv)
1162 {
1163   CAMLparam2 (gv, pathv);
1164   CAMLlocal1 (rv);
1165
1166   guestfs_h *g = Guestfs_val (gv);
1167   if (g == NULL)
1168     caml_failwith ("aug_ls: used handle after closing it");
1169
1170   const char *path = String_val (pathv);
1171   int i;
1172   char **r;
1173
1174   caml_enter_blocking_section ();
1175   r = guestfs_aug_ls (g, path);
1176   caml_leave_blocking_section ();
1177   if (r == NULL)
1178     ocaml_guestfs_raise_error (g, "aug_ls");
1179
1180   rv = caml_copy_string_array ((const char **) r);
1181   for (i = 0; r[i] != NULL; ++i) free (r[i]);
1182   free (r);
1183   CAMLreturn (rv);
1184 }
1185
1186 CAMLprim value
1187 ocaml_guestfs_rm (value gv, value pathv)
1188 {
1189   CAMLparam2 (gv, pathv);
1190   CAMLlocal1 (rv);
1191
1192   guestfs_h *g = Guestfs_val (gv);
1193   if (g == NULL)
1194     caml_failwith ("rm: used handle after closing it");
1195
1196   const char *path = String_val (pathv);
1197   int r;
1198
1199   caml_enter_blocking_section ();
1200   r = guestfs_rm (g, path);
1201   caml_leave_blocking_section ();
1202   if (r == -1)
1203     ocaml_guestfs_raise_error (g, "rm");
1204
1205   rv = Val_unit;
1206   CAMLreturn (rv);
1207 }
1208
1209 CAMLprim value
1210 ocaml_guestfs_rmdir (value gv, value pathv)
1211 {
1212   CAMLparam2 (gv, pathv);
1213   CAMLlocal1 (rv);
1214
1215   guestfs_h *g = Guestfs_val (gv);
1216   if (g == NULL)
1217     caml_failwith ("rmdir: used handle after closing it");
1218
1219   const char *path = String_val (pathv);
1220   int r;
1221
1222   caml_enter_blocking_section ();
1223   r = guestfs_rmdir (g, path);
1224   caml_leave_blocking_section ();
1225   if (r == -1)
1226     ocaml_guestfs_raise_error (g, "rmdir");
1227
1228   rv = Val_unit;
1229   CAMLreturn (rv);
1230 }
1231
1232 CAMLprim value
1233 ocaml_guestfs_rm_rf (value gv, value pathv)
1234 {
1235   CAMLparam2 (gv, pathv);
1236   CAMLlocal1 (rv);
1237
1238   guestfs_h *g = Guestfs_val (gv);
1239   if (g == NULL)
1240     caml_failwith ("rm_rf: used handle after closing it");
1241
1242   const char *path = String_val (pathv);
1243   int r;
1244
1245   caml_enter_blocking_section ();
1246   r = guestfs_rm_rf (g, path);
1247   caml_leave_blocking_section ();
1248   if (r == -1)
1249     ocaml_guestfs_raise_error (g, "rm_rf");
1250
1251   rv = Val_unit;
1252   CAMLreturn (rv);
1253 }
1254
1255 CAMLprim value
1256 ocaml_guestfs_mkdir (value gv, value pathv)
1257 {
1258   CAMLparam2 (gv, pathv);
1259   CAMLlocal1 (rv);
1260
1261   guestfs_h *g = Guestfs_val (gv);
1262   if (g == NULL)
1263     caml_failwith ("mkdir: used handle after closing it");
1264
1265   const char *path = String_val (pathv);
1266   int r;
1267
1268   caml_enter_blocking_section ();
1269   r = guestfs_mkdir (g, path);
1270   caml_leave_blocking_section ();
1271   if (r == -1)
1272     ocaml_guestfs_raise_error (g, "mkdir");
1273
1274   rv = Val_unit;
1275   CAMLreturn (rv);
1276 }
1277
1278 CAMLprim value
1279 ocaml_guestfs_mkdir_p (value gv, value pathv)
1280 {
1281   CAMLparam2 (gv, pathv);
1282   CAMLlocal1 (rv);
1283
1284   guestfs_h *g = Guestfs_val (gv);
1285   if (g == NULL)
1286     caml_failwith ("mkdir_p: used handle after closing it");
1287
1288   const char *path = String_val (pathv);
1289   int r;
1290
1291   caml_enter_blocking_section ();
1292   r = guestfs_mkdir_p (g, path);
1293   caml_leave_blocking_section ();
1294   if (r == -1)
1295     ocaml_guestfs_raise_error (g, "mkdir_p");
1296
1297   rv = Val_unit;
1298   CAMLreturn (rv);
1299 }
1300
1301 CAMLprim value
1302 ocaml_guestfs_chmod (value gv, value modev, value pathv)
1303 {
1304   CAMLparam3 (gv, modev, pathv);
1305   CAMLlocal1 (rv);
1306
1307   guestfs_h *g = Guestfs_val (gv);
1308   if (g == NULL)
1309     caml_failwith ("chmod: used handle after closing it");
1310
1311   int mode = Int_val (modev);
1312   const char *path = String_val (pathv);
1313   int r;
1314
1315   caml_enter_blocking_section ();
1316   r = guestfs_chmod (g, mode, path);
1317   caml_leave_blocking_section ();
1318   if (r == -1)
1319     ocaml_guestfs_raise_error (g, "chmod");
1320
1321   rv = Val_unit;
1322   CAMLreturn (rv);
1323 }
1324
1325 CAMLprim value
1326 ocaml_guestfs_chown (value gv, value ownerv, value groupv, value pathv)
1327 {
1328   CAMLparam4 (gv, ownerv, groupv, pathv);
1329   CAMLlocal1 (rv);
1330
1331   guestfs_h *g = Guestfs_val (gv);
1332   if (g == NULL)
1333     caml_failwith ("chown: used handle after closing it");
1334
1335   int owner = Int_val (ownerv);
1336   int group = Int_val (groupv);
1337   const char *path = String_val (pathv);
1338   int r;
1339
1340   caml_enter_blocking_section ();
1341   r = guestfs_chown (g, owner, group, path);
1342   caml_leave_blocking_section ();
1343   if (r == -1)
1344     ocaml_guestfs_raise_error (g, "chown");
1345
1346   rv = Val_unit;
1347   CAMLreturn (rv);
1348 }
1349