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.
5 * Copyright (C) 2009 Red Hat Inc.
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.
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.
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
33 my_newSVll(long long val) {
39 len = snprintf(buf, 100, "%" PRId64, val);
40 return newSVpv(buf, len);
49 my_newSVull(unsigned long long val) {
55 len = snprintf(buf, 100, "%" PRIu64, val);
56 return newSVpv(buf, len);
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.
65 static char *last_error = NULL;
68 error_handler (guestfs_h *g,
72 if (last_error != NULL) free (last_error);
73 last_error = strdup (msg);
76 /* http://www.perlmonks.org/?node_id=680842 */
78 XS_unpack_charPtrPtr (SV *arg) {
83 if (!arg || !SvOK (arg) || !SvROK (arg) || SvTYPE (SvRV (arg)) != SVt_PVAV) {
84 croak ("array reference expected");
87 av = (AV *)SvRV (arg);
88 ret = (char **)malloc (av_len (av) + 1 + 1);
90 for (i = 0; i <= av_len (av); i++) {
91 SV **elem = av_fetch (av, i, 0);
93 if (!elem || !*elem) {
94 croak ("missing element in list");
97 ret[i] = SvPV_nolen (*elem);
105 MODULE = Sys::Guestfs PACKAGE = Sys::Guestfs
110 RETVAL = guestfs_create ();
112 croak ("could not create guestfs handle");
113 guestfs_set_error_handler (RETVAL, error_handler, NULL);
127 if (guestfs_launch (g) == -1) {
128 croak ("launch: %s", last_error);
135 if (guestfs_wait_ready (g) == -1) {
136 croak ("wait_ready: %s", last_error);
143 if (guestfs_kill_subprocess (g) == -1) {
144 croak ("kill_subprocess: %s", last_error);
148 add_drive (g, filename)
152 if (guestfs_add_drive (g, filename) == -1) {
153 croak ("add_drive: %s", last_error);
157 add_cdrom (g, filename)
161 if (guestfs_add_cdrom (g, filename) == -1) {
162 croak ("add_cdrom: %s", last_error);
166 config (g, qemuparam, qemuvalue)
171 if (guestfs_config (g, qemuparam, qemuvalue) == -1) {
172 croak ("config: %s", last_error);
180 if (guestfs_set_path (g, path) == -1) {
181 croak ("set_path: %s", last_error);
190 path = guestfs_get_path (g);
192 croak ("get_path: %s", last_error);
194 RETVAL = newSVpv (path, 0);
199 set_autosync (g, autosync)
203 if (guestfs_set_autosync (g, autosync) == -1) {
204 croak ("set_autosync: %s", last_error);
213 autosync = guestfs_get_autosync (g);
214 if (autosync == -1) {
215 croak ("get_autosync: %s", last_error);
217 RETVAL = newSViv (autosync);
222 set_verbose (g, verbose)
226 if (guestfs_set_verbose (g, verbose) == -1) {
227 croak ("set_verbose: %s", last_error);
236 verbose = guestfs_get_verbose (g);
238 croak ("get_verbose: %s", last_error);
240 RETVAL = newSViv (verbose);
245 mount (g, device, mountpoint)
250 if (guestfs_mount (g, device, mountpoint) == -1) {
251 croak ("mount: %s", last_error);
258 if (guestfs_sync (g) == -1) {
259 croak ("sync: %s", last_error);
267 if (guestfs_touch (g, path) == -1) {
268 croak ("touch: %s", last_error);
278 content = guestfs_cat (g, path);
279 if (content == NULL) {
280 croak ("cat: %s", last_error);
282 RETVAL = newSVpv (content, 0);
294 listing = guestfs_ll (g, directory);
295 if (listing == NULL) {
296 croak ("ll: %s", last_error);
298 RETVAL = newSVpv (listing, 0);
311 listing = guestfs_ls (g, directory);
312 if (listing == NULL) {
313 croak ("ls: %s", last_error);
315 for (n = 0; listing[n] != NULL; ++n) /**/;
317 for (i = 0; i < n; ++i) {
318 PUSHs (sv_2mortal (newSVpv (listing[i], 0)));
330 devices = guestfs_list_devices (g);
331 if (devices == NULL) {
332 croak ("list_devices: %s", last_error);
334 for (n = 0; devices[n] != NULL; ++n) /**/;
336 for (i = 0; i < n; ++i) {
337 PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
349 partitions = guestfs_list_partitions (g);
350 if (partitions == NULL) {
351 croak ("list_partitions: %s", last_error);
353 for (n = 0; partitions[n] != NULL; ++n) /**/;
355 for (i = 0; i < n; ++i) {
356 PUSHs (sv_2mortal (newSVpv (partitions[i], 0)));
357 free (partitions[i]);
368 physvols = guestfs_pvs (g);
369 if (physvols == NULL) {
370 croak ("pvs: %s", last_error);
372 for (n = 0; physvols[n] != NULL; ++n) /**/;
374 for (i = 0; i < n; ++i) {
375 PUSHs (sv_2mortal (newSVpv (physvols[i], 0)));
387 volgroups = guestfs_vgs (g);
388 if (volgroups == NULL) {
389 croak ("vgs: %s", last_error);
391 for (n = 0; volgroups[n] != NULL; ++n) /**/;
393 for (i = 0; i < n; ++i) {
394 PUSHs (sv_2mortal (newSVpv (volgroups[i], 0)));
406 logvols = guestfs_lvs (g);
407 if (logvols == NULL) {
408 croak ("lvs: %s", last_error);
410 for (n = 0; logvols[n] != NULL; ++n) /**/;
412 for (i = 0; i < n; ++i) {
413 PUSHs (sv_2mortal (newSVpv (logvols[i], 0)));
422 struct guestfs_lvm_pv_list *physvols;
426 physvols = guestfs_pvs_full (g);
427 if (physvols == NULL)
428 croak ("pvs_full: %s", last_error);
429 EXTEND (SP, physvols->len);
430 for (i = 0; i < physvols->len; ++i) {
432 (void) hv_store (hv, "pv_name", 7, newSVpv (physvols->val[i].pv_name, 0), 0);
433 (void) hv_store (hv, "pv_uuid", 7, newSVpv (physvols->val[i].pv_uuid, 32), 0);
434 (void) hv_store (hv, "pv_fmt", 6, newSVpv (physvols->val[i].pv_fmt, 0), 0);
435 (void) hv_store (hv, "pv_size", 7, my_newSVull (physvols->val[i].pv_size), 0);
436 (void) hv_store (hv, "dev_size", 8, my_newSVull (physvols->val[i].dev_size), 0);
437 (void) hv_store (hv, "pv_free", 7, my_newSVull (physvols->val[i].pv_free), 0);
438 (void) hv_store (hv, "pv_used", 7, my_newSVull (physvols->val[i].pv_used), 0);
439 (void) hv_store (hv, "pv_attr", 7, newSVpv (physvols->val[i].pv_attr, 0), 0);
440 (void) hv_store (hv, "pv_pe_count", 11, my_newSVll (physvols->val[i].pv_pe_count), 0);
441 (void) hv_store (hv, "pv_pe_alloc_count", 17, my_newSVll (physvols->val[i].pv_pe_alloc_count), 0);
442 (void) hv_store (hv, "pv_tags", 7, newSVpv (physvols->val[i].pv_tags, 0), 0);
443 (void) hv_store (hv, "pe_start", 8, my_newSVull (physvols->val[i].pe_start), 0);
444 (void) hv_store (hv, "pv_mda_count", 12, my_newSVll (physvols->val[i].pv_mda_count), 0);
445 (void) hv_store (hv, "pv_mda_free", 11, my_newSVull (physvols->val[i].pv_mda_free), 0);
446 PUSHs (sv_2mortal ((SV *) hv));
448 guestfs_free_lvm_pv_list (physvols);
454 struct guestfs_lvm_vg_list *volgroups;
458 volgroups = guestfs_vgs_full (g);
459 if (volgroups == NULL)
460 croak ("vgs_full: %s", last_error);
461 EXTEND (SP, volgroups->len);
462 for (i = 0; i < volgroups->len; ++i) {
464 (void) hv_store (hv, "vg_name", 7, newSVpv (volgroups->val[i].vg_name, 0), 0);
465 (void) hv_store (hv, "vg_uuid", 7, newSVpv (volgroups->val[i].vg_uuid, 32), 0);
466 (void) hv_store (hv, "vg_fmt", 6, newSVpv (volgroups->val[i].vg_fmt, 0), 0);
467 (void) hv_store (hv, "vg_attr", 7, newSVpv (volgroups->val[i].vg_attr, 0), 0);
468 (void) hv_store (hv, "vg_size", 7, my_newSVull (volgroups->val[i].vg_size), 0);
469 (void) hv_store (hv, "vg_free", 7, my_newSVull (volgroups->val[i].vg_free), 0);
470 (void) hv_store (hv, "vg_sysid", 8, newSVpv (volgroups->val[i].vg_sysid, 0), 0);
471 (void) hv_store (hv, "vg_extent_size", 14, my_newSVull (volgroups->val[i].vg_extent_size), 0);
472 (void) hv_store (hv, "vg_extent_count", 15, my_newSVll (volgroups->val[i].vg_extent_count), 0);
473 (void) hv_store (hv, "vg_free_count", 13, my_newSVll (volgroups->val[i].vg_free_count), 0);
474 (void) hv_store (hv, "max_lv", 6, my_newSVll (volgroups->val[i].max_lv), 0);
475 (void) hv_store (hv, "max_pv", 6, my_newSVll (volgroups->val[i].max_pv), 0);
476 (void) hv_store (hv, "pv_count", 8, my_newSVll (volgroups->val[i].pv_count), 0);
477 (void) hv_store (hv, "lv_count", 8, my_newSVll (volgroups->val[i].lv_count), 0);
478 (void) hv_store (hv, "snap_count", 10, my_newSVll (volgroups->val[i].snap_count), 0);
479 (void) hv_store (hv, "vg_seqno", 8, my_newSVll (volgroups->val[i].vg_seqno), 0);
480 (void) hv_store (hv, "vg_tags", 7, newSVpv (volgroups->val[i].vg_tags, 0), 0);
481 (void) hv_store (hv, "vg_mda_count", 12, my_newSVll (volgroups->val[i].vg_mda_count), 0);
482 (void) hv_store (hv, "vg_mda_free", 11, my_newSVull (volgroups->val[i].vg_mda_free), 0);
483 PUSHs (sv_2mortal ((SV *) hv));
485 guestfs_free_lvm_vg_list (volgroups);
491 struct guestfs_lvm_lv_list *logvols;
495 logvols = guestfs_lvs_full (g);
497 croak ("lvs_full: %s", last_error);
498 EXTEND (SP, logvols->len);
499 for (i = 0; i < logvols->len; ++i) {
501 (void) hv_store (hv, "lv_name", 7, newSVpv (logvols->val[i].lv_name, 0), 0);
502 (void) hv_store (hv, "lv_uuid", 7, newSVpv (logvols->val[i].lv_uuid, 32), 0);
503 (void) hv_store (hv, "lv_attr", 7, newSVpv (logvols->val[i].lv_attr, 0), 0);
504 (void) hv_store (hv, "lv_major", 8, my_newSVll (logvols->val[i].lv_major), 0);
505 (void) hv_store (hv, "lv_minor", 8, my_newSVll (logvols->val[i].lv_minor), 0);
506 (void) hv_store (hv, "lv_kernel_major", 15, my_newSVll (logvols->val[i].lv_kernel_major), 0);
507 (void) hv_store (hv, "lv_kernel_minor", 15, my_newSVll (logvols->val[i].lv_kernel_minor), 0);
508 (void) hv_store (hv, "lv_size", 7, my_newSVull (logvols->val[i].lv_size), 0);
509 (void) hv_store (hv, "seg_count", 9, my_newSVll (logvols->val[i].seg_count), 0);
510 (void) hv_store (hv, "origin", 6, newSVpv (logvols->val[i].origin, 0), 0);
511 (void) hv_store (hv, "snap_percent", 12, newSVnv (logvols->val[i].snap_percent), 0);
512 (void) hv_store (hv, "copy_percent", 12, newSVnv (logvols->val[i].copy_percent), 0);
513 (void) hv_store (hv, "move_pv", 7, newSVpv (logvols->val[i].move_pv, 0), 0);
514 (void) hv_store (hv, "lv_tags", 7, newSVpv (logvols->val[i].lv_tags, 0), 0);
515 (void) hv_store (hv, "mirror_log", 10, newSVpv (logvols->val[i].mirror_log, 0), 0);
516 (void) hv_store (hv, "modules", 7, newSVpv (logvols->val[i].modules, 0), 0);
517 PUSHs (sv_2mortal ((SV *) hv));
519 guestfs_free_lvm_lv_list (logvols);
529 lines = guestfs_read_lines (g, path);
531 croak ("read_lines: %s", last_error);
533 for (n = 0; lines[n] != NULL; ++n) /**/;
535 for (i = 0; i < n; ++i) {
536 PUSHs (sv_2mortal (newSVpv (lines[i], 0)));
542 aug_init (g, root, flags)
547 if (guestfs_aug_init (g, root, flags) == -1) {
548 croak ("aug_init: %s", last_error);
555 if (guestfs_aug_close (g) == -1) {
556 croak ("aug_close: %s", last_error);
560 aug_defvar (g, name, expr)
567 nrnodes = guestfs_aug_defvar (g, name, expr);
569 croak ("aug_defvar: %s", last_error);
571 RETVAL = newSViv (nrnodes);
576 aug_defnode (g, name, expr, val)
582 struct guestfs_int_bool *r;
584 r = guestfs_aug_defnode (g, name, expr, val);
586 croak ("aug_defnode: %s", last_error);
589 PUSHs (sv_2mortal (newSViv (r->i)));
590 PUSHs (sv_2mortal (newSViv (r->b)));
591 guestfs_free_int_bool (r);
600 val = guestfs_aug_get (g, path);
602 croak ("aug_get: %s", last_error);
604 RETVAL = newSVpv (val, 0);
610 aug_set (g, path, val)
615 if (guestfs_aug_set (g, path, val) == -1) {
616 croak ("aug_set: %s", last_error);
620 aug_insert (g, path, label, before)
626 if (guestfs_aug_insert (g, path, label, before) == -1) {
627 croak ("aug_insert: %s", last_error);
637 nrnodes = guestfs_aug_rm (g, path);
639 croak ("aug_rm: %s", last_error);
641 RETVAL = newSViv (nrnodes);
646 aug_mv (g, src, dest)
651 if (guestfs_aug_mv (g, src, dest) == -1) {
652 croak ("aug_mv: %s", last_error);
663 matches = guestfs_aug_match (g, path);
664 if (matches == NULL) {
665 croak ("aug_match: %s", last_error);
667 for (n = 0; matches[n] != NULL; ++n) /**/;
669 for (i = 0; i < n; ++i) {
670 PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
679 if (guestfs_aug_save (g) == -1) {
680 croak ("aug_save: %s", last_error);
687 if (guestfs_aug_load (g) == -1) {
688 croak ("aug_load: %s", last_error);
699 matches = guestfs_aug_ls (g, path);
700 if (matches == NULL) {
701 croak ("aug_ls: %s", last_error);
703 for (n = 0; matches[n] != NULL; ++n) /**/;
705 for (i = 0; i < n; ++i) {
706 PUSHs (sv_2mortal (newSVpv (matches[i], 0)));
716 if (guestfs_rm (g, path) == -1) {
717 croak ("rm: %s", last_error);
725 if (guestfs_rmdir (g, path) == -1) {
726 croak ("rmdir: %s", last_error);
734 if (guestfs_rm_rf (g, path) == -1) {
735 croak ("rm_rf: %s", last_error);
743 if (guestfs_mkdir (g, path) == -1) {
744 croak ("mkdir: %s", last_error);
752 if (guestfs_mkdir_p (g, path) == -1) {
753 croak ("mkdir_p: %s", last_error);
757 chmod (g, mode, path)
762 if (guestfs_chmod (g, mode, path) == -1) {
763 croak ("chmod: %s", last_error);
767 chown (g, owner, group, path)
773 if (guestfs_chown (g, owner, group, path) == -1) {
774 croak ("chown: %s", last_error);
784 existsflag = guestfs_exists (g, path);
785 if (existsflag == -1) {
786 croak ("exists: %s", last_error);
788 RETVAL = newSViv (existsflag);
799 fileflag = guestfs_is_file (g, path);
800 if (fileflag == -1) {
801 croak ("is_file: %s", last_error);
803 RETVAL = newSViv (fileflag);
814 dirflag = guestfs_is_dir (g, path);
816 croak ("is_dir: %s", last_error);
818 RETVAL = newSViv (dirflag);
827 if (guestfs_pvcreate (g, device) == -1) {
828 croak ("pvcreate: %s", last_error);
832 vgcreate (g, volgroup, physvols)
837 if (guestfs_vgcreate (g, volgroup, physvols) == -1) {
839 croak ("vgcreate: %s", last_error);
844 lvcreate (g, logvol, volgroup, mbytes)
850 if (guestfs_lvcreate (g, logvol, volgroup, mbytes) == -1) {
851 croak ("lvcreate: %s", last_error);
855 mkfs (g, fstype, device)
860 if (guestfs_mkfs (g, fstype, device) == -1) {
861 croak ("mkfs: %s", last_error);
865 sfdisk (g, device, cyls, heads, sectors, lines)
873 if (guestfs_sfdisk (g, device, cyls, heads, sectors, lines) == -1) {
875 croak ("sfdisk: %s", last_error);
880 write_file (g, path, content, size)
886 if (guestfs_write_file (g, path, content, size) == -1) {
887 croak ("write_file: %s", last_error);
891 umount (g, pathordevice)
895 if (guestfs_umount (g, pathordevice) == -1) {
896 croak ("umount: %s", last_error);
906 devices = guestfs_mounts (g);
907 if (devices == NULL) {
908 croak ("mounts: %s", last_error);
910 for (n = 0; devices[n] != NULL; ++n) /**/;
912 for (i = 0; i < n; ++i) {
913 PUSHs (sv_2mortal (newSVpv (devices[i], 0)));
922 if (guestfs_umount_all (g) == -1) {
923 croak ("umount_all: %s", last_error);
930 if (guestfs_lvm_remove_all (g) == -1) {
931 croak ("lvm_remove_all: %s", last_error);