X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=ruby%2Fext%2Fguestfs%2F_guestfs.c;h=af80e3f5a2145f0e18bee5babc23a12e794ff464;hb=6dff51fc7d8a33925f164bd66c2c26cd4b94b3df;hp=f73a3b78afff97b05315e01ec79e2fa725e6ee57;hpb=bb07a7f858da5d07c57360e62c0ddfd24ce6be45;p=libguestfs.git diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index f73a3b7..af80e3f 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -181,6 +181,44 @@ static VALUE ruby_guestfs_config (VALUE gv, VALUE qemuparamv, VALUE qemuvaluev) return Qnil; } +static VALUE ruby_guestfs_set_qemu (VALUE gv, VALUE qemuv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "set_qemu"); + + const char *qemu = StringValueCStr (qemuv); + if (!qemu) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "qemu", "set_qemu"); + + int r; + + r = guestfs_set_qemu (g, qemu); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_get_qemu (VALUE gv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "get_qemu"); + + + const char *r; + + r = guestfs_get_qemu (g); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return rb_str_new2 (r); +} + static VALUE ruby_guestfs_set_path (VALUE gv, VALUE pathv) { guestfs_h *g; @@ -374,6 +412,40 @@ static VALUE ruby_guestfs_get_state (VALUE gv) return INT2NUM (r); } +static VALUE ruby_guestfs_set_busy (VALUE gv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "set_busy"); + + + int r; + + r = guestfs_set_busy (g); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_set_ready (VALUE gv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "set_ready"); + + + int r; + + r = guestfs_set_ready (g); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + static VALUE ruby_guestfs_mount (VALUE gv, VALUE devicev, VALUE mountpointv) { guestfs_h *g; @@ -1346,6 +1418,7 @@ static VALUE ruby_guestfs_vgcreate (VALUE gv, VALUE volgroupv, VALUE physvolsv) VALUE v = rb_ary_entry (physvolsv, i); physvols[i] = StringValueCStr (v); } + physvols[len] = NULL; } int r; @@ -1431,6 +1504,7 @@ static VALUE ruby_guestfs_sfdisk (VALUE gv, VALUE devicev, VALUE cylsv, VALUE he VALUE v = rb_ary_entry (linesv, i); lines[i] = StringValueCStr (v); } + lines[len] = NULL; } int r; @@ -1587,6 +1661,7 @@ static VALUE ruby_guestfs_command (VALUE gv, VALUE argumentsv) VALUE v = rb_ary_entry (argumentsv, i); arguments[i] = StringValueCStr (v); } + arguments[len] = NULL; } char *r; @@ -1616,6 +1691,7 @@ static VALUE ruby_guestfs_command_lines (VALUE gv, VALUE argumentsv) VALUE v = rb_ary_entry (argumentsv, i); arguments[i] = StringValueCStr (v); } + arguments[len] = NULL; } char **r; @@ -2032,6 +2108,413 @@ static VALUE ruby_guestfs_download (VALUE gv, VALUE remotefilenamev, VALUE filen return Qnil; } +static VALUE ruby_guestfs_checksum (VALUE gv, VALUE csumtypev, VALUE pathv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "checksum"); + + const char *csumtype = StringValueCStr (csumtypev); + if (!csumtype) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "csumtype", "checksum"); + const char *path = StringValueCStr (pathv); + if (!path) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "path", "checksum"); + + char *r; + + r = guestfs_checksum (g, csumtype, path); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_str_new2 (r); + free (r); + return rv; +} + +static VALUE ruby_guestfs_tar_in (VALUE gv, VALUE tarfilev, VALUE directoryv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "tar_in"); + + const char *tarfile = StringValueCStr (tarfilev); + if (!tarfile) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "tarfile", "tar_in"); + const char *directory = StringValueCStr (directoryv); + if (!directory) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "directory", "tar_in"); + + int r; + + r = guestfs_tar_in (g, tarfile, directory); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_tar_out (VALUE gv, VALUE directoryv, VALUE tarfilev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "tar_out"); + + const char *directory = StringValueCStr (directoryv); + if (!directory) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "directory", "tar_out"); + const char *tarfile = StringValueCStr (tarfilev); + if (!tarfile) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "tarfile", "tar_out"); + + int r; + + r = guestfs_tar_out (g, directory, tarfile); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_tgz_in (VALUE gv, VALUE tarballv, VALUE directoryv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "tgz_in"); + + const char *tarball = StringValueCStr (tarballv); + if (!tarball) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "tarball", "tgz_in"); + const char *directory = StringValueCStr (directoryv); + if (!directory) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "directory", "tgz_in"); + + int r; + + r = guestfs_tgz_in (g, tarball, directory); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_tgz_out (VALUE gv, VALUE directoryv, VALUE tarballv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "tgz_out"); + + const char *directory = StringValueCStr (directoryv); + if (!directory) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "directory", "tgz_out"); + const char *tarball = StringValueCStr (tarballv); + if (!tarball) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "tarball", "tgz_out"); + + int r; + + r = guestfs_tgz_out (g, directory, tarball); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_mount_ro (VALUE gv, VALUE devicev, VALUE mountpointv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "mount_ro"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "mount_ro"); + const char *mountpoint = StringValueCStr (mountpointv); + if (!mountpoint) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "mountpoint", "mount_ro"); + + int r; + + r = guestfs_mount_ro (g, device, mountpoint); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_mount_options (VALUE gv, VALUE optionsv, VALUE devicev, VALUE mountpointv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "mount_options"); + + const char *options = StringValueCStr (optionsv); + if (!options) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "options", "mount_options"); + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "mount_options"); + const char *mountpoint = StringValueCStr (mountpointv); + if (!mountpoint) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "mountpoint", "mount_options"); + + int r; + + r = guestfs_mount_options (g, options, device, mountpoint); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_mount_vfs (VALUE gv, VALUE optionsv, VALUE vfstypev, VALUE devicev, VALUE mountpointv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "mount_vfs"); + + const char *options = StringValueCStr (optionsv); + if (!options) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "options", "mount_vfs"); + const char *vfstype = StringValueCStr (vfstypev); + if (!vfstype) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "vfstype", "mount_vfs"); + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "mount_vfs"); + const char *mountpoint = StringValueCStr (mountpointv); + if (!mountpoint) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "mountpoint", "mount_vfs"); + + int r; + + r = guestfs_mount_vfs (g, options, vfstype, device, mountpoint); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_debug (VALUE gv, VALUE subcmdv, VALUE extraargsv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "debug"); + + const char *subcmd = StringValueCStr (subcmdv); + if (!subcmd) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "subcmd", "debug"); + char **extraargs; { + int i, len; + len = RARRAY_LEN (extraargsv); + extraargs = malloc (sizeof (char *) * (len+1)); + for (i = 0; i < len; ++i) { + VALUE v = rb_ary_entry (extraargsv, i); + extraargs[i] = StringValueCStr (v); + } + extraargs[len] = NULL; + } + + char *r; + + r = guestfs_debug (g, subcmd, extraargs); + free (extraargs); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_str_new2 (r); + free (r); + return rv; +} + +static VALUE ruby_guestfs_lvremove (VALUE gv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "lvremove"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "lvremove"); + + int r; + + r = guestfs_lvremove (g, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_vgremove (VALUE gv, VALUE vgnamev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "vgremove"); + + const char *vgname = StringValueCStr (vgnamev); + if (!vgname) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "vgname", "vgremove"); + + int r; + + r = guestfs_vgremove (g, vgname); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_pvremove (VALUE gv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "pvremove"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "pvremove"); + + int r; + + r = guestfs_pvremove (g, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_set_e2label (VALUE gv, VALUE devicev, VALUE labelv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "set_e2label"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "set_e2label"); + const char *label = StringValueCStr (labelv); + if (!label) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "label", "set_e2label"); + + int r; + + r = guestfs_set_e2label (g, device, label); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_get_e2label (VALUE gv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "get_e2label"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "get_e2label"); + + char *r; + + r = guestfs_get_e2label (g, device); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_str_new2 (r); + free (r); + return rv; +} + +static VALUE ruby_guestfs_set_e2uuid (VALUE gv, VALUE devicev, VALUE uuidv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "set_e2uuid"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "set_e2uuid"); + const char *uuid = StringValueCStr (uuidv); + if (!uuid) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "uuid", "set_e2uuid"); + + int r; + + r = guestfs_set_e2uuid (g, device, uuid); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_get_e2uuid (VALUE gv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "get_e2uuid"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "get_e2uuid"); + + char *r; + + r = guestfs_get_e2uuid (g, device); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + VALUE rv = rb_str_new2 (r); + free (r); + return rv; +} + /* Initialize the module. */ void Init__guestfs () { @@ -2054,6 +2537,10 @@ void Init__guestfs () ruby_guestfs_add_cdrom, 1); rb_define_method (c_guestfs, "config", ruby_guestfs_config, 2); + rb_define_method (c_guestfs, "set_qemu", + ruby_guestfs_set_qemu, 1); + rb_define_method (c_guestfs, "get_qemu", + ruby_guestfs_get_qemu, 0); rb_define_method (c_guestfs, "set_path", ruby_guestfs_set_path, 1); rb_define_method (c_guestfs, "get_path", @@ -2076,6 +2563,10 @@ void Init__guestfs () ruby_guestfs_is_busy, 0); rb_define_method (c_guestfs, "get_state", ruby_guestfs_get_state, 0); + rb_define_method (c_guestfs, "set_busy", + ruby_guestfs_set_busy, 0); + rb_define_method (c_guestfs, "set_ready", + ruby_guestfs_set_ready, 0); rb_define_method (c_guestfs, "mount", ruby_guestfs_mount, 2); rb_define_method (c_guestfs, "sync", @@ -2210,4 +2701,36 @@ void Init__guestfs () ruby_guestfs_upload, 2); rb_define_method (c_guestfs, "download", ruby_guestfs_download, 2); + rb_define_method (c_guestfs, "checksum", + ruby_guestfs_checksum, 2); + rb_define_method (c_guestfs, "tar_in", + ruby_guestfs_tar_in, 2); + rb_define_method (c_guestfs, "tar_out", + ruby_guestfs_tar_out, 2); + rb_define_method (c_guestfs, "tgz_in", + ruby_guestfs_tgz_in, 2); + rb_define_method (c_guestfs, "tgz_out", + ruby_guestfs_tgz_out, 2); + rb_define_method (c_guestfs, "mount_ro", + ruby_guestfs_mount_ro, 2); + rb_define_method (c_guestfs, "mount_options", + ruby_guestfs_mount_options, 3); + rb_define_method (c_guestfs, "mount_vfs", + ruby_guestfs_mount_vfs, 4); + rb_define_method (c_guestfs, "debug", + ruby_guestfs_debug, 2); + rb_define_method (c_guestfs, "lvremove", + ruby_guestfs_lvremove, 1); + rb_define_method (c_guestfs, "vgremove", + ruby_guestfs_vgremove, 1); + rb_define_method (c_guestfs, "pvremove", + ruby_guestfs_pvremove, 1); + rb_define_method (c_guestfs, "set_e2label", + ruby_guestfs_set_e2label, 2); + rb_define_method (c_guestfs, "get_e2label", + ruby_guestfs_get_e2label, 1); + rb_define_method (c_guestfs, "set_e2uuid", + ruby_guestfs_set_e2uuid, 2); + rb_define_method (c_guestfs, "get_e2uuid", + ruby_guestfs_get_e2uuid, 1); }