diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/MAX_PROC_NR | 2 | ||||
-rw-r--r-- | src/guestfs-actions.c | 97 | ||||
-rw-r--r-- | src/guestfs-actions.h | 1 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 21 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 20 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 9 |
6 files changed, 148 insertions, 2 deletions
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index c75acbe2..a949a93d 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -127 +128 diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index b34c8017..93fdee6a 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -11649,3 +11649,100 @@ int64_t guestfs_du (guestfs_h *g, return ctx.ret.sizekb; } +struct initrd_list_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_initrd_list_ret ret; +}; + +static void initrd_list_reply_cb (guestfs_h *g, void *data, XDR *xdr) +{ + guestfs_main_loop *ml = guestfs_get_main_loop (g); + struct initrd_list_ctx *ctx = (struct initrd_list_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_initrd_list"); + return; + } + + ml->main_loop_quit (ml, g); + + if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) { + error (g, "%s: failed to parse reply header", "guestfs_initrd_list"); + 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_initrd_list"); + return; + } + goto done; + } + if (!xdr_guestfs_initrd_list_ret (xdr, &ctx->ret)) { + error (g, "%s: failed to parse reply", "guestfs_initrd_list"); + return; + } + done: + ctx->cb_sequence = 1; +} + +char **guestfs_initrd_list (guestfs_h *g, + const char *path) +{ + struct guestfs_initrd_list_args args; + struct initrd_list_ctx ctx; + guestfs_main_loop *ml = guestfs_get_main_loop (g); + int serial; + + if (check_state (g, "guestfs_initrd_list") == -1) return NULL; + guestfs_set_busy (g); + + memset (&ctx, 0, sizeof ctx); + + args.path = (char *) path; + serial = guestfs__send_sync (g, GUESTFS_PROC_INITRD_LIST, + (xdrproc_t) xdr_guestfs_initrd_list_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, initrd_list_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_initrd_list"); + guestfs_end_busy (g); + return NULL; + } + + if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_INITRD_LIST, 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.filenames.filenames_val = + safe_realloc (g, ctx.ret.filenames.filenames_val, + sizeof (char *) * (ctx.ret.filenames.filenames_len + 1)); + ctx.ret.filenames.filenames_val[ctx.ret.filenames.filenames_len] = NULL; + return ctx.ret.filenames.filenames_val; +} + diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 3c983325..43570bbe 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -198,3 +198,4 @@ extern char **guestfs_tail_n (guestfs_h *handle, int nrlines, const char *path); 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); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index 050d9282..6f135dbe 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -2171,6 +2171,27 @@ xdr_guestfs_du_ret (XDR *xdrs, guestfs_du_ret *objp) } bool_t +xdr_guestfs_initrd_list_args (XDR *xdrs, guestfs_initrd_list_args *objp) +{ + register int32_t *buf; + + if (!xdr_string (xdrs, &objp->path, ~0)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_initrd_list_ret (XDR *xdrs, guestfs_initrd_list_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->filenames.filenames_val, (u_int *) &objp->filenames.filenames_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; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index c8231a0d..b850f9f8 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -1111,6 +1111,19 @@ struct guestfs_du_ret { }; typedef struct guestfs_du_ret guestfs_du_ret; +struct guestfs_initrd_list_args { + char *path; +}; +typedef struct guestfs_initrd_list_args guestfs_initrd_list_args; + +struct guestfs_initrd_list_ret { + struct { + u_int filenames_len; + str *filenames_val; + } filenames; +}; +typedef struct guestfs_initrd_list_ret guestfs_initrd_list_ret; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -1239,7 +1252,8 @@ enum guestfs_procedure { GUESTFS_PROC_DF = 125, GUESTFS_PROC_DF_H = 126, GUESTFS_PROC_DU = 127, - GUESTFS_PROC_NR_PROCS = 127 + 1, + GUESTFS_PROC_INITRD_LIST = 128, + GUESTFS_PROC_NR_PROCS = 128 + 1, }; typedef enum guestfs_procedure guestfs_procedure; #define GUESTFS_MESSAGE_MAX 4194304 @@ -1469,6 +1483,8 @@ extern bool_t xdr_guestfs_df_ret (XDR *, guestfs_df_ret*); extern bool_t xdr_guestfs_df_h_ret (XDR *, guestfs_df_h_ret*); 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_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*); @@ -1657,6 +1673,8 @@ extern bool_t xdr_guestfs_df_ret (); extern bool_t xdr_guestfs_df_h_ret (); 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_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 a895b6d5..42040ac4 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -850,6 +850,14 @@ struct guestfs_du_ret { hyper sizekb; }; +struct guestfs_initrd_list_args { + string path<>; +}; + +struct guestfs_initrd_list_ret { + str filenames<>; +}; + enum guestfs_procedure { GUESTFS_PROC_MOUNT = 1, GUESTFS_PROC_SYNC = 2, @@ -978,6 +986,7 @@ enum guestfs_procedure { GUESTFS_PROC_DF = 125, GUESTFS_PROC_DF_H = 126, GUESTFS_PROC_DU = 127, + GUESTFS_PROC_INITRD_LIST = 128, GUESTFS_PROC_NR_PROCS }; |