1 /* libguestfs generated file
2 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
5 * Copyright (C) 2009 Red Hat Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "guestfs_protocol.h"
28 #define error guestfs_error
29 #define perrorf guestfs_perrorf
30 #define safe_malloc guestfs_safe_malloc
31 #define safe_realloc guestfs_safe_realloc
32 #define safe_strdup guestfs_safe_strdup
33 #define safe_memdup guestfs_safe_memdup
35 /* Check the return message from a call for validity. */
37 check_reply_header (guestfs_h *g,
38 const struct guestfs_message_header *hdr,
39 int proc_nr, int serial)
41 if (hdr->prog != GUESTFS_PROGRAM) {
42 error (g, "wrong program (%d/%d)", hdr->prog, GUESTFS_PROGRAM);
45 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
46 error (g, "wrong protocol version (%d/%d)",
47 hdr->vers, GUESTFS_PROTOCOL_VERSION);
50 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
51 error (g, "unexpected message direction (%d/%d)",
52 hdr->direction, GUESTFS_DIRECTION_REPLY);
55 if (hdr->proc != proc_nr) {
56 error (g, "unexpected procedure number (%d/%d)", hdr->proc, proc_nr);
59 if (hdr->serial != serial) {
60 error (g, "unexpected serial (%d/%d)", hdr->serial, serial);
67 /* Check we are in the right state to run a high-level action. */
69 check_state (guestfs_h *g, const char *caller)
71 if (!guestfs_is_ready (g)) {
72 if (guestfs_is_config (g))
73 error (g, "%s: call launch() before using this function",
75 else if (guestfs_is_launching (g))
76 error (g, "%s: call wait_ready() before using this function",
79 error (g, "%s called from the wrong state, %d != READY",
80 caller, guestfs_get_state (g));
87 /* This flag is set by the callbacks, so we know we've done
88 * the callbacks as expected, and in the right sequence.
89 * 0 = not called, 1 = send called,
90 * 1001 = reply called.
93 struct guestfs_message_header hdr;
94 struct guestfs_message_error err;
97 static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
99 guestfs_main_loop *ml = guestfs_get_main_loop (g);
100 struct mount_ctx *ctx = (struct mount_ctx *) data;
102 ml->main_loop_quit (ml, g);
104 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
105 error (g, "%s: failed to parse reply header", "guestfs_mount");
108 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
109 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
110 error (g, "%s: failed to parse reply error", "guestfs_mount");
116 ctx->cb_sequence = 1001;
119 int guestfs_mount (guestfs_h *g,
121 const char *mountpoint)
123 struct guestfs_mount_args args;
124 struct mount_ctx ctx;
125 guestfs_main_loop *ml = guestfs_get_main_loop (g);
128 if (check_state (g, "guestfs_mount") == -1) return -1;
130 memset (&ctx, 0, sizeof ctx);
132 args.device = (char *) device;
133 args.mountpoint = (char *) mountpoint;
134 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT,
135 (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
139 guestfs__switch_to_receiving (g);
141 guestfs_set_reply_callback (g, mount_reply_cb, &ctx);
142 (void) ml->main_loop_run (ml, g);
143 guestfs_set_reply_callback (g, NULL, NULL);
144 if (ctx.cb_sequence != 1001) {
145 error (g, "%s reply failed, see earlier error messages", "guestfs_mount");
149 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
152 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
153 error (g, "%s", ctx.err.error_message);
161 /* This flag is set by the callbacks, so we know we've done
162 * the callbacks as expected, and in the right sequence.
163 * 0 = not called, 1 = send called,
164 * 1001 = reply called.
167 struct guestfs_message_header hdr;
168 struct guestfs_message_error err;
171 static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
173 guestfs_main_loop *ml = guestfs_get_main_loop (g);
174 struct sync_ctx *ctx = (struct sync_ctx *) data;
176 ml->main_loop_quit (ml, g);
178 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
179 error (g, "%s: failed to parse reply header", "guestfs_sync");
182 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
183 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
184 error (g, "%s: failed to parse reply error", "guestfs_sync");
190 ctx->cb_sequence = 1001;
193 int guestfs_sync (guestfs_h *g)
196 guestfs_main_loop *ml = guestfs_get_main_loop (g);
199 if (check_state (g, "guestfs_sync") == -1) return -1;
201 memset (&ctx, 0, sizeof ctx);
203 serial = guestfs__send_sync (g, GUESTFS_PROC_SYNC, NULL, NULL);
207 guestfs__switch_to_receiving (g);
209 guestfs_set_reply_callback (g, sync_reply_cb, &ctx);
210 (void) ml->main_loop_run (ml, g);
211 guestfs_set_reply_callback (g, NULL, NULL);
212 if (ctx.cb_sequence != 1001) {
213 error (g, "%s reply failed, see earlier error messages", "guestfs_sync");
217 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SYNC, serial) == -1)
220 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
221 error (g, "%s", ctx.err.error_message);
229 /* This flag is set by the callbacks, so we know we've done
230 * the callbacks as expected, and in the right sequence.
231 * 0 = not called, 1 = send called,
232 * 1001 = reply called.
235 struct guestfs_message_header hdr;
236 struct guestfs_message_error err;
239 static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
241 guestfs_main_loop *ml = guestfs_get_main_loop (g);
242 struct touch_ctx *ctx = (struct touch_ctx *) data;
244 ml->main_loop_quit (ml, g);
246 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
247 error (g, "%s: failed to parse reply header", "guestfs_touch");
250 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
251 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
252 error (g, "%s: failed to parse reply error", "guestfs_touch");
258 ctx->cb_sequence = 1001;
261 int guestfs_touch (guestfs_h *g,
264 struct guestfs_touch_args args;
265 struct touch_ctx ctx;
266 guestfs_main_loop *ml = guestfs_get_main_loop (g);
269 if (check_state (g, "guestfs_touch") == -1) return -1;
271 memset (&ctx, 0, sizeof ctx);
273 args.path = (char *) path;
274 serial = guestfs__send_sync (g, GUESTFS_PROC_TOUCH,
275 (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
279 guestfs__switch_to_receiving (g);
281 guestfs_set_reply_callback (g, touch_reply_cb, &ctx);
282 (void) ml->main_loop_run (ml, g);
283 guestfs_set_reply_callback (g, NULL, NULL);
284 if (ctx.cb_sequence != 1001) {
285 error (g, "%s reply failed, see earlier error messages", "guestfs_touch");
289 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
292 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
293 error (g, "%s", ctx.err.error_message);
301 /* This flag is set by the callbacks, so we know we've done
302 * the callbacks as expected, and in the right sequence.
303 * 0 = not called, 1 = send called,
304 * 1001 = reply called.
307 struct guestfs_message_header hdr;
308 struct guestfs_message_error err;
309 struct guestfs_cat_ret ret;
312 static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
314 guestfs_main_loop *ml = guestfs_get_main_loop (g);
315 struct cat_ctx *ctx = (struct cat_ctx *) data;
317 ml->main_loop_quit (ml, g);
319 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
320 error (g, "%s: failed to parse reply header", "guestfs_cat");
323 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
324 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
325 error (g, "%s: failed to parse reply error", "guestfs_cat");
330 if (!xdr_guestfs_cat_ret (xdr, &ctx->ret)) {
331 error (g, "%s: failed to parse reply", "guestfs_cat");
335 ctx->cb_sequence = 1001;
338 char *guestfs_cat (guestfs_h *g,
341 struct guestfs_cat_args args;
343 guestfs_main_loop *ml = guestfs_get_main_loop (g);
346 if (check_state (g, "guestfs_cat") == -1) return NULL;
348 memset (&ctx, 0, sizeof ctx);
350 args.path = (char *) path;
351 serial = guestfs__send_sync (g, GUESTFS_PROC_CAT,
352 (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
356 guestfs__switch_to_receiving (g);
358 guestfs_set_reply_callback (g, cat_reply_cb, &ctx);
359 (void) ml->main_loop_run (ml, g);
360 guestfs_set_reply_callback (g, NULL, NULL);
361 if (ctx.cb_sequence != 1001) {
362 error (g, "%s reply failed, see earlier error messages", "guestfs_cat");
366 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CAT, serial) == -1)
369 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
370 error (g, "%s", ctx.err.error_message);
374 return ctx.ret.content; /* caller will free */
378 /* This flag is set by the callbacks, so we know we've done
379 * the callbacks as expected, and in the right sequence.
380 * 0 = not called, 1 = send called,
381 * 1001 = reply called.
384 struct guestfs_message_header hdr;
385 struct guestfs_message_error err;
386 struct guestfs_ll_ret ret;
389 static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
391 guestfs_main_loop *ml = guestfs_get_main_loop (g);
392 struct ll_ctx *ctx = (struct ll_ctx *) data;
394 ml->main_loop_quit (ml, g);
396 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
397 error (g, "%s: failed to parse reply header", "guestfs_ll");
400 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
401 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
402 error (g, "%s: failed to parse reply error", "guestfs_ll");
407 if (!xdr_guestfs_ll_ret (xdr, &ctx->ret)) {
408 error (g, "%s: failed to parse reply", "guestfs_ll");
412 ctx->cb_sequence = 1001;
415 char *guestfs_ll (guestfs_h *g,
416 const char *directory)
418 struct guestfs_ll_args args;
420 guestfs_main_loop *ml = guestfs_get_main_loop (g);
423 if (check_state (g, "guestfs_ll") == -1) return NULL;
425 memset (&ctx, 0, sizeof ctx);
427 args.directory = (char *) directory;
428 serial = guestfs__send_sync (g, GUESTFS_PROC_LL,
429 (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
433 guestfs__switch_to_receiving (g);
435 guestfs_set_reply_callback (g, ll_reply_cb, &ctx);
436 (void) ml->main_loop_run (ml, g);
437 guestfs_set_reply_callback (g, NULL, NULL);
438 if (ctx.cb_sequence != 1001) {
439 error (g, "%s reply failed, see earlier error messages", "guestfs_ll");
443 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LL, serial) == -1)
446 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
447 error (g, "%s", ctx.err.error_message);
451 return ctx.ret.listing; /* caller will free */
455 /* This flag is set by the callbacks, so we know we've done
456 * the callbacks as expected, and in the right sequence.
457 * 0 = not called, 1 = send called,
458 * 1001 = reply called.
461 struct guestfs_message_header hdr;
462 struct guestfs_message_error err;
463 struct guestfs_ls_ret ret;
466 static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
468 guestfs_main_loop *ml = guestfs_get_main_loop (g);
469 struct ls_ctx *ctx = (struct ls_ctx *) data;
471 ml->main_loop_quit (ml, g);
473 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
474 error (g, "%s: failed to parse reply header", "guestfs_ls");
477 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
478 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
479 error (g, "%s: failed to parse reply error", "guestfs_ls");
484 if (!xdr_guestfs_ls_ret (xdr, &ctx->ret)) {
485 error (g, "%s: failed to parse reply", "guestfs_ls");
489 ctx->cb_sequence = 1001;
492 char **guestfs_ls (guestfs_h *g,
493 const char *directory)
495 struct guestfs_ls_args args;
497 guestfs_main_loop *ml = guestfs_get_main_loop (g);
500 if (check_state (g, "guestfs_ls") == -1) return NULL;
502 memset (&ctx, 0, sizeof ctx);
504 args.directory = (char *) directory;
505 serial = guestfs__send_sync (g, GUESTFS_PROC_LS,
506 (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
510 guestfs__switch_to_receiving (g);
512 guestfs_set_reply_callback (g, ls_reply_cb, &ctx);
513 (void) ml->main_loop_run (ml, g);
514 guestfs_set_reply_callback (g, NULL, NULL);
515 if (ctx.cb_sequence != 1001) {
516 error (g, "%s reply failed, see earlier error messages", "guestfs_ls");
520 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LS, serial) == -1)
523 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
524 error (g, "%s", ctx.err.error_message);
528 /* caller will free this, but we need to add a NULL entry */
529 ctx.ret.listing.listing_val =
530 safe_realloc (g, ctx.ret.listing.listing_val,
531 sizeof (char *) * (ctx.ret.listing.listing_len + 1));
532 ctx.ret.listing.listing_val[ctx.ret.listing.listing_len] = NULL;
533 return ctx.ret.listing.listing_val;
536 struct list_devices_ctx {
537 /* This flag is set by the callbacks, so we know we've done
538 * the callbacks as expected, and in the right sequence.
539 * 0 = not called, 1 = send called,
540 * 1001 = reply called.
543 struct guestfs_message_header hdr;
544 struct guestfs_message_error err;
545 struct guestfs_list_devices_ret ret;
548 static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
550 guestfs_main_loop *ml = guestfs_get_main_loop (g);
551 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
553 ml->main_loop_quit (ml, g);
555 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
556 error (g, "%s: failed to parse reply header", "guestfs_list_devices");
559 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
560 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
561 error (g, "%s: failed to parse reply error", "guestfs_list_devices");
566 if (!xdr_guestfs_list_devices_ret (xdr, &ctx->ret)) {
567 error (g, "%s: failed to parse reply", "guestfs_list_devices");
571 ctx->cb_sequence = 1001;
574 char **guestfs_list_devices (guestfs_h *g)
576 struct list_devices_ctx ctx;
577 guestfs_main_loop *ml = guestfs_get_main_loop (g);
580 if (check_state (g, "guestfs_list_devices") == -1) return NULL;
582 memset (&ctx, 0, sizeof ctx);
584 serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
588 guestfs__switch_to_receiving (g);
590 guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx);
591 (void) ml->main_loop_run (ml, g);
592 guestfs_set_reply_callback (g, NULL, NULL);
593 if (ctx.cb_sequence != 1001) {
594 error (g, "%s reply failed, see earlier error messages", "guestfs_list_devices");
598 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1)
601 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
602 error (g, "%s", ctx.err.error_message);
606 /* caller will free this, but we need to add a NULL entry */
607 ctx.ret.devices.devices_val =
608 safe_realloc (g, ctx.ret.devices.devices_val,
609 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
610 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
611 return ctx.ret.devices.devices_val;
614 struct list_partitions_ctx {
615 /* This flag is set by the callbacks, so we know we've done
616 * the callbacks as expected, and in the right sequence.
617 * 0 = not called, 1 = send called,
618 * 1001 = reply called.
621 struct guestfs_message_header hdr;
622 struct guestfs_message_error err;
623 struct guestfs_list_partitions_ret ret;
626 static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
628 guestfs_main_loop *ml = guestfs_get_main_loop (g);
629 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
631 ml->main_loop_quit (ml, g);
633 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
634 error (g, "%s: failed to parse reply header", "guestfs_list_partitions");
637 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
638 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
639 error (g, "%s: failed to parse reply error", "guestfs_list_partitions");
644 if (!xdr_guestfs_list_partitions_ret (xdr, &ctx->ret)) {
645 error (g, "%s: failed to parse reply", "guestfs_list_partitions");
649 ctx->cb_sequence = 1001;
652 char **guestfs_list_partitions (guestfs_h *g)
654 struct list_partitions_ctx ctx;
655 guestfs_main_loop *ml = guestfs_get_main_loop (g);
658 if (check_state (g, "guestfs_list_partitions") == -1) return NULL;
660 memset (&ctx, 0, sizeof ctx);
662 serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
666 guestfs__switch_to_receiving (g);
668 guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx);
669 (void) ml->main_loop_run (ml, g);
670 guestfs_set_reply_callback (g, NULL, NULL);
671 if (ctx.cb_sequence != 1001) {
672 error (g, "%s reply failed, see earlier error messages", "guestfs_list_partitions");
676 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1)
679 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
680 error (g, "%s", ctx.err.error_message);
684 /* caller will free this, but we need to add a NULL entry */
685 ctx.ret.partitions.partitions_val =
686 safe_realloc (g, ctx.ret.partitions.partitions_val,
687 sizeof (char *) * (ctx.ret.partitions.partitions_len + 1));
688 ctx.ret.partitions.partitions_val[ctx.ret.partitions.partitions_len] = NULL;
689 return ctx.ret.partitions.partitions_val;
693 /* This flag is set by the callbacks, so we know we've done
694 * the callbacks as expected, and in the right sequence.
695 * 0 = not called, 1 = send called,
696 * 1001 = reply called.
699 struct guestfs_message_header hdr;
700 struct guestfs_message_error err;
701 struct guestfs_pvs_ret ret;
704 static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
706 guestfs_main_loop *ml = guestfs_get_main_loop (g);
707 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
709 ml->main_loop_quit (ml, g);
711 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
712 error (g, "%s: failed to parse reply header", "guestfs_pvs");
715 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
716 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
717 error (g, "%s: failed to parse reply error", "guestfs_pvs");
722 if (!xdr_guestfs_pvs_ret (xdr, &ctx->ret)) {
723 error (g, "%s: failed to parse reply", "guestfs_pvs");
727 ctx->cb_sequence = 1001;
730 char **guestfs_pvs (guestfs_h *g)
733 guestfs_main_loop *ml = guestfs_get_main_loop (g);
736 if (check_state (g, "guestfs_pvs") == -1) return NULL;
738 memset (&ctx, 0, sizeof ctx);
740 serial = guestfs__send_sync (g, GUESTFS_PROC_PVS, NULL, NULL);
744 guestfs__switch_to_receiving (g);
746 guestfs_set_reply_callback (g, pvs_reply_cb, &ctx);
747 (void) ml->main_loop_run (ml, g);
748 guestfs_set_reply_callback (g, NULL, NULL);
749 if (ctx.cb_sequence != 1001) {
750 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs");
754 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS, serial) == -1)
757 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
758 error (g, "%s", ctx.err.error_message);
762 /* caller will free this, but we need to add a NULL entry */
763 ctx.ret.physvols.physvols_val =
764 safe_realloc (g, ctx.ret.physvols.physvols_val,
765 sizeof (char *) * (ctx.ret.physvols.physvols_len + 1));
766 ctx.ret.physvols.physvols_val[ctx.ret.physvols.physvols_len] = NULL;
767 return ctx.ret.physvols.physvols_val;
771 /* This flag is set by the callbacks, so we know we've done
772 * the callbacks as expected, and in the right sequence.
773 * 0 = not called, 1 = send called,
774 * 1001 = reply called.
777 struct guestfs_message_header hdr;
778 struct guestfs_message_error err;
779 struct guestfs_vgs_ret ret;
782 static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
784 guestfs_main_loop *ml = guestfs_get_main_loop (g);
785 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
787 ml->main_loop_quit (ml, g);
789 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
790 error (g, "%s: failed to parse reply header", "guestfs_vgs");
793 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
794 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
795 error (g, "%s: failed to parse reply error", "guestfs_vgs");
800 if (!xdr_guestfs_vgs_ret (xdr, &ctx->ret)) {
801 error (g, "%s: failed to parse reply", "guestfs_vgs");
805 ctx->cb_sequence = 1001;
808 char **guestfs_vgs (guestfs_h *g)
811 guestfs_main_loop *ml = guestfs_get_main_loop (g);
814 if (check_state (g, "guestfs_vgs") == -1) return NULL;
816 memset (&ctx, 0, sizeof ctx);
818 serial = guestfs__send_sync (g, GUESTFS_PROC_VGS, NULL, NULL);
822 guestfs__switch_to_receiving (g);
824 guestfs_set_reply_callback (g, vgs_reply_cb, &ctx);
825 (void) ml->main_loop_run (ml, g);
826 guestfs_set_reply_callback (g, NULL, NULL);
827 if (ctx.cb_sequence != 1001) {
828 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs");
832 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS, serial) == -1)
835 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
836 error (g, "%s", ctx.err.error_message);
840 /* caller will free this, but we need to add a NULL entry */
841 ctx.ret.volgroups.volgroups_val =
842 safe_realloc (g, ctx.ret.volgroups.volgroups_val,
843 sizeof (char *) * (ctx.ret.volgroups.volgroups_len + 1));
844 ctx.ret.volgroups.volgroups_val[ctx.ret.volgroups.volgroups_len] = NULL;
845 return ctx.ret.volgroups.volgroups_val;
849 /* This flag is set by the callbacks, so we know we've done
850 * the callbacks as expected, and in the right sequence.
851 * 0 = not called, 1 = send called,
852 * 1001 = reply called.
855 struct guestfs_message_header hdr;
856 struct guestfs_message_error err;
857 struct guestfs_lvs_ret ret;
860 static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
862 guestfs_main_loop *ml = guestfs_get_main_loop (g);
863 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
865 ml->main_loop_quit (ml, g);
867 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
868 error (g, "%s: failed to parse reply header", "guestfs_lvs");
871 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
872 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
873 error (g, "%s: failed to parse reply error", "guestfs_lvs");
878 if (!xdr_guestfs_lvs_ret (xdr, &ctx->ret)) {
879 error (g, "%s: failed to parse reply", "guestfs_lvs");
883 ctx->cb_sequence = 1001;
886 char **guestfs_lvs (guestfs_h *g)
889 guestfs_main_loop *ml = guestfs_get_main_loop (g);
892 if (check_state (g, "guestfs_lvs") == -1) return NULL;
894 memset (&ctx, 0, sizeof ctx);
896 serial = guestfs__send_sync (g, GUESTFS_PROC_LVS, NULL, NULL);
900 guestfs__switch_to_receiving (g);
902 guestfs_set_reply_callback (g, lvs_reply_cb, &ctx);
903 (void) ml->main_loop_run (ml, g);
904 guestfs_set_reply_callback (g, NULL, NULL);
905 if (ctx.cb_sequence != 1001) {
906 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs");
910 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS, serial) == -1)
913 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
914 error (g, "%s", ctx.err.error_message);
918 /* caller will free this, but we need to add a NULL entry */
919 ctx.ret.logvols.logvols_val =
920 safe_realloc (g, ctx.ret.logvols.logvols_val,
921 sizeof (char *) * (ctx.ret.logvols.logvols_len + 1));
922 ctx.ret.logvols.logvols_val[ctx.ret.logvols.logvols_len] = NULL;
923 return ctx.ret.logvols.logvols_val;
926 struct pvs_full_ctx {
927 /* This flag is set by the callbacks, so we know we've done
928 * the callbacks as expected, and in the right sequence.
929 * 0 = not called, 1 = send called,
930 * 1001 = reply called.
933 struct guestfs_message_header hdr;
934 struct guestfs_message_error err;
935 struct guestfs_pvs_full_ret ret;
938 static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
940 guestfs_main_loop *ml = guestfs_get_main_loop (g);
941 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
943 ml->main_loop_quit (ml, g);
945 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
946 error (g, "%s: failed to parse reply header", "guestfs_pvs_full");
949 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
950 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
951 error (g, "%s: failed to parse reply error", "guestfs_pvs_full");
956 if (!xdr_guestfs_pvs_full_ret (xdr, &ctx->ret)) {
957 error (g, "%s: failed to parse reply", "guestfs_pvs_full");
961 ctx->cb_sequence = 1001;
964 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
966 struct pvs_full_ctx ctx;
967 guestfs_main_loop *ml = guestfs_get_main_loop (g);
970 if (check_state (g, "guestfs_pvs_full") == -1) return NULL;
972 memset (&ctx, 0, sizeof ctx);
974 serial = guestfs__send_sync (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
978 guestfs__switch_to_receiving (g);
980 guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx);
981 (void) ml->main_loop_run (ml, g);
982 guestfs_set_reply_callback (g, NULL, NULL);
983 if (ctx.cb_sequence != 1001) {
984 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs_full");
988 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1)
991 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
992 error (g, "%s", ctx.err.error_message);
996 /* caller will free this */
997 return safe_memdup (g, &ctx.ret.physvols, sizeof (ctx.ret.physvols));
1000 struct vgs_full_ctx {
1001 /* This flag is set by the callbacks, so we know we've done
1002 * the callbacks as expected, and in the right sequence.
1003 * 0 = not called, 1 = send called,
1004 * 1001 = reply called.
1007 struct guestfs_message_header hdr;
1008 struct guestfs_message_error err;
1009 struct guestfs_vgs_full_ret ret;
1012 static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1014 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1015 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1017 ml->main_loop_quit (ml, g);
1019 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1020 error (g, "%s: failed to parse reply header", "guestfs_vgs_full");
1023 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1024 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1025 error (g, "%s: failed to parse reply error", "guestfs_vgs_full");
1030 if (!xdr_guestfs_vgs_full_ret (xdr, &ctx->ret)) {
1031 error (g, "%s: failed to parse reply", "guestfs_vgs_full");
1035 ctx->cb_sequence = 1001;
1038 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
1040 struct vgs_full_ctx ctx;
1041 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1044 if (check_state (g, "guestfs_vgs_full") == -1) return NULL;
1046 memset (&ctx, 0, sizeof ctx);
1048 serial = guestfs__send_sync (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
1052 guestfs__switch_to_receiving (g);
1053 ctx.cb_sequence = 0;
1054 guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx);
1055 (void) ml->main_loop_run (ml, g);
1056 guestfs_set_reply_callback (g, NULL, NULL);
1057 if (ctx.cb_sequence != 1001) {
1058 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs_full");
1062 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1)
1065 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1066 error (g, "%s", ctx.err.error_message);
1070 /* caller will free this */
1071 return safe_memdup (g, &ctx.ret.volgroups, sizeof (ctx.ret.volgroups));
1074 struct lvs_full_ctx {
1075 /* This flag is set by the callbacks, so we know we've done
1076 * the callbacks as expected, and in the right sequence.
1077 * 0 = not called, 1 = send called,
1078 * 1001 = reply called.
1081 struct guestfs_message_header hdr;
1082 struct guestfs_message_error err;
1083 struct guestfs_lvs_full_ret ret;
1086 static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1088 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1089 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1091 ml->main_loop_quit (ml, g);
1093 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1094 error (g, "%s: failed to parse reply header", "guestfs_lvs_full");
1097 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1098 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1099 error (g, "%s: failed to parse reply error", "guestfs_lvs_full");
1104 if (!xdr_guestfs_lvs_full_ret (xdr, &ctx->ret)) {
1105 error (g, "%s: failed to parse reply", "guestfs_lvs_full");
1109 ctx->cb_sequence = 1001;
1112 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
1114 struct lvs_full_ctx ctx;
1115 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1118 if (check_state (g, "guestfs_lvs_full") == -1) return NULL;
1120 memset (&ctx, 0, sizeof ctx);
1122 serial = guestfs__send_sync (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
1126 guestfs__switch_to_receiving (g);
1127 ctx.cb_sequence = 0;
1128 guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx);
1129 (void) ml->main_loop_run (ml, g);
1130 guestfs_set_reply_callback (g, NULL, NULL);
1131 if (ctx.cb_sequence != 1001) {
1132 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs_full");
1136 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1)
1139 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1140 error (g, "%s", ctx.err.error_message);
1144 /* caller will free this */
1145 return safe_memdup (g, &ctx.ret.logvols, sizeof (ctx.ret.logvols));
1148 struct read_lines_ctx {
1149 /* This flag is set by the callbacks, so we know we've done
1150 * the callbacks as expected, and in the right sequence.
1151 * 0 = not called, 1 = send called,
1152 * 1001 = reply called.
1155 struct guestfs_message_header hdr;
1156 struct guestfs_message_error err;
1157 struct guestfs_read_lines_ret ret;
1160 static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1162 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1163 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1165 ml->main_loop_quit (ml, g);
1167 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1168 error (g, "%s: failed to parse reply header", "guestfs_read_lines");
1171 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1172 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1173 error (g, "%s: failed to parse reply error", "guestfs_read_lines");
1178 if (!xdr_guestfs_read_lines_ret (xdr, &ctx->ret)) {
1179 error (g, "%s: failed to parse reply", "guestfs_read_lines");
1183 ctx->cb_sequence = 1001;
1186 char **guestfs_read_lines (guestfs_h *g,
1189 struct guestfs_read_lines_args args;
1190 struct read_lines_ctx ctx;
1191 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1194 if (check_state (g, "guestfs_read_lines") == -1) return NULL;
1196 memset (&ctx, 0, sizeof ctx);
1198 args.path = (char *) path;
1199 serial = guestfs__send_sync (g, GUESTFS_PROC_READ_LINES,
1200 (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
1204 guestfs__switch_to_receiving (g);
1205 ctx.cb_sequence = 0;
1206 guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx);
1207 (void) ml->main_loop_run (ml, g);
1208 guestfs_set_reply_callback (g, NULL, NULL);
1209 if (ctx.cb_sequence != 1001) {
1210 error (g, "%s reply failed, see earlier error messages", "guestfs_read_lines");
1214 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_READ_LINES, serial) == -1)
1217 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1218 error (g, "%s", ctx.err.error_message);
1222 /* caller will free this, but we need to add a NULL entry */
1223 ctx.ret.lines.lines_val =
1224 safe_realloc (g, ctx.ret.lines.lines_val,
1225 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
1226 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
1227 return ctx.ret.lines.lines_val;
1230 struct aug_init_ctx {
1231 /* This flag is set by the callbacks, so we know we've done
1232 * the callbacks as expected, and in the right sequence.
1233 * 0 = not called, 1 = send called,
1234 * 1001 = reply called.
1237 struct guestfs_message_header hdr;
1238 struct guestfs_message_error err;
1241 static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1243 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1244 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1246 ml->main_loop_quit (ml, g);
1248 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1249 error (g, "%s: failed to parse reply header", "guestfs_aug_init");
1252 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1253 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1254 error (g, "%s: failed to parse reply error", "guestfs_aug_init");
1260 ctx->cb_sequence = 1001;
1263 int guestfs_aug_init (guestfs_h *g,
1267 struct guestfs_aug_init_args args;
1268 struct aug_init_ctx ctx;
1269 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1272 if (check_state (g, "guestfs_aug_init") == -1) return -1;
1274 memset (&ctx, 0, sizeof ctx);
1276 args.root = (char *) root;
1278 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INIT,
1279 (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
1283 guestfs__switch_to_receiving (g);
1284 ctx.cb_sequence = 0;
1285 guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx);
1286 (void) ml->main_loop_run (ml, g);
1287 guestfs_set_reply_callback (g, NULL, NULL);
1288 if (ctx.cb_sequence != 1001) {
1289 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_init");
1293 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1)
1296 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1297 error (g, "%s", ctx.err.error_message);
1304 struct aug_close_ctx {
1305 /* This flag is set by the callbacks, so we know we've done
1306 * the callbacks as expected, and in the right sequence.
1307 * 0 = not called, 1 = send called,
1308 * 1001 = reply called.
1311 struct guestfs_message_header hdr;
1312 struct guestfs_message_error err;
1315 static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1317 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1318 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1320 ml->main_loop_quit (ml, g);
1322 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1323 error (g, "%s: failed to parse reply header", "guestfs_aug_close");
1326 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1327 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1328 error (g, "%s: failed to parse reply error", "guestfs_aug_close");
1334 ctx->cb_sequence = 1001;
1337 int guestfs_aug_close (guestfs_h *g)
1339 struct aug_close_ctx ctx;
1340 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1343 if (check_state (g, "guestfs_aug_close") == -1) return -1;
1345 memset (&ctx, 0, sizeof ctx);
1347 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
1351 guestfs__switch_to_receiving (g);
1352 ctx.cb_sequence = 0;
1353 guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx);
1354 (void) ml->main_loop_run (ml, g);
1355 guestfs_set_reply_callback (g, NULL, NULL);
1356 if (ctx.cb_sequence != 1001) {
1357 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_close");
1361 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1)
1364 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1365 error (g, "%s", ctx.err.error_message);
1372 struct aug_defvar_ctx {
1373 /* This flag is set by the callbacks, so we know we've done
1374 * the callbacks as expected, and in the right sequence.
1375 * 0 = not called, 1 = send called,
1376 * 1001 = reply called.
1379 struct guestfs_message_header hdr;
1380 struct guestfs_message_error err;
1381 struct guestfs_aug_defvar_ret ret;
1384 static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1386 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1387 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1389 ml->main_loop_quit (ml, g);
1391 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1392 error (g, "%s: failed to parse reply header", "guestfs_aug_defvar");
1395 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1396 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1397 error (g, "%s: failed to parse reply error", "guestfs_aug_defvar");
1402 if (!xdr_guestfs_aug_defvar_ret (xdr, &ctx->ret)) {
1403 error (g, "%s: failed to parse reply", "guestfs_aug_defvar");
1407 ctx->cb_sequence = 1001;
1410 int guestfs_aug_defvar (guestfs_h *g,
1414 struct guestfs_aug_defvar_args args;
1415 struct aug_defvar_ctx ctx;
1416 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1419 if (check_state (g, "guestfs_aug_defvar") == -1) return -1;
1421 memset (&ctx, 0, sizeof ctx);
1423 args.name = (char *) name;
1424 args.expr = expr ? (char **) &expr : NULL;
1425 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFVAR,
1426 (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
1430 guestfs__switch_to_receiving (g);
1431 ctx.cb_sequence = 0;
1432 guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx);
1433 (void) ml->main_loop_run (ml, g);
1434 guestfs_set_reply_callback (g, NULL, NULL);
1435 if (ctx.cb_sequence != 1001) {
1436 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defvar");
1440 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1)
1443 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1444 error (g, "%s", ctx.err.error_message);
1448 return ctx.ret.nrnodes;
1451 struct aug_defnode_ctx {
1452 /* This flag is set by the callbacks, so we know we've done
1453 * the callbacks as expected, and in the right sequence.
1454 * 0 = not called, 1 = send called,
1455 * 1001 = reply called.
1458 struct guestfs_message_header hdr;
1459 struct guestfs_message_error err;
1460 struct guestfs_aug_defnode_ret ret;
1463 static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1465 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1466 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1468 ml->main_loop_quit (ml, g);
1470 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1471 error (g, "%s: failed to parse reply header", "guestfs_aug_defnode");
1474 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1475 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1476 error (g, "%s: failed to parse reply error", "guestfs_aug_defnode");
1481 if (!xdr_guestfs_aug_defnode_ret (xdr, &ctx->ret)) {
1482 error (g, "%s: failed to parse reply", "guestfs_aug_defnode");
1486 ctx->cb_sequence = 1001;
1489 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
1494 struct guestfs_aug_defnode_args args;
1495 struct aug_defnode_ctx ctx;
1496 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1499 if (check_state (g, "guestfs_aug_defnode") == -1) return NULL;
1501 memset (&ctx, 0, sizeof ctx);
1503 args.name = (char *) name;
1504 args.expr = (char *) expr;
1505 args.val = (char *) val;
1506 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFNODE,
1507 (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
1511 guestfs__switch_to_receiving (g);
1512 ctx.cb_sequence = 0;
1513 guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx);
1514 (void) ml->main_loop_run (ml, g);
1515 guestfs_set_reply_callback (g, NULL, NULL);
1516 if (ctx.cb_sequence != 1001) {
1517 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defnode");
1521 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1)
1524 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1525 error (g, "%s", ctx.err.error_message);
1529 /* caller with free this */
1530 return safe_memdup (g, &ctx.ret, sizeof (ctx.ret));
1533 struct aug_get_ctx {
1534 /* This flag is set by the callbacks, so we know we've done
1535 * the callbacks as expected, and in the right sequence.
1536 * 0 = not called, 1 = send called,
1537 * 1001 = reply called.
1540 struct guestfs_message_header hdr;
1541 struct guestfs_message_error err;
1542 struct guestfs_aug_get_ret ret;
1545 static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1547 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1548 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1550 ml->main_loop_quit (ml, g);
1552 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1553 error (g, "%s: failed to parse reply header", "guestfs_aug_get");
1556 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1557 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1558 error (g, "%s: failed to parse reply error", "guestfs_aug_get");
1563 if (!xdr_guestfs_aug_get_ret (xdr, &ctx->ret)) {
1564 error (g, "%s: failed to parse reply", "guestfs_aug_get");
1568 ctx->cb_sequence = 1001;
1571 char *guestfs_aug_get (guestfs_h *g,
1574 struct guestfs_aug_get_args args;
1575 struct aug_get_ctx ctx;
1576 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1579 if (check_state (g, "guestfs_aug_get") == -1) return NULL;
1581 memset (&ctx, 0, sizeof ctx);
1583 args.path = (char *) path;
1584 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_GET,
1585 (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
1589 guestfs__switch_to_receiving (g);
1590 ctx.cb_sequence = 0;
1591 guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx);
1592 (void) ml->main_loop_run (ml, g);
1593 guestfs_set_reply_callback (g, NULL, NULL);
1594 if (ctx.cb_sequence != 1001) {
1595 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_get");
1599 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_GET, serial) == -1)
1602 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1603 error (g, "%s", ctx.err.error_message);
1607 return ctx.ret.val; /* caller will free */
1610 struct aug_set_ctx {
1611 /* This flag is set by the callbacks, so we know we've done
1612 * the callbacks as expected, and in the right sequence.
1613 * 0 = not called, 1 = send called,
1614 * 1001 = reply called.
1617 struct guestfs_message_header hdr;
1618 struct guestfs_message_error err;
1621 static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1623 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1624 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1626 ml->main_loop_quit (ml, g);
1628 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1629 error (g, "%s: failed to parse reply header", "guestfs_aug_set");
1632 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1633 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1634 error (g, "%s: failed to parse reply error", "guestfs_aug_set");
1640 ctx->cb_sequence = 1001;
1643 int guestfs_aug_set (guestfs_h *g,
1647 struct guestfs_aug_set_args args;
1648 struct aug_set_ctx ctx;
1649 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1652 if (check_state (g, "guestfs_aug_set") == -1) return -1;
1654 memset (&ctx, 0, sizeof ctx);
1656 args.path = (char *) path;
1657 args.val = (char *) val;
1658 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SET,
1659 (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
1663 guestfs__switch_to_receiving (g);
1664 ctx.cb_sequence = 0;
1665 guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx);
1666 (void) ml->main_loop_run (ml, g);
1667 guestfs_set_reply_callback (g, NULL, NULL);
1668 if (ctx.cb_sequence != 1001) {
1669 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_set");
1673 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SET, serial) == -1)
1676 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1677 error (g, "%s", ctx.err.error_message);
1684 struct aug_insert_ctx {
1685 /* This flag is set by the callbacks, so we know we've done
1686 * the callbacks as expected, and in the right sequence.
1687 * 0 = not called, 1 = send called,
1688 * 1001 = reply called.
1691 struct guestfs_message_header hdr;
1692 struct guestfs_message_error err;
1695 static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1697 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1698 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
1700 ml->main_loop_quit (ml, g);
1702 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1703 error (g, "%s: failed to parse reply header", "guestfs_aug_insert");
1706 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1707 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1708 error (g, "%s: failed to parse reply error", "guestfs_aug_insert");
1714 ctx->cb_sequence = 1001;
1717 int guestfs_aug_insert (guestfs_h *g,
1722 struct guestfs_aug_insert_args args;
1723 struct aug_insert_ctx ctx;
1724 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1727 if (check_state (g, "guestfs_aug_insert") == -1) return -1;
1729 memset (&ctx, 0, sizeof ctx);
1731 args.path = (char *) path;
1732 args.label = (char *) label;
1733 args.before = before;
1734 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INSERT,
1735 (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
1739 guestfs__switch_to_receiving (g);
1740 ctx.cb_sequence = 0;
1741 guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx);
1742 (void) ml->main_loop_run (ml, g);
1743 guestfs_set_reply_callback (g, NULL, NULL);
1744 if (ctx.cb_sequence != 1001) {
1745 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_insert");
1749 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1)
1752 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1753 error (g, "%s", ctx.err.error_message);
1761 /* This flag is set by the callbacks, so we know we've done
1762 * the callbacks as expected, and in the right sequence.
1763 * 0 = not called, 1 = send called,
1764 * 1001 = reply called.
1767 struct guestfs_message_header hdr;
1768 struct guestfs_message_error err;
1769 struct guestfs_aug_rm_ret ret;
1772 static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1774 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1775 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
1777 ml->main_loop_quit (ml, g);
1779 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1780 error (g, "%s: failed to parse reply header", "guestfs_aug_rm");
1783 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1784 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1785 error (g, "%s: failed to parse reply error", "guestfs_aug_rm");
1790 if (!xdr_guestfs_aug_rm_ret (xdr, &ctx->ret)) {
1791 error (g, "%s: failed to parse reply", "guestfs_aug_rm");
1795 ctx->cb_sequence = 1001;
1798 int guestfs_aug_rm (guestfs_h *g,
1801 struct guestfs_aug_rm_args args;
1802 struct aug_rm_ctx ctx;
1803 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1806 if (check_state (g, "guestfs_aug_rm") == -1) return -1;
1808 memset (&ctx, 0, sizeof ctx);
1810 args.path = (char *) path;
1811 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_RM,
1812 (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
1816 guestfs__switch_to_receiving (g);
1817 ctx.cb_sequence = 0;
1818 guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx);
1819 (void) ml->main_loop_run (ml, g);
1820 guestfs_set_reply_callback (g, NULL, NULL);
1821 if (ctx.cb_sequence != 1001) {
1822 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_rm");
1826 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_RM, serial) == -1)
1829 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1830 error (g, "%s", ctx.err.error_message);
1834 return ctx.ret.nrnodes;
1838 /* This flag is set by the callbacks, so we know we've done
1839 * the callbacks as expected, and in the right sequence.
1840 * 0 = not called, 1 = send called,
1841 * 1001 = reply called.
1844 struct guestfs_message_header hdr;
1845 struct guestfs_message_error err;
1848 static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1850 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1851 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
1853 ml->main_loop_quit (ml, g);
1855 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1856 error (g, "%s: failed to parse reply header", "guestfs_aug_mv");
1859 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1860 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1861 error (g, "%s: failed to parse reply error", "guestfs_aug_mv");
1867 ctx->cb_sequence = 1001;
1870 int guestfs_aug_mv (guestfs_h *g,
1874 struct guestfs_aug_mv_args args;
1875 struct aug_mv_ctx ctx;
1876 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1879 if (check_state (g, "guestfs_aug_mv") == -1) return -1;
1881 memset (&ctx, 0, sizeof ctx);
1883 args.src = (char *) src;
1884 args.dest = (char *) dest;
1885 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MV,
1886 (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
1890 guestfs__switch_to_receiving (g);
1891 ctx.cb_sequence = 0;
1892 guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx);
1893 (void) ml->main_loop_run (ml, g);
1894 guestfs_set_reply_callback (g, NULL, NULL);
1895 if (ctx.cb_sequence != 1001) {
1896 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_mv");
1900 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MV, serial) == -1)
1903 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1904 error (g, "%s", ctx.err.error_message);
1911 struct aug_match_ctx {
1912 /* This flag is set by the callbacks, so we know we've done
1913 * the callbacks as expected, and in the right sequence.
1914 * 0 = not called, 1 = send called,
1915 * 1001 = reply called.
1918 struct guestfs_message_header hdr;
1919 struct guestfs_message_error err;
1920 struct guestfs_aug_match_ret ret;
1923 static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1925 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1926 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
1928 ml->main_loop_quit (ml, g);
1930 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1931 error (g, "%s: failed to parse reply header", "guestfs_aug_match");
1934 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1935 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1936 error (g, "%s: failed to parse reply error", "guestfs_aug_match");
1941 if (!xdr_guestfs_aug_match_ret (xdr, &ctx->ret)) {
1942 error (g, "%s: failed to parse reply", "guestfs_aug_match");
1946 ctx->cb_sequence = 1001;
1949 char **guestfs_aug_match (guestfs_h *g,
1952 struct guestfs_aug_match_args args;
1953 struct aug_match_ctx ctx;
1954 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1957 if (check_state (g, "guestfs_aug_match") == -1) return NULL;
1959 memset (&ctx, 0, sizeof ctx);
1961 args.path = (char *) path;
1962 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MATCH,
1963 (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
1967 guestfs__switch_to_receiving (g);
1968 ctx.cb_sequence = 0;
1969 guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx);
1970 (void) ml->main_loop_run (ml, g);
1971 guestfs_set_reply_callback (g, NULL, NULL);
1972 if (ctx.cb_sequence != 1001) {
1973 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_match");
1977 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1)
1980 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1981 error (g, "%s", ctx.err.error_message);
1985 /* caller will free this, but we need to add a NULL entry */
1986 ctx.ret.matches.matches_val =
1987 safe_realloc (g, ctx.ret.matches.matches_val,
1988 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
1989 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
1990 return ctx.ret.matches.matches_val;
1993 struct aug_save_ctx {
1994 /* This flag is set by the callbacks, so we know we've done
1995 * the callbacks as expected, and in the right sequence.
1996 * 0 = not called, 1 = send called,
1997 * 1001 = reply called.
2000 struct guestfs_message_header hdr;
2001 struct guestfs_message_error err;
2004 static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2006 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2007 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2009 ml->main_loop_quit (ml, g);
2011 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2012 error (g, "%s: failed to parse reply header", "guestfs_aug_save");
2015 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2016 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2017 error (g, "%s: failed to parse reply error", "guestfs_aug_save");
2023 ctx->cb_sequence = 1001;
2026 int guestfs_aug_save (guestfs_h *g)
2028 struct aug_save_ctx ctx;
2029 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2032 if (check_state (g, "guestfs_aug_save") == -1) return -1;
2034 memset (&ctx, 0, sizeof ctx);
2036 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
2040 guestfs__switch_to_receiving (g);
2041 ctx.cb_sequence = 0;
2042 guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx);
2043 (void) ml->main_loop_run (ml, g);
2044 guestfs_set_reply_callback (g, NULL, NULL);
2045 if (ctx.cb_sequence != 1001) {
2046 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_save");
2050 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1)
2053 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2054 error (g, "%s", ctx.err.error_message);
2061 struct aug_load_ctx {
2062 /* This flag is set by the callbacks, so we know we've done
2063 * the callbacks as expected, and in the right sequence.
2064 * 0 = not called, 1 = send called,
2065 * 1001 = reply called.
2068 struct guestfs_message_header hdr;
2069 struct guestfs_message_error err;
2072 static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2074 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2075 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2077 ml->main_loop_quit (ml, g);
2079 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2080 error (g, "%s: failed to parse reply header", "guestfs_aug_load");
2083 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2084 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2085 error (g, "%s: failed to parse reply error", "guestfs_aug_load");
2091 ctx->cb_sequence = 1001;
2094 int guestfs_aug_load (guestfs_h *g)
2096 struct aug_load_ctx ctx;
2097 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2100 if (check_state (g, "guestfs_aug_load") == -1) return -1;
2102 memset (&ctx, 0, sizeof ctx);
2104 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
2108 guestfs__switch_to_receiving (g);
2109 ctx.cb_sequence = 0;
2110 guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx);
2111 (void) ml->main_loop_run (ml, g);
2112 guestfs_set_reply_callback (g, NULL, NULL);
2113 if (ctx.cb_sequence != 1001) {
2114 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_load");
2118 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1)
2121 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2122 error (g, "%s", ctx.err.error_message);
2130 /* This flag is set by the callbacks, so we know we've done
2131 * the callbacks as expected, and in the right sequence.
2132 * 0 = not called, 1 = send called,
2133 * 1001 = reply called.
2136 struct guestfs_message_header hdr;
2137 struct guestfs_message_error err;
2138 struct guestfs_aug_ls_ret ret;
2141 static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2143 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2144 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2146 ml->main_loop_quit (ml, g);
2148 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2149 error (g, "%s: failed to parse reply header", "guestfs_aug_ls");
2152 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2153 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2154 error (g, "%s: failed to parse reply error", "guestfs_aug_ls");
2159 if (!xdr_guestfs_aug_ls_ret (xdr, &ctx->ret)) {
2160 error (g, "%s: failed to parse reply", "guestfs_aug_ls");
2164 ctx->cb_sequence = 1001;
2167 char **guestfs_aug_ls (guestfs_h *g,
2170 struct guestfs_aug_ls_args args;
2171 struct aug_ls_ctx ctx;
2172 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2175 if (check_state (g, "guestfs_aug_ls") == -1) return NULL;
2177 memset (&ctx, 0, sizeof ctx);
2179 args.path = (char *) path;
2180 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LS,
2181 (xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
2185 guestfs__switch_to_receiving (g);
2186 ctx.cb_sequence = 0;
2187 guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx);
2188 (void) ml->main_loop_run (ml, g);
2189 guestfs_set_reply_callback (g, NULL, NULL);
2190 if (ctx.cb_sequence != 1001) {
2191 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_ls");
2195 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LS, serial) == -1)
2198 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2199 error (g, "%s", ctx.err.error_message);
2203 /* caller will free this, but we need to add a NULL entry */
2204 ctx.ret.matches.matches_val =
2205 safe_realloc (g, ctx.ret.matches.matches_val,
2206 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2207 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2208 return ctx.ret.matches.matches_val;
2212 /* This flag is set by the callbacks, so we know we've done
2213 * the callbacks as expected, and in the right sequence.
2214 * 0 = not called, 1 = send called,
2215 * 1001 = reply called.
2218 struct guestfs_message_header hdr;
2219 struct guestfs_message_error err;
2222 static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2224 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2225 struct rm_ctx *ctx = (struct rm_ctx *) data;
2227 ml->main_loop_quit (ml, g);
2229 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2230 error (g, "%s: failed to parse reply header", "guestfs_rm");
2233 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2234 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2235 error (g, "%s: failed to parse reply error", "guestfs_rm");
2241 ctx->cb_sequence = 1001;
2244 int guestfs_rm (guestfs_h *g,
2247 struct guestfs_rm_args args;
2249 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2252 if (check_state (g, "guestfs_rm") == -1) return -1;
2254 memset (&ctx, 0, sizeof ctx);
2256 args.path = (char *) path;
2257 serial = guestfs__send_sync (g, GUESTFS_PROC_RM,
2258 (xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
2262 guestfs__switch_to_receiving (g);
2263 ctx.cb_sequence = 0;
2264 guestfs_set_reply_callback (g, rm_reply_cb, &ctx);
2265 (void) ml->main_loop_run (ml, g);
2266 guestfs_set_reply_callback (g, NULL, NULL);
2267 if (ctx.cb_sequence != 1001) {
2268 error (g, "%s reply failed, see earlier error messages", "guestfs_rm");
2272 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM, serial) == -1)
2275 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2276 error (g, "%s", ctx.err.error_message);
2284 /* This flag is set by the callbacks, so we know we've done
2285 * the callbacks as expected, and in the right sequence.
2286 * 0 = not called, 1 = send called,
2287 * 1001 = reply called.
2290 struct guestfs_message_header hdr;
2291 struct guestfs_message_error err;
2294 static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2296 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2297 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2299 ml->main_loop_quit (ml, g);
2301 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2302 error (g, "%s: failed to parse reply header", "guestfs_rmdir");
2305 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2306 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2307 error (g, "%s: failed to parse reply error", "guestfs_rmdir");
2313 ctx->cb_sequence = 1001;
2316 int guestfs_rmdir (guestfs_h *g,
2319 struct guestfs_rmdir_args args;
2320 struct rmdir_ctx ctx;
2321 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2324 if (check_state (g, "guestfs_rmdir") == -1) return -1;
2326 memset (&ctx, 0, sizeof ctx);
2328 args.path = (char *) path;
2329 serial = guestfs__send_sync (g, GUESTFS_PROC_RMDIR,
2330 (xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
2334 guestfs__switch_to_receiving (g);
2335 ctx.cb_sequence = 0;
2336 guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx);
2337 (void) ml->main_loop_run (ml, g);
2338 guestfs_set_reply_callback (g, NULL, NULL);
2339 if (ctx.cb_sequence != 1001) {
2340 error (g, "%s reply failed, see earlier error messages", "guestfs_rmdir");
2344 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RMDIR, serial) == -1)
2347 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2348 error (g, "%s", ctx.err.error_message);
2356 /* This flag is set by the callbacks, so we know we've done
2357 * the callbacks as expected, and in the right sequence.
2358 * 0 = not called, 1 = send called,
2359 * 1001 = reply called.
2362 struct guestfs_message_header hdr;
2363 struct guestfs_message_error err;
2366 static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2368 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2369 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2371 ml->main_loop_quit (ml, g);
2373 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2374 error (g, "%s: failed to parse reply header", "guestfs_rm_rf");
2377 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2378 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2379 error (g, "%s: failed to parse reply error", "guestfs_rm_rf");
2385 ctx->cb_sequence = 1001;
2388 int guestfs_rm_rf (guestfs_h *g,
2391 struct guestfs_rm_rf_args args;
2392 struct rm_rf_ctx ctx;
2393 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2396 if (check_state (g, "guestfs_rm_rf") == -1) return -1;
2398 memset (&ctx, 0, sizeof ctx);
2400 args.path = (char *) path;
2401 serial = guestfs__send_sync (g, GUESTFS_PROC_RM_RF,
2402 (xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
2406 guestfs__switch_to_receiving (g);
2407 ctx.cb_sequence = 0;
2408 guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx);
2409 (void) ml->main_loop_run (ml, g);
2410 guestfs_set_reply_callback (g, NULL, NULL);
2411 if (ctx.cb_sequence != 1001) {
2412 error (g, "%s reply failed, see earlier error messages", "guestfs_rm_rf");
2416 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM_RF, serial) == -1)
2419 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2420 error (g, "%s", ctx.err.error_message);
2428 /* This flag is set by the callbacks, so we know we've done
2429 * the callbacks as expected, and in the right sequence.
2430 * 0 = not called, 1 = send called,
2431 * 1001 = reply called.
2434 struct guestfs_message_header hdr;
2435 struct guestfs_message_error err;
2438 static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2440 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2441 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
2443 ml->main_loop_quit (ml, g);
2445 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2446 error (g, "%s: failed to parse reply header", "guestfs_mkdir");
2449 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2450 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2451 error (g, "%s: failed to parse reply error", "guestfs_mkdir");
2457 ctx->cb_sequence = 1001;
2460 int guestfs_mkdir (guestfs_h *g,
2463 struct guestfs_mkdir_args args;
2464 struct mkdir_ctx ctx;
2465 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2468 if (check_state (g, "guestfs_mkdir") == -1) return -1;
2470 memset (&ctx, 0, sizeof ctx);
2472 args.path = (char *) path;
2473 serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR,
2474 (xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
2478 guestfs__switch_to_receiving (g);
2479 ctx.cb_sequence = 0;
2480 guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx);
2481 (void) ml->main_loop_run (ml, g);
2482 guestfs_set_reply_callback (g, NULL, NULL);
2483 if (ctx.cb_sequence != 1001) {
2484 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir");
2488 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR, serial) == -1)
2491 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2492 error (g, "%s", ctx.err.error_message);
2499 struct mkdir_p_ctx {
2500 /* This flag is set by the callbacks, so we know we've done
2501 * the callbacks as expected, and in the right sequence.
2502 * 0 = not called, 1 = send called,
2503 * 1001 = reply called.
2506 struct guestfs_message_header hdr;
2507 struct guestfs_message_error err;
2510 static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2512 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2513 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
2515 ml->main_loop_quit (ml, g);
2517 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2518 error (g, "%s: failed to parse reply header", "guestfs_mkdir_p");
2521 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2522 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2523 error (g, "%s: failed to parse reply error", "guestfs_mkdir_p");
2529 ctx->cb_sequence = 1001;
2532 int guestfs_mkdir_p (guestfs_h *g,
2535 struct guestfs_mkdir_p_args args;
2536 struct mkdir_p_ctx ctx;
2537 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2540 if (check_state (g, "guestfs_mkdir_p") == -1) return -1;
2542 memset (&ctx, 0, sizeof ctx);
2544 args.path = (char *) path;
2545 serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR_P,
2546 (xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
2550 guestfs__switch_to_receiving (g);
2551 ctx.cb_sequence = 0;
2552 guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx);
2553 (void) ml->main_loop_run (ml, g);
2554 guestfs_set_reply_callback (g, NULL, NULL);
2555 if (ctx.cb_sequence != 1001) {
2556 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir_p");
2560 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR_P, serial) == -1)
2563 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2564 error (g, "%s", ctx.err.error_message);
2572 /* This flag is set by the callbacks, so we know we've done
2573 * the callbacks as expected, and in the right sequence.
2574 * 0 = not called, 1 = send called,
2575 * 1001 = reply called.
2578 struct guestfs_message_header hdr;
2579 struct guestfs_message_error err;
2582 static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2584 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2585 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
2587 ml->main_loop_quit (ml, g);
2589 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2590 error (g, "%s: failed to parse reply header", "guestfs_chmod");
2593 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2594 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2595 error (g, "%s: failed to parse reply error", "guestfs_chmod");
2601 ctx->cb_sequence = 1001;
2604 int guestfs_chmod (guestfs_h *g,
2608 struct guestfs_chmod_args args;
2609 struct chmod_ctx ctx;
2610 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2613 if (check_state (g, "guestfs_chmod") == -1) return -1;
2615 memset (&ctx, 0, sizeof ctx);
2618 args.path = (char *) path;
2619 serial = guestfs__send_sync (g, GUESTFS_PROC_CHMOD,
2620 (xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
2624 guestfs__switch_to_receiving (g);
2625 ctx.cb_sequence = 0;
2626 guestfs_set_reply_callback (g, chmod_reply_cb, &ctx);
2627 (void) ml->main_loop_run (ml, g);
2628 guestfs_set_reply_callback (g, NULL, NULL);
2629 if (ctx.cb_sequence != 1001) {
2630 error (g, "%s reply failed, see earlier error messages", "guestfs_chmod");
2634 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHMOD, serial) == -1)
2637 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2638 error (g, "%s", ctx.err.error_message);
2646 /* This flag is set by the callbacks, so we know we've done
2647 * the callbacks as expected, and in the right sequence.
2648 * 0 = not called, 1 = send called,
2649 * 1001 = reply called.
2652 struct guestfs_message_header hdr;
2653 struct guestfs_message_error err;
2656 static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2658 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2659 struct chown_ctx *ctx = (struct chown_ctx *) data;
2661 ml->main_loop_quit (ml, g);
2663 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2664 error (g, "%s: failed to parse reply header", "guestfs_chown");
2667 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2668 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2669 error (g, "%s: failed to parse reply error", "guestfs_chown");
2675 ctx->cb_sequence = 1001;
2678 int guestfs_chown (guestfs_h *g,
2683 struct guestfs_chown_args args;
2684 struct chown_ctx ctx;
2685 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2688 if (check_state (g, "guestfs_chown") == -1) return -1;
2690 memset (&ctx, 0, sizeof ctx);
2694 args.path = (char *) path;
2695 serial = guestfs__send_sync (g, GUESTFS_PROC_CHOWN,
2696 (xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
2700 guestfs__switch_to_receiving (g);
2701 ctx.cb_sequence = 0;
2702 guestfs_set_reply_callback (g, chown_reply_cb, &ctx);
2703 (void) ml->main_loop_run (ml, g);
2704 guestfs_set_reply_callback (g, NULL, NULL);
2705 if (ctx.cb_sequence != 1001) {
2706 error (g, "%s reply failed, see earlier error messages", "guestfs_chown");
2710 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHOWN, serial) == -1)
2713 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2714 error (g, "%s", ctx.err.error_message);
2722 /* This flag is set by the callbacks, so we know we've done
2723 * the callbacks as expected, and in the right sequence.
2724 * 0 = not called, 1 = send called,
2725 * 1001 = reply called.
2728 struct guestfs_message_header hdr;
2729 struct guestfs_message_error err;
2730 struct guestfs_exists_ret ret;
2733 static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2735 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2736 struct exists_ctx *ctx = (struct exists_ctx *) data;
2738 ml->main_loop_quit (ml, g);
2740 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2741 error (g, "%s: failed to parse reply header", "guestfs_exists");
2744 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2745 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2746 error (g, "%s: failed to parse reply error", "guestfs_exists");
2751 if (!xdr_guestfs_exists_ret (xdr, &ctx->ret)) {
2752 error (g, "%s: failed to parse reply", "guestfs_exists");
2756 ctx->cb_sequence = 1001;
2759 int guestfs_exists (guestfs_h *g,
2762 struct guestfs_exists_args args;
2763 struct exists_ctx ctx;
2764 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2767 if (check_state (g, "guestfs_exists") == -1) return -1;
2769 memset (&ctx, 0, sizeof ctx);
2771 args.path = (char *) path;
2772 serial = guestfs__send_sync (g, GUESTFS_PROC_EXISTS,
2773 (xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
2777 guestfs__switch_to_receiving (g);
2778 ctx.cb_sequence = 0;
2779 guestfs_set_reply_callback (g, exists_reply_cb, &ctx);
2780 (void) ml->main_loop_run (ml, g);
2781 guestfs_set_reply_callback (g, NULL, NULL);
2782 if (ctx.cb_sequence != 1001) {
2783 error (g, "%s reply failed, see earlier error messages", "guestfs_exists");
2787 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EXISTS, serial) == -1)
2790 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2791 error (g, "%s", ctx.err.error_message);
2795 return ctx.ret.existsflag;
2798 struct is_file_ctx {
2799 /* This flag is set by the callbacks, so we know we've done
2800 * the callbacks as expected, and in the right sequence.
2801 * 0 = not called, 1 = send called,
2802 * 1001 = reply called.
2805 struct guestfs_message_header hdr;
2806 struct guestfs_message_error err;
2807 struct guestfs_is_file_ret ret;
2810 static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2812 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2813 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
2815 ml->main_loop_quit (ml, g);
2817 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2818 error (g, "%s: failed to parse reply header", "guestfs_is_file");
2821 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2822 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2823 error (g, "%s: failed to parse reply error", "guestfs_is_file");
2828 if (!xdr_guestfs_is_file_ret (xdr, &ctx->ret)) {
2829 error (g, "%s: failed to parse reply", "guestfs_is_file");
2833 ctx->cb_sequence = 1001;
2836 int guestfs_is_file (guestfs_h *g,
2839 struct guestfs_is_file_args args;
2840 struct is_file_ctx ctx;
2841 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2844 if (check_state (g, "guestfs_is_file") == -1) return -1;
2846 memset (&ctx, 0, sizeof ctx);
2848 args.path = (char *) path;
2849 serial = guestfs__send_sync (g, GUESTFS_PROC_IS_FILE,
2850 (xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
2854 guestfs__switch_to_receiving (g);
2855 ctx.cb_sequence = 0;
2856 guestfs_set_reply_callback (g, is_file_reply_cb, &ctx);
2857 (void) ml->main_loop_run (ml, g);
2858 guestfs_set_reply_callback (g, NULL, NULL);
2859 if (ctx.cb_sequence != 1001) {
2860 error (g, "%s reply failed, see earlier error messages", "guestfs_is_file");
2864 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_FILE, serial) == -1)
2867 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2868 error (g, "%s", ctx.err.error_message);
2872 return ctx.ret.fileflag;
2876 /* This flag is set by the callbacks, so we know we've done
2877 * the callbacks as expected, and in the right sequence.
2878 * 0 = not called, 1 = send called,
2879 * 1001 = reply called.
2882 struct guestfs_message_header hdr;
2883 struct guestfs_message_error err;
2884 struct guestfs_is_dir_ret ret;
2887 static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2889 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2890 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
2892 ml->main_loop_quit (ml, g);
2894 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2895 error (g, "%s: failed to parse reply header", "guestfs_is_dir");
2898 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2899 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2900 error (g, "%s: failed to parse reply error", "guestfs_is_dir");
2905 if (!xdr_guestfs_is_dir_ret (xdr, &ctx->ret)) {
2906 error (g, "%s: failed to parse reply", "guestfs_is_dir");
2910 ctx->cb_sequence = 1001;
2913 int guestfs_is_dir (guestfs_h *g,
2916 struct guestfs_is_dir_args args;
2917 struct is_dir_ctx ctx;
2918 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2921 if (check_state (g, "guestfs_is_dir") == -1) return -1;
2923 memset (&ctx, 0, sizeof ctx);
2925 args.path = (char *) path;
2926 serial = guestfs__send_sync (g, GUESTFS_PROC_IS_DIR,
2927 (xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
2931 guestfs__switch_to_receiving (g);
2932 ctx.cb_sequence = 0;
2933 guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx);
2934 (void) ml->main_loop_run (ml, g);
2935 guestfs_set_reply_callback (g, NULL, NULL);
2936 if (ctx.cb_sequence != 1001) {
2937 error (g, "%s reply failed, see earlier error messages", "guestfs_is_dir");
2941 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_DIR, serial) == -1)
2944 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2945 error (g, "%s", ctx.err.error_message);
2949 return ctx.ret.dirflag;
2952 struct pvcreate_ctx {
2953 /* This flag is set by the callbacks, so we know we've done
2954 * the callbacks as expected, and in the right sequence.
2955 * 0 = not called, 1 = send called,
2956 * 1001 = reply called.
2959 struct guestfs_message_header hdr;
2960 struct guestfs_message_error err;
2963 static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2965 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2966 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
2968 ml->main_loop_quit (ml, g);
2970 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2971 error (g, "%s: failed to parse reply header", "guestfs_pvcreate");
2974 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2975 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2976 error (g, "%s: failed to parse reply error", "guestfs_pvcreate");
2982 ctx->cb_sequence = 1001;
2985 int guestfs_pvcreate (guestfs_h *g,
2988 struct guestfs_pvcreate_args args;
2989 struct pvcreate_ctx ctx;
2990 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2993 if (check_state (g, "guestfs_pvcreate") == -1) return -1;
2995 memset (&ctx, 0, sizeof ctx);
2997 args.device = (char *) device;
2998 serial = guestfs__send_sync (g, GUESTFS_PROC_PVCREATE,
2999 (xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
3003 guestfs__switch_to_receiving (g);
3004 ctx.cb_sequence = 0;
3005 guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx);
3006 (void) ml->main_loop_run (ml, g);
3007 guestfs_set_reply_callback (g, NULL, NULL);
3008 if (ctx.cb_sequence != 1001) {
3009 error (g, "%s reply failed, see earlier error messages", "guestfs_pvcreate");
3013 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVCREATE, serial) == -1)
3016 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3017 error (g, "%s", ctx.err.error_message);
3024 struct vgcreate_ctx {
3025 /* This flag is set by the callbacks, so we know we've done
3026 * the callbacks as expected, and in the right sequence.
3027 * 0 = not called, 1 = send called,
3028 * 1001 = reply called.
3031 struct guestfs_message_header hdr;
3032 struct guestfs_message_error err;
3035 static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3037 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3038 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3040 ml->main_loop_quit (ml, g);
3042 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3043 error (g, "%s: failed to parse reply header", "guestfs_vgcreate");
3046 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3047 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3048 error (g, "%s: failed to parse reply error", "guestfs_vgcreate");
3054 ctx->cb_sequence = 1001;
3057 int guestfs_vgcreate (guestfs_h *g,
3058 const char *volgroup,
3059 char * const* const physvols)
3061 struct guestfs_vgcreate_args args;
3062 struct vgcreate_ctx ctx;
3063 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3066 if (check_state (g, "guestfs_vgcreate") == -1) return -1;
3068 memset (&ctx, 0, sizeof ctx);
3070 args.volgroup = (char *) volgroup;
3071 args.physvols.physvols_val = (char **) physvols;
3072 for (args.physvols.physvols_len = 0; physvols[args.physvols.physvols_len]; args.physvols.physvols_len++) ;
3073 serial = guestfs__send_sync (g, GUESTFS_PROC_VGCREATE,
3074 (xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
3078 guestfs__switch_to_receiving (g);
3079 ctx.cb_sequence = 0;
3080 guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx);
3081 (void) ml->main_loop_run (ml, g);
3082 guestfs_set_reply_callback (g, NULL, NULL);
3083 if (ctx.cb_sequence != 1001) {
3084 error (g, "%s reply failed, see earlier error messages", "guestfs_vgcreate");
3088 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGCREATE, serial) == -1)
3091 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3092 error (g, "%s", ctx.err.error_message);
3099 struct lvcreate_ctx {
3100 /* This flag is set by the callbacks, so we know we've done
3101 * the callbacks as expected, and in the right sequence.
3102 * 0 = not called, 1 = send called,
3103 * 1001 = reply called.
3106 struct guestfs_message_header hdr;
3107 struct guestfs_message_error err;
3110 static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3112 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3113 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3115 ml->main_loop_quit (ml, g);
3117 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3118 error (g, "%s: failed to parse reply header", "guestfs_lvcreate");
3121 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3122 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3123 error (g, "%s: failed to parse reply error", "guestfs_lvcreate");
3129 ctx->cb_sequence = 1001;
3132 int guestfs_lvcreate (guestfs_h *g,
3134 const char *volgroup,
3137 struct guestfs_lvcreate_args args;
3138 struct lvcreate_ctx ctx;
3139 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3142 if (check_state (g, "guestfs_lvcreate") == -1) return -1;
3144 memset (&ctx, 0, sizeof ctx);
3146 args.logvol = (char *) logvol;
3147 args.volgroup = (char *) volgroup;
3148 args.mbytes = mbytes;
3149 serial = guestfs__send_sync (g, GUESTFS_PROC_LVCREATE,
3150 (xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
3154 guestfs__switch_to_receiving (g);
3155 ctx.cb_sequence = 0;
3156 guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx);
3157 (void) ml->main_loop_run (ml, g);
3158 guestfs_set_reply_callback (g, NULL, NULL);
3159 if (ctx.cb_sequence != 1001) {
3160 error (g, "%s reply failed, see earlier error messages", "guestfs_lvcreate");
3164 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVCREATE, serial) == -1)
3167 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3168 error (g, "%s", ctx.err.error_message);
3176 /* This flag is set by the callbacks, so we know we've done
3177 * the callbacks as expected, and in the right sequence.
3178 * 0 = not called, 1 = send called,
3179 * 1001 = reply called.
3182 struct guestfs_message_header hdr;
3183 struct guestfs_message_error err;
3186 static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3188 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3189 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3191 ml->main_loop_quit (ml, g);
3193 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3194 error (g, "%s: failed to parse reply header", "guestfs_mkfs");
3197 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3198 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3199 error (g, "%s: failed to parse reply error", "guestfs_mkfs");
3205 ctx->cb_sequence = 1001;
3208 int guestfs_mkfs (guestfs_h *g,
3212 struct guestfs_mkfs_args args;
3213 struct mkfs_ctx ctx;
3214 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3217 if (check_state (g, "guestfs_mkfs") == -1) return -1;
3219 memset (&ctx, 0, sizeof ctx);
3221 args.fstype = (char *) fstype;
3222 args.device = (char *) device;
3223 serial = guestfs__send_sync (g, GUESTFS_PROC_MKFS,
3224 (xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
3228 guestfs__switch_to_receiving (g);
3229 ctx.cb_sequence = 0;
3230 guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx);
3231 (void) ml->main_loop_run (ml, g);
3232 guestfs_set_reply_callback (g, NULL, NULL);
3233 if (ctx.cb_sequence != 1001) {
3234 error (g, "%s reply failed, see earlier error messages", "guestfs_mkfs");
3238 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFS, serial) == -1)
3241 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3242 error (g, "%s", ctx.err.error_message);
3250 /* This flag is set by the callbacks, so we know we've done
3251 * the callbacks as expected, and in the right sequence.
3252 * 0 = not called, 1 = send called,
3253 * 1001 = reply called.
3256 struct guestfs_message_header hdr;
3257 struct guestfs_message_error err;
3260 static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3262 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3263 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
3265 ml->main_loop_quit (ml, g);
3267 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3268 error (g, "%s: failed to parse reply header", "guestfs_sfdisk");
3271 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3272 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3273 error (g, "%s: failed to parse reply error", "guestfs_sfdisk");
3279 ctx->cb_sequence = 1001;
3282 int guestfs_sfdisk (guestfs_h *g,
3287 char * const* const lines)
3289 struct guestfs_sfdisk_args args;
3290 struct sfdisk_ctx ctx;
3291 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3294 if (check_state (g, "guestfs_sfdisk") == -1) return -1;
3296 memset (&ctx, 0, sizeof ctx);
3298 args.device = (char *) device;
3301 args.sectors = sectors;
3302 args.lines.lines_val = (char **) lines;
3303 for (args.lines.lines_len = 0; lines[args.lines.lines_len]; args.lines.lines_len++) ;
3304 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK,
3305 (xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
3309 guestfs__switch_to_receiving (g);
3310 ctx.cb_sequence = 0;
3311 guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx);
3312 (void) ml->main_loop_run (ml, g);
3313 guestfs_set_reply_callback (g, NULL, NULL);
3314 if (ctx.cb_sequence != 1001) {
3315 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk");
3319 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK, serial) == -1)
3322 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3323 error (g, "%s", ctx.err.error_message);
3330 struct write_file_ctx {
3331 /* This flag is set by the callbacks, so we know we've done
3332 * the callbacks as expected, and in the right sequence.
3333 * 0 = not called, 1 = send called,
3334 * 1001 = reply called.
3337 struct guestfs_message_header hdr;
3338 struct guestfs_message_error err;
3341 static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3343 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3344 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
3346 ml->main_loop_quit (ml, g);
3348 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3349 error (g, "%s: failed to parse reply header", "guestfs_write_file");
3352 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3353 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3354 error (g, "%s: failed to parse reply error", "guestfs_write_file");
3360 ctx->cb_sequence = 1001;
3363 int guestfs_write_file (guestfs_h *g,
3365 const char *content,
3368 struct guestfs_write_file_args args;
3369 struct write_file_ctx ctx;
3370 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3373 if (check_state (g, "guestfs_write_file") == -1) return -1;
3375 memset (&ctx, 0, sizeof ctx);
3377 args.path = (char *) path;
3378 args.content = (char *) content;
3380 serial = guestfs__send_sync (g, GUESTFS_PROC_WRITE_FILE,
3381 (xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
3385 guestfs__switch_to_receiving (g);
3386 ctx.cb_sequence = 0;
3387 guestfs_set_reply_callback (g, write_file_reply_cb, &ctx);
3388 (void) ml->main_loop_run (ml, g);
3389 guestfs_set_reply_callback (g, NULL, NULL);
3390 if (ctx.cb_sequence != 1001) {
3391 error (g, "%s reply failed, see earlier error messages", "guestfs_write_file");
3395 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WRITE_FILE, serial) == -1)
3398 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3399 error (g, "%s", ctx.err.error_message);
3407 /* This flag is set by the callbacks, so we know we've done
3408 * the callbacks as expected, and in the right sequence.
3409 * 0 = not called, 1 = send called,
3410 * 1001 = reply called.
3413 struct guestfs_message_header hdr;
3414 struct guestfs_message_error err;
3417 static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3419 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3420 struct umount_ctx *ctx = (struct umount_ctx *) data;
3422 ml->main_loop_quit (ml, g);
3424 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3425 error (g, "%s: failed to parse reply header", "guestfs_umount");
3428 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3429 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3430 error (g, "%s: failed to parse reply error", "guestfs_umount");
3436 ctx->cb_sequence = 1001;
3439 int guestfs_umount (guestfs_h *g,
3440 const char *pathordevice)
3442 struct guestfs_umount_args args;
3443 struct umount_ctx ctx;
3444 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3447 if (check_state (g, "guestfs_umount") == -1) return -1;
3449 memset (&ctx, 0, sizeof ctx);
3451 args.pathordevice = (char *) pathordevice;
3452 serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT,
3453 (xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
3457 guestfs__switch_to_receiving (g);
3458 ctx.cb_sequence = 0;
3459 guestfs_set_reply_callback (g, umount_reply_cb, &ctx);
3460 (void) ml->main_loop_run (ml, g);
3461 guestfs_set_reply_callback (g, NULL, NULL);
3462 if (ctx.cb_sequence != 1001) {
3463 error (g, "%s reply failed, see earlier error messages", "guestfs_umount");
3467 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT, serial) == -1)
3470 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3471 error (g, "%s", ctx.err.error_message);
3479 /* This flag is set by the callbacks, so we know we've done
3480 * the callbacks as expected, and in the right sequence.
3481 * 0 = not called, 1 = send called,
3482 * 1001 = reply called.
3485 struct guestfs_message_header hdr;
3486 struct guestfs_message_error err;
3487 struct guestfs_mounts_ret ret;
3490 static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3492 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3493 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
3495 ml->main_loop_quit (ml, g);
3497 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3498 error (g, "%s: failed to parse reply header", "guestfs_mounts");
3501 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3502 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3503 error (g, "%s: failed to parse reply error", "guestfs_mounts");
3508 if (!xdr_guestfs_mounts_ret (xdr, &ctx->ret)) {
3509 error (g, "%s: failed to parse reply", "guestfs_mounts");
3513 ctx->cb_sequence = 1001;
3516 char **guestfs_mounts (guestfs_h *g)
3518 struct mounts_ctx ctx;
3519 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3522 if (check_state (g, "guestfs_mounts") == -1) return NULL;
3524 memset (&ctx, 0, sizeof ctx);
3526 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNTS, NULL, NULL);
3530 guestfs__switch_to_receiving (g);
3531 ctx.cb_sequence = 0;
3532 guestfs_set_reply_callback (g, mounts_reply_cb, &ctx);
3533 (void) ml->main_loop_run (ml, g);
3534 guestfs_set_reply_callback (g, NULL, NULL);
3535 if (ctx.cb_sequence != 1001) {
3536 error (g, "%s reply failed, see earlier error messages", "guestfs_mounts");
3540 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNTS, serial) == -1)
3543 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3544 error (g, "%s", ctx.err.error_message);
3548 /* caller will free this, but we need to add a NULL entry */
3549 ctx.ret.devices.devices_val =
3550 safe_realloc (g, ctx.ret.devices.devices_val,
3551 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
3552 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
3553 return ctx.ret.devices.devices_val;
3556 struct umount_all_ctx {
3557 /* This flag is set by the callbacks, so we know we've done
3558 * the callbacks as expected, and in the right sequence.
3559 * 0 = not called, 1 = send called,
3560 * 1001 = reply called.
3563 struct guestfs_message_header hdr;
3564 struct guestfs_message_error err;
3567 static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3569 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3570 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
3572 ml->main_loop_quit (ml, g);
3574 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3575 error (g, "%s: failed to parse reply header", "guestfs_umount_all");
3578 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3579 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3580 error (g, "%s: failed to parse reply error", "guestfs_umount_all");
3586 ctx->cb_sequence = 1001;
3589 int guestfs_umount_all (guestfs_h *g)
3591 struct umount_all_ctx ctx;
3592 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3595 if (check_state (g, "guestfs_umount_all") == -1) return -1;
3597 memset (&ctx, 0, sizeof ctx);
3599 serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT_ALL, NULL, NULL);
3603 guestfs__switch_to_receiving (g);
3604 ctx.cb_sequence = 0;
3605 guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx);
3606 (void) ml->main_loop_run (ml, g);
3607 guestfs_set_reply_callback (g, NULL, NULL);
3608 if (ctx.cb_sequence != 1001) {
3609 error (g, "%s reply failed, see earlier error messages", "guestfs_umount_all");
3613 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT_ALL, serial) == -1)
3616 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3617 error (g, "%s", ctx.err.error_message);
3624 struct lvm_remove_all_ctx {
3625 /* This flag is set by the callbacks, so we know we've done
3626 * the callbacks as expected, and in the right sequence.
3627 * 0 = not called, 1 = send called,
3628 * 1001 = reply called.
3631 struct guestfs_message_header hdr;
3632 struct guestfs_message_error err;
3635 static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3637 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3638 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
3640 ml->main_loop_quit (ml, g);
3642 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3643 error (g, "%s: failed to parse reply header", "guestfs_lvm_remove_all");
3646 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3647 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3648 error (g, "%s: failed to parse reply error", "guestfs_lvm_remove_all");
3654 ctx->cb_sequence = 1001;
3657 int guestfs_lvm_remove_all (guestfs_h *g)
3659 struct lvm_remove_all_ctx ctx;
3660 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3663 if (check_state (g, "guestfs_lvm_remove_all") == -1) return -1;
3665 memset (&ctx, 0, sizeof ctx);
3667 serial = guestfs__send_sync (g, GUESTFS_PROC_LVM_REMOVE_ALL, NULL, NULL);
3671 guestfs__switch_to_receiving (g);
3672 ctx.cb_sequence = 0;
3673 guestfs_set_reply_callback (g, lvm_remove_all_reply_cb, &ctx);
3674 (void) ml->main_loop_run (ml, g);
3675 guestfs_set_reply_callback (g, NULL, NULL);
3676 if (ctx.cb_sequence != 1001) {
3677 error (g, "%s reply failed, see earlier error messages", "guestfs_lvm_remove_all");
3681 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVM_REMOVE_ALL, serial) == -1)
3684 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3685 error (g, "%s", ctx.err.error_message);
3693 /* This flag is set by the callbacks, so we know we've done
3694 * the callbacks as expected, and in the right sequence.
3695 * 0 = not called, 1 = send called,
3696 * 1001 = reply called.
3699 struct guestfs_message_header hdr;
3700 struct guestfs_message_error err;
3701 struct guestfs_file_ret ret;
3704 static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3706 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3707 struct file_ctx *ctx = (struct file_ctx *) data;
3709 ml->main_loop_quit (ml, g);
3711 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3712 error (g, "%s: failed to parse reply header", "guestfs_file");
3715 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3716 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3717 error (g, "%s: failed to parse reply error", "guestfs_file");
3722 if (!xdr_guestfs_file_ret (xdr, &ctx->ret)) {
3723 error (g, "%s: failed to parse reply", "guestfs_file");
3727 ctx->cb_sequence = 1001;
3730 char *guestfs_file (guestfs_h *g,
3733 struct guestfs_file_args args;
3734 struct file_ctx ctx;
3735 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3738 if (check_state (g, "guestfs_file") == -1) return NULL;
3740 memset (&ctx, 0, sizeof ctx);
3742 args.path = (char *) path;
3743 serial = guestfs__send_sync (g, GUESTFS_PROC_FILE,
3744 (xdrproc_t) xdr_guestfs_file_args, (char *) &args);
3748 guestfs__switch_to_receiving (g);
3749 ctx.cb_sequence = 0;
3750 guestfs_set_reply_callback (g, file_reply_cb, &ctx);
3751 (void) ml->main_loop_run (ml, g);
3752 guestfs_set_reply_callback (g, NULL, NULL);
3753 if (ctx.cb_sequence != 1001) {
3754 error (g, "%s reply failed, see earlier error messages", "guestfs_file");
3758 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FILE, serial) == -1)
3761 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3762 error (g, "%s", ctx.err.error_message);
3766 return ctx.ret.description; /* caller will free */
3769 struct command_ctx {
3770 /* This flag is set by the callbacks, so we know we've done
3771 * the callbacks as expected, and in the right sequence.
3772 * 0 = not called, 1 = send called,
3773 * 1001 = reply called.
3776 struct guestfs_message_header hdr;
3777 struct guestfs_message_error err;
3778 struct guestfs_command_ret ret;
3781 static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3783 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3784 struct command_ctx *ctx = (struct command_ctx *) data;
3786 ml->main_loop_quit (ml, g);
3788 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3789 error (g, "%s: failed to parse reply header", "guestfs_command");
3792 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3793 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3794 error (g, "%s: failed to parse reply error", "guestfs_command");
3799 if (!xdr_guestfs_command_ret (xdr, &ctx->ret)) {
3800 error (g, "%s: failed to parse reply", "guestfs_command");
3804 ctx->cb_sequence = 1001;
3807 char *guestfs_command (guestfs_h *g,
3808 char * const* const arguments)
3810 struct guestfs_command_args args;
3811 struct command_ctx ctx;
3812 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3815 if (check_state (g, "guestfs_command") == -1) return NULL;
3817 memset (&ctx, 0, sizeof ctx);
3819 args.arguments.arguments_val = (char **) arguments;
3820 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
3821 serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND,
3822 (xdrproc_t) xdr_guestfs_command_args, (char *) &args);
3826 guestfs__switch_to_receiving (g);
3827 ctx.cb_sequence = 0;
3828 guestfs_set_reply_callback (g, command_reply_cb, &ctx);
3829 (void) ml->main_loop_run (ml, g);
3830 guestfs_set_reply_callback (g, NULL, NULL);
3831 if (ctx.cb_sequence != 1001) {
3832 error (g, "%s reply failed, see earlier error messages", "guestfs_command");
3836 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND, serial) == -1)
3839 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3840 error (g, "%s", ctx.err.error_message);
3844 return ctx.ret.output; /* caller will free */
3847 struct command_lines_ctx {
3848 /* This flag is set by the callbacks, so we know we've done
3849 * the callbacks as expected, and in the right sequence.
3850 * 0 = not called, 1 = send called,
3851 * 1001 = reply called.
3854 struct guestfs_message_header hdr;
3855 struct guestfs_message_error err;
3856 struct guestfs_command_lines_ret ret;
3859 static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3861 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3862 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
3864 ml->main_loop_quit (ml, g);
3866 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3867 error (g, "%s: failed to parse reply header", "guestfs_command_lines");
3870 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3871 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3872 error (g, "%s: failed to parse reply error", "guestfs_command_lines");
3877 if (!xdr_guestfs_command_lines_ret (xdr, &ctx->ret)) {
3878 error (g, "%s: failed to parse reply", "guestfs_command_lines");
3882 ctx->cb_sequence = 1001;
3885 char **guestfs_command_lines (guestfs_h *g,
3886 char * const* const arguments)
3888 struct guestfs_command_lines_args args;
3889 struct command_lines_ctx ctx;
3890 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3893 if (check_state (g, "guestfs_command_lines") == -1) return NULL;
3895 memset (&ctx, 0, sizeof ctx);
3897 args.arguments.arguments_val = (char **) arguments;
3898 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
3899 serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND_LINES,
3900 (xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args);
3904 guestfs__switch_to_receiving (g);
3905 ctx.cb_sequence = 0;
3906 guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx);
3907 (void) ml->main_loop_run (ml, g);
3908 guestfs_set_reply_callback (g, NULL, NULL);
3909 if (ctx.cb_sequence != 1001) {
3910 error (g, "%s reply failed, see earlier error messages", "guestfs_command_lines");
3914 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND_LINES, serial) == -1)
3917 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3918 error (g, "%s", ctx.err.error_message);
3922 /* caller will free this, but we need to add a NULL entry */
3923 ctx.ret.lines.lines_val =
3924 safe_realloc (g, ctx.ret.lines.lines_val,
3925 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
3926 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
3927 return ctx.ret.lines.lines_val;
3931 /* This flag is set by the callbacks, so we know we've done
3932 * the callbacks as expected, and in the right sequence.
3933 * 0 = not called, 1 = send called,
3934 * 1001 = reply called.
3937 struct guestfs_message_header hdr;
3938 struct guestfs_message_error err;
3939 struct guestfs_stat_ret ret;
3942 static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3944 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3945 struct stat_ctx *ctx = (struct stat_ctx *) data;
3947 ml->main_loop_quit (ml, g);
3949 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3950 error (g, "%s: failed to parse reply header", "guestfs_stat");
3953 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3954 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3955 error (g, "%s: failed to parse reply error", "guestfs_stat");
3960 if (!xdr_guestfs_stat_ret (xdr, &ctx->ret)) {
3961 error (g, "%s: failed to parse reply", "guestfs_stat");
3965 ctx->cb_sequence = 1001;
3968 struct guestfs_stat *guestfs_stat (guestfs_h *g,
3971 struct guestfs_stat_args args;
3972 struct stat_ctx ctx;
3973 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3976 if (check_state (g, "guestfs_stat") == -1) return NULL;
3978 memset (&ctx, 0, sizeof ctx);
3980 args.path = (char *) path;
3981 serial = guestfs__send_sync (g, GUESTFS_PROC_STAT,
3982 (xdrproc_t) xdr_guestfs_stat_args, (char *) &args);
3986 guestfs__switch_to_receiving (g);
3987 ctx.cb_sequence = 0;
3988 guestfs_set_reply_callback (g, stat_reply_cb, &ctx);
3989 (void) ml->main_loop_run (ml, g);
3990 guestfs_set_reply_callback (g, NULL, NULL);
3991 if (ctx.cb_sequence != 1001) {
3992 error (g, "%s reply failed, see earlier error messages", "guestfs_stat");
3996 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STAT, serial) == -1)
3999 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4000 error (g, "%s", ctx.err.error_message);
4004 /* caller will free this */
4005 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4009 /* This flag is set by the callbacks, so we know we've done
4010 * the callbacks as expected, and in the right sequence.
4011 * 0 = not called, 1 = send called,
4012 * 1001 = reply called.
4015 struct guestfs_message_header hdr;
4016 struct guestfs_message_error err;
4017 struct guestfs_lstat_ret ret;
4020 static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4022 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4023 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4025 ml->main_loop_quit (ml, g);
4027 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4028 error (g, "%s: failed to parse reply header", "guestfs_lstat");
4031 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4032 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4033 error (g, "%s: failed to parse reply error", "guestfs_lstat");
4038 if (!xdr_guestfs_lstat_ret (xdr, &ctx->ret)) {
4039 error (g, "%s: failed to parse reply", "guestfs_lstat");
4043 ctx->cb_sequence = 1001;
4046 struct guestfs_stat *guestfs_lstat (guestfs_h *g,
4049 struct guestfs_lstat_args args;
4050 struct lstat_ctx ctx;
4051 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4054 if (check_state (g, "guestfs_lstat") == -1) return NULL;
4056 memset (&ctx, 0, sizeof ctx);
4058 args.path = (char *) path;
4059 serial = guestfs__send_sync (g, GUESTFS_PROC_LSTAT,
4060 (xdrproc_t) xdr_guestfs_lstat_args, (char *) &args);
4064 guestfs__switch_to_receiving (g);
4065 ctx.cb_sequence = 0;
4066 guestfs_set_reply_callback (g, lstat_reply_cb, &ctx);
4067 (void) ml->main_loop_run (ml, g);
4068 guestfs_set_reply_callback (g, NULL, NULL);
4069 if (ctx.cb_sequence != 1001) {
4070 error (g, "%s reply failed, see earlier error messages", "guestfs_lstat");
4074 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LSTAT, serial) == -1)
4077 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4078 error (g, "%s", ctx.err.error_message);
4082 /* caller will free this */
4083 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4086 struct statvfs_ctx {
4087 /* This flag is set by the callbacks, so we know we've done
4088 * the callbacks as expected, and in the right sequence.
4089 * 0 = not called, 1 = send called,
4090 * 1001 = reply called.
4093 struct guestfs_message_header hdr;
4094 struct guestfs_message_error err;
4095 struct guestfs_statvfs_ret ret;
4098 static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4100 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4101 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
4103 ml->main_loop_quit (ml, g);
4105 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4106 error (g, "%s: failed to parse reply header", "guestfs_statvfs");
4109 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4110 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4111 error (g, "%s: failed to parse reply error", "guestfs_statvfs");
4116 if (!xdr_guestfs_statvfs_ret (xdr, &ctx->ret)) {
4117 error (g, "%s: failed to parse reply", "guestfs_statvfs");
4121 ctx->cb_sequence = 1001;
4124 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
4127 struct guestfs_statvfs_args args;
4128 struct statvfs_ctx ctx;
4129 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4132 if (check_state (g, "guestfs_statvfs") == -1) return NULL;
4134 memset (&ctx, 0, sizeof ctx);
4136 args.path = (char *) path;
4137 serial = guestfs__send_sync (g, GUESTFS_PROC_STATVFS,
4138 (xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args);
4142 guestfs__switch_to_receiving (g);
4143 ctx.cb_sequence = 0;
4144 guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx);
4145 (void) ml->main_loop_run (ml, g);
4146 guestfs_set_reply_callback (g, NULL, NULL);
4147 if (ctx.cb_sequence != 1001) {
4148 error (g, "%s reply failed, see earlier error messages", "guestfs_statvfs");
4152 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STATVFS, serial) == -1)
4155 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4156 error (g, "%s", ctx.err.error_message);
4160 /* caller will free this */
4161 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4164 struct tune2fs_l_ctx {
4165 /* This flag is set by the callbacks, so we know we've done
4166 * the callbacks as expected, and in the right sequence.
4167 * 0 = not called, 1 = send called,
4168 * 1001 = reply called.
4171 struct guestfs_message_header hdr;
4172 struct guestfs_message_error err;
4173 struct guestfs_tune2fs_l_ret ret;
4176 static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4178 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4179 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
4181 ml->main_loop_quit (ml, g);
4183 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4184 error (g, "%s: failed to parse reply header", "guestfs_tune2fs_l");
4187 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4188 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4189 error (g, "%s: failed to parse reply error", "guestfs_tune2fs_l");
4194 if (!xdr_guestfs_tune2fs_l_ret (xdr, &ctx->ret)) {
4195 error (g, "%s: failed to parse reply", "guestfs_tune2fs_l");
4199 ctx->cb_sequence = 1001;
4202 char **guestfs_tune2fs_l (guestfs_h *g,
4205 struct guestfs_tune2fs_l_args args;
4206 struct tune2fs_l_ctx ctx;
4207 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4210 if (check_state (g, "guestfs_tune2fs_l") == -1) return NULL;
4212 memset (&ctx, 0, sizeof ctx);
4214 args.device = (char *) device;
4215 serial = guestfs__send_sync (g, GUESTFS_PROC_TUNE2FS_L,
4216 (xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args);
4220 guestfs__switch_to_receiving (g);
4221 ctx.cb_sequence = 0;
4222 guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx);
4223 (void) ml->main_loop_run (ml, g);
4224 guestfs_set_reply_callback (g, NULL, NULL);
4225 if (ctx.cb_sequence != 1001) {
4226 error (g, "%s reply failed, see earlier error messages", "guestfs_tune2fs_l");
4230 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TUNE2FS_L, serial) == -1)
4233 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4234 error (g, "%s", ctx.err.error_message);
4238 /* caller will free this, but we need to add a NULL entry */
4239 ctx.ret.superblock.superblock_val =
4240 safe_realloc (g, ctx.ret.superblock.superblock_val,
4241 sizeof (char *) * (ctx.ret.superblock.superblock_len + 1));
4242 ctx.ret.superblock.superblock_val[ctx.ret.superblock.superblock_len] = NULL;
4243 return ctx.ret.superblock.superblock_val;
4246 struct blockdev_setro_ctx {
4247 /* This flag is set by the callbacks, so we know we've done
4248 * the callbacks as expected, and in the right sequence.
4249 * 0 = not called, 1 = send called,
4250 * 1001 = reply called.
4253 struct guestfs_message_header hdr;
4254 struct guestfs_message_error err;
4257 static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4259 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4260 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
4262 ml->main_loop_quit (ml, g);
4264 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4265 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setro");
4268 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4269 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4270 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setro");
4276 ctx->cb_sequence = 1001;
4279 int guestfs_blockdev_setro (guestfs_h *g,
4282 struct guestfs_blockdev_setro_args args;
4283 struct blockdev_setro_ctx ctx;
4284 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4287 if (check_state (g, "guestfs_blockdev_setro") == -1) return -1;
4289 memset (&ctx, 0, sizeof ctx);
4291 args.device = (char *) device;
4292 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRO,
4293 (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args);
4297 guestfs__switch_to_receiving (g);
4298 ctx.cb_sequence = 0;
4299 guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx);
4300 (void) ml->main_loop_run (ml, g);
4301 guestfs_set_reply_callback (g, NULL, NULL);
4302 if (ctx.cb_sequence != 1001) {
4303 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setro");
4307 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1)
4310 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4311 error (g, "%s", ctx.err.error_message);
4318 struct blockdev_setrw_ctx {
4319 /* This flag is set by the callbacks, so we know we've done
4320 * the callbacks as expected, and in the right sequence.
4321 * 0 = not called, 1 = send called,
4322 * 1001 = reply called.
4325 struct guestfs_message_header hdr;
4326 struct guestfs_message_error err;
4329 static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4331 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4332 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
4334 ml->main_loop_quit (ml, g);
4336 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4337 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setrw");
4340 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4341 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4342 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setrw");
4348 ctx->cb_sequence = 1001;
4351 int guestfs_blockdev_setrw (guestfs_h *g,
4354 struct guestfs_blockdev_setrw_args args;
4355 struct blockdev_setrw_ctx ctx;
4356 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4359 if (check_state (g, "guestfs_blockdev_setrw") == -1) return -1;
4361 memset (&ctx, 0, sizeof ctx);
4363 args.device = (char *) device;
4364 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRW,
4365 (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args);
4369 guestfs__switch_to_receiving (g);
4370 ctx.cb_sequence = 0;
4371 guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx);
4372 (void) ml->main_loop_run (ml, g);
4373 guestfs_set_reply_callback (g, NULL, NULL);
4374 if (ctx.cb_sequence != 1001) {
4375 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setrw");
4379 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1)
4382 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4383 error (g, "%s", ctx.err.error_message);
4390 struct blockdev_getro_ctx {
4391 /* This flag is set by the callbacks, so we know we've done
4392 * the callbacks as expected, and in the right sequence.
4393 * 0 = not called, 1 = send called,
4394 * 1001 = reply called.
4397 struct guestfs_message_header hdr;
4398 struct guestfs_message_error err;
4399 struct guestfs_blockdev_getro_ret ret;
4402 static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4404 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4405 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
4407 ml->main_loop_quit (ml, g);
4409 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4410 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getro");
4413 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4414 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4415 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getro");
4420 if (!xdr_guestfs_blockdev_getro_ret (xdr, &ctx->ret)) {
4421 error (g, "%s: failed to parse reply", "guestfs_blockdev_getro");
4425 ctx->cb_sequence = 1001;
4428 int guestfs_blockdev_getro (guestfs_h *g,
4431 struct guestfs_blockdev_getro_args args;
4432 struct blockdev_getro_ctx ctx;
4433 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4436 if (check_state (g, "guestfs_blockdev_getro") == -1) return -1;
4438 memset (&ctx, 0, sizeof ctx);
4440 args.device = (char *) device;
4441 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETRO,
4442 (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args);
4446 guestfs__switch_to_receiving (g);
4447 ctx.cb_sequence = 0;
4448 guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx);
4449 (void) ml->main_loop_run (ml, g);
4450 guestfs_set_reply_callback (g, NULL, NULL);
4451 if (ctx.cb_sequence != 1001) {
4452 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getro");
4456 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1)
4459 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4460 error (g, "%s", ctx.err.error_message);
4467 struct blockdev_getss_ctx {
4468 /* This flag is set by the callbacks, so we know we've done
4469 * the callbacks as expected, and in the right sequence.
4470 * 0 = not called, 1 = send called,
4471 * 1001 = reply called.
4474 struct guestfs_message_header hdr;
4475 struct guestfs_message_error err;
4476 struct guestfs_blockdev_getss_ret ret;
4479 static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4481 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4482 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
4484 ml->main_loop_quit (ml, g);
4486 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4487 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getss");
4490 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4491 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4492 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getss");
4497 if (!xdr_guestfs_blockdev_getss_ret (xdr, &ctx->ret)) {
4498 error (g, "%s: failed to parse reply", "guestfs_blockdev_getss");
4502 ctx->cb_sequence = 1001;
4505 int guestfs_blockdev_getss (guestfs_h *g,
4508 struct guestfs_blockdev_getss_args args;
4509 struct blockdev_getss_ctx ctx;
4510 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4513 if (check_state (g, "guestfs_blockdev_getss") == -1) return -1;
4515 memset (&ctx, 0, sizeof ctx);
4517 args.device = (char *) device;
4518 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSS,
4519 (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args);
4523 guestfs__switch_to_receiving (g);
4524 ctx.cb_sequence = 0;
4525 guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx);
4526 (void) ml->main_loop_run (ml, g);
4527 guestfs_set_reply_callback (g, NULL, NULL);
4528 if (ctx.cb_sequence != 1001) {
4529 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getss");
4533 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1)
4536 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4537 error (g, "%s", ctx.err.error_message);
4541 return ctx.ret.sectorsize;
4544 struct blockdev_getbsz_ctx {
4545 /* This flag is set by the callbacks, so we know we've done
4546 * the callbacks as expected, and in the right sequence.
4547 * 0 = not called, 1 = send called,
4548 * 1001 = reply called.
4551 struct guestfs_message_header hdr;
4552 struct guestfs_message_error err;
4553 struct guestfs_blockdev_getbsz_ret ret;
4556 static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4558 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4559 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
4561 ml->main_loop_quit (ml, g);
4563 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4564 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getbsz");
4567 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4568 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4569 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getbsz");
4574 if (!xdr_guestfs_blockdev_getbsz_ret (xdr, &ctx->ret)) {
4575 error (g, "%s: failed to parse reply", "guestfs_blockdev_getbsz");
4579 ctx->cb_sequence = 1001;
4582 int guestfs_blockdev_getbsz (guestfs_h *g,
4585 struct guestfs_blockdev_getbsz_args args;
4586 struct blockdev_getbsz_ctx ctx;
4587 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4590 if (check_state (g, "guestfs_blockdev_getbsz") == -1) return -1;
4592 memset (&ctx, 0, sizeof ctx);
4594 args.device = (char *) device;
4595 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETBSZ,
4596 (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args);
4600 guestfs__switch_to_receiving (g);
4601 ctx.cb_sequence = 0;
4602 guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx);
4603 (void) ml->main_loop_run (ml, g);
4604 guestfs_set_reply_callback (g, NULL, NULL);
4605 if (ctx.cb_sequence != 1001) {
4606 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getbsz");
4610 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1)
4613 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4614 error (g, "%s", ctx.err.error_message);
4618 return ctx.ret.blocksize;
4621 struct blockdev_setbsz_ctx {
4622 /* This flag is set by the callbacks, so we know we've done
4623 * the callbacks as expected, and in the right sequence.
4624 * 0 = not called, 1 = send called,
4625 * 1001 = reply called.
4628 struct guestfs_message_header hdr;
4629 struct guestfs_message_error err;
4632 static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4634 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4635 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
4637 ml->main_loop_quit (ml, g);
4639 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4640 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setbsz");
4643 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4644 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4645 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setbsz");
4651 ctx->cb_sequence = 1001;
4654 int guestfs_blockdev_setbsz (guestfs_h *g,
4658 struct guestfs_blockdev_setbsz_args args;
4659 struct blockdev_setbsz_ctx ctx;
4660 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4663 if (check_state (g, "guestfs_blockdev_setbsz") == -1) return -1;
4665 memset (&ctx, 0, sizeof ctx);
4667 args.device = (char *) device;
4668 args.blocksize = blocksize;
4669 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETBSZ,
4670 (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args);
4674 guestfs__switch_to_receiving (g);
4675 ctx.cb_sequence = 0;
4676 guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx);
4677 (void) ml->main_loop_run (ml, g);
4678 guestfs_set_reply_callback (g, NULL, NULL);
4679 if (ctx.cb_sequence != 1001) {
4680 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setbsz");
4684 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1)
4687 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4688 error (g, "%s", ctx.err.error_message);
4695 struct blockdev_getsz_ctx {
4696 /* This flag is set by the callbacks, so we know we've done
4697 * the callbacks as expected, and in the right sequence.
4698 * 0 = not called, 1 = send called,
4699 * 1001 = reply called.
4702 struct guestfs_message_header hdr;
4703 struct guestfs_message_error err;
4704 struct guestfs_blockdev_getsz_ret ret;
4707 static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4709 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4710 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
4712 ml->main_loop_quit (ml, g);
4714 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4715 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsz");
4718 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4719 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4720 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsz");
4725 if (!xdr_guestfs_blockdev_getsz_ret (xdr, &ctx->ret)) {
4726 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsz");
4730 ctx->cb_sequence = 1001;
4733 int64_t guestfs_blockdev_getsz (guestfs_h *g,
4736 struct guestfs_blockdev_getsz_args args;
4737 struct blockdev_getsz_ctx ctx;
4738 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4741 if (check_state (g, "guestfs_blockdev_getsz") == -1) return -1;
4743 memset (&ctx, 0, sizeof ctx);
4745 args.device = (char *) device;
4746 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSZ,
4747 (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args);
4751 guestfs__switch_to_receiving (g);
4752 ctx.cb_sequence = 0;
4753 guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx);
4754 (void) ml->main_loop_run (ml, g);
4755 guestfs_set_reply_callback (g, NULL, NULL);
4756 if (ctx.cb_sequence != 1001) {
4757 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsz");
4761 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1)
4764 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4765 error (g, "%s", ctx.err.error_message);
4769 return ctx.ret.sizeinsectors;
4772 struct blockdev_getsize64_ctx {
4773 /* This flag is set by the callbacks, so we know we've done
4774 * the callbacks as expected, and in the right sequence.
4775 * 0 = not called, 1 = send called,
4776 * 1001 = reply called.
4779 struct guestfs_message_header hdr;
4780 struct guestfs_message_error err;
4781 struct guestfs_blockdev_getsize64_ret ret;
4784 static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4786 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4787 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
4789 ml->main_loop_quit (ml, g);
4791 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4792 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsize64");
4795 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4796 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4797 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsize64");
4802 if (!xdr_guestfs_blockdev_getsize64_ret (xdr, &ctx->ret)) {
4803 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsize64");
4807 ctx->cb_sequence = 1001;
4810 int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
4813 struct guestfs_blockdev_getsize64_args args;
4814 struct blockdev_getsize64_ctx ctx;
4815 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4818 if (check_state (g, "guestfs_blockdev_getsize64") == -1) return -1;
4820 memset (&ctx, 0, sizeof ctx);
4822 args.device = (char *) device;
4823 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64,
4824 (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args);
4828 guestfs__switch_to_receiving (g);
4829 ctx.cb_sequence = 0;
4830 guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx);
4831 (void) ml->main_loop_run (ml, g);
4832 guestfs_set_reply_callback (g, NULL, NULL);
4833 if (ctx.cb_sequence != 1001) {
4834 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsize64");
4838 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1)
4841 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4842 error (g, "%s", ctx.err.error_message);
4846 return ctx.ret.sizeinbytes;
4849 struct blockdev_flushbufs_ctx {
4850 /* This flag is set by the callbacks, so we know we've done
4851 * the callbacks as expected, and in the right sequence.
4852 * 0 = not called, 1 = send called,
4853 * 1001 = reply called.
4856 struct guestfs_message_header hdr;
4857 struct guestfs_message_error err;
4860 static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4862 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4863 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
4865 ml->main_loop_quit (ml, g);
4867 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4868 error (g, "%s: failed to parse reply header", "guestfs_blockdev_flushbufs");
4871 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4872 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4873 error (g, "%s: failed to parse reply error", "guestfs_blockdev_flushbufs");
4879 ctx->cb_sequence = 1001;
4882 int guestfs_blockdev_flushbufs (guestfs_h *g,
4885 struct guestfs_blockdev_flushbufs_args args;
4886 struct blockdev_flushbufs_ctx ctx;
4887 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4890 if (check_state (g, "guestfs_blockdev_flushbufs") == -1) return -1;
4892 memset (&ctx, 0, sizeof ctx);
4894 args.device = (char *) device;
4895 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS,
4896 (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args);
4900 guestfs__switch_to_receiving (g);
4901 ctx.cb_sequence = 0;
4902 guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx);
4903 (void) ml->main_loop_run (ml, g);
4904 guestfs_set_reply_callback (g, NULL, NULL);
4905 if (ctx.cb_sequence != 1001) {
4906 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_flushbufs");
4910 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1)
4913 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4914 error (g, "%s", ctx.err.error_message);
4921 struct blockdev_rereadpt_ctx {
4922 /* This flag is set by the callbacks, so we know we've done
4923 * the callbacks as expected, and in the right sequence.
4924 * 0 = not called, 1 = send called,
4925 * 1001 = reply called.
4928 struct guestfs_message_header hdr;
4929 struct guestfs_message_error err;
4932 static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4934 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4935 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
4937 ml->main_loop_quit (ml, g);
4939 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4940 error (g, "%s: failed to parse reply header", "guestfs_blockdev_rereadpt");
4943 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4944 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4945 error (g, "%s: failed to parse reply error", "guestfs_blockdev_rereadpt");
4951 ctx->cb_sequence = 1001;
4954 int guestfs_blockdev_rereadpt (guestfs_h *g,
4957 struct guestfs_blockdev_rereadpt_args args;
4958 struct blockdev_rereadpt_ctx ctx;
4959 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4962 if (check_state (g, "guestfs_blockdev_rereadpt") == -1) return -1;
4964 memset (&ctx, 0, sizeof ctx);
4966 args.device = (char *) device;
4967 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_REREADPT,
4968 (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args);
4972 guestfs__switch_to_receiving (g);
4973 ctx.cb_sequence = 0;
4974 guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx);
4975 (void) ml->main_loop_run (ml, g);
4976 guestfs_set_reply_callback (g, NULL, NULL);
4977 if (ctx.cb_sequence != 1001) {
4978 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_rereadpt");
4982 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1)
4985 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4986 error (g, "%s", ctx.err.error_message);
4994 /* This flag is set by the callbacks, so we know we've done
4995 * the callbacks as expected, and in the right sequence.
4996 * 0 = not called, 1 = send called,
4997 * 1001 = reply called.
5000 struct guestfs_message_header hdr;
5001 struct guestfs_message_error err;
5004 static void upload_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5006 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5007 struct upload_ctx *ctx = (struct upload_ctx *) data;
5009 ml->main_loop_quit (ml, g);
5011 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5012 error (g, "%s: failed to parse reply header", "guestfs_upload");
5015 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5016 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5017 error (g, "%s: failed to parse reply error", "guestfs_upload");
5023 ctx->cb_sequence = 1001;
5026 int guestfs_upload (guestfs_h *g,
5027 const char *filename,
5028 const char *remotefilename)
5030 struct guestfs_upload_args args;
5031 struct upload_ctx ctx;
5032 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5035 if (check_state (g, "guestfs_upload") == -1) return -1;
5037 memset (&ctx, 0, sizeof ctx);
5039 args.remotefilename = (char *) remotefilename;
5040 serial = guestfs__send_sync (g, GUESTFS_PROC_UPLOAD,
5041 (xdrproc_t) xdr_guestfs_upload_args, (char *) &args);
5045 if (guestfs__send_file_sync (g, filename) == -1)
5048 guestfs__switch_to_receiving (g);
5049 ctx.cb_sequence = 0;
5050 guestfs_set_reply_callback (g, upload_reply_cb, &ctx);
5051 (void) ml->main_loop_run (ml, g);
5052 guestfs_set_reply_callback (g, NULL, NULL);
5053 if (ctx.cb_sequence != 1001) {
5054 error (g, "%s reply failed, see earlier error messages", "guestfs_upload");
5058 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UPLOAD, serial) == -1)
5061 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5062 error (g, "%s", ctx.err.error_message);
5069 struct download_ctx {
5070 /* This flag is set by the callbacks, so we know we've done
5071 * the callbacks as expected, and in the right sequence.
5072 * 0 = not called, 1 = send called,
5073 * 1001 = reply called.
5076 struct guestfs_message_header hdr;
5077 struct guestfs_message_error err;
5080 static void download_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5082 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5083 struct download_ctx *ctx = (struct download_ctx *) data;
5085 ml->main_loop_quit (ml, g);
5087 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5088 error (g, "%s: failed to parse reply header", "guestfs_download");
5091 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5092 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5093 error (g, "%s: failed to parse reply error", "guestfs_download");
5099 ctx->cb_sequence = 1001;
5102 int guestfs_download (guestfs_h *g,
5103 const char *remotefilename,
5104 const char *filename)
5106 struct guestfs_download_args args;
5107 struct download_ctx ctx;
5108 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5111 if (check_state (g, "guestfs_download") == -1) return -1;
5113 memset (&ctx, 0, sizeof ctx);
5115 args.remotefilename = (char *) remotefilename;
5116 serial = guestfs__send_sync (g, GUESTFS_PROC_DOWNLOAD,
5117 (xdrproc_t) xdr_guestfs_download_args, (char *) &args);
5121 guestfs__switch_to_receiving (g);
5122 ctx.cb_sequence = 0;
5123 guestfs_set_reply_callback (g, download_reply_cb, &ctx);
5124 (void) ml->main_loop_run (ml, g);
5125 guestfs_set_reply_callback (g, NULL, NULL);
5126 if (ctx.cb_sequence != 1001) {
5127 error (g, "%s reply failed, see earlier error messages", "guestfs_download");
5131 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DOWNLOAD, serial) == -1)
5134 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5135 error (g, "%s", ctx.err.error_message);
5139 if (guestfs__receive_file_sync (g, filename) == -1)