fprintf (stderr, "warning: \"guestfs_scrub_freespace\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_df\" has no tests\n");
fprintf (stderr, "warning: \"guestfs_df_h\" has no tests\n");
+ fprintf (stderr, "warning: \"guestfs_mount_loop\" has no tests\n");
}
static int test_initrd_list_0_skip (void)
extern char *do_df_h (void);
extern int64_t do_du (char *path);
extern char **do_initrd_list (char *path);
+extern int do_mount_loop (char *file, char *mountpoint);
xdr_free ((xdrproc_t) xdr_guestfs_initrd_list_args, (char *) &args);
}
+static void mount_loop_stub (XDR *xdr_in)
+{
+ int r;
+ struct guestfs_mount_loop_args args;
+ char *file;
+ char *mountpoint;
+
+ memset (&args, 0, sizeof args);
+
+ if (!xdr_guestfs_mount_loop_args (xdr_in, &args)) {
+ reply_with_error ("%s: daemon failed to decode procedure arguments", "mount_loop");
+ return;
+ }
+ file = args.file;
+ mountpoint = args.mountpoint;
+
+ r = do_mount_loop (file, mountpoint);
+ if (r == -1)
+ /* do_mount_loop has already called reply_with_error */
+ goto done;
+
+ reply (NULL, NULL);
+done:
+ xdr_free ((xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
+}
+
void dispatch_incoming_message (XDR *xdr_in)
{
switch (proc_nr) {
case GUESTFS_PROC_INITRD_LIST:
initrd_list_stub (xdr_in);
break;
+ case GUESTFS_PROC_MOUNT_LOOP:
+ mount_loop_stub (xdr_in);
+ break;
default:
reply_with_error ("dispatch_incoming_message: unknown procedure number %d, set LIBGUESTFS_PATH to point to the matching libguestfs appliance directory", proc_nr);
}
printf ("%-20s %s\n", "mkdtemp", "create a temporary directory");
printf ("%-20s %s\n", "mkfs", "make a filesystem");
printf ("%-20s %s\n", "mount", "mount a guest disk at a position in the filesystem");
+ printf ("%-20s %s\n", "mount-loop", "mount a file using the loop device");
printf ("%-20s %s\n", "mount-options", "mount a guest disk with mount options");
printf ("%-20s %s\n", "mount-ro", "mount a guest disk, read-only");
printf ("%-20s %s\n", "mount-vfs", "mount a guest disk with mount options and vfstype");
if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
pod2text ("initrd-list - list files in an initrd", " initrd-list <path>\n\nThis command lists out files contained in an initrd.\n\nThe files are listed without any initial C</> character. The\nfiles are listed in the order they appear (not necessarily\nalphabetical). Directory names are listed as separate items.\n\nOld Linux kernels (2.4 and earlier) used a compressed ext2\nfilesystem as initrd. We I<only> support the newer initramfs\nformat (compressed cpio files).");
else
+ if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+ pod2text ("mount-loop - mount a file using the loop device", " mount-loop <file> <mountpoint>\n\nThis command lets you mount C<file> (a filesystem image\nin a file) on a mount point. It is entirely equivalent to\nthe command C<mount -o loop file mountpoint>.");
+ else
display_builtin_command (cmd);
}
return 0;
}
+static int run_mount_loop (const char *cmd, int argc, char *argv[])
+{
+ int r;
+ const char *file;
+ const char *mountpoint;
+ if (argc != 2) {
+ fprintf (stderr, "%s should have 2 parameter(s)\n", cmd);
+ fprintf (stderr, "type 'help %s' for help on %s\n", cmd, cmd);
+ return -1;
+ }
+ file = argv[0];
+ mountpoint = argv[1];
+ r = guestfs_mount_loop (g, file, mountpoint);
+ return r;
+}
+
int run_action (const char *cmd, int argc, char *argv[])
{
if (strcasecmp (cmd, "launch") == 0 || strcasecmp (cmd, "run") == 0)
if (strcasecmp (cmd, "initrd_list") == 0 || strcasecmp (cmd, "initrd-list") == 0)
return run_initrd_list (cmd, argc, argv);
else
+ if (strcasecmp (cmd, "mount_loop") == 0 || strcasecmp (cmd, "mount-loop") == 0)
+ return run_mount_loop (cmd, argc, argv);
+ else
{
fprintf (stderr, "%s: unknown command\n", cmd);
return -1;
"df-h",
"du",
"initrd-list",
+ "mount-loop",
NULL
};
The filesystem options C<sync> and C<noatime> are set with this
call, in order to improve reliability.
+=head2 mount-loop
+
+ mount-loop file mountpoint
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
=head2 mount-options
mount-options options device mountpoint
This function returns 0 on success or -1 on error.
+=head2 guestfs_mount_loop
+
+ int guestfs_mount_loop (guestfs_h *handle,
+ const char *file,
+ const char *mountpoint);
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
+This function returns 0 on success or -1 on error.
+
=head2 guestfs_mount_options
int guestfs_mount_options (guestfs_h *handle,
wc_l,
wc_w,
wc_c,
- du
+ du,
+ mount_loop
) where
import Foreign
import Foreign.C
fail err
else return (fromIntegral r)
+foreign import ccall unsafe "guestfs_mount_loop" c_mount_loop
+ :: GuestfsP -> CString -> CString -> IO (CInt)
+
+mount_loop :: GuestfsH -> String -> String -> IO ()
+mount_loop h file mountpoint = do
+ r <- withCString file $ \file -> withCString mountpoint $ \mountpoint -> withForeignPtr h (\p -> c_mount_loop p file mountpoint)
+ if (r == -1)
+ then do
+ err <- last_error h
+ fail err
+ else return ()
+
private native String[] _initrd_list (long g, String path)
throws LibGuestFSException;
+ /**
+ * mount a file using the loop device
+ * <p>
+ * This command lets you mount "file" (a filesystem image
+ * in a file) on a mount point. It is entirely equivalent
+ * to the command "mount -o loop file mountpoint".
+ * <p>
+ * @throws LibGuestFSException
+ */
+ public void mount_loop (String file, String mountpoint)
+ throws LibGuestFSException
+ {
+ if (g == 0)
+ throw new LibGuestFSException ("mount_loop: handle is closed");
+ _mount_loop (g, file, mountpoint);
+ }
+ private native void _mount_loop (long g, String file, String mountpoint)
+ throws LibGuestFSException;
+
}
return jr;
}
+JNIEXPORT void JNICALL
+Java_com_redhat_et_libguestfs_GuestFS__1mount_1loop
+ (JNIEnv *env, jobject obj, jlong jg, jstring jfile, jstring jmountpoint)
+{
+ guestfs_h *g = (guestfs_h *) (long) jg;
+ int r;
+ const char *file;
+ const char *mountpoint;
+
+ file = (*env)->GetStringUTFChars (env, jfile, NULL);
+ mountpoint = (*env)->GetStringUTFChars (env, jmountpoint, NULL);
+ r = guestfs_mount_loop (g, file, mountpoint);
+ (*env)->ReleaseStringUTFChars (env, jfile, file);
+ (*env)->ReleaseStringUTFChars (env, jmountpoint, mountpoint);
+ if (r == -1) {
+ throw_exception (env, guestfs_last_error (g));
+ return ;
+ }
+}
+
external df_h : t -> string = "ocaml_guestfs_df_h"
external du : t -> string -> int64 = "ocaml_guestfs_du"
external initrd_list : t -> string -> string array = "ocaml_guestfs_initrd_list"
+external mount_loop : t -> string -> string -> unit = "ocaml_guestfs_mount_loop"
val initrd_list : t -> string -> string array
(** list files in an initrd *)
+val mount_loop : t -> string -> string -> unit
+(** mount a file using the loop device *)
+
CAMLreturn (rv);
}
+CAMLprim value
+ocaml_guestfs_mount_loop (value gv, value filev, value mountpointv)
+{
+ CAMLparam3 (gv, filev, mountpointv);
+ CAMLlocal1 (rv);
+
+ guestfs_h *g = Guestfs_val (gv);
+ if (g == NULL)
+ caml_failwith ("mount_loop: used handle after closing it");
+
+ const char *file = String_val (filev);
+ const char *mountpoint = String_val (mountpointv);
+ int r;
+
+ caml_enter_blocking_section ();
+ r = guestfs_mount_loop (g, file, mountpoint);
+ caml_leave_blocking_section ();
+ if (r == -1)
+ ocaml_guestfs_raise_error (g, "mount_loop");
+
+ rv = Val_unit;
+ CAMLreturn (rv);
+}
+
}
free (filenames);
+void
+mount_loop (g, file, mountpoint)
+ guestfs_h *g;
+ char *file;
+ char *mountpoint;
+PREINIT:
+ int r;
+ PPCODE:
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1)
+ croak ("mount_loop: %s", guestfs_last_error (g));
+
The filesystem options C<sync> and C<noatime> are set with this
call, in order to improve reliability.
+=item $h->mount_loop ($file, $mountpoint);
+
+This command lets you mount C<file> (a filesystem image
+in a file) on a mount point. It is entirely equivalent to
+the command C<mount -o loop file mountpoint>.
+
=item $h->mount_options ($options, $device, $mountpoint);
This is the same as the C<$h-E<gt>mount> command, but it
return py_r;
}
+static PyObject *
+py_guestfs_mount_loop (PyObject *self, PyObject *args)
+{
+ PyObject *py_g;
+ guestfs_h *g;
+ PyObject *py_r;
+ int r;
+ const char *file;
+ const char *mountpoint;
+
+ if (!PyArg_ParseTuple (args, (char *) "Oss:guestfs_mount_loop",
+ &py_g, &file, &mountpoint))
+ return NULL;
+ g = get_handle (py_g);
+
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1) {
+ PyErr_SetString (PyExc_RuntimeError, guestfs_last_error (g));
+ return NULL;
+ }
+
+ Py_INCREF (Py_None);
+ py_r = Py_None;
+ return py_r;
+}
+
static PyMethodDef methods[] = {
{ (char *) "create", py_guestfs_create, METH_VARARGS, NULL },
{ (char *) "close", py_guestfs_close, METH_VARARGS, NULL },
{ (char *) "df_h", py_guestfs_df_h, METH_VARARGS, NULL },
{ (char *) "du", py_guestfs_du, METH_VARARGS, NULL },
{ (char *) "initrd_list", py_guestfs_initrd_list, METH_VARARGS, NULL },
+ { (char *) "mount_loop", py_guestfs_mount_loop, METH_VARARGS, NULL },
{ NULL, NULL, 0, NULL }
};
"""
return libguestfsmod.initrd_list (self._o, path)
+ def mount_loop (self, file, mountpoint):
+ u"""This command lets you mount "file" (a filesystem image
+ in a file) on a mount point. It is entirely equivalent
+ to the command "mount -o loop file mountpoint".
+ """
+ return libguestfsmod.mount_loop (self._o, file, mountpoint)
+
return rv;
}
+static VALUE ruby_guestfs_mount_loop (VALUE gv, VALUE filev, 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_loop");
+
+ Check_Type (filev, T_STRING);
+ const char *file = StringValueCStr (filev);
+ if (!file)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "file", "mount_loop");
+ Check_Type (mountpointv, T_STRING);
+ const char *mountpoint = StringValueCStr (mountpointv);
+ if (!mountpoint)
+ rb_raise (rb_eTypeError, "expected string for parameter %s of %s",
+ "mountpoint", "mount_loop");
+
+ int r;
+
+ r = guestfs_mount_loop (g, file, mountpoint);
+ if (r == -1)
+ rb_raise (e_Error, "%s", guestfs_last_error (g));
+
+ return Qnil;
+}
+
/* Initialize the module. */
void Init__guestfs ()
{
ruby_guestfs_du, 1);
rb_define_method (c_guestfs, "initrd_list",
ruby_guestfs_initrd_list, 1);
+ rb_define_method (c_guestfs, "mount_loop",
+ ruby_guestfs_mount_loop, 2);
}
return ctx.ret.filenames.filenames_val;
}
+struct mount_loop_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;
+};
+
+static void mount_loop_reply_cb (guestfs_h *g, void *data, XDR *xdr)
+{
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ struct mount_loop_ctx *ctx = (struct mount_loop_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_mount_loop");
+ return;
+ }
+
+ ml->main_loop_quit (ml, g);
+
+ if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
+ error (g, "%s: failed to parse reply header", "guestfs_mount_loop");
+ 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_mount_loop");
+ return;
+ }
+ goto done;
+ }
+ done:
+ ctx->cb_sequence = 1;
+}
+
+int guestfs_mount_loop (guestfs_h *g,
+ const char *file,
+ const char *mountpoint)
+{
+ struct guestfs_mount_loop_args args;
+ struct mount_loop_ctx ctx;
+ guestfs_main_loop *ml = guestfs_get_main_loop (g);
+ int serial;
+
+ if (check_state (g, "guestfs_mount_loop") == -1) return -1;
+ guestfs_set_busy (g);
+
+ memset (&ctx, 0, sizeof ctx);
+
+ args.file = (char *) file;
+ args.mountpoint = (char *) mountpoint;
+ serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_LOOP,
+ (xdrproc_t) xdr_guestfs_mount_loop_args, (char *) &args);
+ if (serial == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs__switch_to_receiving (g);
+ ctx.cb_sequence = 0;
+ guestfs_set_reply_callback (g, mount_loop_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_mount_loop");
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_LOOP, serial) == -1) {
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
+ error (g, "%s", ctx.err.error_message);
+ free (ctx.err.error_message);
+ guestfs_end_busy (g);
+ return -1;
+ }
+
+ guestfs_end_busy (g);
+ return 0;
+}
+
extern char *guestfs_df_h (guestfs_h *handle);
extern int64_t guestfs_du (guestfs_h *handle, const char *path);
extern char **guestfs_initrd_list (guestfs_h *handle, const char *path);
+extern int guestfs_mount_loop (guestfs_h *handle, const char *file, const char *mountpoint);
}
bool_t
+xdr_guestfs_mount_loop_args (XDR *xdrs, guestfs_mount_loop_args *objp)
+{
+ register int32_t *buf;
+
+ if (!xdr_string (xdrs, &objp->file, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->mountpoint, ~0))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_guestfs_procedure (XDR *xdrs, guestfs_procedure *objp)
{
register int32_t *buf;
};
typedef struct guestfs_initrd_list_ret guestfs_initrd_list_ret;
+struct guestfs_mount_loop_args {
+ char *file;
+ char *mountpoint;
+};
+typedef struct guestfs_mount_loop_args guestfs_mount_loop_args;
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_DF_H = 126,
GUESTFS_PROC_DU = 127,
GUESTFS_PROC_INITRD_LIST = 128,
- GUESTFS_PROC_NR_PROCS = 128 + 1,
+ GUESTFS_PROC_MOUNT_LOOP = 129,
+ GUESTFS_PROC_NR_PROCS = 129 + 1,
};
typedef enum guestfs_procedure guestfs_procedure;
#define GUESTFS_MESSAGE_MAX 4194304
extern bool_t xdr_guestfs_du_ret (XDR *, guestfs_du_ret*);
extern bool_t xdr_guestfs_initrd_list_args (XDR *, guestfs_initrd_list_args*);
extern bool_t xdr_guestfs_initrd_list_ret (XDR *, guestfs_initrd_list_ret*);
+extern bool_t xdr_guestfs_mount_loop_args (XDR *, guestfs_mount_loop_args*);
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_du_ret ();
extern bool_t xdr_guestfs_initrd_list_args ();
extern bool_t xdr_guestfs_initrd_list_ret ();
+extern bool_t xdr_guestfs_mount_loop_args ();
extern bool_t xdr_guestfs_procedure ();
extern bool_t xdr_guestfs_message_direction ();
extern bool_t xdr_guestfs_message_status ();
str filenames<>;
};
+struct guestfs_mount_loop_args {
+ string file<>;
+ string mountpoint<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
GUESTFS_PROC_DF_H = 126,
GUESTFS_PROC_DU = 127,
GUESTFS_PROC_INITRD_LIST = 128,
+ GUESTFS_PROC_MOUNT_LOOP = 129,
GUESTFS_PROC_NR_PROCS
};