X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=ruby%2Fext%2Fguestfs%2F_guestfs.c;h=eed0b80e9ba378293ae243bef9be34c8f4486b69;hb=d9ea3e8d979c3ade1b21f27083788fd33fa3b1fa;hp=89eb6afd4781cf207561e1fdbc343ef89f09609c;hpb=79cdf81e2fb717ea4372a55170d16800cdbddf23;p=libguestfs.git diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index 89eb6af..eed0b80 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -1413,11 +1413,12 @@ static VALUE ruby_guestfs_vgcreate (VALUE gv, VALUE volgroupv, VALUE physvolsv) char **physvols; { int i, len; len = RARRAY_LEN (physvolsv); - physvols = malloc (sizeof (char *) * (len+1)); + physvols = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); for (i = 0; i < len; ++i) { VALUE v = rb_ary_entry (physvolsv, i); physvols[i] = StringValueCStr (v); } + physvols[len] = NULL; } int r; @@ -1498,11 +1499,12 @@ static VALUE ruby_guestfs_sfdisk (VALUE gv, VALUE devicev, VALUE cylsv, VALUE he char **lines; { int i, len; len = RARRAY_LEN (linesv); - lines = malloc (sizeof (char *) * (len+1)); + lines = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); for (i = 0; i < len; ++i) { VALUE v = rb_ary_entry (linesv, i); lines[i] = StringValueCStr (v); } + lines[len] = NULL; } int r; @@ -1654,11 +1656,12 @@ static VALUE ruby_guestfs_command (VALUE gv, VALUE argumentsv) char **arguments; { int i, len; len = RARRAY_LEN (argumentsv); - arguments = malloc (sizeof (char *) * (len+1)); + arguments = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); for (i = 0; i < len; ++i) { VALUE v = rb_ary_entry (argumentsv, i); arguments[i] = StringValueCStr (v); } + arguments[len] = NULL; } char *r; @@ -1683,11 +1686,12 @@ static VALUE ruby_guestfs_command_lines (VALUE gv, VALUE argumentsv) char **arguments; { int i, len; len = RARRAY_LEN (argumentsv); - arguments = malloc (sizeof (char *) * (len+1)); + arguments = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); for (i = 0; i < len; ++i) { VALUE v = rb_ary_entry (argumentsv, i); arguments[i] = StringValueCStr (v); } + arguments[len] = NULL; } char **r; @@ -2318,6 +2322,399 @@ static VALUE ruby_guestfs_mount_vfs (VALUE gv, VALUE optionsv, VALUE vfstypev, V 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 = guestfs_safe_malloc (g, 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; +} + +static VALUE ruby_guestfs_fsck (VALUE gv, VALUE fstypev, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "fsck"); + + const char *fstype = StringValueCStr (fstypev); + if (!fstype) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "fstype", "fsck"); + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "fsck"); + + int r; + + r = guestfs_fsck (g, fstype, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return INT2NUM (r); +} + +static VALUE ruby_guestfs_zero (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", "zero"); + + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "zero"); + + int r; + + r = guestfs_zero (g, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_grub_install (VALUE gv, VALUE rootv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "grub_install"); + + const char *root = StringValueCStr (rootv); + if (!root) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "root", "grub_install"); + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "grub_install"); + + int r; + + r = guestfs_grub_install (g, root, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_cp (VALUE gv, VALUE srcv, VALUE destv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "cp"); + + const char *src = StringValueCStr (srcv); + if (!src) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "src", "cp"); + const char *dest = StringValueCStr (destv); + if (!dest) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "dest", "cp"); + + int r; + + r = guestfs_cp (g, src, dest); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_cp_a (VALUE gv, VALUE srcv, VALUE destv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "cp_a"); + + const char *src = StringValueCStr (srcv); + if (!src) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "src", "cp_a"); + const char *dest = StringValueCStr (destv); + if (!dest) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "dest", "cp_a"); + + int r; + + r = guestfs_cp_a (g, src, dest); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_mv (VALUE gv, VALUE srcv, VALUE destv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "mv"); + + const char *src = StringValueCStr (srcv); + if (!src) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "src", "mv"); + const char *dest = StringValueCStr (destv); + if (!dest) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "dest", "mv"); + + int r; + + r = guestfs_mv (g, src, dest); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_drop_caches (VALUE gv, VALUE whattodropv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "drop_caches"); + + int whattodrop = NUM2INT (whattodropv); + + int r; + + r = guestfs_drop_caches (g, whattodrop); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_dmesg (VALUE gv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "dmesg"); + + + char *r; + + r = guestfs_dmesg (g); + 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_ping_daemon (VALUE gv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "ping_daemon"); + + + int r; + + r = guestfs_ping_daemon (g); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + /* Initialize the module. */ void Init__guestfs () { @@ -2520,4 +2917,38 @@ void Init__guestfs () 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); + rb_define_method (c_guestfs, "fsck", + ruby_guestfs_fsck, 2); + rb_define_method (c_guestfs, "zero", + ruby_guestfs_zero, 1); + rb_define_method (c_guestfs, "grub_install", + ruby_guestfs_grub_install, 2); + rb_define_method (c_guestfs, "cp", + ruby_guestfs_cp, 2); + rb_define_method (c_guestfs, "cp_a", + ruby_guestfs_cp_a, 2); + rb_define_method (c_guestfs, "mv", + ruby_guestfs_mv, 2); + rb_define_method (c_guestfs, "drop_caches", + ruby_guestfs_drop_caches, 1); + rb_define_method (c_guestfs, "dmesg", + ruby_guestfs_dmesg, 0); + rb_define_method (c_guestfs, "ping_daemon", + ruby_guestfs_ping_daemon, 0); }