Fixed Perl bindings, they now work properly.
[libguestfs.git] / perl / Guestfs.xs
1 /* libguestfs generated file
2  * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3  * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "EXTERN.h"
23 #include "perl.h"
24 #include "XSUB.h"
25
26 #include <guestfs.h>
27
28 #ifndef PRId64
29 #define PRId64 "lld"
30 #endif
31
32 static SV *
33 my_newSVll(long long val) {
34 #ifdef USE_64_BIT_ALL
35   return newSViv(val);
36 #else
37   char buf[100];
38   int len;
39   len = snprintf(buf, 100, "%" PRId64, val);
40   return newSVpv(buf, len);
41 #endif
42 }
43
44 #ifndef PRIu64
45 #define PRIu64 "llu"
46 #endif
47
48 static SV *
49 my_newSVull(unsigned long long val) {
50 #ifdef USE_64_BIT_ALL
51   return newSVuv(val);
52 #else
53   char buf[100];
54   int len;
55   len = snprintf(buf, 100, "%" PRIu64, val);
56   return newSVpv(buf, len);
57 #endif
58 }
59
60 /* XXX Not thread-safe, and in general not safe if the caller is
61  * issuing multiple requests in parallel (on different guestfs
62  * handles).  We should use the guestfs_h handle passed to the
63  * error handle to distinguish these cases.
64  */
65 static char *last_error = NULL;
66
67 static void
68 error_handler (guestfs_h *g,
69                void *data,
70                const char *msg)
71 {
72   if (last_error != NULL) free (last_error);
73   last_error = strdup (msg);
74 }
75
76 MODULE = Sys::Guestfs  PACKAGE = Sys::Guestfs
77
78 guestfs_h *
79 _create ()
80    CODE:
81       RETVAL = guestfs_create ();
82       if (!RETVAL)
83         croak ("could not create guestfs handle");
84       guestfs_set_error_handler (RETVAL, error_handler, NULL);
85  OUTPUT:
86       RETVAL
87
88 void
89 DESTROY (g)
90       guestfs_h *g;
91  PPCODE:
92       guestfs_close (g);
93
94 void
95 add_drive (g, filename)
96       guestfs_h *g;
97       const char *filename;
98    CODE:
99       if (guestfs_add_drive (g, filename) == -1)
100         croak ("add_drive: %s", last_error);
101
102 void
103 add_cdrom (g, filename)
104       guestfs_h *g;
105       const char *filename;
106    CODE:
107       if (guestfs_add_cdrom (g, filename) == -1)
108         croak ("add_cdrom: %s", last_error);
109
110 void
111 config (g, param, value)
112       guestfs_h *g;
113       const char *param;
114       const char *value;
115    CODE:
116       if (guestfs_config (g, param, value) == -1)
117         croak ("config: %s", last_error);
118
119 void
120 launch (g)
121       guestfs_h *g;
122    CODE:
123       if (guestfs_launch (g) == -1)
124         croak ("launch: %s", last_error);
125
126 void
127 wait_ready (g)
128       guestfs_h *g;
129    CODE:
130       if (guestfs_wait_ready (g) == -1)
131         croak ("wait_ready: %s", last_error);
132
133 void
134 set_path (g, path)
135       guestfs_h *g;
136       const char *path;
137    CODE:
138       guestfs_set_path (g, path);
139
140 SV *
141 get_path (g)
142       guestfs_h *g;
143 PREINIT:
144       const char *path;
145    CODE:
146       path = guestfs_get_path (g);
147       RETVAL = newSVpv (path, 0);
148  OUTPUT:
149       RETVAL
150
151 void
152 set_autosync (g, autosync)
153       guestfs_h *g;
154       int autosync;
155    CODE:
156       guestfs_set_autosync (g, autosync);
157
158 SV *
159 get_autosync (g)
160       guestfs_h *g;
161 PREINIT:
162       int autosync;
163    CODE:
164       autosync = guestfs_get_autosync (g);
165       RETVAL = newSViv (autosync);
166  OUTPUT:
167       RETVAL
168
169 void
170 set_verbose (g, verbose)
171       guestfs_h *g;
172       int verbose;
173    CODE:
174       guestfs_set_verbose (g, verbose);
175
176 SV *
177 get_verbose (g)
178       guestfs_h *g;
179 PREINIT:
180       int verbose;
181    CODE:
182       verbose = guestfs_get_verbose (g);
183       RETVAL = newSViv (verbose);
184  OUTPUT:
185       RETVAL
186
187 void
188 mount (g, device, mountpoint)
189       guestfs_h *g;
190       char *device;
191       char *mountpoint;
192  PPCODE:
193       if (guestfs_mount (g, device, mountpoint) == -1)
194         croak ("mount: %s", last_error);
195
196 void
197 sync (g)
198       guestfs_h *g;
199  PPCODE:
200       if (guestfs_sync (g) == -1)
201         croak ("sync: %s", last_error);
202
203 void
204 touch (g, path)
205       guestfs_h *g;
206       char *path;
207  PPCODE:
208       if (guestfs_touch (g, path) == -1)
209         croak ("touch: %s", last_error);
210
211 SV *
212 cat (g, path)
213       guestfs_h *g;
214       char *path;
215 PREINIT:
216       char *content;
217    CODE:
218       content = guestfs_cat (g, path);
219       if (content == NULL)
220         croak ("cat: %s", last_error);
221       RETVAL = newSVpv (content, 0);
222       free (content);
223  OUTPUT:
224       RETVAL
225
226 SV *
227 ll (g, directory)
228       guestfs_h *g;
229       char *directory;
230 PREINIT:
231       char *listing;
232    CODE:
233       listing = guestfs_ll (g, directory);
234       if (listing == NULL)
235         croak ("ll: %s", last_error);
236       RETVAL = newSVpv (listing, 0);
237       free (listing);
238  OUTPUT:
239       RETVAL
240
241 void
242 ls (g, directory)
243       guestfs_h *g;
244       char *directory;
245 PREINIT:
246       char **listing;
247       int i, n;
248  PPCODE:
249       listing = guestfs_ls (g, directory);
250       if (listing == NULL)
251         croak ("ls: %s", last_error);
252       for (n = 0; listing[n] != NULL; ++n) /**/;
253       EXTEND (SP, n);
254       for (i = 0; i < n; ++i) {
255         PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
256         free (listing[i]);
257       }
258       free (listing);
259
260 void
261 list_devices (g)
262       guestfs_h *g;
263 PREINIT:
264       char **devices;
265       int i, n;
266  PPCODE:
267       devices = guestfs_list_devices (g);
268       if (devices == NULL)
269         croak ("list_devices: %s", last_error);
270       for (n = 0; devices[n] != NULL; ++n) /**/;
271       EXTEND (SP, n);
272       for (i = 0; i < n; ++i) {
273         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
274         free (devices[i]);
275       }
276       free (devices);
277
278 void
279 list_partitions (g)
280       guestfs_h *g;
281 PREINIT:
282       char **partitions;
283       int i, n;
284  PPCODE:
285       partitions = guestfs_list_partitions (g);
286       if (partitions == NULL)
287         croak ("list_partitions: %s", last_error);
288       for (n = 0; partitions[n] != NULL; ++n) /**/;
289       EXTEND (SP, n);
290       for (i = 0; i < n; ++i) {
291         PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
292         free (partitions[i]);
293       }
294       free (partitions);
295
296 void
297 pvs (g)
298       guestfs_h *g;
299 PREINIT:
300       char **physvols;
301       int i, n;
302  PPCODE:
303       physvols = guestfs_pvs (g);
304       if (physvols == NULL)
305         croak ("pvs: %s", last_error);
306       for (n = 0; physvols[n] != NULL; ++n) /**/;
307       EXTEND (SP, n);
308       for (i = 0; i < n; ++i) {
309         PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
310         free (physvols[i]);
311       }
312       free (physvols);
313
314 void
315 vgs (g)
316       guestfs_h *g;
317 PREINIT:
318       char **volgroups;
319       int i, n;
320  PPCODE:
321       volgroups = guestfs_vgs (g);
322       if (volgroups == NULL)
323         croak ("vgs: %s", last_error);
324       for (n = 0; volgroups[n] != NULL; ++n) /**/;
325       EXTEND (SP, n);
326       for (i = 0; i < n; ++i) {
327         PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
328         free (volgroups[i]);
329       }
330       free (volgroups);
331
332 void
333 lvs (g)
334       guestfs_h *g;
335 PREINIT:
336       char **logvols;
337       int i, n;
338  PPCODE:
339       logvols = guestfs_lvs (g);
340       if (logvols == NULL)
341         croak ("lvs: %s", last_error);
342       for (n = 0; logvols[n] != NULL; ++n) /**/;
343       EXTEND (SP, n);
344       for (i = 0; i < n; ++i) {
345         PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
346         free (logvols[i]);
347       }
348       free (logvols);
349
350 void
351 pvs_full (g)
352       guestfs_h *g;
353 PREINIT:
354       struct guestfs_lvm_pv_list *physvols;
355       int i;
356       HV *hv;
357  PPCODE:
358       physvols = guestfs_pvs_full (g);
359       if (physvols == NULL)
360         croak ("pvs_full: %s", last_error);
361       EXTEND (SP, physvols->len);
362       for (i = 0; i < physvols->len; ++i) {
363         hv = newHV ();
364         (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
365         (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
366         (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
367         (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
368         (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
369         (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
370         (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
371         (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
372         (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
373         (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
374         (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
375         (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
376         (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
377         (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
378         PUSHs (sv_2mortal ((SV *) hv));
379       }
380       guestfs_free_lvm_pv_list (physvols);
381
382 void
383 vgs_full (g)
384       guestfs_h *g;
385 PREINIT:
386       struct guestfs_lvm_vg_list *volgroups;
387       int i;
388       HV *hv;
389  PPCODE:
390       volgroups = guestfs_vgs_full (g);
391       if (volgroups == NULL)
392         croak ("vgs_full: %s", last_error);
393       EXTEND (SP, volgroups->len);
394       for (i = 0; i < volgroups->len; ++i) {
395         hv = newHV ();
396         (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
397         (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
398         (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
399         (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
400         (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
401         (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
402         (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
403         (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
404         (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
405         (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
406         (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
407         (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
408         (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
409         (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
410         (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
411         (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
412         (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
413         (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
414         (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
415         PUSHs (sv_2mortal ((SV *) hv));
416       }
417       guestfs_free_lvm_vg_list (volgroups);
418
419 void
420 lvs_full (g)
421       guestfs_h *g;
422 PREINIT:
423       struct guestfs_lvm_lv_list *logvols;
424       int i;
425       HV *hv;
426  PPCODE:
427       logvols = guestfs_lvs_full (g);
428       if (logvols == NULL)
429         croak ("lvs_full: %s", last_error);
430       EXTEND (SP, logvols->len);
431       for (i = 0; i < logvols->len; ++i) {
432         hv = newHV ();
433         (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
434         (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
435         (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
436         (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
437         (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
438         (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
439         (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
440         (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
441         (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
442         (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
443         (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
444         (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
445         (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
446         (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
447         (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
448         (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
449         PUSHs (sv_2mortal ((SV *) hv));
450       }
451       guestfs_free_lvm_lv_list (logvols);
452