X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=ruby%2Fext%2Fguestfs%2F_guestfs.c;h=f78506b58059dbfb92a986fa4feae8170859519f;hp=4983932f98d3dc7c664c9e5d0d2eb7bba5f98209;hb=ca4a0c718083db4485edebe4d1b931090e098fa5;hpb=d1a1ab972bb22f4c38a21fcc73f81650aaa03b4e diff --git a/ruby/ext/guestfs/_guestfs.c b/ruby/ext/guestfs/_guestfs.c index 4983932..f78506b 100644 --- a/ruby/ext/guestfs/_guestfs.c +++ b/ruby/ext/guestfs/_guestfs.c @@ -83,7 +83,8 @@ static VALUE ruby_guestfs_test0 (VALUE gv, VALUE strv, VALUE optstrv, VALUE strl rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "str", "test0"); const char *optstr = !NIL_P (optstrv) ? StringValueCStr (optstrv) : NULL; - char **strlist; { + char **strlist; + { int i, len; len = RARRAY_LEN (strlistv); strlist = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -2268,7 +2269,8 @@ static VALUE ruby_guestfs_vgcreate (VALUE gv, VALUE volgroupv, VALUE physvolsv) if (!volgroup) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "volgroup", "vgcreate"); - char **physvols; { + char **physvols; + { int i, len; len = RARRAY_LEN (physvolsv); physvols = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -2354,7 +2356,8 @@ static VALUE ruby_guestfs_sfdisk (VALUE gv, VALUE devicev, VALUE cylsv, VALUE he int cyls = NUM2INT (cylsv); int heads = NUM2INT (headsv); int sectors = NUM2INT (sectorsv); - char **lines; { + char **lines; + { int i, len; len = RARRAY_LEN (linesv); lines = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -2511,7 +2514,8 @@ static VALUE ruby_guestfs_command (VALUE gv, VALUE argumentsv) if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "command"); - char **arguments; { + char **arguments; + { int i, len; len = RARRAY_LEN (argumentsv); arguments = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -2541,7 +2545,8 @@ static VALUE ruby_guestfs_command_lines (VALUE gv, VALUE argumentsv) if (!g) rb_raise (rb_eArgError, "%s: used handle after closing it", "command_lines"); - char **arguments; { + char **arguments; + { int i, len; len = RARRAY_LEN (argumentsv); arguments = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -3191,7 +3196,8 @@ static VALUE ruby_guestfs_debug (VALUE gv, VALUE subcmdv, VALUE extraargsv) if (!subcmd) rb_raise (rb_eTypeError, "expected string for parameter %s of %s", "subcmd", "debug"); - char **extraargs; { + char **extraargs; + { int i, len; len = RARRAY_LEN (extraargsv); extraargs = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -3849,7 +3855,8 @@ static VALUE ruby_guestfs_vg_activate (VALUE gv, VALUE activatev, VALUE volgroup rb_raise (rb_eArgError, "%s: used handle after closing it", "vg_activate"); int activate = RTEST (activatev); - char **volgroups; { + char **volgroups; + { int i, len; len = RARRAY_LEN (volgroupsv); volgroups = guestfs_safe_malloc (g, sizeof (char *) * (len+1)); @@ -3963,6 +3970,127 @@ static VALUE ruby_guestfs_e2fsck_f (VALUE gv, VALUE devicev) return Qnil; } +static VALUE ruby_guestfs_sleep (VALUE gv, VALUE secsv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "sleep"); + + int secs = NUM2INT (secsv); + + int r; + + r = guestfs_sleep (g, secs); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return Qnil; +} + +static VALUE ruby_guestfs_ntfs_3g_probe (VALUE gv, VALUE rwv, VALUE devicev) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "ntfs_3g_probe"); + + int rw = RTEST (rwv); + const char *device = StringValueCStr (devicev); + if (!device) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "device", "ntfs_3g_probe"); + + int r; + + r = guestfs_ntfs_3g_probe (g, rw, device); + if (r == -1) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + return INT2NUM (r); +} + +static VALUE ruby_guestfs_sh (VALUE gv, VALUE commandv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "sh"); + + const char *command = StringValueCStr (commandv); + if (!command) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "command", "sh"); + + char *r; + + r = guestfs_sh (g, command); + 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_sh_lines (VALUE gv, VALUE commandv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "sh_lines"); + + const char *command = StringValueCStr (commandv); + if (!command) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "command", "sh_lines"); + + char **r; + + r = guestfs_sh_lines (g, command); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + int i, len = 0; + for (i = 0; r[i] != NULL; ++i) len++; + VALUE rv = rb_ary_new2 (len); + for (i = 0; r[i] != NULL; ++i) { + rb_ary_push (rv, rb_str_new2 (r[i])); + free (r[i]); + } + free (r); + return rv; +} + +static VALUE ruby_guestfs_glob_expand (VALUE gv, VALUE patternv) +{ + guestfs_h *g; + Data_Get_Struct (gv, guestfs_h, g); + if (!g) + rb_raise (rb_eArgError, "%s: used handle after closing it", "glob_expand"); + + const char *pattern = StringValueCStr (patternv); + if (!pattern) + rb_raise (rb_eTypeError, "expected string for parameter %s of %s", + "pattern", "glob_expand"); + + char **r; + + r = guestfs_glob_expand (g, pattern); + if (r == NULL) + rb_raise (e_Error, "%s", guestfs_last_error (g)); + + int i, len = 0; + for (i = 0; r[i] != NULL; ++i) len++; + VALUE rv = rb_ary_new2 (len); + for (i = 0; r[i] != NULL; ++i) { + rb_ary_push (rv, rb_str_new2 (r[i])); + free (r[i]); + } + free (r); + return rv; +} + /* Initialize the module. */ void Init__guestfs () { @@ -4293,4 +4421,14 @@ void Init__guestfs () ruby_guestfs_find, 1); rb_define_method (c_guestfs, "e2fsck_f", ruby_guestfs_e2fsck_f, 1); + rb_define_method (c_guestfs, "sleep", + ruby_guestfs_sleep, 1); + rb_define_method (c_guestfs, "ntfs_3g_probe", + ruby_guestfs_ntfs_3g_probe, 2); + rb_define_method (c_guestfs, "sh", + ruby_guestfs_sh, 1); + rb_define_method (c_guestfs, "sh_lines", + ruby_guestfs_sh_lines, 1); + rb_define_method (c_guestfs, "glob_expand", + ruby_guestfs_glob_expand, 1); }