First version of Perl bindings, compiled but not tested.
[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 /* #include cannot be used for local files in XS */
29
30 #ifndef PRId64
31 #define PRId64 "lld"
32 #endif
33
34 static SV *
35 my_newSVll(long long val) {
36 #ifdef USE_64_BIT_ALL
37   return newSViv(val);
38 #else
39   char buf[100];
40   int len;
41   len = snprintf(buf, 100, "%" PRId64, val);
42   return newSVpv(buf, len);
43 #endif
44 }
45
46 #ifndef PRIu64
47 #define PRIu64 "llu"
48 #endif
49
50 static SV *
51 my_newSVull(unsigned long long val) {
52 #ifdef USE_64_BIT_ALL
53   return newSVuv(val);
54 #else
55   char buf[100];
56   int len;
57   len = snprintf(buf, 100, "%" PRIu64, val);
58   return newSVpv(buf, len);
59 #endif
60 }
61
62 /* XXX Not thread-safe, and in general not safe if the caller is
63  * issuing multiple requests in parallel (on different guestfs
64  * handles).  We should use the guestfs_h handle passed to the
65  * error handle to distinguish these cases.
66  */
67 static char *last_error = NULL;
68
69 static void
70 error_handler (guestfs_h *g,
71                void *data,
72                const char *msg)
73 {
74   if (last_error != NULL) free (last_error);
75   last_error = strdup (msg);
76 }
77
78 MODULE = Sys::Guestfs  PACKAGE = Sys::Guestfs
79
80 guestfs_h *
81 _create ()
82 CODE:
83     RETVAL = guestfs_create ();
84     if (!RETVAL)
85       croak ("could not create guestfs handle");
86     guestfs_set_error_handler (RETVAL, error_handler, NULL);
87 OUTPUT:
88     RETVAL
89
90 void
91 DESTROY (g)
92     guestfs_h *g;
93 PPCODE:
94     guestfs_close (g);
95
96 void
97 mount (g, device, mountpoint)
98       guestfs_h *g;
99       char *device;
100       char *mountpoint;
101  PPCODE:
102       if (guestfs_mount (g, device, mountpoint) == -1)
103         croak ("mount: %s", last_error);
104
105 void
106 sync (g)
107       guestfs_h *g;
108  PPCODE:
109       if (guestfs_sync (g) == -1)
110         croak ("sync: %s", last_error);
111
112 void
113 touch (g, path)
114       guestfs_h *g;
115       char *path;
116  PPCODE:
117       if (guestfs_touch (g, path) == -1)
118         croak ("touch: %s", last_error);
119
120 SV *
121 cat (g, path)
122       guestfs_h *g;
123       char *path;
124 PREINIT:
125       char *content;
126    CODE:
127       content = guestfs_cat (g, path);
128       if (content == NULL)
129         croak ("cat: %s", last_error);
130       RETVAL = newSVpv (content, 0);
131       free (content);
132  OUTPUT:
133       RETVAL
134
135 SV *
136 ll (g, directory)
137       guestfs_h *g;
138       char *directory;
139 PREINIT:
140       char *listing;
141    CODE:
142       listing = guestfs_ll (g, directory);
143       if (listing == NULL)
144         croak ("ll: %s", last_error);
145       RETVAL = newSVpv (listing, 0);
146       free (listing);
147  OUTPUT:
148       RETVAL
149
150 void
151 ls (g, directory)
152       guestfs_h *g;
153       char *directory;
154 PREINIT:
155       char **listing;
156       int i, n;
157  PPCODE:
158       listing = guestfs_ls (g, directory);
159       if (listing == NULL)
160         croak ("ls: %s", last_error);
161       for (n = 0; listing[n] != NULL; ++n) /**/;
162       EXTEND (SP, n);
163       for (i = 0; i < n; ++i) {
164         PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
165         free (listing[i]);
166       }
167       free (listing);
168
169 void
170 list_devices (g)
171       guestfs_h *g;
172 PREINIT:
173       char **devices;
174       int i, n;
175  PPCODE:
176       devices = guestfs_list_devices (g);
177       if (devices == NULL)
178         croak ("list_devices: %s", last_error);
179       for (n = 0; devices[n] != NULL; ++n) /**/;
180       EXTEND (SP, n);
181       for (i = 0; i < n; ++i) {
182         PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
183         free (devices[i]);
184       }
185       free (devices);
186
187 void
188 list_partitions (g)
189       guestfs_h *g;
190 PREINIT:
191       char **partitions;
192       int i, n;
193  PPCODE:
194       partitions = guestfs_list_partitions (g);
195       if (partitions == NULL)
196         croak ("list_partitions: %s", last_error);
197       for (n = 0; partitions[n] != NULL; ++n) /**/;
198       EXTEND (SP, n);
199       for (i = 0; i < n; ++i) {
200         PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
201         free (partitions[i]);
202       }
203       free (partitions);
204
205 void
206 pvs (g)
207       guestfs_h *g;
208 PREINIT:
209       char **physvols;
210       int i, n;
211  PPCODE:
212       physvols = guestfs_pvs (g);
213       if (physvols == NULL)
214         croak ("pvs: %s", last_error);
215       for (n = 0; physvols[n] != NULL; ++n) /**/;
216       EXTEND (SP, n);
217       for (i = 0; i < n; ++i) {
218         PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
219         free (physvols[i]);
220       }
221       free (physvols);
222
223 void
224 vgs (g)
225       guestfs_h *g;
226 PREINIT:
227       char **volgroups;
228       int i, n;
229  PPCODE:
230       volgroups = guestfs_vgs (g);
231       if (volgroups == NULL)
232         croak ("vgs: %s", last_error);
233       for (n = 0; volgroups[n] != NULL; ++n) /**/;
234       EXTEND (SP, n);
235       for (i = 0; i < n; ++i) {
236         PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
237         free (volgroups[i]);
238       }
239       free (volgroups);
240
241 void
242 lvs (g)
243       guestfs_h *g;
244 PREINIT:
245       char **logvols;
246       int i, n;
247  PPCODE:
248       logvols = guestfs_lvs (g);
249       if (logvols == NULL)
250         croak ("lvs: %s", last_error);
251       for (n = 0; logvols[n] != NULL; ++n) /**/;
252       EXTEND (SP, n);
253       for (i = 0; i < n; ++i) {
254         PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
255         free (logvols[i]);
256       }
257       free (logvols);
258
259 void
260 pvs_full (g)
261       guestfs_h *g;
262 PREINIT:
263       struct guestfs_lvm_pv_list *physvols;
264       int i;
265       HV *hv;
266  PPCODE:
267       physvols = guestfs_pvs_full (g);
268       if (physvols == NULL)
269         croak ("pvs_full: %s", last_error);
270       EXTEND (SP, physvols->len);
271       for (i = 0; i < physvols->len; ++i) {
272         hv = newHV ();
273         (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
274         (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
275         (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
276         (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
277         (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
278         (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
279         (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
280         (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
281         (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
282         (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
283         (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
284         (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
285         (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
286         (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
287         PUSHs (sv_2mortal ((SV *) hv));
288       }
289       guestfs_free_lvm_pv_list (physvols);
290
291 void
292 vgs_full (g)
293       guestfs_h *g;
294 PREINIT:
295       struct guestfs_lvm_vg_list *volgroups;
296       int i;
297       HV *hv;
298  PPCODE:
299       volgroups = guestfs_vgs_full (g);
300       if (volgroups == NULL)
301         croak ("vgs_full: %s", last_error);
302       EXTEND (SP, volgroups->len);
303       for (i = 0; i < volgroups->len; ++i) {
304         hv = newHV ();
305         (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
306         (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
307         (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
308         (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
309         (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
310         (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
311         (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
312         (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
313         (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
314         (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
315         (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
316         (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
317         (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
318         (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
319         (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
320         (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
321         (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
322         (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
323         (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
324         PUSHs (sv_2mortal ((SV *) hv));
325       }
326       guestfs_free_lvm_vg_list (volgroups);
327
328 void
329 lvs_full (g)
330       guestfs_h *g;
331 PREINIT:
332       struct guestfs_lvm_lv_list *logvols;
333       int i;
334       HV *hv;
335  PPCODE:
336       logvols = guestfs_lvs_full (g);
337       if (logvols == NULL)
338         croak ("lvs_full: %s", last_error);
339       EXTEND (SP, logvols->len);
340       for (i = 0; i < logvols->len; ++i) {
341         hv = newHV ();
342         (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
343         (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
344         (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
345         (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
346         (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
347         (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
348         (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
349         (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
350         (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
351         (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
352         (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
353         (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
354         (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
355         (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
356         (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
357         (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
358         PUSHs (sv_2mortal ((SV *) hv));
359       }
360       guestfs_free_lvm_lv_list (logvols);
361