Separate out the high-level API actions.
[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 PREINIT:
110       int r;
111  PPCODE:
112       r = guestfs_launch (g);
113       if (r == -1)
114         croak ("launch: %s", guestfs_last_error (g));
115
116 void
117 wait_ready (g)
118       guestfs_h *g;
119 PREINIT:
120       int r;
121  PPCODE:
122       r = guestfs_wait_ready (g);
123       if (r == -1)
124         croak ("wait_ready: %s", guestfs_last_error (g));
125
126 void
127 kill_subprocess (g)
128       guestfs_h *g;
129 PREINIT:
130       int r;
131  PPCODE:
132       r = guestfs_kill_subprocess (g);
133       if (r == -1)
134         croak ("kill_subprocess: %s", guestfs_last_error (g));
135
136 void
137 add_drive (g, filename)
138       guestfs_h *g;
139       char *filename;
140 PREINIT:
141       int r;
142  PPCODE:
143       r = guestfs_add_drive (g, filename);
144       if (r == -1)
145         croak ("add_drive: %s", guestfs_last_error (g));
146
147 void
148 add_cdrom (g, filename)
149       guestfs_h *g;
150       char *filename;
151 PREINIT:
152       int r;
153  PPCODE:
154       r = guestfs_add_cdrom (g, filename);
155       if (r == -1)
156         croak ("add_cdrom: %s", guestfs_last_error (g));
157
158 void
159 config (g, qemuparam, qemuvalue)
160       guestfs_h *g;
161       char *qemuparam;
162       char *qemuvalue;
163 PREINIT:
164       int r;
165  PPCODE:
166       r = guestfs_config (g, qemuparam, qemuvalue);
167       if (r == -1)
168         croak ("config: %s", guestfs_last_error (g));
169
170 void
171 set_path (g, path)
172       guestfs_h *g;
173       char *path;
174 PREINIT:
175       int r;
176  PPCODE:
177       r = guestfs_set_path (g, path);
178       if (r == -1)
179         croak ("set_path: %s", guestfs_last_error (g));
180
181 SV *
182 get_path (g)
183       guestfs_h *g;
184 PREINIT:
185       const char *path;
186    CODE:
187       path = guestfs_get_path (g);
188       if (path == NULL)
189         croak ("get_path: %s", guestfs_last_error (g));
190       RETVAL = newSVpv (path, 0);
191  OUTPUT:
192       RETVAL
193
194 void
195 set_autosync (g, autosync)
196       guestfs_h *g;
197       int autosync;
198 PREINIT:
199       int r;
200  PPCODE:
201       r = guestfs_set_autosync (g, autosync);
202       if (r == -1)
203         croak ("set_autosync: %s", guestfs_last_error (g));
204
205 SV *
206 get_autosync (g)
207       guestfs_h *g;
208 PREINIT:
209       int autosync;
210    CODE:
211       autosync = guestfs_get_autosync (g);
212       if (autosync == -1)
213         croak ("get_autosync: %s", guestfs_last_error (g));
214       RETVAL = newSViv (autosync);
215  OUTPUT:
216       RETVAL
217
218 void
219 set_verbose (g, verbose)
220       guestfs_h *g;
221       int verbose;
222 PREINIT:
223       int r;
224  PPCODE:
225       r = guestfs_set_verbose (g, verbose);
226       if (r == -1)
227         croak ("set_verbose: %s", guestfs_last_error (g));
228
229 SV *
230 get_verbose (g)
231       guestfs_h *g;
232 PREINIT:
233       int verbose;
234    CODE:
235       verbose = guestfs_get_verbose (g);
236       if (verbose == -1)
237         croak ("get_verbose: %s", guestfs_last_error (g));
238       RETVAL = newSViv (verbose);
239  OUTPUT:
240       RETVAL
241
242 SV *
243 is_ready (g)
244       guestfs_h *g;
245 PREINIT:
246       int ready;
247    CODE:
248       ready = guestfs_is_ready (g);
249       if (ready == -1)
250         croak ("is_ready: %s", guestfs_last_error (g));
251       RETVAL = newSViv (ready);
252  OUTPUT:
253       RETVAL
254
255 SV *
256 is_config (g)
257       guestfs_h *g;
258 PREINIT:
259       int config;
260    CODE:
261       config = guestfs_is_config (g);
262       if (config == -1)
263         croak ("is_config: %s", guestfs_last_error (g));
264       RETVAL = newSViv (config);
265  OUTPUT:
266       RETVAL
267
268 SV *
269 is_launching (g)
270       guestfs_h *g;
271 PREINIT:
272       int launching;
273    CODE:
274       launching = guestfs_is_launching (g);
275       if (launching == -1)
276         croak ("is_launching: %s", guestfs_last_error (g));
277       RETVAL = newSViv (launching);
278  OUTPUT:
279       RETVAL
280
281 SV *
282 is_busy (g)
283       guestfs_h *g;
284 PREINIT:
285       int busy;
286    CODE:
287       busy = guestfs_is_busy (g);
288       if (busy == -1)
289         croak ("is_busy: %s", guestfs_last_error (g));
290       RETVAL = newSViv (busy);
291  OUTPUT:
292       RETVAL
293
294 SV *
295 get_state (g)
296       guestfs_h *g;
297 PREINIT:
298       int state;
299    CODE:
300       state = guestfs_get_state (g);
301       if (state == -1)
302         croak ("get_state: %s", guestfs_last_error (g));
303       RETVAL = newSViv (state);
304  OUTPUT:
305       RETVAL
306
307 void
308 mount (g, device, mountpoint)
309       guestfs_h *g;
310       char *device;
311       char *mountpoint;
312 PREINIT:
313       int r;
314  PPCODE:
315       r = guestfs_mount (g, device, mountpoint);
316       if (r == -1)
317         croak ("mount: %s", guestfs_last_error (g));
318
319 void
320 sync (g)
321       guestfs_h *g;
322 PREINIT:
323       int r;
324  PPCODE:
325       r = guestfs_sync (g);
326       if (r == -1)
327         croak ("sync: %s", guestfs_last_error (g));
328
329 void
330 touch (g, path)
331       guestfs_h *g;
332       char *path;
333 PREINIT:
334       int r;
335  PPCODE:
336       r = guestfs_touch (g, path);
337       if (r == -1)
338         croak ("touch: %s", guestfs_last_error (g));
339
340 SV *
341 cat (g, path)
342       guestfs_h *g;
343       char *path;
344 PREINIT:
345       char *content;
346    CODE:
347       content = guestfs_cat (g, path);
348       if (content == NULL)
349         croak ("cat: %s", guestfs_last_error (g));
350       RETVAL = newSVpv (content, 0);
351       free (content);
352  OUTPUT:
353       RETVAL
354
355 SV *
356 ll (g, directory)
357       guestfs_h *g;
358       char *directory;
359 PREINIT:
360       char *listing;
361    CODE:
362       listing = guestfs_ll (g, directory);
363       if (listing == NULL)
364         croak ("ll: %s", guestfs_last_error (g));
365       RETVAL = newSVpv (listing, 0);
366       free (listing);
367  OUTPUT:
368       RETVAL
369
370 void
371 ls (g, directory)
372       guestfs_h *g;
373       char *directory;
374 PREINIT:
375       char **listing;
376       int i, n;
377  PPCODE:
378       listing = guestfs_ls (g, directory);
379       if (listing == NULL)
380         croak ("ls: %s", guestfs_last_error (g));
381       for (n = 0; listing[n] != NULL; ++n) /**/;
382       EXTEND (SP, n);
383       for (i = 0; i < n; ++i) {
384         PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
385         free (listing[i]);
386       }
387       free (listing);
388
389 void
390 list_devices (g)
391       guestfs_h *g;
392 PREINIT:
393       char **devices;
394       int i, n;
395  PPCODE:
396       devices = guestfs_list_devices (g);
397       if (devices == NULL)
398         croak ("list_devices: %s", guestfs_last_error (g));
399       for (n = 0; devices[n] != NULL; ++n) /**/;
400       EXTEND (SP, n);
401       for (i = 0; i < n; ++i) {
402         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
403         free (devices[i]);
404       }
405       free (devices);
406
407 void
408 list_partitions (g)
409       guestfs_h *g;
410 PREINIT:
411       char **partitions;
412       int i, n;
413  PPCODE:
414       partitions = guestfs_list_partitions (g);
415       if (partitions == NULL)
416         croak ("list_partitions: %s", guestfs_last_error (g));
417       for (n = 0; partitions[n] != NULL; ++n) /**/;
418       EXTEND (SP, n);
419       for (i = 0; i < n; ++i) {
420         PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
421         free (partitions[i]);
422       }
423       free (partitions);
424
425 void
426 pvs (g)
427       guestfs_h *g;
428 PREINIT:
429       char **physvols;
430       int i, n;
431  PPCODE:
432       physvols = guestfs_pvs (g);
433       if (physvols == NULL)
434         croak ("pvs: %s", guestfs_last_error (g));
435       for (n = 0; physvols[n] != NULL; ++n) /**/;
436       EXTEND (SP, n);
437       for (i = 0; i < n; ++i) {
438         PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
439         free (physvols[i]);
440       }
441       free (physvols);
442
443 void
444 vgs (g)
445       guestfs_h *g;
446 PREINIT:
447       char **volgroups;
448       int i, n;
449  PPCODE:
450       volgroups = guestfs_vgs (g);
451       if (volgroups == NULL)
452         croak ("vgs: %s", guestfs_last_error (g));
453       for (n = 0; volgroups[n] != NULL; ++n) /**/;
454       EXTEND (SP, n);
455       for (i = 0; i < n; ++i) {
456         PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
457         free (volgroups[i]);
458       }
459       free (volgroups);
460
461 void
462 lvs (g)
463       guestfs_h *g;
464 PREINIT:
465       char **logvols;
466       int i, n;
467  PPCODE:
468       logvols = guestfs_lvs (g);
469       if (logvols == NULL)
470         croak ("lvs: %s", guestfs_last_error (g));
471       for (n = 0; logvols[n] != NULL; ++n) /**/;
472       EXTEND (SP, n);
473       for (i = 0; i < n; ++i) {
474         PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
475         free (logvols[i]);
476       }
477       free (logvols);
478
479 void
480 pvs_full (g)
481       guestfs_h *g;
482 PREINIT:
483       struct guestfs_lvm_pv_list *physvols;
484       int i;
485       HV *hv;
486  PPCODE:
487       physvols = guestfs_pvs_full (g);
488       if (physvols == NULL)
489         croak ("pvs_full: %s", guestfs_last_error (g));
490       EXTEND (SP, physvols->len);
491       for (i = 0; i < physvols->len; ++i) {
492         hv = newHV ();
493         (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
494         (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
495         (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
496         (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
497         (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
498         (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
499         (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
500         (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
501         (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
502         (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
503         (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
504         (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
505         (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
506         (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
507         PUSHs (sv_2mortal ((SV *) hv));
508       }
509       guestfs_free_lvm_pv_list (physvols);
510
511 void
512 vgs_full (g)
513       guestfs_h *g;
514 PREINIT:
515       struct guestfs_lvm_vg_list *volgroups;
516       int i;
517       HV *hv;
518  PPCODE:
519       volgroups = guestfs_vgs_full (g);
520       if (volgroups == NULL)
521         croak ("vgs_full: %s", guestfs_last_error (g));
522       EXTEND (SP, volgroups->len);
523       for (i = 0; i < volgroups->len; ++i) {
524         hv = newHV ();
525         (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
526         (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
527         (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
528         (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
529         (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
530         (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
531         (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
532         (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
533         (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
534         (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
535         (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
536         (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
537         (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
538         (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
539         (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
540         (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
541         (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
542         (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
543         (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
544         PUSHs (sv_2mortal ((SV *) hv));
545       }
546       guestfs_free_lvm_vg_list (volgroups);
547
548 void
549 lvs_full (g)
550       guestfs_h *g;
551 PREINIT:
552       struct guestfs_lvm_lv_list *logvols;
553       int i;
554       HV *hv;
555  PPCODE:
556       logvols = guestfs_lvs_full (g);
557       if (logvols == NULL)
558         croak ("lvs_full: %s", guestfs_last_error (g));
559       EXTEND (SP, logvols->len);
560       for (i = 0; i < logvols->len; ++i) {
561         hv = newHV ();
562         (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
563         (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
564         (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
565         (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
566         (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
567         (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
568         (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
569         (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
570         (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
571         (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
572         (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
573         (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
574         (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
575         (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
576         (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
577         (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
578         PUSHs (sv_2mortal ((SV *) hv));
579       }
580       guestfs_free_lvm_lv_list (logvols);
581
582 void
583 read_lines (g, path)
584       guestfs_h *g;
585       char *path;
586 PREINIT:
587       char **lines;
588       int i, n;
589  PPCODE:
590       lines = guestfs_read_lines (g, path);
591       if (lines == NULL)
592         croak ("read_lines: %s", guestfs_last_error (g));
593       for (n = 0; lines[n] != NULL; ++n) /**/;
594       EXTEND (SP, n);
595       for (i = 0; i < n; ++i) {
596         PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
597         free (lines[i]);
598       }
599       free (lines);
600
601 void
602 aug_init (g, root, flags)
603       guestfs_h *g;
604       char *root;
605       int flags;
606 PREINIT:
607       int r;
608  PPCODE:
609       r = guestfs_aug_init (g, root, flags);
610       if (r == -1)
611         croak ("aug_init: %s", guestfs_last_error (g));
612
613 void
614 aug_close (g)
615       guestfs_h *g;
616 PREINIT:
617       int r;
618  PPCODE:
619       r = guestfs_aug_close (g);
620       if (r == -1)
621         croak ("aug_close: %s", guestfs_last_error (g));
622
623 SV *
624 aug_defvar (g, name, expr)
625       guestfs_h *g;
626       char *name;
627       char *expr;
628 PREINIT:
629       int nrnodes;
630    CODE:
631       nrnodes = guestfs_aug_defvar (g, name, expr);
632       if (nrnodes == -1)
633         croak ("aug_defvar: %s", guestfs_last_error (g));
634       RETVAL = newSViv (nrnodes);
635  OUTPUT:
636       RETVAL
637
638 void
639 aug_defnode (g, name, expr, val)
640       guestfs_h *g;
641       char *name;
642       char *expr;
643       char *val;
644 PREINIT:
645       struct guestfs_int_bool *r;
646  PPCODE:
647       r = guestfs_aug_defnode (g, name, expr, val);
648       if (r == NULL)
649         croak ("aug_defnode: %s", guestfs_last_error (g));
650       EXTEND (SP, 2);
651       PUSHs (sv_2mortal (newSViv (r->i)));
652       PUSHs (sv_2mortal (newSViv (r->b)));
653       guestfs_free_int_bool (r);
654
655 SV *
656 aug_get (g, path)
657       guestfs_h *g;
658       char *path;
659 PREINIT:
660       char *val;
661    CODE:
662       val = guestfs_aug_get (g, path);
663       if (val == NULL)
664         croak ("aug_get: %s", guestfs_last_error (g));
665       RETVAL = newSVpv (val, 0);
666       free (val);
667  OUTPUT:
668       RETVAL
669
670 void
671 aug_set (g, path, val)
672       guestfs_h *g;
673       char *path;
674       char *val;
675 PREINIT:
676       int r;
677  PPCODE:
678       r = guestfs_aug_set (g, path, val);
679       if (r == -1)
680         croak ("aug_set: %s", guestfs_last_error (g));
681
682 void
683 aug_insert (g, path, label, before)
684       guestfs_h *g;
685       char *path;
686       char *label;
687       int before;
688 PREINIT:
689       int r;
690  PPCODE:
691       r = guestfs_aug_insert (g, path, label, before);
692       if (r == -1)
693         croak ("aug_insert: %s", guestfs_last_error (g));
694
695 SV *
696 aug_rm (g, path)
697       guestfs_h *g;
698       char *path;
699 PREINIT:
700       int nrnodes;
701    CODE:
702       nrnodes = guestfs_aug_rm (g, path);
703       if (nrnodes == -1)
704         croak ("aug_rm: %s", guestfs_last_error (g));
705       RETVAL = newSViv (nrnodes);
706  OUTPUT:
707       RETVAL
708
709 void
710 aug_mv (g, src, dest)
711       guestfs_h *g;
712       char *src;
713       char *dest;
714 PREINIT:
715       int r;
716  PPCODE:
717       r = guestfs_aug_mv (g, src, dest);
718       if (r == -1)
719         croak ("aug_mv: %s", guestfs_last_error (g));
720
721 void
722 aug_match (g, path)
723       guestfs_h *g;
724       char *path;
725 PREINIT:
726       char **matches;
727       int i, n;
728  PPCODE:
729       matches = guestfs_aug_match (g, path);
730       if (matches == NULL)
731         croak ("aug_match: %s", guestfs_last_error (g));
732       for (n = 0; matches[n] != NULL; ++n) /**/;
733       EXTEND (SP, n);
734       for (i = 0; i < n; ++i) {
735         PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
736         free (matches[i]);
737       }
738       free (matches);
739
740 void
741 aug_save (g)
742       guestfs_h *g;
743 PREINIT:
744       int r;
745  PPCODE:
746       r = guestfs_aug_save (g);
747       if (r == -1)
748         croak ("aug_save: %s", guestfs_last_error (g));
749
750 void
751 aug_load (g)
752       guestfs_h *g;
753 PREINIT:
754       int r;
755  PPCODE:
756       r = guestfs_aug_load (g);
757       if (r == -1)
758         croak ("aug_load: %s", guestfs_last_error (g));
759
760 void
761 aug_ls (g, path)
762       guestfs_h *g;
763       char *path;
764 PREINIT:
765       char **matches;
766       int i, n;
767  PPCODE:
768       matches = guestfs_aug_ls (g, path);
769       if (matches == NULL)
770         croak ("aug_ls: %s", guestfs_last_error (g));
771       for (n = 0; matches[n] != NULL; ++n) /**/;
772       EXTEND (SP, n);
773       for (i = 0; i < n; ++i) {
774         PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
775         free (matches[i]);
776       }
777       free (matches);
778
779 void
780 rm (g, path)
781       guestfs_h *g;
782       char *path;
783 PREINIT:
784       int r;
785  PPCODE:
786       r = guestfs_rm (g, path);
787       if (r == -1)
788         croak ("rm: %s", guestfs_last_error (g));
789
790 void
791 rmdir (g, path)
792       guestfs_h *g;
793       char *path;
794 PREINIT:
795       int r;
796  PPCODE:
797       r = guestfs_rmdir (g, path);
798       if (r == -1)
799         croak ("rmdir: %s", guestfs_last_error (g));
800
801 void
802 rm_rf (g, path)
803       guestfs_h *g;
804       char *path;
805 PREINIT:
806       int r;
807  PPCODE:
808       r = guestfs_rm_rf (g, path);
809       if (r == -1)
810         croak ("rm_rf: %s", guestfs_last_error (g));
811
812 void
813 mkdir (g, path)
814       guestfs_h *g;
815       char *path;
816 PREINIT:
817       int r;
818  PPCODE:
819       r = guestfs_mkdir (g, path);
820       if (r == -1)
821         croak ("mkdir: %s", guestfs_last_error (g));
822
823 void
824 mkdir_p (g, path)
825       guestfs_h *g;
826       char *path;
827 PREINIT:
828       int r;
829  PPCODE:
830       r = guestfs_mkdir_p (g, path);
831       if (r == -1)
832         croak ("mkdir_p: %s", guestfs_last_error (g));
833
834 void
835 chmod (g, mode, path)
836       guestfs_h *g;
837       int mode;
838       char *path;
839 PREINIT:
840       int r;
841  PPCODE:
842       r = guestfs_chmod (g, mode, path);
843       if (r == -1)
844         croak ("chmod: %s", guestfs_last_error (g));
845
846 void
847 chown (g, owner, group, path)
848       guestfs_h *g;
849       int owner;
850       int group;
851       char *path;
852 PREINIT:
853       int r;
854  PPCODE:
855       r = guestfs_chown (g, owner, group, path);
856       if (r == -1)
857         croak ("chown: %s", guestfs_last_error (g));
858
859 SV *
860 exists (g, path)
861       guestfs_h *g;
862       char *path;
863 PREINIT:
864       int existsflag;
865    CODE:
866       existsflag = guestfs_exists (g, path);
867       if (existsflag == -1)
868         croak ("exists: %s", guestfs_last_error (g));
869       RETVAL = newSViv (existsflag);
870  OUTPUT:
871       RETVAL
872
873 SV *
874 is_file (g, path)
875       guestfs_h *g;
876       char *path;
877 PREINIT:
878       int fileflag;
879    CODE:
880       fileflag = guestfs_is_file (g, path);
881       if (fileflag == -1)
882         croak ("is_file: %s", guestfs_last_error (g));
883       RETVAL = newSViv (fileflag);
884  OUTPUT:
885       RETVAL
886
887 SV *
888 is_dir (g, path)
889       guestfs_h *g;
890       char *path;
891 PREINIT:
892       int dirflag;
893    CODE:
894       dirflag = guestfs_is_dir (g, path);
895       if (dirflag == -1)
896         croak ("is_dir: %s", guestfs_last_error (g));
897       RETVAL = newSViv (dirflag);
898  OUTPUT:
899       RETVAL
900
901 void
902 pvcreate (g, device)
903       guestfs_h *g;
904       char *device;
905 PREINIT:
906       int r;
907  PPCODE:
908       r = guestfs_pvcreate (g, device);
909       if (r == -1)
910         croak ("pvcreate: %s", guestfs_last_error (g));
911
912 void
913 vgcreate (g, volgroup, physvols)
914       guestfs_h *g;
915       char *volgroup;
916       char **physvols;
917 PREINIT:
918       int r;
919  PPCODE:
920       r = guestfs_vgcreate (g, volgroup, physvols);
921       free (physvols);
922       if (r == -1)
923         croak ("vgcreate: %s", guestfs_last_error (g));
924
925 void
926 lvcreate (g, logvol, volgroup, mbytes)
927       guestfs_h *g;
928       char *logvol;
929       char *volgroup;
930       int mbytes;
931 PREINIT:
932       int r;
933  PPCODE:
934       r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
935       if (r == -1)
936         croak ("lvcreate: %s", guestfs_last_error (g));
937
938 void
939 mkfs (g, fstype, device)
940       guestfs_h *g;
941       char *fstype;
942       char *device;
943 PREINIT:
944       int r;
945  PPCODE:
946       r = guestfs_mkfs (g, fstype, device);
947       if (r == -1)
948         croak ("mkfs: %s", guestfs_last_error (g));
949
950 void
951 sfdisk (g, device, cyls, heads, sectors, lines)
952       guestfs_h *g;
953       char *device;
954       int cyls;
955       int heads;
956       int sectors;
957       char **lines;
958 PREINIT:
959       int r;
960  PPCODE:
961       r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
962       free (lines);
963       if (r == -1)
964         croak ("sfdisk: %s", guestfs_last_error (g));
965
966 void
967 write_file (g, path, content, size)
968       guestfs_h *g;
969       char *path;
970       char *content;
971       int size;
972 PREINIT:
973       int r;
974  PPCODE:
975       r = guestfs_write_file (g, path, content, size);
976       if (r == -1)
977         croak ("write_file: %s", guestfs_last_error (g));
978
979 void
980 umount (g, pathordevice)
981       guestfs_h *g;
982       char *pathordevice;
983 PREINIT:
984       int r;
985  PPCODE:
986       r = guestfs_umount (g, pathordevice);
987       if (r == -1)
988         croak ("umount: %s", guestfs_last_error (g));
989
990 void
991 mounts (g)
992       guestfs_h *g;
993 PREINIT:
994       char **devices;
995       int i, n;
996  PPCODE:
997       devices = guestfs_mounts (g);
998       if (devices == NULL)
999         croak ("mounts: %s", guestfs_last_error (g));
1000       for (n = 0; devices[n] != NULL; ++n) /**/;
1001       EXTEND (SP, n);
1002       for (i = 0; i < n; ++i) {
1003         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
1004         free (devices[i]);
1005       }
1006       free (devices);
1007
1008 void
1009 umount_all (g)
1010       guestfs_h *g;
1011 PREINIT:
1012       int r;
1013  PPCODE:
1014       r = guestfs_umount_all (g);
1015       if (r == -1)
1016         croak ("umount_all: %s", guestfs_last_error (g));
1017
1018 void
1019 lvm_remove_all (g)
1020       guestfs_h *g;
1021 PREINIT:
1022       int r;
1023  PPCODE:
1024       r = guestfs_lvm_remove_all (g);
1025       if (r == -1)
1026         croak ("lvm_remove_all: %s", guestfs_last_error (g));
1027
1028 SV *
1029 file (g, path)
1030       guestfs_h *g;
1031       char *path;
1032 PREINIT:
1033       char *description;
1034    CODE:
1035       description = guestfs_file (g, path);
1036       if (description == NULL)
1037         croak ("file: %s", guestfs_last_error (g));
1038       RETVAL = newSVpv (description, 0);
1039       free (description);
1040  OUTPUT:
1041       RETVAL
1042
1043 SV *
1044 command (g, arguments)
1045       guestfs_h *g;
1046       char **arguments;
1047 PREINIT:
1048       char *output;
1049    CODE:
1050       output = guestfs_command (g, arguments);
1051       free (arguments);
1052       if (output == NULL)
1053         croak ("command: %s", guestfs_last_error (g));
1054       RETVAL = newSVpv (output, 0);
1055       free (output);
1056  OUTPUT:
1057       RETVAL
1058
1059 void
1060 command_lines (g, arguments)
1061       guestfs_h *g;
1062       char **arguments;
1063 PREINIT:
1064       char **lines;
1065       int i, n;
1066  PPCODE:
1067       lines = guestfs_command_lines (g, arguments);
1068       free (arguments);
1069       if (lines == NULL)
1070         croak ("command_lines: %s", guestfs_last_error (g));
1071       for (n = 0; lines[n] != NULL; ++n) /**/;
1072       EXTEND (SP, n);
1073       for (i = 0; i < n; ++i) {
1074         PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
1075         free (lines[i]);
1076       }
1077       free (lines);
1078
1079 void
1080 stat (g, path)
1081       guestfs_h *g;
1082       char *path;
1083 PREINIT:
1084       struct guestfs_stat *statbuf;
1085  PPCODE:
1086       statbuf = guestfs_stat (g, path);
1087       if (statbuf == NULL)
1088         croak ("stat: %s", guestfs_last_error (g));
1089       EXTEND (SP, 13);
1090       PUSHs (sv_2mortal (my_newSVll (statbuf->dev)));
1091       PUSHs (sv_2mortal (my_newSVll (statbuf->ino)));
1092       PUSHs (sv_2mortal (my_newSVll (statbuf->mode)));
1093       PUSHs (sv_2mortal (my_newSVll (statbuf->nlink)));
1094       PUSHs (sv_2mortal (my_newSVll (statbuf->uid)));
1095       PUSHs (sv_2mortal (my_newSVll (statbuf->gid)));
1096       PUSHs (sv_2mortal (my_newSVll (statbuf->rdev)));
1097       PUSHs (sv_2mortal (my_newSVll (statbuf->size)));
1098       PUSHs (sv_2mortal (my_newSVll (statbuf->blksize)));
1099       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1100       PUSHs (sv_2mortal (my_newSVll (statbuf->atime)));
1101       PUSHs (sv_2mortal (my_newSVll (statbuf->mtime)));
1102       PUSHs (sv_2mortal (my_newSVll (statbuf->ctime)));
1103       free (statbuf);
1104
1105 void
1106 lstat (g, path)
1107       guestfs_h *g;
1108       char *path;
1109 PREINIT:
1110       struct guestfs_stat *statbuf;
1111  PPCODE:
1112       statbuf = guestfs_lstat (g, path);
1113       if (statbuf == NULL)
1114         croak ("lstat: %s", guestfs_last_error (g));
1115       EXTEND (SP, 13);
1116       PUSHs (sv_2mortal (my_newSVll (statbuf->dev)));
1117       PUSHs (sv_2mortal (my_newSVll (statbuf->ino)));
1118       PUSHs (sv_2mortal (my_newSVll (statbuf->mode)));
1119       PUSHs (sv_2mortal (my_newSVll (statbuf->nlink)));
1120       PUSHs (sv_2mortal (my_newSVll (statbuf->uid)));
1121       PUSHs (sv_2mortal (my_newSVll (statbuf->gid)));
1122       PUSHs (sv_2mortal (my_newSVll (statbuf->rdev)));
1123       PUSHs (sv_2mortal (my_newSVll (statbuf->size)));
1124       PUSHs (sv_2mortal (my_newSVll (statbuf->blksize)));
1125       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1126       PUSHs (sv_2mortal (my_newSVll (statbuf->atime)));
1127       PUSHs (sv_2mortal (my_newSVll (statbuf->mtime)));
1128       PUSHs (sv_2mortal (my_newSVll (statbuf->ctime)));
1129       free (statbuf);
1130
1131 void
1132 statvfs (g, path)
1133       guestfs_h *g;
1134       char *path;
1135 PREINIT:
1136       struct guestfs_statvfs *statbuf;
1137  PPCODE:
1138       statbuf = guestfs_statvfs (g, path);
1139       if (statbuf == NULL)
1140         croak ("statvfs: %s", guestfs_last_error (g));
1141       EXTEND (SP, 11);
1142       PUSHs (sv_2mortal (my_newSVll (statbuf->bsize)));
1143       PUSHs (sv_2mortal (my_newSVll (statbuf->frsize)));
1144       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1145       PUSHs (sv_2mortal (my_newSVll (statbuf->bfree)));
1146       PUSHs (sv_2mortal (my_newSVll (statbuf->bavail)));
1147       PUSHs (sv_2mortal (my_newSVll (statbuf->files)));
1148       PUSHs (sv_2mortal (my_newSVll (statbuf->ffree)));
1149       PUSHs (sv_2mortal (my_newSVll (statbuf->favail)));
1150       PUSHs (sv_2mortal (my_newSVll (statbuf->fsid)));
1151       PUSHs (sv_2mortal (my_newSVll (statbuf->flag)));
1152       PUSHs (sv_2mortal (my_newSVll (statbuf->namemax)));
1153       free (statbuf);
1154
1155 void
1156 tune2fs_l (g, device)
1157       guestfs_h *g;
1158       char *device;
1159 PREINIT:
1160       char **superblock;
1161       int i, n;
1162  PPCODE:
1163       superblock = guestfs_tune2fs_l (g, device);
1164       if (superblock == NULL)
1165         croak ("tune2fs_l: %s", guestfs_last_error (g));
1166       for (n = 0; superblock[n] != NULL; ++n) /**/;
1167       EXTEND (SP, n);
1168       for (i = 0; i < n; ++i) {
1169         PUSHs (sv_2mortal (newSVpv (superblock[i], 0)));
1170         free (superblock[i]);
1171       }
1172       free (superblock);
1173
1174 void
1175 blockdev_setro (g, device)
1176       guestfs_h *g;
1177       char *device;
1178 PREINIT:
1179       int r;
1180  PPCODE:
1181       r = guestfs_blockdev_setro (g, device);
1182       if (r == -1)
1183         croak ("blockdev_setro: %s", guestfs_last_error (g));
1184
1185 void
1186 blockdev_setrw (g, device)
1187       guestfs_h *g;
1188       char *device;
1189 PREINIT:
1190       int r;
1191  PPCODE:
1192       r = guestfs_blockdev_setrw (g, device);
1193       if (r == -1)
1194         croak ("blockdev_setrw: %s", guestfs_last_error (g));
1195
1196 SV *
1197 blockdev_getro (g, device)
1198       guestfs_h *g;
1199       char *device;
1200 PREINIT:
1201       int ro;
1202    CODE:
1203       ro = guestfs_blockdev_getro (g, device);
1204       if (ro == -1)
1205         croak ("blockdev_getro: %s", guestfs_last_error (g));
1206       RETVAL = newSViv (ro);
1207  OUTPUT:
1208       RETVAL
1209
1210 SV *
1211 blockdev_getss (g, device)
1212       guestfs_h *g;
1213       char *device;
1214 PREINIT:
1215       int sectorsize;
1216    CODE:
1217       sectorsize = guestfs_blockdev_getss (g, device);
1218       if (sectorsize == -1)
1219         croak ("blockdev_getss: %s", guestfs_last_error (g));
1220       RETVAL = newSViv (sectorsize);
1221  OUTPUT:
1222       RETVAL
1223
1224 SV *
1225 blockdev_getbsz (g, device)
1226       guestfs_h *g;
1227       char *device;
1228 PREINIT:
1229       int blocksize;
1230    CODE:
1231       blocksize = guestfs_blockdev_getbsz (g, device);
1232       if (blocksize == -1)
1233         croak ("blockdev_getbsz: %s", guestfs_last_error (g));
1234       RETVAL = newSViv (blocksize);
1235  OUTPUT:
1236       RETVAL
1237
1238 void
1239 blockdev_setbsz (g, device, blocksize)
1240       guestfs_h *g;
1241       char *device;
1242       int blocksize;
1243 PREINIT:
1244       int r;
1245  PPCODE:
1246       r = guestfs_blockdev_setbsz (g, device, blocksize);
1247       if (r == -1)
1248         croak ("blockdev_setbsz: %s", guestfs_last_error (g));
1249
1250 SV *
1251 blockdev_getsz (g, device)
1252       guestfs_h *g;
1253       char *device;
1254 PREINIT:
1255       int64_t sizeinsectors;
1256    CODE:
1257       sizeinsectors = guestfs_blockdev_getsz (g, device);
1258       if (sizeinsectors == -1)
1259         croak ("blockdev_getsz: %s", guestfs_last_error (g));
1260       RETVAL = my_newSVll (sizeinsectors);
1261  OUTPUT:
1262       RETVAL
1263
1264 SV *
1265 blockdev_getsize64 (g, device)
1266       guestfs_h *g;
1267       char *device;
1268 PREINIT:
1269       int64_t sizeinbytes;
1270    CODE:
1271       sizeinbytes = guestfs_blockdev_getsize64 (g, device);
1272       if (sizeinbytes == -1)
1273         croak ("blockdev_getsize64: %s", guestfs_last_error (g));
1274       RETVAL = my_newSVll (sizeinbytes);
1275  OUTPUT:
1276       RETVAL
1277
1278 void
1279 blockdev_flushbufs (g, device)
1280       guestfs_h *g;
1281       char *device;
1282 PREINIT:
1283       int r;
1284  PPCODE:
1285       r = guestfs_blockdev_flushbufs (g, device);
1286       if (r == -1)
1287         croak ("blockdev_flushbufs: %s", guestfs_last_error (g));
1288
1289 void
1290 blockdev_rereadpt (g, device)
1291       guestfs_h *g;
1292       char *device;
1293 PREINIT:
1294       int r;
1295  PPCODE:
1296       r = guestfs_blockdev_rereadpt (g, device);
1297       if (r == -1)
1298         croak ("blockdev_rereadpt: %s", guestfs_last_error (g));
1299