fprintf (stderr, "warning: \"guestfs_sh_lines\" has no tests\n");
}
+static int test_glob_expand_0_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_0");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_0 (void)
+{
+ if (test_glob_expand_0_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_0");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_0: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (0) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/b/c/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_glob_expand_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/d";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_0: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_glob_expand_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/e";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_0: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_glob_expand_0: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_glob_expand_1_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_1");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_1 (void)
+{
+ if (test_glob_expand_1_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_1");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_1: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (1) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/*/c/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_glob_expand_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/d";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_1: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_glob_expand_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "/a/b/c/e";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_glob_expand_1: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_glob_expand_1: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
+static int test_glob_expand_2_skip (void)
+{
+ const char *str;
+
+ str = getenv ("SKIP_TEST_GLOB_EXPAND_2");
+ if (str && strcmp (str, "1") == 0) return 1;
+ str = getenv ("SKIP_TEST_GLOB_EXPAND");
+ if (str && strcmp (str, "1") == 0) return 1;
+ return 0;
+}
+
+static int test_glob_expand_2 (void)
+{
+ if (test_glob_expand_2_skip ()) {
+ printf ("%s skipped (reason: SKIP_TEST_* variable set)\n", "test_glob_expand_2");
+ return 0;
+ }
+
+ /* InitBasicFS for test_glob_expand_2: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ int r;
+ suppress_error = 0;
+ r = guestfs_blockdev_setrw (g, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_umount_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ int r;
+ suppress_error = 0;
+ r = guestfs_lvm_remove_all (g);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda";
+ char lines_0[] = ",";
+ char *lines[] = {
+ lines_0,
+ NULL
+ };
+ int r;
+ suppress_error = 0;
+ r = guestfs_sfdisk (g, device, 0, 0, 0, lines);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char fstype[] = "ext2";
+ char device[] = "/dev/sda1";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for glob_expand (2) */
+ {
+ char path[] = "/a/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir_p (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/d";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/a/b/c/e";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char pattern[] = "/a/*/x/*";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL)
+ return -1;
+ if (r[0] != NULL) {
+ fprintf (stderr, "test_glob_expand_2: extra elements returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ for (i = 0; r[i] != NULL; ++i)
+ free (r[i]);
+ free (r);
+ }
+ return 0;
+}
+
static int test_ntfs_3g_probe_0_skip (void)
{
const char *str;
/* Cancel previous alarm. */
alarm (0);
- nr_tests = 146;
+ nr_tests = 149;
test_num++;
+ printf ("%3d/%3d test_glob_expand_0\n", test_num, nr_tests);
+ if (test_glob_expand_0 () == -1) {
+ printf ("test_glob_expand_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_glob_expand_1\n", test_num, nr_tests);
+ if (test_glob_expand_1 () == -1) {
+ printf ("test_glob_expand_1 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_glob_expand_2\n", test_num, nr_tests);
+ if (test_glob_expand_2 () == -1) {
+ printf ("test_glob_expand_2 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_ntfs_3g_probe_0\n", test_num, nr_tests);
if (test_ntfs_3g_probe_0 () == -1) {
printf ("test_ntfs_3g_probe_0 FAILED\n");
extern int do_ntfs_3g_probe (int rw, char *device);
extern char *do_sh (char *command);
extern char **do_sh_lines (char *command);
+extern char **do_glob_expand (char *pattern);
xdr_free ((xdrproc_t) xdr_guestfs_sh_lines_args, (char *) &args);
}
+static void glob_expand_stub (XDR *xdr_in)
+{
+ char **r;
+ struct guestfs_glob_expand_args args;
+ char *pattern;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_glob_expand_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "glob_expand");
+ return;
+ }
+ pattern = args.pattern;
+
+ r = do_glob_expand (pattern);
+ if (r == NULL)
+ /* do_glob_expand has already called reply_with_error */
+ goto done;
+
+ struct guestfs_glob_expand_ret ret;
+ ret.paths.paths_len = count_strings (r);
+ ret.paths.paths_val = r;
+ reply ((xdrproc_t) &xdr_guestfs_glob_expand_ret, (char *) &ret);
+ free_strings (r);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_glob_expand_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_SH_LINES:
sh_lines_stub (xdr_in);
break;
+ case GUESTFS_PROC_GLOB_EXPAND:
+ glob_expand_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "get-qemu", "get the qemu binary");
printf ("%-20s %s\n", "get-state", "get the current state");
printf ("%-20s %s\n", "get-verbose", "get verbose mode");
+ printf ("%-20s %s\n", "glob-expand", "expand a wildcard path");
printf ("%-20s %s\n", "grub-install", "install GRUB");
printf ("%-20s %s\n", "hexdump", "dump a file in hexadecimal");
printf ("%-20s %s\n", "is-busy", "is busy processing a command");
if (strcasecmp (cmd, "sh_lines") == 0 || strcasecmp (cmd, "sh-lines") == 0)
pod2text ("sh-lines - run a command via the shell returning lines", " sh-lines <command>\n\nThis is the same as C<sh>, but splits the result\ninto a list of lines.\n\nSee also: C<command_lines>");
else
+ if (strcasecmp (cmd, "glob_expand") == 0 || strcasecmp (cmd, "glob-expand") == 0)
+ pod2text ("glob-expand - expand a wildcard path", " glob-expand <pattern>\n\nThis command searches for all the pathnames matching\nC<pattern> according to the wildcard expansion rules\nused by the shell.\n\nIf no paths match, then this returns an empty list\n(note: not an error).\n\nIt is just a wrapper around the C L<glob(3)> function\nwith flags C<GLOB_MARK|GLOB_BRACE>.\nSee that manual page for more details.");
+ else
display_builtin_command (cmd);
}
return 0;
}
+static int run_glob_expand (const char *cmd, int argc, char *argv[])
+{
+ char **r;
+ const char *pattern;
+ if (argc != 1) {
+ fprintf (stderr, "%s should have 1 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ pattern = argv[0];
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL) return -1;
+ print_strings (r);
+ free_strings (r);
+ return 0;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "sh_lines") == 0 || strcasecmp (cmd, "sh-lines") == 0)
return run_sh_lines (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "glob_expand") == 0 || strcasecmp (cmd, "glob-expand") == 0)
+ return run_glob_expand (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"ntfs-3g-probe",
"sh",
"sh-lines",
+ "glob-expand",
NULL
};
This returns the verbose messages flag.
+=head2 glob-expand
+
+ glob-expand pattern
+
+This command searches for all the pathnames matching
+C<pattern> according to the wildcard expansion rules
+used by the shell.
+
+If no paths match, then this returns an empty list
+(note: not an error).
+
+It is just a wrapper around the C L<glob(3)> function
+with flags C<GLOB_MARK|GLOB_BRACE>.
+See that manual page for more details.
+
=head2 grub-install
grub-install root device
This function returns a C truth value on success or -1 on error.
+=head2 guestfs_glob_expand
+
+ char **guestfs_glob_expand (guestfs_h *handle,
+ const char *pattern);
+
+This command searches for all the pathnames matching
+C<pattern> according to the wildcard expansion rules
+used by the shell.
+
+If no paths match, then this returns an empty list
+(note: not an error).
+
+It is just a wrapper around the C L<glob(3)> function
+with flags C<GLOB_MARK|GLOB_BRACE>.
+See that manual page for more details.
+
+This function returns a NULL-terminated array of strings
+(like L<environ(3)>), or NULL if there was an error.
+I<The caller must free the strings and the array after use>.
+
=head2 guestfs_grub_install
int guestfs_grub_install (guestfs_h *handle,
private native String[] _sh_lines (long g, String command)
throws LibGuestFSException;
+ /**
+ * expand a wildcard path
+ * <p>
+ * This command searches for all the pathnames matching
+ * "pattern" according to the wildcard expansion rules used
+ * by the shell.
+ * <p>
+ * If no paths match, then this returns an empty list
+ * (note: not an error).
+ * <p>
+ * It is just a wrapper around the C glob(3) function with
+ * flags "GLOB_MARK|GLOB_BRACE". See that manual page for
+ * more details.
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public String[] glob_expand (String pattern)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("glob_expand: handle is closed");
+ return _glob_expand (g, pattern);
+ }
+ private native String[] _glob_expand (long g, String pattern)
+ throws LibGuestFSException;
+
}
return jr;
}
+JNIEXPORT jobjectArray JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1glob_1expand
+ (JNIEnv *env, jobject obj, jlong jg, jstring jpattern)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ jobjectArray jr;
+ int r_len;
+ jclass cl;
+ jstring jstr;
+ char **r;
+ const char *pattern;
+ int i;
+
+ pattern = (*env)->GetStringUTFChars (env, jpattern, NULL);
+ r = guestfs_glob_expand (g, pattern);
+ (*env)->ReleaseStringUTFChars (env, jpattern, pattern);
+ if (r == NULL) {
+ throw_exception (env, guestfs_last_error (g));
+ return NULL;
+ }
+ for (r_len = 0; r[r_len] != NULL; ++r_len) ;
+ cl = (*env)->FindClass (env, "java/lang/String");
+ jstr = (*env)->NewStringUTF (env, "");
+ jr = (*env)->NewObjectArray (env, r_len, cl, jstr);
+ for (i = 0; i < r_len; ++i) {
+ jstr = (*env)->NewStringUTF (env, r[i]);
+ (*env)->SetObjectArrayElement (env, jr, i, jstr);
+ free (r[i]);
+ }
+ free (r);
+ return jr;
+}
+
external ntfs_3g_probe : t -> bool -> string -> int = "ocaml_guestfs_ntfs_3g_probe"
external sh : t -> string -> string = "ocaml_guestfs_sh"
external sh_lines : t -> string -> string array = "ocaml_guestfs_sh_lines"
+external glob_expand : t -> string -> string array = "ocaml_guestfs_glob_expand"
val sh_lines : t -> string -> string array
(** run a command via the shell returning lines *)
+val glob_expand : t -> string -> string array
+(** expand a wildcard path *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_glob_expand (value gv, value patternv)
+{
+ CAMLparam2 (gv, patternv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("glob_expand: used handle after closing it");
+
+ const char *pattern = String_val (patternv);
+ int i;
+ char **r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_glob_expand (g, pattern);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "glob_expand");
+
+ rv = caml_copy_string_array ((const char **) r);
+ for (i = 0; r[i] != NULL; ++i) free (r[i]);
+ free (r);
+ CAMLreturn (rv);
+}
+
}
free (lines);
+void
+glob_expand (g, pattern)
+ guestfs_h *g;
+ char *pattern;
+PREINIT:
+ char **paths;
+ int i, n;
+ PPCODE:
+ paths = guestfs_glob_expand (g, pattern);
+ if (paths == NULL)
+ croak ("glob_expand: %s", guestfs_last_error (g));
+ for (n = 0; paths[n] != NULL; ++n) /**/;
+ EXTEND (SP, n);
+ for (i = 0; i < n; ++i) {
+ PUSHs (sv_2mortal (newSVpv (paths[i], 0)));
+ free (paths[i]);
+ }
+ free (paths);
+
This returns the verbose messages flag.
+=item @paths = $h->glob_expand ($pattern);
+
+This command searches for all the pathnames matching
+C<pattern> according to the wildcard expansion rules
+used by the shell.
+
+If no paths match, then this returns an empty list
+(note: not an error).
+
+It is just a wrapper around the C L<glob(3)> function
+with flags C<GLOB_MARK|GLOB_BRACE>.
+See that manual page for more details.
+
=item $h->grub_install ($root, $device);
This command installs GRUB (the Grand Unified Bootloader) on
return py_r;
}
+static PyObject *
+py_guestfs_glob_expand (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ char **r;
+ const char *pattern;
+
+ if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_glob_expand",
+ &py_g, &pattern))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_glob_expand (g, pattern);
+ if (r == NULL) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ py_r = put_string_list (r);
+ free_strings (r);
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
{ (char *) "ntfs_3g_probe", py_guestfs_ntfs_3g_probe, METH_VARARGS, NULL },
{ (char *) "sh", py_guestfs_sh, METH_VARARGS, NULL },
{ (char *) "sh_lines", py_guestfs_sh_lines, METH_VARARGS, NULL },
+ { (char *) "glob_expand", py_guestfs_glob_expand, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.sh_lines (self._o, command)
+ def glob_expand (self, pattern):
+ u"""This command searches for all the pathnames matching
+ "pattern" according to the wildcard expansion rules used
+ by the shell.
+
+ If no paths match, then this returns an empty list
+ (note: not an error).
+
+ It is just a wrapper around the C glob(3) function with
+ flags "GLOB_MARK|GLOB_BRACE". See that manual page for
+ more details.
+
+ This function returns a list of strings.
+ """
+ return libguestfsmod.glob_expand (self._o, pattern)
+
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 ()
{
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);
}
return ctx.ret.lines.lines_val;
}
+struct glob_expand_ctx {
+ /* This flag is set by the callbacks, so we know we've done
+ * the callbacks as expected, and in the right sequence.
+ * 0 = not called, 1 = reply_cb called.
+ */
+ int cb_sequence;
+ struct guestfs_message_header hdr;
+ struct guestfs_message_error err;
+ struct guestfs_glob_expand_ret ret;
+};
+
+static void glob_expand_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct glob_expand_ctx *ctx = (struct glob_expand_ctx *) data;
+
+ /* This should definitely not happen. */
+ if (ctx->cb_sequence != 0) {
+ ctx->cb_sequence = 9999;
+ error (g, "%s: internal error: reply callback called twice", "guestfs_glob_expand");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_glob_expand");
+ return;
+ }
+ if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
+ if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
+ error (g, "%s: failed to parse reply error", "guestfs_glob_expand");
+ return;
+ }
+ goto done;
+ }
+ if (!xdr_guestfs_glob_expand_ret (xdr, &ctx->ret)) {
+ error (g, "%s: failed to parse reply", "guestfs_glob_expand");
+ return;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+char **guestfs_glob_expand (guestfs_h *g,
+ const char *pattern)
+{
+ struct guestfs_glob_expand_args args;
+ struct glob_expand_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_glob_expand") == -1) return NULL;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.pattern = (char *) pattern;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_GLOB_EXPAND,
+ (xdrproc_t) xdr_guestfs_glob_expand_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, glob_expand_reply_cb, &ctx);
+ (void) ml->main_loop_run (ml, g);
+ guestfs_set_reply_callback (g, NULL, NULL);
+ if (ctx.cb_sequence != 1) {
+ error (g, "%s reply failed, see earlier error messages", "guestfs_glob_expand");
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GLOB_EXPAND, serial) == -1) {
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ guestfs_end_busy (g);
+ /* caller will free this, but we need to add a NULL entry */
+ ctx.ret.paths.paths_val =
+ safe_realloc (g, ctx.ret.paths.paths_val,
+ sizeof (char *) * (ctx.ret.paths.paths_len + 1));
+ ctx.ret.paths.paths_val[ctx.ret.paths.paths_len] = NULL;
+ return ctx.ret.paths.paths_val;
+}
+
extern int guestfs_ntfs_3g_probe (guestfs_h *handle, int rw, const char *device);
extern char *guestfs_sh (guestfs_h *handle, const char *command);
extern char **guestfs_sh_lines (guestfs_h *handle, const char *command);
+extern char **guestfs_glob_expand (guestfs_h *handle, const char *pattern);
}
bool_t
+xdr_guestfs_glob_expand_args (XDR *xdrs, guestfs_glob_expand_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->pattern, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_glob_expand_ret (XDR *xdrs, guestfs_glob_expand_ret *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_array (xdrs, (char **)&objp->paths.paths_val, (u_int *) &objp->paths.paths_len, ~0,
+ sizeof (str), (xdrproc_t) xdr_str))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_sh_lines_ret guestfs_sh_lines_ret;
+struct guestfs_glob_expand_args {
+ char *pattern;
+};
+typedef struct guestfs_glob_expand_args guestfs_glob_expand_args;
+
+struct guestfs_glob_expand_ret {
+ struct {
+ u_int paths_len;
+ str *paths_val;
+ } paths;
+};
+typedef struct guestfs_glob_expand_ret guestfs_glob_expand_ret;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_NTFS_3G_PROBE = 110,
GUESTFS_PROC_SH = 111,
GUESTFS_PROC_SH_LINES = 112,
- GUESTFS_PROC_NR_PROCS = 112 + 1,
+ GUESTFS_PROC_GLOB_EXPAND = 113,
+ GUESTFS_PROC_NR_PROCS = 113 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_sh_ret (XDR *, guestfs_sh_ret*);
extern bool_t xdr_guestfs_sh_lines_args (XDR *, guestfs_sh_lines_args*);
extern bool_t xdr_guestfs_sh_lines_ret (XDR *, guestfs_sh_lines_ret*);
+extern bool_t xdr_guestfs_glob_expand_args (XDR *, guestfs_glob_expand_args*);
+extern bool_t xdr_guestfs_glob_expand_ret (XDR *, guestfs_glob_expand_ret*);
extern bool_t xdr_guestfs_procedure (XDR *, guestfs_procedure*);
extern bool_t xdr_guestfs_message_direction (XDR *, guestfs_message_direction*);
extern bool_t xdr_guestfs_message_status (XDR *, guestfs_message_status*);
extern bool_t xdr_guestfs_sh_ret ();
extern bool_t xdr_guestfs_sh_lines_args ();
extern bool_t xdr_guestfs_sh_lines_ret ();
+extern bool_t xdr_guestfs_glob_expand_args ();
+extern bool_t xdr_guestfs_glob_expand_ret ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
str lines<>;
};
+struct guestfs_glob_expand_args {
+ string pattern<>;
+};
+
+struct guestfs_glob_expand_ret {
+ str paths<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_NTFS_3G_PROBE = 110,
GUESTFS_PROC_SH = 111,
GUESTFS_PROC_SH_LINES = 112,
+ GUESTFS_PROC_GLOB_EXPAND = 113,
GUESTFS_PROC_NR_PROCS
};