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