Generated code for tune2fs-l command and RHashtable return type.
[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 void
243 mount (g, device, mountpoint)
244       guestfs_h *g;
245       char *device;
246       char *mountpoint;
247 PREINIT:
248       int r;
249  PPCODE:
250       r = guestfs_mount (g, device, mountpoint);
251       if (r == -1)
252         croak ("mount: %s", guestfs_last_error (g));
253
254 void
255 sync (g)
256       guestfs_h *g;
257 PREINIT:
258       int r;
259  PPCODE:
260       r = guestfs_sync (g);
261       if (r == -1)
262         croak ("sync: %s", guestfs_last_error (g));
263
264 void
265 touch (g, path)
266       guestfs_h *g;
267       char *path;
268 PREINIT:
269       int r;
270  PPCODE:
271       r = guestfs_touch (g, path);
272       if (r == -1)
273         croak ("touch: %s", guestfs_last_error (g));
274
275 SV *
276 cat (g, path)
277       guestfs_h *g;
278       char *path;
279 PREINIT:
280       char *content;
281    CODE:
282       content = guestfs_cat (g, path);
283       if (content == NULL)
284         croak ("cat: %s", guestfs_last_error (g));
285       RETVAL = newSVpv (content, 0);
286       free (content);
287  OUTPUT:
288       RETVAL
289
290 SV *
291 ll (g, directory)
292       guestfs_h *g;
293       char *directory;
294 PREINIT:
295       char *listing;
296    CODE:
297       listing = guestfs_ll (g, directory);
298       if (listing == NULL)
299         croak ("ll: %s", guestfs_last_error (g));
300       RETVAL = newSVpv (listing, 0);
301       free (listing);
302  OUTPUT:
303       RETVAL
304
305 void
306 ls (g, directory)
307       guestfs_h *g;
308       char *directory;
309 PREINIT:
310       char **listing;
311       int i, n;
312  PPCODE:
313       listing = guestfs_ls (g, directory);
314       if (listing == NULL)
315         croak ("ls: %s", guestfs_last_error (g));
316       for (n = 0; listing[n] != NULL; ++n) /**/;
317       EXTEND (SP, n);
318       for (i = 0; i < n; ++i) {
319         PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
320         free (listing[i]);
321       }
322       free (listing);
323
324 void
325 list_devices (g)
326       guestfs_h *g;
327 PREINIT:
328       char **devices;
329       int i, n;
330  PPCODE:
331       devices = guestfs_list_devices (g);
332       if (devices == NULL)
333         croak ("list_devices: %s", guestfs_last_error (g));
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", guestfs_last_error (g));
352       for (n = 0; partitions[n] != NULL; ++n) /**/;
353       EXTEND (SP, n);
354       for (i = 0; i < n; ++i) {
355         PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
356         free (partitions[i]);
357       }
358       free (partitions);
359
360 void
361 pvs (g)
362       guestfs_h *g;
363 PREINIT:
364       char **physvols;
365       int i, n;
366  PPCODE:
367       physvols = guestfs_pvs (g);
368       if (physvols == NULL)
369         croak ("pvs: %s", guestfs_last_error (g));
370       for (n = 0; physvols[n] != NULL; ++n) /**/;
371       EXTEND (SP, n);
372       for (i = 0; i < n; ++i) {
373         PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
374         free (physvols[i]);
375       }
376       free (physvols);
377
378 void
379 vgs (g)
380       guestfs_h *g;
381 PREINIT:
382       char **volgroups;
383       int i, n;
384  PPCODE:
385       volgroups = guestfs_vgs (g);
386       if (volgroups == NULL)
387         croak ("vgs: %s", guestfs_last_error (g));
388       for (n = 0; volgroups[n] != NULL; ++n) /**/;
389       EXTEND (SP, n);
390       for (i = 0; i < n; ++i) {
391         PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
392         free (volgroups[i]);
393       }
394       free (volgroups);
395
396 void
397 lvs (g)
398       guestfs_h *g;
399 PREINIT:
400       char **logvols;
401       int i, n;
402  PPCODE:
403       logvols = guestfs_lvs (g);
404       if (logvols == NULL)
405         croak ("lvs: %s", guestfs_last_error (g));
406       for (n = 0; logvols[n] != NULL; ++n) /**/;
407       EXTEND (SP, n);
408       for (i = 0; i < n; ++i) {
409         PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
410         free (logvols[i]);
411       }
412       free (logvols);
413
414 void
415 pvs_full (g)
416       guestfs_h *g;
417 PREINIT:
418       struct guestfs_lvm_pv_list *physvols;
419       int i;
420       HV *hv;
421  PPCODE:
422       physvols = guestfs_pvs_full (g);
423       if (physvols == NULL)
424         croak ("pvs_full: %s", guestfs_last_error (g));
425       EXTEND (SP, physvols->len);
426       for (i = 0; i < physvols->len; ++i) {
427         hv = newHV ();
428         (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
429         (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
430         (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
431         (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
432         (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
433         (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
434         (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
435         (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
436         (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
437         (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
438         (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
439         (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
440         (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
441         (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
442         PUSHs (sv_2mortal ((SV *) hv));
443       }
444       guestfs_free_lvm_pv_list (physvols);
445
446 void
447 vgs_full (g)
448       guestfs_h *g;
449 PREINIT:
450       struct guestfs_lvm_vg_list *volgroups;
451       int i;
452       HV *hv;
453  PPCODE:
454       volgroups = guestfs_vgs_full (g);
455       if (volgroups == NULL)
456         croak ("vgs_full: %s", guestfs_last_error (g));
457       EXTEND (SP, volgroups->len);
458       for (i = 0; i < volgroups->len; ++i) {
459         hv = newHV ();
460         (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
461         (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
462         (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
463         (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
464         (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
465         (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
466         (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
467         (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
468         (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
469         (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
470         (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
471         (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
472         (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
473         (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
474         (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
475         (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
476         (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
477         (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
478         (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
479         PUSHs (sv_2mortal ((SV *) hv));
480       }
481       guestfs_free_lvm_vg_list (volgroups);
482
483 void
484 lvs_full (g)
485       guestfs_h *g;
486 PREINIT:
487       struct guestfs_lvm_lv_list *logvols;
488       int i;
489       HV *hv;
490  PPCODE:
491       logvols = guestfs_lvs_full (g);
492       if (logvols == NULL)
493         croak ("lvs_full: %s", guestfs_last_error (g));
494       EXTEND (SP, logvols->len);
495       for (i = 0; i < logvols->len; ++i) {
496         hv = newHV ();
497         (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
498         (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
499         (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
500         (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
501         (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
502         (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
503         (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
504         (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
505         (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
506         (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
507         (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
508         (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
509         (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
510         (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
511         (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
512         (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
513         PUSHs (sv_2mortal ((SV *) hv));
514       }
515       guestfs_free_lvm_lv_list (logvols);
516
517 void
518 read_lines (g, path)
519       guestfs_h *g;
520       char *path;
521 PREINIT:
522       char **lines;
523       int i, n;
524  PPCODE:
525       lines = guestfs_read_lines (g, path);
526       if (lines == NULL)
527         croak ("read_lines: %s", guestfs_last_error (g));
528       for (n = 0; lines[n] != NULL; ++n) /**/;
529       EXTEND (SP, n);
530       for (i = 0; i < n; ++i) {
531         PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
532         free (lines[i]);
533       }
534       free (lines);
535
536 void
537 aug_init (g, root, flags)
538       guestfs_h *g;
539       char *root;
540       int flags;
541 PREINIT:
542       int r;
543  PPCODE:
544       r = guestfs_aug_init (g, root, flags);
545       if (r == -1)
546         croak ("aug_init: %s", guestfs_last_error (g));
547
548 void
549 aug_close (g)
550       guestfs_h *g;
551 PREINIT:
552       int r;
553  PPCODE:
554       r = guestfs_aug_close (g);
555       if (r == -1)
556         croak ("aug_close: %s", guestfs_last_error (g));
557
558 SV *
559 aug_defvar (g, name, expr)
560       guestfs_h *g;
561       char *name;
562       char *expr;
563 PREINIT:
564       int nrnodes;
565    CODE:
566       nrnodes = guestfs_aug_defvar (g, name, expr);
567       if (nrnodes == -1)
568         croak ("aug_defvar: %s", guestfs_last_error (g));
569       RETVAL = newSViv (nrnodes);
570  OUTPUT:
571       RETVAL
572
573 void
574 aug_defnode (g, name, expr, val)
575       guestfs_h *g;
576       char *name;
577       char *expr;
578       char *val;
579 PREINIT:
580       struct guestfs_int_bool *r;
581  PPCODE:
582       r = guestfs_aug_defnode (g, name, expr, val);
583       if (r == NULL)
584         croak ("aug_defnode: %s", guestfs_last_error (g));
585       EXTEND (SP, 2);
586       PUSHs (sv_2mortal (newSViv (r->i)));
587       PUSHs (sv_2mortal (newSViv (r->b)));
588       guestfs_free_int_bool (r);
589
590 SV *
591 aug_get (g, path)
592       guestfs_h *g;
593       char *path;
594 PREINIT:
595       char *val;
596    CODE:
597       val = guestfs_aug_get (g, path);
598       if (val == NULL)
599         croak ("aug_get: %s", guestfs_last_error (g));
600       RETVAL = newSVpv (val, 0);
601       free (val);
602  OUTPUT:
603       RETVAL
604
605 void
606 aug_set (g, path, val)
607       guestfs_h *g;
608       char *path;
609       char *val;
610 PREINIT:
611       int r;
612  PPCODE:
613       r = guestfs_aug_set (g, path, val);
614       if (r == -1)
615         croak ("aug_set: %s", guestfs_last_error (g));
616
617 void
618 aug_insert (g, path, label, before)
619       guestfs_h *g;
620       char *path;
621       char *label;
622       int before;
623 PREINIT:
624       int r;
625  PPCODE:
626       r = guestfs_aug_insert (g, path, label, before);
627       if (r == -1)
628         croak ("aug_insert: %s", guestfs_last_error (g));
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", guestfs_last_error (g));
640       RETVAL = newSViv (nrnodes);
641  OUTPUT:
642       RETVAL
643
644 void
645 aug_mv (g, src, dest)
646       guestfs_h *g;
647       char *src;
648       char *dest;
649 PREINIT:
650       int r;
651  PPCODE:
652       r = guestfs_aug_mv (g, src, dest);
653       if (r == -1)
654         croak ("aug_mv: %s", guestfs_last_error (g));
655
656 void
657 aug_match (g, path)
658       guestfs_h *g;
659       char *path;
660 PREINIT:
661       char **matches;
662       int i, n;
663  PPCODE:
664       matches = guestfs_aug_match (g, path);
665       if (matches == NULL)
666         croak ("aug_match: %s", guestfs_last_error (g));
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 PREINIT:
679       int r;
680  PPCODE:
681       r = guestfs_aug_save (g);
682       if (r == -1)
683         croak ("aug_save: %s", guestfs_last_error (g));
684
685 void
686 aug_load (g)
687       guestfs_h *g;
688 PREINIT:
689       int r;
690  PPCODE:
691       r = guestfs_aug_load (g);
692       if (r == -1)
693         croak ("aug_load: %s", guestfs_last_error (g));
694
695 void
696 aug_ls (g, path)
697       guestfs_h *g;
698       char *path;
699 PREINIT:
700       char **matches;
701       int i, n;
702  PPCODE:
703       matches = guestfs_aug_ls (g, path);
704       if (matches == NULL)
705         croak ("aug_ls: %s", guestfs_last_error (g));
706       for (n = 0; matches[n] != NULL; ++n) /**/;
707       EXTEND (SP, n);
708       for (i = 0; i < n; ++i) {
709         PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
710         free (matches[i]);
711       }
712       free (matches);
713
714 void
715 rm (g, path)
716       guestfs_h *g;
717       char *path;
718 PREINIT:
719       int r;
720  PPCODE:
721       r = guestfs_rm (g, path);
722       if (r == -1)
723         croak ("rm: %s", guestfs_last_error (g));
724
725 void
726 rmdir (g, path)
727       guestfs_h *g;
728       char *path;
729 PREINIT:
730       int r;
731  PPCODE:
732       r = guestfs_rmdir (g, path);
733       if (r == -1)
734         croak ("rmdir: %s", guestfs_last_error (g));
735
736 void
737 rm_rf (g, path)
738       guestfs_h *g;
739       char *path;
740 PREINIT:
741       int r;
742  PPCODE:
743       r = guestfs_rm_rf (g, path);
744       if (r == -1)
745         croak ("rm_rf: %s", guestfs_last_error (g));
746
747 void
748 mkdir (g, path)
749       guestfs_h *g;
750       char *path;
751 PREINIT:
752       int r;
753  PPCODE:
754       r = guestfs_mkdir (g, path);
755       if (r == -1)
756         croak ("mkdir: %s", guestfs_last_error (g));
757
758 void
759 mkdir_p (g, path)
760       guestfs_h *g;
761       char *path;
762 PREINIT:
763       int r;
764  PPCODE:
765       r = guestfs_mkdir_p (g, path);
766       if (r == -1)
767         croak ("mkdir_p: %s", guestfs_last_error (g));
768
769 void
770 chmod (g, mode, path)
771       guestfs_h *g;
772       int mode;
773       char *path;
774 PREINIT:
775       int r;
776  PPCODE:
777       r = guestfs_chmod (g, mode, path);
778       if (r == -1)
779         croak ("chmod: %s", guestfs_last_error (g));
780
781 void
782 chown (g, owner, group, path)
783       guestfs_h *g;
784       int owner;
785       int group;
786       char *path;
787 PREINIT:
788       int r;
789  PPCODE:
790       r = guestfs_chown (g, owner, group, path);
791       if (r == -1)
792         croak ("chown: %s", guestfs_last_error (g));
793
794 SV *
795 exists (g, path)
796       guestfs_h *g;
797       char *path;
798 PREINIT:
799       int existsflag;
800    CODE:
801       existsflag = guestfs_exists (g, path);
802       if (existsflag == -1)
803         croak ("exists: %s", guestfs_last_error (g));
804       RETVAL = newSViv (existsflag);
805  OUTPUT:
806       RETVAL
807
808 SV *
809 is_file (g, path)
810       guestfs_h *g;
811       char *path;
812 PREINIT:
813       int fileflag;
814    CODE:
815       fileflag = guestfs_is_file (g, path);
816       if (fileflag == -1)
817         croak ("is_file: %s", guestfs_last_error (g));
818       RETVAL = newSViv (fileflag);
819  OUTPUT:
820       RETVAL
821
822 SV *
823 is_dir (g, path)
824       guestfs_h *g;
825       char *path;
826 PREINIT:
827       int dirflag;
828    CODE:
829       dirflag = guestfs_is_dir (g, path);
830       if (dirflag == -1)
831         croak ("is_dir: %s", guestfs_last_error (g));
832       RETVAL = newSViv (dirflag);
833  OUTPUT:
834       RETVAL
835
836 void
837 pvcreate (g, device)
838       guestfs_h *g;
839       char *device;
840 PREINIT:
841       int r;
842  PPCODE:
843       r = guestfs_pvcreate (g, device);
844       if (r == -1)
845         croak ("pvcreate: %s", guestfs_last_error (g));
846
847 void
848 vgcreate (g, volgroup, physvols)
849       guestfs_h *g;
850       char *volgroup;
851       char **physvols;
852 PREINIT:
853       int r;
854  PPCODE:
855       r = guestfs_vgcreate (g, volgroup, physvols);
856       free (physvols);
857       if (r == -1)
858         croak ("vgcreate: %s", guestfs_last_error (g));
859
860 void
861 lvcreate (g, logvol, volgroup, mbytes)
862       guestfs_h *g;
863       char *logvol;
864       char *volgroup;
865       int mbytes;
866 PREINIT:
867       int r;
868  PPCODE:
869       r = guestfs_lvcreate (g, logvol, volgroup, mbytes);
870       if (r == -1)
871         croak ("lvcreate: %s", guestfs_last_error (g));
872
873 void
874 mkfs (g, fstype, device)
875       guestfs_h *g;
876       char *fstype;
877       char *device;
878 PREINIT:
879       int r;
880  PPCODE:
881       r = guestfs_mkfs (g, fstype, device);
882       if (r == -1)
883         croak ("mkfs: %s", guestfs_last_error (g));
884
885 void
886 sfdisk (g, device, cyls, heads, sectors, lines)
887       guestfs_h *g;
888       char *device;
889       int cyls;
890       int heads;
891       int sectors;
892       char **lines;
893 PREINIT:
894       int r;
895  PPCODE:
896       r = guestfs_sfdisk (g, device, cyls, heads, sectors, lines);
897       free (lines);
898       if (r == -1)
899         croak ("sfdisk: %s", guestfs_last_error (g));
900
901 void
902 write_file (g, path, content, size)
903       guestfs_h *g;
904       char *path;
905       char *content;
906       int size;
907 PREINIT:
908       int r;
909  PPCODE:
910       r = guestfs_write_file (g, path, content, size);
911       if (r == -1)
912         croak ("write_file: %s", guestfs_last_error (g));
913
914 void
915 umount (g, pathordevice)
916       guestfs_h *g;
917       char *pathordevice;
918 PREINIT:
919       int r;
920  PPCODE:
921       r = guestfs_umount (g, pathordevice);
922       if (r == -1)
923         croak ("umount: %s", guestfs_last_error (g));
924
925 void
926 mounts (g)
927       guestfs_h *g;
928 PREINIT:
929       char **devices;
930       int i, n;
931  PPCODE:
932       devices = guestfs_mounts (g);
933       if (devices == NULL)
934         croak ("mounts: %s", guestfs_last_error (g));
935       for (n = 0; devices[n] != NULL; ++n) /**/;
936       EXTEND (SP, n);
937       for (i = 0; i < n; ++i) {
938         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
939         free (devices[i]);
940       }
941       free (devices);
942
943 void
944 umount_all (g)
945       guestfs_h *g;
946 PREINIT:
947       int r;
948  PPCODE:
949       r = guestfs_umount_all (g);
950       if (r == -1)
951         croak ("umount_all: %s", guestfs_last_error (g));
952
953 void
954 lvm_remove_all (g)
955       guestfs_h *g;
956 PREINIT:
957       int r;
958  PPCODE:
959       r = guestfs_lvm_remove_all (g);
960       if (r == -1)
961         croak ("lvm_remove_all: %s", guestfs_last_error (g));
962
963 SV *
964 file (g, path)
965       guestfs_h *g;
966       char *path;
967 PREINIT:
968       char *description;
969    CODE:
970       description = guestfs_file (g, path);
971       if (description == NULL)
972         croak ("file: %s", guestfs_last_error (g));
973       RETVAL = newSVpv (description, 0);
974       free (description);
975  OUTPUT:
976       RETVAL
977
978 SV *
979 command (g, arguments)
980       guestfs_h *g;
981       char **arguments;
982 PREINIT:
983       char *output;
984    CODE:
985       output = guestfs_command (g, arguments);
986       free (arguments);
987       if (output == NULL)
988         croak ("command: %s", guestfs_last_error (g));
989       RETVAL = newSVpv (output, 0);
990       free (output);
991  OUTPUT:
992       RETVAL
993
994 void
995 command_lines (g, arguments)
996       guestfs_h *g;
997       char **arguments;
998 PREINIT:
999       char **lines;
1000       int i, n;
1001  PPCODE:
1002       lines = guestfs_command_lines (g, arguments);
1003       free (arguments);
1004       if (lines == NULL)
1005         croak ("command_lines: %s", guestfs_last_error (g));
1006       for (n = 0; lines[n] != NULL; ++n) /**/;
1007       EXTEND (SP, n);
1008       for (i = 0; i < n; ++i) {
1009         PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
1010         free (lines[i]);
1011       }
1012       free (lines);
1013
1014 void
1015 stat (g, path)
1016       guestfs_h *g;
1017       char *path;
1018 PREINIT:
1019       struct guestfs_stat *statbuf;
1020  PPCODE:
1021       statbuf = guestfs_stat (g, path);
1022       if (statbuf == NULL)
1023         croak ("stat: %s", guestfs_last_error (g));
1024       EXTEND (SP, 13);
1025       PUSHs (sv_2mortal (my_newSVll (statbuf->dev)));
1026       PUSHs (sv_2mortal (my_newSVll (statbuf->ino)));
1027       PUSHs (sv_2mortal (my_newSVll (statbuf->mode)));
1028       PUSHs (sv_2mortal (my_newSVll (statbuf->nlink)));
1029       PUSHs (sv_2mortal (my_newSVll (statbuf->uid)));
1030       PUSHs (sv_2mortal (my_newSVll (statbuf->gid)));
1031       PUSHs (sv_2mortal (my_newSVll (statbuf->rdev)));
1032       PUSHs (sv_2mortal (my_newSVll (statbuf->size)));
1033       PUSHs (sv_2mortal (my_newSVll (statbuf->blksize)));
1034       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1035       PUSHs (sv_2mortal (my_newSVll (statbuf->atime)));
1036       PUSHs (sv_2mortal (my_newSVll (statbuf->mtime)));
1037       PUSHs (sv_2mortal (my_newSVll (statbuf->ctime)));
1038       free (statbuf);
1039
1040 void
1041 lstat (g, path)
1042       guestfs_h *g;
1043       char *path;
1044 PREINIT:
1045       struct guestfs_stat *statbuf;
1046  PPCODE:
1047       statbuf = guestfs_lstat (g, path);
1048       if (statbuf == NULL)
1049         croak ("lstat: %s", guestfs_last_error (g));
1050       EXTEND (SP, 13);
1051       PUSHs (sv_2mortal (my_newSVll (statbuf->dev)));
1052       PUSHs (sv_2mortal (my_newSVll (statbuf->ino)));
1053       PUSHs (sv_2mortal (my_newSVll (statbuf->mode)));
1054       PUSHs (sv_2mortal (my_newSVll (statbuf->nlink)));
1055       PUSHs (sv_2mortal (my_newSVll (statbuf->uid)));
1056       PUSHs (sv_2mortal (my_newSVll (statbuf->gid)));
1057       PUSHs (sv_2mortal (my_newSVll (statbuf->rdev)));
1058       PUSHs (sv_2mortal (my_newSVll (statbuf->size)));
1059       PUSHs (sv_2mortal (my_newSVll (statbuf->blksize)));
1060       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1061       PUSHs (sv_2mortal (my_newSVll (statbuf->atime)));
1062       PUSHs (sv_2mortal (my_newSVll (statbuf->mtime)));
1063       PUSHs (sv_2mortal (my_newSVll (statbuf->ctime)));
1064       free (statbuf);
1065
1066 void
1067 statvfs (g, path)
1068       guestfs_h *g;
1069       char *path;
1070 PREINIT:
1071       struct guestfs_statvfs *statbuf;
1072  PPCODE:
1073       statbuf = guestfs_statvfs (g, path);
1074       if (statbuf == NULL)
1075         croak ("statvfs: %s", guestfs_last_error (g));
1076       EXTEND (SP, 11);
1077       PUSHs (sv_2mortal (my_newSVll (statbuf->bsize)));
1078       PUSHs (sv_2mortal (my_newSVll (statbuf->frsize)));
1079       PUSHs (sv_2mortal (my_newSVll (statbuf->blocks)));
1080       PUSHs (sv_2mortal (my_newSVll (statbuf->bfree)));
1081       PUSHs (sv_2mortal (my_newSVll (statbuf->bavail)));
1082       PUSHs (sv_2mortal (my_newSVll (statbuf->files)));
1083       PUSHs (sv_2mortal (my_newSVll (statbuf->ffree)));
1084       PUSHs (sv_2mortal (my_newSVll (statbuf->favail)));
1085       PUSHs (sv_2mortal (my_newSVll (statbuf->fsid)));
1086       PUSHs (sv_2mortal (my_newSVll (statbuf->flag)));
1087       PUSHs (sv_2mortal (my_newSVll (statbuf->namemax)));
1088       free (statbuf);
1089
1090 void
1091 tune2fs_l (g, device)
1092       guestfs_h *g;
1093       char *device;
1094 PREINIT:
1095       char **superblock;
1096       int i, n;
1097  PPCODE:
1098       superblock = guestfs_tune2fs_l (g, device);
1099       if (superblock == NULL)
1100         croak ("tune2fs_l: %s", guestfs_last_error (g));
1101       for (n = 0; superblock[n] != NULL; ++n) /**/;
1102       EXTEND (SP, n);
1103       for (i = 0; i < n; ++i) {
1104         PUSHs (sv_2mortal (newSVpv (superblock[i], 0)));
1105         free (superblock[i]);
1106       }
1107       free (superblock);
1108