summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/MAX_PROC_NR2
-rw-r--r--src/guestfs-actions.c89
-rw-r--r--src/guestfs-actions.h1
-rw-r--r--src/guestfs_protocol.c12
-rw-r--r--src/guestfs_protocol.h11
-rw-r--r--src/guestfs_protocol.x6
6 files changed, 119 insertions, 2 deletions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index a949a93d..b0d73241 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-128
+129
diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c
index 93fdee6a..94a08629 100644
--- a/src/guestfs-actions.c
+++ b/src/guestfs-actions.c
@@ -11746,3 +11746,92 @@ char **guestfs_initrd_list (guestfs_h *g,
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;
+}
+
diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h
index 43570bbe..c0002662 100644
--- a/src/guestfs-actions.h
+++ b/src/guestfs-actions.h
@@ -199,3 +199,4 @@ extern char *guestfs_df (guestfs_h *handle);
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);
diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c
index 6f135dbe..9b12986c 100644
--- a/src/guestfs_protocol.c
+++ b/src/guestfs_protocol.c
@@ -2192,6 +2192,18 @@ xdr_guestfs_initrd_list_ret (XDR *xdrs, guestfs_initrd_list_ret *objp)
}
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;
diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h
index b850f9f8..d127b884 100644
--- a/src/guestfs_protocol.h
+++ b/src/guestfs_protocol.h
@@ -1124,6 +1124,12 @@ struct guestfs_initrd_list_ret {
};
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,
@@ -1253,7 +1259,8 @@ enum guestfs_procedure {
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
@@ -1485,6 +1492,7 @@ extern bool_t xdr_guestfs_du_args (XDR *, guestfs_du_args*);
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*);
@@ -1675,6 +1683,7 @@ extern bool_t xdr_guestfs_du_args ();
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 ();
diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x
index 42040ac4..fdc67c15 100644
--- a/src/guestfs_protocol.x
+++ b/src/guestfs_protocol.x
@@ -858,6 +858,11 @@ struct guestfs_initrd_list_ret {
str filenames<>;
};
+struct guestfs_mount_loop_args {
+ string file<>;
+ string mountpoint<>;
+};
+
enum guestfs_procedure {
GUESTFS_PROC_MOUNT = 1,
GUESTFS_PROC_SYNC = 2,
@@ -987,6 +992,7 @@ enum guestfs_procedure {
GUESTFS_PROC_DF_H = 126,
GUESTFS_PROC_DU = 127,
GUESTFS_PROC_INITRD_LIST = 128,
+ GUESTFS_PROC_MOUNT_LOOP = 129,
GUESTFS_PROC_NR_PROCS
};