extern int do_vg_activate (int activate, char * const* const volgroups);
extern int do_lvresize (const char *device, int mbytes);
extern int do_resize2fs (const char *device);
+extern char **do_find (const char *directory);
xdr_free ((xdrproc_t) xdr_guestfs_resize2fs_args, (char *) &args);
}
+static void find_stub (XDR *xdr_in)
+{
+ char **r;
+ struct guestfs_find_args args;
+ const char *directory;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_find_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "find");
+ return;
+ }
+ directory = args.directory;
+
+ r = do_find (directory);
+ if (r == NULL)
+ /* do_find has already called reply_with_error */
+ goto done;
+
+ struct guestfs_find_ret ret;
+ ret.names.names_len = count_strings (r);
+ ret.names.names_val = r;
+ reply ((xdrproc_t) &xdr_guestfs_find_ret, (char *) &ret);
+ free_strings (r);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_find_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_RESIZE2FS:
resize2fs_stub (xdr_in);
break;
+ case GUESTFS_PROC_FIND:
+ find_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d", proc_nr);
}
printf ("%-20s %s\n", "equal", "test if two files have equal contents");
printf ("%-20s %s\n", "exists", "test if file or directory exists");
printf ("%-20s %s\n", "file", "determine file type");
+ printf ("%-20s %s\n", "find", "find all files and directories");
printf ("%-20s %s\n", "fsck", "run the filesystem checker");
printf ("%-20s %s\n", "get-append", "get the additional kernel options");
printf ("%-20s %s\n", "get-autosync", "get autosync mode");
if (strcasecmp (cmd, "resize2fs") == 0)
pod2text ("resize2fs - resize an ext2/ext3 filesystem", " resize2fs <device>\n\nThis resizes an ext2 or ext3 filesystem to match the size of\nthe underlying device.");
else
+ if (strcasecmp (cmd, "find") == 0)
+ pod2text ("find - find all files and directories", " find <directory>\n\nThis command lists out all files and directories, recursively,\nstarting at C<directory>. It is essentially equivalent to\nrunning the shell command C<find directory -print> but some\npost-processing happens on the output, described below.\n\nThis returns a list of strings I<without any prefix>. Thus\nif the directory structure was:\n\n /tmp/a\n /tmp/b\n /tmp/c/d\n\nthen the returned list from C<find> C</tmp> would be\n4 elements:\n\n a\n b\n c\n c/d\n\nIf C<directory> is not a directory, then this command returns\nan error.\n\nThe returned list is sorted.");
+ else
display_builtin_command (cmd);
}
return r;
}
+static int run_find (const char *cmd, int argc, char *argv[])
+{
+ char **r;
+ const char *directory;
+ 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;
+ }
+ directory = argv[0];
+ r = guestfs_find (g, directory);
+ 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, "resize2fs") == 0)
return run_resize2fs (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "find") == 0)
+ return run_find (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"equal",
"exists",
"file",
+ "find",
"fsck",
"get-append",
"get-autosync",
particular that the filename is not prepended to the output
(the C<-b> option).
+=head2 find
+
+ find directory
+
+This command lists out all files and directories, recursively,
+starting at C<directory>. It is essentially equivalent to
+running the shell command C<find directory -print> but some
+post-processing happens on the output, described below.
+
+This returns a list of strings I<without any prefix>. Thus
+if the directory structure was:
+
+ /tmp/a
+ /tmp/b
+ /tmp/c/d
+
+then the returned list from C<find> C</tmp> would be
+4 elements:
+
+ a
+ b
+ c
+ c/d
+
+If C<directory> is not a directory, then this command returns
+an error.
+
+The returned list is sorted.
+
=head2 fsck
fsck fstype device
This function returns a string, or NULL on error.
I<The caller must free the returned string after use>.
+=head2 guestfs_find
+
+ char **guestfs_find (guestfs_h *handle,
+ const char *directory);
+
+This command lists out all files and directories, recursively,
+starting at C<directory>. It is essentially equivalent to
+running the shell command C<find directory -print> but some
+post-processing happens on the output, described below.
+
+This returns a list of strings I<without any prefix>. Thus
+if the directory structure was:
+
+ /tmp/a
+ /tmp/b
+ /tmp/c/d
+
+then the returned list from C<guestfs_find> C</tmp> would be
+4 elements:
+
+ a
+ b
+ c
+ c/d
+
+If C<directory> is not a directory, then this command returns
+an error.
+
+The returned list is sorted.
+
+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_fsck
int guestfs_fsck (guestfs_h *handle,
private native void _resize2fs (long g, String device)
throws LibGuestFSException;
+ /**
+ * find all files and directories
+ *
+ * This command lists out all files and directories,
+ * recursively, starting at "directory". It is essentially
+ * equivalent to running the shell command "find directory
+ * -print" but some post-processing happens on the output,
+ * described below.
+ *
+ * This returns a list of strings *without any prefix*.
+ * Thus if the directory structure was:
+ *
+ * /tmp/a
+ * /tmp/b
+ * /tmp/c/d
+ *
+ * then the returned list from "g.find" "/tmp" would be 4
+ * elements:
+ *
+ * a
+ * b
+ * c
+ * c/d
+ *
+ * If "directory" is not a directory, then this command
+ * returns an error.
+ *
+ * The returned list is sorted.
+ *
+ * @throws LibGuestFSException
+ */
+ public String[] find (String directory)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("find: handle is closed");
+ return _find (g, directory);
+ }
+ private native String[] _find (long g, String directory)
+ throws LibGuestFSException;
+
}
}
}
+JNIEXPORT jobjectArray JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1find
+ (JNIEnv *env, jobject obj, jlong jg, jstring jdirectory)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ jobjectArray jr;
+ int r_len;
+ jclass cl;
+ jstring jstr;
+ char **r;
+ const char *directory;
+ int i;
+
+ directory = (*env)->GetStringUTFChars (env, jdirectory, NULL);
+ r = guestfs_find (g, directory);
+ (*env)->ReleaseStringUTFChars (env, jdirectory, directory);
+ 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 vg_activate : t -> bool -> string array -> unit = "ocaml_guestfs_vg_activate"
external lvresize : t -> string -> int -> unit = "ocaml_guestfs_lvresize"
external resize2fs : t -> string -> unit = "ocaml_guestfs_resize2fs"
+external find : t -> string -> string array = "ocaml_guestfs_find"
val resize2fs : t -> string -> unit
(** resize an ext2/ext3 filesystem *)
+val find : t -> string -> string array
+(** find all files and directories *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_find (value gv, value directoryv)
+{
+ CAMLparam2 (gv, directoryv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("find: used handle after closing it");
+
+ const char *directory = String_val (directoryv);
+ int i;
+ char **r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_find (g, directory);
+ caml_leave_blocking_section ();
+ if (r == NULL)
+ ocaml_guestfs_raise_error (g, "find");
+
+ rv = caml_copy_string_array ((const char **) r);
+ for (i = 0; r[i] != NULL; ++i) free (r[i]);
+ free (r);
+ CAMLreturn (rv);
+}
+
if (r == -1)
croak ("resize2fs: %s", guestfs_last_error (g));
+void
+find (g, directory)
+ guestfs_h *g;
+ char *directory;
+PREINIT:
+ char **names;
+ int i, n;
+ PPCODE:
+ names = guestfs_find (g, directory);
+ if (names == NULL)
+ croak ("find: %s", guestfs_last_error (g));
+ for (n = 0; names[n] != NULL; ++n) /**/;
+ EXTEND (SP, n);
+ for (i = 0; i < n; ++i) {
+ PUSHs (sv_2mortal (newSVpv (names[i], 0)));
+ free (names[i]);
+ }
+ free (names);
+
particular that the filename is not prepended to the output
(the C<-b> option).
+=item @names = $h->find ($directory);
+
+This command lists out all files and directories, recursively,
+starting at C<directory>. It is essentially equivalent to
+running the shell command C<find directory -print> but some
+post-processing happens on the output, described below.
+
+This returns a list of strings I<without any prefix>. Thus
+if the directory structure was:
+
+ /tmp/a
+ /tmp/b
+ /tmp/c/d
+
+then the returned list from C<$h-E<gt>find> C</tmp> would be
+4 elements:
+
+ a
+ b
+ c
+ c/d
+
+If C<directory> is not a directory, then this command returns
+an error.
+
+The returned list is sorted.
+
=item $status = $h->fsck ($fstype, $device);
This runs the filesystem checker (fsck) on C<device> which
return py_r;
}
+static PyObject *
+py_guestfs_find (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ char **r;
+ const char *directory;
+
+ if (!PyArg_ParseTuple (args, (char *) "Os:guestfs_find",
+ &py_g, &directory))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_find (g, directory);
+ 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 *) "vg_activate", py_guestfs_vg_activate, METH_VARARGS, NULL },
{ (char *) "lvresize", py_guestfs_lvresize, METH_VARARGS, NULL },
{ (char *) "resize2fs", py_guestfs_resize2fs, METH_VARARGS, NULL },
+ { (char *) "find", py_guestfs_find, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.resize2fs (self._o, device)
+ def find (self, directory):
+ u"""This command lists out all files and directories,
+ recursively, starting at "directory". It is essentially
+ equivalent to running the shell command "find directory
+ -print" but some post-processing happens on the output,
+ described below.
+
+ This returns a list of strings *without any prefix*.
+ Thus if the directory structure was:
+
+ /tmp/a
+ /tmp/b
+ /tmp/c/d
+
+ then the returned list from "g.find" "/tmp" would be 4
+ elements:
+
+ a
+ b
+ c
+ c/d
+
+ If "directory" is not a directory, then this command
+ returns an error.
+
+ The returned list is sorted.
+
+ This function returns a list of strings.
+ """
+ return libguestfsmod.find (self._o, directory)
+
return Qnil;
}
+static VALUE ruby_guestfs_find (VALUE gv, VALUE directoryv)
+{
+ guestfs_h *g;
+ Data_Get_Struct (gv, guestfs_h, g);
+ if (!g)
+ rb_raise (rb_eArgError, "%s: used handle after closing it", "find");
+
+ const char *directory = StringValueCStr (directoryv);
+ if (!directory)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "directory", "find");
+
+ char **r;
+
+ r = guestfs_find (g, directory);
+ 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_lvresize, 2);
rb_define_method (c_guestfs, "resize2fs",
ruby_guestfs_resize2fs, 1);
+ rb_define_method (c_guestfs, "find",
+ ruby_guestfs_find, 1);
}
return 0;
}
+struct find_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_find_ret ret;
+};
+
+static void find_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct find_ctx *ctx = (struct find_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_find");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_find");
+ 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_find");
+ return;
+ }
+ goto done;
+ }
+ if (!xdr_guestfs_find_ret (xdr, &ctx->ret)) {
+ error (g, "%s: failed to parse reply", "guestfs_find");
+ return;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+char **guestfs_find (guestfs_h *g,
+ const char *directory)
+{
+ struct guestfs_find_args args;
+ struct find_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_find") == -1) return NULL;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.directory = (char *) directory;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_FIND,
+ (xdrproc_t) xdr_guestfs_find_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, find_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_find");
+ guestfs_end_busy (g);
+ return NULL;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FIND, 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.names.names_val =
+ safe_realloc (g, ctx.ret.names.names_val,
+ sizeof (char *) * (ctx.ret.names.names_len + 1));
+ ctx.ret.names.names_val[ctx.ret.names.names_len] = NULL;
+ return ctx.ret.names.names_val;
+}
+
extern int guestfs_vg_activate (guestfs_h *handle, int activate, char * const* const volgroups);
extern int guestfs_lvresize (guestfs_h *handle, const char *device, int mbytes);
extern int guestfs_resize2fs (guestfs_h *handle, const char *device);
+extern char **guestfs_find (guestfs_h *handle, const char *directory);
}
bool_t
+xdr_guestfs_find_args (XDR *xdrs, guestfs_find_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->directory, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_guestfs_find_ret (XDR *xdrs, guestfs_find_ret *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_array (xdrs, (char **)&objp->names.names_val, (u_int *) &objp->names.names_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_resize2fs_args guestfs_resize2fs_args;
+struct guestfs_find_args {
+ char *directory;
+};
+typedef struct guestfs_find_args guestfs_find_args;
+
+struct guestfs_find_ret {
+ struct {
+ u_int names_len;
+ str *names_val;
+ } names;
+};
+typedef struct guestfs_find_ret guestfs_find_ret;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_VG_ACTIVATE = 104,
GUESTFS_PROC_LVRESIZE = 105,
GUESTFS_PROC_RESIZE2FS = 106,
- GUESTFS_PROC_NR_PROCS = 106 + 1,
+ GUESTFS_PROC_FIND = 107,
+ GUESTFS_PROC_NR_PROCS = 107 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_vg_activate_args (XDR *, guestfs_vg_activate_args*);
extern bool_t xdr_guestfs_lvresize_args (XDR *, guestfs_lvresize_args*);
extern bool_t xdr_guestfs_resize2fs_args (XDR *, guestfs_resize2fs_args*);
+extern bool_t xdr_guestfs_find_args (XDR *, guestfs_find_args*);
+extern bool_t xdr_guestfs_find_ret (XDR *, guestfs_find_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_vg_activate_args ();
extern bool_t xdr_guestfs_lvresize_args ();
extern bool_t xdr_guestfs_resize2fs_args ();
+extern bool_t xdr_guestfs_find_args ();
+extern bool_t xdr_guestfs_find_ret ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
string device<>;
};
+struct guestfs_find_args {
+ string directory<>;
+};
+
+struct guestfs_find_ret {
+ str names<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_VG_ACTIVATE = 104,
GUESTFS_PROC_LVRESIZE = 105,
GUESTFS_PROC_RESIZE2FS = 106,
+ GUESTFS_PROC_FIND = 107,
GUESTFS_PROC_NR_PROCS
};
fprintf (stderr, "warning: \"guestfs_resize2fs\" has no tests\n");
}
+static int test_find_0 (void)
+{
+ /* InitBasicFS for test_find_0: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for find (0) */
+ {
+ char directory[] = "/";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_find (g, directory);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_find_0: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "lost+found";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_find_0: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (r[1] != NULL) {
+ fprintf (stderr, "test_find_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_find_1 (void)
+{
+ /* InitBasicFS for test_find_1: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for find (1) */
+ {
+ char path[] = "/a";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/b";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkdir (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char path[] = "/b/c";
+ int r;
+ suppress_error = 0;
+ r = guestfs_touch (g, path);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char directory[] = "/";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_find (g, directory);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_find_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "a";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_find_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "b";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (!r[2]) {
+ fprintf (stderr, "test_find_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "b/c";
+ if (strcmp (r[2], expected) != 0) {
+ fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[2]);
+ return -1;
+ }
+ }
+ if (!r[3]) {
+ fprintf (stderr, "test_find_1: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "lost+found";
+ if (strcmp (r[3], expected) != 0) {
+ fprintf (stderr, "test_find_1: expected \"%s\" but got \"%s\"\n", expected, r[3]);
+ return -1;
+ }
+ }
+ if (r[4] != NULL) {
+ fprintf (stderr, "test_find_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_find_2 (void)
+{
+ /* InitBasicFS for test_find_2: create ext2 on /dev/sda1 */
+ {
+ char device[] = "/dev/sda";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ 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";
+ device[5] = devchar;
+ int r;
+ suppress_error = 0;
+ r = guestfs_mkfs (g, fstype, device);
+ if (r == -1)
+ return -1;
+ }
+ {
+ char device[] = "/dev/sda1";
+ device[5] = devchar;
+ char mountpoint[] = "/";
+ int r;
+ suppress_error = 0;
+ r = guestfs_mount (g, device, mountpoint);
+ if (r == -1)
+ return -1;
+ }
+ /* TestOutputList for find (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 directory[] = "/a/b/";
+ char **r;
+ int i;
+ suppress_error = 0;
+ r = guestfs_find (g, directory);
+ if (r == NULL)
+ return -1;
+ if (!r[0]) {
+ fprintf (stderr, "test_find_2: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "c";
+ if (strcmp (r[0], expected) != 0) {
+ fprintf (stderr, "test_find_2: expected \"%s\" but got \"%s\"\n", expected, r[0]);
+ return -1;
+ }
+ }
+ if (!r[1]) {
+ fprintf (stderr, "test_find_2: short list returned from command\n");
+ print_strings (r);
+ return -1;
+ }
+ {
+ char expected[] = "c/d";
+ if (strcmp (r[1], expected) != 0) {
+ fprintf (stderr, "test_find_2: expected \"%s\" but got \"%s\"\n", expected, r[1]);
+ return -1;
+ }
+ }
+ if (r[2] != NULL) {
+ fprintf (stderr, "test_find_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_lvresize_0 (void)
{
/* InitNone|InitEmpty for test_lvresize_0 */
free (devs[i]);
free (devs);
- nr_tests = 137;
+ nr_tests = 140;
test_num++;
+ printf ("%3d/%3d test_find_0\n", test_num, nr_tests);
+ if (test_find_0 () == -1) {
+ printf ("test_find_0 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_find_1\n", test_num, nr_tests);
+ if (test_find_1 () == -1) {
+ printf ("test_find_1 FAILED\n");
+ failed++;
+ }
+ test_num++;
+ printf ("%3d/%3d test_find_2\n", test_num, nr_tests);
+ if (test_find_2 () == -1) {
+ printf ("test_find_2 FAILED\n");
+ failed++;
+ }
+ test_num++;
printf ("%3d/%3d test_lvresize_0\n", test_num, nr_tests);
if (test_lvresize_0 () == -1) {
printf ("test_lvresize_0 FAILED\n");