Minor adjustments for 0.8 release.
[libguestfs.git] / perl / Guestfs.xs
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 "EXTERN.h"
23 #include "perl.h"
24 #include "XSUB.h"
25
26 #include <guestfs.h>
27
28 #ifndef PRId64
29 #define PRId64 "lld"
30 #endif
31
32 static SV *
33 my_newSVll(long long val) {
34 #ifdef USE_64_BIT_ALL
35   return newSViv(val);
36 #else
37   char buf[100];
38   int len;
39   len = snprintf(buf, 100, "%" PRId64, val);
40   return newSVpv(buf, len);
41 #endif
42 }
43
44 #ifndef PRIu64
45 #define PRIu64 "llu"
46 #endif
47
48 static SV *
49 my_newSVull(unsigned long long val) {
50 #ifdef USE_64_BIT_ALL
51   return newSVuv(val);
52 #else
53   char buf[100];
54   int len;
55   len = snprintf(buf, 100, "%" PRIu64, val);
56   return newSVpv(buf, len);
57 #endif
58 }
59
60 /* XXX Not thread-safe, and in general not safe if the caller is
61  * issuing multiple requests in parallel (on different guestfs
62  * handles).  We should use the guestfs_h handle passed to the
63  * error handle to distinguish these cases.
64  */
65 static char *last_error = NULL;
66
67 static void
68 error_handler (guestfs_h *g,
69                void *data,
70                const char *msg)
71 {
72   if (last_error != NULL) free (last_error);
73   last_error = strdup (msg);
74 }
75
76 /* http://www.perlmonks.org/?node_id=680842 */
77 static char **
78 XS_unpack_charPtrPtr (SV *arg) {
79   char **ret;
80   AV *av;
81   I32 i;
82
83   if (!arg || !SvOK (arg) || !SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) {
84     croak ("array reference expected");
85   }
86
87   av = (AV *)SvRV (arg);
88   ret = (char **)malloc (av_len (av) + 1 + 1);
89
90   for (i = 0; i <= av_len (av); i++) {
91     SV **elem = av_fetch (av, i, 0);
92
93       if (!elem || !*elem) {
94         croak ("missing element in list");
95       }
96
97       ret[i] = SvPV_nolen (*elem);
98   }
99
100   ret[i + 1] = NULL;
101
102   return ret;
103 }
104
105 MODULE = Sys::Guestfs  PACKAGE = Sys::Guestfs
106
107 guestfs_h *
108 _create ()
109    CODE:
110       RETVAL = guestfs_create ();
111       if (!RETVAL)
112         croak ("could not create guestfs handle");
113       guestfs_set_error_handler (RETVAL, error_handler, NULL);
114  OUTPUT:
115       RETVAL
116
117 void
118 DESTROY (g)
119       guestfs_h *g;
120  PPCODE:
121       guestfs_close (g);
122
123 void
124 launch (g)
125       guestfs_h *g;
126  PPCODE:
127       if (guestfs_launch (g) == -1) {
128         croak ("launch: %s", last_error);
129       }
130
131 void
132 wait_ready (g)
133       guestfs_h *g;
134  PPCODE:
135       if (guestfs_wait_ready (g) == -1) {
136         croak ("wait_ready: %s", last_error);
137       }
138
139 void
140 kill_subprocess (g)
141       guestfs_h *g;
142  PPCODE:
143       if (guestfs_kill_subprocess (g) == -1) {
144         croak ("kill_subprocess: %s", last_error);
145       }
146
147 void
148 add_drive (g, filename)
149       guestfs_h *g;
150       char *filename;
151  PPCODE:
152       if (guestfs_add_drive (g, filename) == -1) {
153         croak ("add_drive: %s", last_error);
154       }
155
156 void
157 add_cdrom (g, filename)
158       guestfs_h *g;
159       char *filename;
160  PPCODE:
161       if (guestfs_add_cdrom (g, filename) == -1) {
162         croak ("add_cdrom: %s", last_error);
163       }
164
165 void
166 config (g, qemuparam, qemuvalue)
167       guestfs_h *g;
168       char *qemuparam;
169       char *qemuvalue;
170  PPCODE:
171       if (guestfs_config (g, qemuparam, qemuvalue) == -1) {
172         croak ("config: %s", last_error);
173       }
174
175 void
176 set_path (g, path)
177       guestfs_h *g;
178       char *path;
179  PPCODE:
180       if (guestfs_set_path (g, path) == -1) {
181         croak ("set_path: %s", last_error);
182       }
183
184 SV *
185 get_path (g)
186       guestfs_h *g;
187 PREINIT:
188       const char *path;
189    CODE:
190       path = guestfs_get_path (g);
191       if (path == NULL) {
192         croak ("get_path: %s", last_error);
193       }
194       RETVAL = newSVpv (path, 0);
195  OUTPUT:
196       RETVAL
197
198 void
199 set_autosync (g, autosync)
200       guestfs_h *g;
201       int autosync;
202  PPCODE:
203       if (guestfs_set_autosync (g, autosync) == -1) {
204         croak ("set_autosync: %s", last_error);
205       }
206
207 SV *
208 get_autosync (g)
209       guestfs_h *g;
210 PREINIT:
211       int autosync;
212    CODE:
213       autosync = guestfs_get_autosync (g);
214       if (autosync == -1) {
215         croak ("get_autosync: %s", last_error);
216       }
217       RETVAL = newSViv (autosync);
218  OUTPUT:
219       RETVAL
220
221 void
222 set_verbose (g, verbose)
223       guestfs_h *g;
224       int verbose;
225  PPCODE:
226       if (guestfs_set_verbose (g, verbose) == -1) {
227         croak ("set_verbose: %s", last_error);
228       }
229
230 SV *
231 get_verbose (g)
232       guestfs_h *g;
233 PREINIT:
234       int verbose;
235    CODE:
236       verbose = guestfs_get_verbose (g);
237       if (verbose == -1) {
238         croak ("get_verbose: %s", last_error);
239       }
240       RETVAL = newSViv (verbose);
241  OUTPUT:
242       RETVAL
243
244 void
245 mount (g, device, mountpoint)
246       guestfs_h *g;
247       char *device;
248       char *mountpoint;
249  PPCODE:
250       if (guestfs_mount (g, device, mountpoint) == -1) {
251         croak ("mount: %s", last_error);
252       }
253
254 void
255 sync (g)
256       guestfs_h *g;
257  PPCODE:
258       if (guestfs_sync (g) == -1) {
259         croak ("sync: %s", last_error);
260       }
261
262 void
263 touch (g, path)
264       guestfs_h *g;
265       char *path;
266  PPCODE:
267       if (guestfs_touch (g, path) == -1) {
268         croak ("touch: %s", last_error);
269       }
270
271 SV *
272 cat (g, path)
273       guestfs_h *g;
274       char *path;
275 PREINIT:
276       char *content;
277    CODE:
278       content = guestfs_cat (g, path);
279       if (content == NULL) {
280         croak ("cat: %s", last_error);
281       }
282       RETVAL = newSVpv (content, 0);
283       free (content);
284  OUTPUT:
285       RETVAL
286
287 SV *
288 ll (g, directory)
289       guestfs_h *g;
290       char *directory;
291 PREINIT:
292       char *listing;
293    CODE:
294       listing = guestfs_ll (g, directory);
295       if (listing == NULL) {
296         croak ("ll: %s", last_error);
297       }
298       RETVAL = newSVpv (listing, 0);
299       free (listing);
300  OUTPUT:
301       RETVAL
302
303 void
304 ls (g, directory)
305       guestfs_h *g;
306       char *directory;
307 PREINIT:
308       char **listing;
309       int i, n;
310  PPCODE:
311       listing = guestfs_ls (g, directory);
312       if (listing == NULL) {
313         croak ("ls: %s", last_error);
314       }
315       for (n = 0; listing[n] != NULL; ++n) /**/;
316       EXTEND (SP, n);
317       for (i = 0; i < n; ++i) {
318         PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
319         free (listing[i]);
320       }
321       free (listing);
322
323 void
324 list_devices (g)
325       guestfs_h *g;
326 PREINIT:
327       char **devices;
328       int i, n;
329  PPCODE:
330       devices = guestfs_list_devices (g);
331       if (devices == NULL) {
332         croak ("list_devices: %s", last_error);
333       }
334       for (n = 0; devices[n] != NULL; ++n) /**/;
335       EXTEND (SP, n);
336       for (i = 0; i < n; ++i) {
337         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
338         free (devices[i]);
339       }
340       free (devices);
341
342 void
343 list_partitions (g)
344       guestfs_h *g;
345 PREINIT:
346       char **partitions;
347       int i, n;
348  PPCODE:
349       partitions = guestfs_list_partitions (g);
350       if (partitions == NULL) {
351         croak ("list_partitions: %s", last_error);
352       }
353       for (n = 0; partitions[n] != NULL; ++n) /**/;
354       EXTEND (SP, n);
355       for (i = 0; i < n; ++i) {
356         PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
357         free (partitions[i]);
358       }
359       free (partitions);
360
361 void
362 pvs (g)
363       guestfs_h *g;
364 PREINIT:
365       char **physvols;
366       int i, n;
367  PPCODE:
368       physvols = guestfs_pvs (g);
369       if (physvols == NULL) {
370         croak ("pvs: %s", last_error);
371       }
372       for (n = 0; physvols[n] != NULL; ++n) /**/;
373       EXTEND (SP, n);
374       for (i = 0; i < n; ++i) {
375         PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
376         free (physvols[i]);
377       }
378       free (physvols);
379
380 void
381 vgs (g)
382       guestfs_h *g;
383 PREINIT:
384       char **volgroups;
385       int i, n;
386  PPCODE:
387       volgroups = guestfs_vgs (g);
388       if (volgroups == NULL) {
389         croak ("vgs: %s", last_error);
390       }
391       for (n = 0; volgroups[n] != NULL; ++n) /**/;
392       EXTEND (SP, n);
393       for (i = 0; i < n; ++i) {
394         PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
395         free (volgroups[i]);
396       }
397       free (volgroups);
398
399 void
400 lvs (g)
401       guestfs_h *g;
402 PREINIT:
403       char **logvols;
404       int i, n;
405  PPCODE:
406       logvols = guestfs_lvs (g);
407       if (logvols == NULL) {
408         croak ("lvs: %s", last_error);
409       }
410       for (n = 0; logvols[n] != NULL; ++n) /**/;
411       EXTEND (SP, n);
412       for (i = 0; i < n; ++i) {
413         PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
414         free (logvols[i]);
415       }
416       free (logvols);
417
418 void
419 pvs_full (g)
420       guestfs_h *g;
421 PREINIT:
422       struct guestfs_lvm_pv_list *physvols;
423       int i;
424       HV *hv;
425  PPCODE:
426       physvols = guestfs_pvs_full (g);
427       if (physvols == NULL)
428         croak ("pvs_full: %s", last_error);
429       EXTEND (SP, physvols->len);
430       for (i = 0; i < physvols->len; ++i) {
431         hv = newHV ();
432         (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
433         (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
434         (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
435         (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
436         (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
437         (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
438         (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
439         (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
440         (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
441         (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
442         (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
443         (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
444         (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
445         (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
446         PUSHs (sv_2mortal ((SV *) hv));
447       }
448       guestfs_free_lvm_pv_list (physvols);
449
450 void
451 vgs_full (g)
452       guestfs_h *g;
453 PREINIT:
454       struct guestfs_lvm_vg_list *volgroups;
455       int i;
456       HV *hv;
457  PPCODE:
458       volgroups = guestfs_vgs_full (g);
459       if (volgroups == NULL)
460         croak ("vgs_full: %s", last_error);
461       EXTEND (SP, volgroups->len);
462       for (i = 0; i < volgroups->len; ++i) {
463         hv = newHV ();
464         (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
465         (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
466         (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
467         (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
468         (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
469         (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
470         (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
471         (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
472         (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
473         (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
474         (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
475         (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
476         (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
477         (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
478         (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
479         (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
480         (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
481         (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
482         (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
483         PUSHs (sv_2mortal ((SV *) hv));
484       }
485       guestfs_free_lvm_vg_list (volgroups);
486
487 void
488 lvs_full (g)
489       guestfs_h *g;
490 PREINIT:
491       struct guestfs_lvm_lv_list *logvols;
492       int i;
493       HV *hv;
494  PPCODE:
495       logvols = guestfs_lvs_full (g);
496       if (logvols == NULL)
497         croak ("lvs_full: %s", last_error);
498       EXTEND (SP, logvols->len);
499       for (i = 0; i < logvols->len; ++i) {
500         hv = newHV ();
501         (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
502         (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
503         (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
504         (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
505         (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
506         (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
507         (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
508         (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
509         (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
510         (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
511         (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
512         (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
513         (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
514         (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
515         (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
516         (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
517         PUSHs (sv_2mortal ((SV *) hv));
518       }
519       guestfs_free_lvm_lv_list (logvols);
520
521 void
522 read_lines (g, path)
523       guestfs_h *g;
524       char *path;
525 PREINIT:
526       char **lines;
527       int i, n;
528  PPCODE:
529       lines = guestfs_read_lines (g, path);
530       if (lines == NULL) {
531         croak ("read_lines: %s", last_error);
532       }
533       for (n = 0; lines[n] != NULL; ++n) /**/;
534       EXTEND (SP, n);
535       for (i = 0; i < n; ++i) {
536         PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
537         free (lines[i]);
538       }
539       free (lines);
540
541 void
542 aug_init (g, root, flags)
543       guestfs_h *g;
544       char *root;
545       int flags;
546  PPCODE:
547       if (guestfs_aug_init (g, root, flags) == -1) {
548         croak ("aug_init: %s", last_error);
549       }
550
551 void
552 aug_close (g)
553       guestfs_h *g;
554  PPCODE:
555       if (guestfs_aug_close (g) == -1) {
556         croak ("aug_close: %s", last_error);
557       }
558
559 SV *
560 aug_defvar (g, name, expr)
561       guestfs_h *g;
562       char *name;
563       char *expr;
564 PREINIT:
565       int nrnodes;
566    CODE:
567       nrnodes = guestfs_aug_defvar (g, name, expr);
568       if (nrnodes == -1) {
569         croak ("aug_defvar: %s", last_error);
570       }
571       RETVAL = newSViv (nrnodes);
572  OUTPUT:
573       RETVAL
574
575 void
576 aug_defnode (g, name, expr, val)
577       guestfs_h *g;
578       char *name;
579       char *expr;
580       char *val;
581 PREINIT:
582       struct guestfs_int_bool *r;
583  PPCODE:
584       r = guestfs_aug_defnode (g, name, expr, val);
585       if (r == NULL) {
586         croak ("aug_defnode: %s", last_error);
587       }
588       EXTEND (SP, 2);
589       PUSHs (sv_2mortal (newSViv (r->i)));
590       PUSHs (sv_2mortal (newSViv (r->b)));
591       guestfs_free_int_bool (r);
592
593 SV *
594 aug_get (g, path)
595       guestfs_h *g;
596       char *path;
597 PREINIT:
598       char *val;
599    CODE:
600       val = guestfs_aug_get (g, path);
601       if (val == NULL) {
602         croak ("aug_get: %s", last_error);
603       }
604       RETVAL = newSVpv (val, 0);
605       free (val);
606  OUTPUT:
607       RETVAL
608
609 void
610 aug_set (g, path, val)
611       guestfs_h *g;
612       char *path;
613       char *val;
614  PPCODE:
615       if (guestfs_aug_set (g, path, val) == -1) {
616         croak ("aug_set: %s", last_error);
617       }
618
619 void
620 aug_insert (g, path, label, before)
621       guestfs_h *g;
622       char *path;
623       char *label;
624       int before;
625  PPCODE:
626       if (guestfs_aug_insert (g, path, label, before) == -1) {
627         croak ("aug_insert: %s", last_error);
628       }
629
630 SV *
631 aug_rm (g, path)
632       guestfs_h *g;
633       char *path;
634 PREINIT:
635       int nrnodes;
636    CODE:
637       nrnodes = guestfs_aug_rm (g, path);
638       if (nrnodes == -1) {
639         croak ("aug_rm: %s", last_error);
640       }
641       RETVAL = newSViv (nrnodes);
642  OUTPUT:
643       RETVAL
644
645 void
646 aug_mv (g, src, dest)
647       guestfs_h *g;
648       char *src;
649       char *dest;
650  PPCODE:
651       if (guestfs_aug_mv (g, src, dest) == -1) {
652         croak ("aug_mv: %s", last_error);
653       }
654
655 void
656 aug_match (g, path)
657       guestfs_h *g;
658       char *path;
659 PREINIT:
660       char **matches;
661       int i, n;
662  PPCODE:
663       matches = guestfs_aug_match (g, path);
664       if (matches == NULL) {
665         croak ("aug_match: %s", last_error);
666       }
667       for (n = 0; matches[n] != NULL; ++n) /**/;
668       EXTEND (SP, n);
669       for (i = 0; i < n; ++i) {
670         PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
671         free (matches[i]);
672       }
673       free (matches);
674
675 void
676 aug_save (g)
677       guestfs_h *g;
678  PPCODE:
679       if (guestfs_aug_save (g) == -1) {
680         croak ("aug_save: %s", last_error);
681       }
682
683 void
684 aug_load (g)
685       guestfs_h *g;
686  PPCODE:
687       if (guestfs_aug_load (g) == -1) {
688         croak ("aug_load: %s", last_error);
689       }
690
691 void
692 aug_ls (g, path)
693       guestfs_h *g;
694       char *path;
695 PREINIT:
696       char **matches;
697       int i, n;
698  PPCODE:
699       matches = guestfs_aug_ls (g, path);
700       if (matches == NULL) {
701         croak ("aug_ls: %s", last_error);
702       }
703       for (n = 0; matches[n] != NULL; ++n) /**/;
704       EXTEND (SP, n);
705       for (i = 0; i < n; ++i) {
706         PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
707         free (matches[i]);
708       }
709       free (matches);
710
711 void
712 rm (g, path)
713       guestfs_h *g;
714       char *path;
715  PPCODE:
716       if (guestfs_rm (g, path) == -1) {
717         croak ("rm: %s", last_error);
718       }
719
720 void
721 rmdir (g, path)
722       guestfs_h *g;
723       char *path;
724  PPCODE:
725       if (guestfs_rmdir (g, path) == -1) {
726         croak ("rmdir: %s", last_error);
727       }
728
729 void
730 rm_rf (g, path)
731       guestfs_h *g;
732       char *path;
733  PPCODE:
734       if (guestfs_rm_rf (g, path) == -1) {
735         croak ("rm_rf: %s", last_error);
736       }
737
738 void
739 mkdir (g, path)
740       guestfs_h *g;
741       char *path;
742  PPCODE:
743       if (guestfs_mkdir (g, path) == -1) {
744         croak ("mkdir: %s", last_error);
745       }
746
747 void
748 mkdir_p (g, path)
749       guestfs_h *g;
750       char *path;
751  PPCODE:
752       if (guestfs_mkdir_p (g, path) == -1) {
753         croak ("mkdir_p: %s", last_error);
754       }
755
756 void
757 chmod (g, mode, path)
758       guestfs_h *g;
759       int mode;
760       char *path;
761  PPCODE:
762       if (guestfs_chmod (g, mode, path) == -1) {
763         croak ("chmod: %s", last_error);
764       }
765
766 void
767 chown (g, owner, group, path)
768       guestfs_h *g;
769       int owner;
770       int group;
771       char *path;
772  PPCODE:
773       if (guestfs_chown (g, owner, group, path) == -1) {
774         croak ("chown: %s", last_error);
775       }
776
777 SV *
778 exists (g, path)
779       guestfs_h *g;
780       char *path;
781 PREINIT:
782       int existsflag;
783    CODE:
784       existsflag = guestfs_exists (g, path);
785       if (existsflag == -1) {
786         croak ("exists: %s", last_error);
787       }
788       RETVAL = newSViv (existsflag);
789  OUTPUT:
790       RETVAL
791
792 SV *
793 is_file (g, path)
794       guestfs_h *g;
795       char *path;
796 PREINIT:
797       int fileflag;
798    CODE:
799       fileflag = guestfs_is_file (g, path);
800       if (fileflag == -1) {
801         croak ("is_file: %s", last_error);
802       }
803       RETVAL = newSViv (fileflag);
804  OUTPUT:
805       RETVAL
806
807 SV *
808 is_dir (g, path)
809       guestfs_h *g;
810       char *path;
811 PREINIT:
812       int dirflag;
813    CODE:
814       dirflag = guestfs_is_dir (g, path);
815       if (dirflag == -1) {
816         croak ("is_dir: %s", last_error);
817       }
818       RETVAL = newSViv (dirflag);
819  OUTPUT:
820       RETVAL
821
822 void
823 pvcreate (g, device)
824       guestfs_h *g;
825       char *device;
826  PPCODE:
827       if (guestfs_pvcreate (g, device) == -1) {
828         croak ("pvcreate: %s", last_error);
829       }
830
831 void
832 vgcreate (g, volgroup, physvols)
833       guestfs_h *g;
834       char *volgroup;
835       char **physvols;
836  PPCODE:
837       if (guestfs_vgcreate (g, volgroup, physvols) == -1) {
838         free (physvols);
839         croak ("vgcreate: %s", last_error);
840       }
841         free (physvols);
842
843 void
844 lvcreate (g, logvol, volgroup, mbytes)
845       guestfs_h *g;
846       char *logvol;
847       char *volgroup;
848       int mbytes;
849  PPCODE:
850       if (guestfs_lvcreate (g, logvol, volgroup, mbytes) == -1) {
851         croak ("lvcreate: %s", last_error);
852       }
853
854 void
855 mkfs (g, fstype, device)
856       guestfs_h *g;
857       char *fstype;
858       char *device;
859  PPCODE:
860       if (guestfs_mkfs (g, fstype, device) == -1) {
861         croak ("mkfs: %s", last_error);
862       }
863
864 void
865 sfdisk (g, device, cyls, heads, sectors, lines)
866       guestfs_h *g;
867       char *device;
868       int cyls;
869       int heads;
870       int sectors;
871       char **lines;
872  PPCODE:
873       if (guestfs_sfdisk (g, device, cyls, heads, sectors, lines) == -1) {
874         free (lines);
875         croak ("sfdisk: %s", last_error);
876       }
877         free (lines);
878
879 void
880 write_file (g, path, content, size)
881       guestfs_h *g;
882       char *path;
883       char *content;
884       int size;
885  PPCODE:
886       if (guestfs_write_file (g, path, content, size) == -1) {
887         croak ("write_file: %s", last_error);
888       }
889
890 void
891 umount (g, pathordevice)
892       guestfs_h *g;
893       char *pathordevice;
894  PPCODE:
895       if (guestfs_umount (g, pathordevice) == -1) {
896         croak ("umount: %s", last_error);
897       }
898
899 void
900 mounts (g)
901       guestfs_h *g;
902 PREINIT:
903       char **devices;
904       int i, n;
905  PPCODE:
906       devices = guestfs_mounts (g);
907       if (devices == NULL) {
908         croak ("mounts: %s", last_error);
909       }
910       for (n = 0; devices[n] != NULL; ++n) /**/;
911       EXTEND (SP, n);
912       for (i = 0; i < n; ++i) {
913         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
914         free (devices[i]);
915       }
916       free (devices);
917
918 void
919 umount_all (g)
920       guestfs_h *g;
921  PPCODE:
922       if (guestfs_umount_all (g) == -1) {
923         croak ("umount_all: %s", last_error);
924       }
925
926 void
927 lvm_remove_all (g)
928       guestfs_h *g;
929  PPCODE:
930       if (guestfs_lvm_remove_all (g) == -1) {
931         croak ("lvm_remove_all: %s", last_error);
932       }
933