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 = reply_cb called.
92 struct guestfs_message_header hdr;
93 struct guestfs_message_error err;
96 static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
98 guestfs_main_loop *ml = guestfs_get_main_loop (g);
99 struct mount_ctx *ctx = (struct mount_ctx *) data;
101 /* This should definitely not happen. */
102 if (ctx->cb_sequence != 0) {
103 ctx->cb_sequence = 9999;
104 error (g, "%s: internal error: reply callback called twice", "guestfs_mount");
108 ml->main_loop_quit (ml, g);
110 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
111 error (g, "%s: failed to parse reply header", "guestfs_mount");
114 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
115 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
116 error (g, "%s: failed to parse reply error", "guestfs_mount");
122 ctx->cb_sequence = 1;
125 int guestfs_mount (guestfs_h *g,
127 const char *mountpoint)
129 struct guestfs_mount_args args;
130 struct mount_ctx ctx;
131 guestfs_main_loop *ml = guestfs_get_main_loop (g);
134 if (check_state (g, "guestfs_mount") == -1) return -1;
135 guestfs_set_busy (g);
137 memset (&ctx, 0, sizeof ctx);
139 args.device = (char *) device;
140 args.mountpoint = (char *) mountpoint;
141 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT,
142 (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
144 guestfs_end_busy (g);
148 guestfs__switch_to_receiving (g);
150 guestfs_set_reply_callback (g, mount_reply_cb, &ctx);
151 (void) ml->main_loop_run (ml, g);
152 guestfs_set_reply_callback (g, NULL, NULL);
153 if (ctx.cb_sequence != 1) {
154 error (g, "%s reply failed, see earlier error messages", "guestfs_mount");
155 guestfs_end_busy (g);
159 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT, serial) == -1) {
160 guestfs_end_busy (g);
164 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
165 error (g, "%s", ctx.err.error_message);
166 free (ctx.err.error_message);
167 guestfs_end_busy (g);
171 guestfs_end_busy (g);
176 /* This flag is set by the callbacks, so we know we've done
177 * the callbacks as expected, and in the right sequence.
178 * 0 = not called, 1 = reply_cb called.
181 struct guestfs_message_header hdr;
182 struct guestfs_message_error err;
185 static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
187 guestfs_main_loop *ml = guestfs_get_main_loop (g);
188 struct sync_ctx *ctx = (struct sync_ctx *) data;
190 /* This should definitely not happen. */
191 if (ctx->cb_sequence != 0) {
192 ctx->cb_sequence = 9999;
193 error (g, "%s: internal error: reply callback called twice", "guestfs_sync");
197 ml->main_loop_quit (ml, g);
199 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
200 error (g, "%s: failed to parse reply header", "guestfs_sync");
203 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
204 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
205 error (g, "%s: failed to parse reply error", "guestfs_sync");
211 ctx->cb_sequence = 1;
214 int guestfs_sync (guestfs_h *g)
217 guestfs_main_loop *ml = guestfs_get_main_loop (g);
220 if (check_state (g, "guestfs_sync") == -1) return -1;
221 guestfs_set_busy (g);
223 memset (&ctx, 0, sizeof ctx);
225 serial = guestfs__send_sync (g, GUESTFS_PROC_SYNC, NULL, NULL);
227 guestfs_end_busy (g);
231 guestfs__switch_to_receiving (g);
233 guestfs_set_reply_callback (g, sync_reply_cb, &ctx);
234 (void) ml->main_loop_run (ml, g);
235 guestfs_set_reply_callback (g, NULL, NULL);
236 if (ctx.cb_sequence != 1) {
237 error (g, "%s reply failed, see earlier error messages", "guestfs_sync");
238 guestfs_end_busy (g);
242 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SYNC, serial) == -1) {
243 guestfs_end_busy (g);
247 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
248 error (g, "%s", ctx.err.error_message);
249 free (ctx.err.error_message);
250 guestfs_end_busy (g);
254 guestfs_end_busy (g);
259 /* This flag is set by the callbacks, so we know we've done
260 * the callbacks as expected, and in the right sequence.
261 * 0 = not called, 1 = reply_cb called.
264 struct guestfs_message_header hdr;
265 struct guestfs_message_error err;
268 static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
270 guestfs_main_loop *ml = guestfs_get_main_loop (g);
271 struct touch_ctx *ctx = (struct touch_ctx *) data;
273 /* This should definitely not happen. */
274 if (ctx->cb_sequence != 0) {
275 ctx->cb_sequence = 9999;
276 error (g, "%s: internal error: reply callback called twice", "guestfs_touch");
280 ml->main_loop_quit (ml, g);
282 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
283 error (g, "%s: failed to parse reply header", "guestfs_touch");
286 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
287 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
288 error (g, "%s: failed to parse reply error", "guestfs_touch");
294 ctx->cb_sequence = 1;
297 int guestfs_touch (guestfs_h *g,
300 struct guestfs_touch_args args;
301 struct touch_ctx ctx;
302 guestfs_main_loop *ml = guestfs_get_main_loop (g);
305 if (check_state (g, "guestfs_touch") == -1) return -1;
306 guestfs_set_busy (g);
308 memset (&ctx, 0, sizeof ctx);
310 args.path = (char *) path;
311 serial = guestfs__send_sync (g, GUESTFS_PROC_TOUCH,
312 (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
314 guestfs_end_busy (g);
318 guestfs__switch_to_receiving (g);
320 guestfs_set_reply_callback (g, touch_reply_cb, &ctx);
321 (void) ml->main_loop_run (ml, g);
322 guestfs_set_reply_callback (g, NULL, NULL);
323 if (ctx.cb_sequence != 1) {
324 error (g, "%s reply failed, see earlier error messages", "guestfs_touch");
325 guestfs_end_busy (g);
329 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TOUCH, serial) == -1) {
330 guestfs_end_busy (g);
334 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
335 error (g, "%s", ctx.err.error_message);
336 free (ctx.err.error_message);
337 guestfs_end_busy (g);
341 guestfs_end_busy (g);
346 /* This flag is set by the callbacks, so we know we've done
347 * the callbacks as expected, and in the right sequence.
348 * 0 = not called, 1 = reply_cb called.
351 struct guestfs_message_header hdr;
352 struct guestfs_message_error err;
353 struct guestfs_cat_ret ret;
356 static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
358 guestfs_main_loop *ml = guestfs_get_main_loop (g);
359 struct cat_ctx *ctx = (struct cat_ctx *) data;
361 /* This should definitely not happen. */
362 if (ctx->cb_sequence != 0) {
363 ctx->cb_sequence = 9999;
364 error (g, "%s: internal error: reply callback called twice", "guestfs_cat");
368 ml->main_loop_quit (ml, g);
370 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
371 error (g, "%s: failed to parse reply header", "guestfs_cat");
374 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
375 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
376 error (g, "%s: failed to parse reply error", "guestfs_cat");
381 if (!xdr_guestfs_cat_ret (xdr, &ctx->ret)) {
382 error (g, "%s: failed to parse reply", "guestfs_cat");
386 ctx->cb_sequence = 1;
389 char *guestfs_cat (guestfs_h *g,
392 struct guestfs_cat_args args;
394 guestfs_main_loop *ml = guestfs_get_main_loop (g);
397 if (check_state (g, "guestfs_cat") == -1) return NULL;
398 guestfs_set_busy (g);
400 memset (&ctx, 0, sizeof ctx);
402 args.path = (char *) path;
403 serial = guestfs__send_sync (g, GUESTFS_PROC_CAT,
404 (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
406 guestfs_end_busy (g);
410 guestfs__switch_to_receiving (g);
412 guestfs_set_reply_callback (g, cat_reply_cb, &ctx);
413 (void) ml->main_loop_run (ml, g);
414 guestfs_set_reply_callback (g, NULL, NULL);
415 if (ctx.cb_sequence != 1) {
416 error (g, "%s reply failed, see earlier error messages", "guestfs_cat");
417 guestfs_end_busy (g);
421 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CAT, serial) == -1) {
422 guestfs_end_busy (g);
426 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
427 error (g, "%s", ctx.err.error_message);
428 free (ctx.err.error_message);
429 guestfs_end_busy (g);
433 guestfs_end_busy (g);
434 return ctx.ret.content; /* caller will free */
438 /* This flag is set by the callbacks, so we know we've done
439 * the callbacks as expected, and in the right sequence.
440 * 0 = not called, 1 = reply_cb called.
443 struct guestfs_message_header hdr;
444 struct guestfs_message_error err;
445 struct guestfs_ll_ret ret;
448 static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
450 guestfs_main_loop *ml = guestfs_get_main_loop (g);
451 struct ll_ctx *ctx = (struct ll_ctx *) data;
453 /* This should definitely not happen. */
454 if (ctx->cb_sequence != 0) {
455 ctx->cb_sequence = 9999;
456 error (g, "%s: internal error: reply callback called twice", "guestfs_ll");
460 ml->main_loop_quit (ml, g);
462 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
463 error (g, "%s: failed to parse reply header", "guestfs_ll");
466 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
467 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
468 error (g, "%s: failed to parse reply error", "guestfs_ll");
473 if (!xdr_guestfs_ll_ret (xdr, &ctx->ret)) {
474 error (g, "%s: failed to parse reply", "guestfs_ll");
478 ctx->cb_sequence = 1;
481 char *guestfs_ll (guestfs_h *g,
482 const char *directory)
484 struct guestfs_ll_args args;
486 guestfs_main_loop *ml = guestfs_get_main_loop (g);
489 if (check_state (g, "guestfs_ll") == -1) return NULL;
490 guestfs_set_busy (g);
492 memset (&ctx, 0, sizeof ctx);
494 args.directory = (char *) directory;
495 serial = guestfs__send_sync (g, GUESTFS_PROC_LL,
496 (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
498 guestfs_end_busy (g);
502 guestfs__switch_to_receiving (g);
504 guestfs_set_reply_callback (g, ll_reply_cb, &ctx);
505 (void) ml->main_loop_run (ml, g);
506 guestfs_set_reply_callback (g, NULL, NULL);
507 if (ctx.cb_sequence != 1) {
508 error (g, "%s reply failed, see earlier error messages", "guestfs_ll");
509 guestfs_end_busy (g);
513 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LL, serial) == -1) {
514 guestfs_end_busy (g);
518 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
519 error (g, "%s", ctx.err.error_message);
520 free (ctx.err.error_message);
521 guestfs_end_busy (g);
525 guestfs_end_busy (g);
526 return ctx.ret.listing; /* caller will free */
530 /* This flag is set by the callbacks, so we know we've done
531 * the callbacks as expected, and in the right sequence.
532 * 0 = not called, 1 = reply_cb called.
535 struct guestfs_message_header hdr;
536 struct guestfs_message_error err;
537 struct guestfs_ls_ret ret;
540 static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
542 guestfs_main_loop *ml = guestfs_get_main_loop (g);
543 struct ls_ctx *ctx = (struct ls_ctx *) data;
545 /* This should definitely not happen. */
546 if (ctx->cb_sequence != 0) {
547 ctx->cb_sequence = 9999;
548 error (g, "%s: internal error: reply callback called twice", "guestfs_ls");
552 ml->main_loop_quit (ml, g);
554 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
555 error (g, "%s: failed to parse reply header", "guestfs_ls");
558 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
559 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
560 error (g, "%s: failed to parse reply error", "guestfs_ls");
565 if (!xdr_guestfs_ls_ret (xdr, &ctx->ret)) {
566 error (g, "%s: failed to parse reply", "guestfs_ls");
570 ctx->cb_sequence = 1;
573 char **guestfs_ls (guestfs_h *g,
574 const char *directory)
576 struct guestfs_ls_args args;
578 guestfs_main_loop *ml = guestfs_get_main_loop (g);
581 if (check_state (g, "guestfs_ls") == -1) return NULL;
582 guestfs_set_busy (g);
584 memset (&ctx, 0, sizeof ctx);
586 args.directory = (char *) directory;
587 serial = guestfs__send_sync (g, GUESTFS_PROC_LS,
588 (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
590 guestfs_end_busy (g);
594 guestfs__switch_to_receiving (g);
596 guestfs_set_reply_callback (g, ls_reply_cb, &ctx);
597 (void) ml->main_loop_run (ml, g);
598 guestfs_set_reply_callback (g, NULL, NULL);
599 if (ctx.cb_sequence != 1) {
600 error (g, "%s reply failed, see earlier error messages", "guestfs_ls");
601 guestfs_end_busy (g);
605 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LS, serial) == -1) {
606 guestfs_end_busy (g);
610 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
611 error (g, "%s", ctx.err.error_message);
612 free (ctx.err.error_message);
613 guestfs_end_busy (g);
617 guestfs_end_busy (g);
618 /* caller will free this, but we need to add a NULL entry */
619 ctx.ret.listing.listing_val =
620 safe_realloc (g, ctx.ret.listing.listing_val,
621 sizeof (char *) * (ctx.ret.listing.listing_len + 1));
622 ctx.ret.listing.listing_val[ctx.ret.listing.listing_len] = NULL;
623 return ctx.ret.listing.listing_val;
626 struct list_devices_ctx {
627 /* This flag is set by the callbacks, so we know we've done
628 * the callbacks as expected, and in the right sequence.
629 * 0 = not called, 1 = reply_cb called.
632 struct guestfs_message_header hdr;
633 struct guestfs_message_error err;
634 struct guestfs_list_devices_ret ret;
637 static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
639 guestfs_main_loop *ml = guestfs_get_main_loop (g);
640 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
642 /* This should definitely not happen. */
643 if (ctx->cb_sequence != 0) {
644 ctx->cb_sequence = 9999;
645 error (g, "%s: internal error: reply callback called twice", "guestfs_list_devices");
649 ml->main_loop_quit (ml, g);
651 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
652 error (g, "%s: failed to parse reply header", "guestfs_list_devices");
655 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
656 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
657 error (g, "%s: failed to parse reply error", "guestfs_list_devices");
662 if (!xdr_guestfs_list_devices_ret (xdr, &ctx->ret)) {
663 error (g, "%s: failed to parse reply", "guestfs_list_devices");
667 ctx->cb_sequence = 1;
670 char **guestfs_list_devices (guestfs_h *g)
672 struct list_devices_ctx ctx;
673 guestfs_main_loop *ml = guestfs_get_main_loop (g);
676 if (check_state (g, "guestfs_list_devices") == -1) return NULL;
677 guestfs_set_busy (g);
679 memset (&ctx, 0, sizeof ctx);
681 serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
683 guestfs_end_busy (g);
687 guestfs__switch_to_receiving (g);
689 guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx);
690 (void) ml->main_loop_run (ml, g);
691 guestfs_set_reply_callback (g, NULL, NULL);
692 if (ctx.cb_sequence != 1) {
693 error (g, "%s reply failed, see earlier error messages", "guestfs_list_devices");
694 guestfs_end_busy (g);
698 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1) {
699 guestfs_end_busy (g);
703 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
704 error (g, "%s", ctx.err.error_message);
705 free (ctx.err.error_message);
706 guestfs_end_busy (g);
710 guestfs_end_busy (g);
711 /* caller will free this, but we need to add a NULL entry */
712 ctx.ret.devices.devices_val =
713 safe_realloc (g, ctx.ret.devices.devices_val,
714 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
715 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
716 return ctx.ret.devices.devices_val;
719 struct list_partitions_ctx {
720 /* This flag is set by the callbacks, so we know we've done
721 * the callbacks as expected, and in the right sequence.
722 * 0 = not called, 1 = reply_cb called.
725 struct guestfs_message_header hdr;
726 struct guestfs_message_error err;
727 struct guestfs_list_partitions_ret ret;
730 static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
732 guestfs_main_loop *ml = guestfs_get_main_loop (g);
733 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
735 /* This should definitely not happen. */
736 if (ctx->cb_sequence != 0) {
737 ctx->cb_sequence = 9999;
738 error (g, "%s: internal error: reply callback called twice", "guestfs_list_partitions");
742 ml->main_loop_quit (ml, g);
744 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
745 error (g, "%s: failed to parse reply header", "guestfs_list_partitions");
748 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
749 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
750 error (g, "%s: failed to parse reply error", "guestfs_list_partitions");
755 if (!xdr_guestfs_list_partitions_ret (xdr, &ctx->ret)) {
756 error (g, "%s: failed to parse reply", "guestfs_list_partitions");
760 ctx->cb_sequence = 1;
763 char **guestfs_list_partitions (guestfs_h *g)
765 struct list_partitions_ctx ctx;
766 guestfs_main_loop *ml = guestfs_get_main_loop (g);
769 if (check_state (g, "guestfs_list_partitions") == -1) return NULL;
770 guestfs_set_busy (g);
772 memset (&ctx, 0, sizeof ctx);
774 serial = guestfs__send_sync (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
776 guestfs_end_busy (g);
780 guestfs__switch_to_receiving (g);
782 guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx);
783 (void) ml->main_loop_run (ml, g);
784 guestfs_set_reply_callback (g, NULL, NULL);
785 if (ctx.cb_sequence != 1) {
786 error (g, "%s reply failed, see earlier error messages", "guestfs_list_partitions");
787 guestfs_end_busy (g);
791 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1) {
792 guestfs_end_busy (g);
796 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
797 error (g, "%s", ctx.err.error_message);
798 free (ctx.err.error_message);
799 guestfs_end_busy (g);
803 guestfs_end_busy (g);
804 /* caller will free this, but we need to add a NULL entry */
805 ctx.ret.partitions.partitions_val =
806 safe_realloc (g, ctx.ret.partitions.partitions_val,
807 sizeof (char *) * (ctx.ret.partitions.partitions_len + 1));
808 ctx.ret.partitions.partitions_val[ctx.ret.partitions.partitions_len] = NULL;
809 return ctx.ret.partitions.partitions_val;
813 /* This flag is set by the callbacks, so we know we've done
814 * the callbacks as expected, and in the right sequence.
815 * 0 = not called, 1 = reply_cb called.
818 struct guestfs_message_header hdr;
819 struct guestfs_message_error err;
820 struct guestfs_pvs_ret ret;
823 static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
825 guestfs_main_loop *ml = guestfs_get_main_loop (g);
826 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
828 /* This should definitely not happen. */
829 if (ctx->cb_sequence != 0) {
830 ctx->cb_sequence = 9999;
831 error (g, "%s: internal error: reply callback called twice", "guestfs_pvs");
835 ml->main_loop_quit (ml, g);
837 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
838 error (g, "%s: failed to parse reply header", "guestfs_pvs");
841 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
842 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
843 error (g, "%s: failed to parse reply error", "guestfs_pvs");
848 if (!xdr_guestfs_pvs_ret (xdr, &ctx->ret)) {
849 error (g, "%s: failed to parse reply", "guestfs_pvs");
853 ctx->cb_sequence = 1;
856 char **guestfs_pvs (guestfs_h *g)
859 guestfs_main_loop *ml = guestfs_get_main_loop (g);
862 if (check_state (g, "guestfs_pvs") == -1) return NULL;
863 guestfs_set_busy (g);
865 memset (&ctx, 0, sizeof ctx);
867 serial = guestfs__send_sync (g, GUESTFS_PROC_PVS, NULL, NULL);
869 guestfs_end_busy (g);
873 guestfs__switch_to_receiving (g);
875 guestfs_set_reply_callback (g, pvs_reply_cb, &ctx);
876 (void) ml->main_loop_run (ml, g);
877 guestfs_set_reply_callback (g, NULL, NULL);
878 if (ctx.cb_sequence != 1) {
879 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs");
880 guestfs_end_busy (g);
884 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS, serial) == -1) {
885 guestfs_end_busy (g);
889 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
890 error (g, "%s", ctx.err.error_message);
891 free (ctx.err.error_message);
892 guestfs_end_busy (g);
896 guestfs_end_busy (g);
897 /* caller will free this, but we need to add a NULL entry */
898 ctx.ret.physvols.physvols_val =
899 safe_realloc (g, ctx.ret.physvols.physvols_val,
900 sizeof (char *) * (ctx.ret.physvols.physvols_len + 1));
901 ctx.ret.physvols.physvols_val[ctx.ret.physvols.physvols_len] = NULL;
902 return ctx.ret.physvols.physvols_val;
906 /* This flag is set by the callbacks, so we know we've done
907 * the callbacks as expected, and in the right sequence.
908 * 0 = not called, 1 = reply_cb called.
911 struct guestfs_message_header hdr;
912 struct guestfs_message_error err;
913 struct guestfs_vgs_ret ret;
916 static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
918 guestfs_main_loop *ml = guestfs_get_main_loop (g);
919 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
921 /* This should definitely not happen. */
922 if (ctx->cb_sequence != 0) {
923 ctx->cb_sequence = 9999;
924 error (g, "%s: internal error: reply callback called twice", "guestfs_vgs");
928 ml->main_loop_quit (ml, g);
930 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
931 error (g, "%s: failed to parse reply header", "guestfs_vgs");
934 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
935 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
936 error (g, "%s: failed to parse reply error", "guestfs_vgs");
941 if (!xdr_guestfs_vgs_ret (xdr, &ctx->ret)) {
942 error (g, "%s: failed to parse reply", "guestfs_vgs");
946 ctx->cb_sequence = 1;
949 char **guestfs_vgs (guestfs_h *g)
952 guestfs_main_loop *ml = guestfs_get_main_loop (g);
955 if (check_state (g, "guestfs_vgs") == -1) return NULL;
956 guestfs_set_busy (g);
958 memset (&ctx, 0, sizeof ctx);
960 serial = guestfs__send_sync (g, GUESTFS_PROC_VGS, NULL, NULL);
962 guestfs_end_busy (g);
966 guestfs__switch_to_receiving (g);
968 guestfs_set_reply_callback (g, vgs_reply_cb, &ctx);
969 (void) ml->main_loop_run (ml, g);
970 guestfs_set_reply_callback (g, NULL, NULL);
971 if (ctx.cb_sequence != 1) {
972 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs");
973 guestfs_end_busy (g);
977 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS, serial) == -1) {
978 guestfs_end_busy (g);
982 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
983 error (g, "%s", ctx.err.error_message);
984 free (ctx.err.error_message);
985 guestfs_end_busy (g);
989 guestfs_end_busy (g);
990 /* caller will free this, but we need to add a NULL entry */
991 ctx.ret.volgroups.volgroups_val =
992 safe_realloc (g, ctx.ret.volgroups.volgroups_val,
993 sizeof (char *) * (ctx.ret.volgroups.volgroups_len + 1));
994 ctx.ret.volgroups.volgroups_val[ctx.ret.volgroups.volgroups_len] = NULL;
995 return ctx.ret.volgroups.volgroups_val;
999 /* This flag is set by the callbacks, so we know we've done
1000 * the callbacks as expected, and in the right sequence.
1001 * 0 = not called, 1 = reply_cb called.
1004 struct guestfs_message_header hdr;
1005 struct guestfs_message_error err;
1006 struct guestfs_lvs_ret ret;
1009 static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1011 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1012 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
1014 /* This should definitely not happen. */
1015 if (ctx->cb_sequence != 0) {
1016 ctx->cb_sequence = 9999;
1017 error (g, "%s: internal error: reply callback called twice", "guestfs_lvs");
1021 ml->main_loop_quit (ml, g);
1023 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1024 error (g, "%s: failed to parse reply header", "guestfs_lvs");
1027 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1028 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1029 error (g, "%s: failed to parse reply error", "guestfs_lvs");
1034 if (!xdr_guestfs_lvs_ret (xdr, &ctx->ret)) {
1035 error (g, "%s: failed to parse reply", "guestfs_lvs");
1039 ctx->cb_sequence = 1;
1042 char **guestfs_lvs (guestfs_h *g)
1045 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1048 if (check_state (g, "guestfs_lvs") == -1) return NULL;
1049 guestfs_set_busy (g);
1051 memset (&ctx, 0, sizeof ctx);
1053 serial = guestfs__send_sync (g, GUESTFS_PROC_LVS, NULL, NULL);
1055 guestfs_end_busy (g);
1059 guestfs__switch_to_receiving (g);
1060 ctx.cb_sequence = 0;
1061 guestfs_set_reply_callback (g, lvs_reply_cb, &ctx);
1062 (void) ml->main_loop_run (ml, g);
1063 guestfs_set_reply_callback (g, NULL, NULL);
1064 if (ctx.cb_sequence != 1) {
1065 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs");
1066 guestfs_end_busy (g);
1070 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS, serial) == -1) {
1071 guestfs_end_busy (g);
1075 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1076 error (g, "%s", ctx.err.error_message);
1077 free (ctx.err.error_message);
1078 guestfs_end_busy (g);
1082 guestfs_end_busy (g);
1083 /* caller will free this, but we need to add a NULL entry */
1084 ctx.ret.logvols.logvols_val =
1085 safe_realloc (g, ctx.ret.logvols.logvols_val,
1086 sizeof (char *) * (ctx.ret.logvols.logvols_len + 1));
1087 ctx.ret.logvols.logvols_val[ctx.ret.logvols.logvols_len] = NULL;
1088 return ctx.ret.logvols.logvols_val;
1091 struct pvs_full_ctx {
1092 /* This flag is set by the callbacks, so we know we've done
1093 * the callbacks as expected, and in the right sequence.
1094 * 0 = not called, 1 = reply_cb called.
1097 struct guestfs_message_header hdr;
1098 struct guestfs_message_error err;
1099 struct guestfs_pvs_full_ret ret;
1102 static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1104 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1105 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
1107 /* This should definitely not happen. */
1108 if (ctx->cb_sequence != 0) {
1109 ctx->cb_sequence = 9999;
1110 error (g, "%s: internal error: reply callback called twice", "guestfs_pvs_full");
1114 ml->main_loop_quit (ml, g);
1116 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1117 error (g, "%s: failed to parse reply header", "guestfs_pvs_full");
1120 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1121 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1122 error (g, "%s: failed to parse reply error", "guestfs_pvs_full");
1127 if (!xdr_guestfs_pvs_full_ret (xdr, &ctx->ret)) {
1128 error (g, "%s: failed to parse reply", "guestfs_pvs_full");
1132 ctx->cb_sequence = 1;
1135 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
1137 struct pvs_full_ctx ctx;
1138 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1141 if (check_state (g, "guestfs_pvs_full") == -1) return NULL;
1142 guestfs_set_busy (g);
1144 memset (&ctx, 0, sizeof ctx);
1146 serial = guestfs__send_sync (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
1148 guestfs_end_busy (g);
1152 guestfs__switch_to_receiving (g);
1153 ctx.cb_sequence = 0;
1154 guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx);
1155 (void) ml->main_loop_run (ml, g);
1156 guestfs_set_reply_callback (g, NULL, NULL);
1157 if (ctx.cb_sequence != 1) {
1158 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs_full");
1159 guestfs_end_busy (g);
1163 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1) {
1164 guestfs_end_busy (g);
1168 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1169 error (g, "%s", ctx.err.error_message);
1170 free (ctx.err.error_message);
1171 guestfs_end_busy (g);
1175 guestfs_end_busy (g);
1176 /* caller will free this */
1177 return safe_memdup (g, &ctx.ret.physvols, sizeof (ctx.ret.physvols));
1180 struct vgs_full_ctx {
1181 /* This flag is set by the callbacks, so we know we've done
1182 * the callbacks as expected, and in the right sequence.
1183 * 0 = not called, 1 = reply_cb called.
1186 struct guestfs_message_header hdr;
1187 struct guestfs_message_error err;
1188 struct guestfs_vgs_full_ret ret;
1191 static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1193 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1194 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1196 /* This should definitely not happen. */
1197 if (ctx->cb_sequence != 0) {
1198 ctx->cb_sequence = 9999;
1199 error (g, "%s: internal error: reply callback called twice", "guestfs_vgs_full");
1203 ml->main_loop_quit (ml, g);
1205 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1206 error (g, "%s: failed to parse reply header", "guestfs_vgs_full");
1209 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1210 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1211 error (g, "%s: failed to parse reply error", "guestfs_vgs_full");
1216 if (!xdr_guestfs_vgs_full_ret (xdr, &ctx->ret)) {
1217 error (g, "%s: failed to parse reply", "guestfs_vgs_full");
1221 ctx->cb_sequence = 1;
1224 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
1226 struct vgs_full_ctx ctx;
1227 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1230 if (check_state (g, "guestfs_vgs_full") == -1) return NULL;
1231 guestfs_set_busy (g);
1233 memset (&ctx, 0, sizeof ctx);
1235 serial = guestfs__send_sync (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
1237 guestfs_end_busy (g);
1241 guestfs__switch_to_receiving (g);
1242 ctx.cb_sequence = 0;
1243 guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx);
1244 (void) ml->main_loop_run (ml, g);
1245 guestfs_set_reply_callback (g, NULL, NULL);
1246 if (ctx.cb_sequence != 1) {
1247 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs_full");
1248 guestfs_end_busy (g);
1252 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1) {
1253 guestfs_end_busy (g);
1257 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1258 error (g, "%s", ctx.err.error_message);
1259 free (ctx.err.error_message);
1260 guestfs_end_busy (g);
1264 guestfs_end_busy (g);
1265 /* caller will free this */
1266 return safe_memdup (g, &ctx.ret.volgroups, sizeof (ctx.ret.volgroups));
1269 struct lvs_full_ctx {
1270 /* This flag is set by the callbacks, so we know we've done
1271 * the callbacks as expected, and in the right sequence.
1272 * 0 = not called, 1 = reply_cb called.
1275 struct guestfs_message_header hdr;
1276 struct guestfs_message_error err;
1277 struct guestfs_lvs_full_ret ret;
1280 static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1282 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1283 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1285 /* This should definitely not happen. */
1286 if (ctx->cb_sequence != 0) {
1287 ctx->cb_sequence = 9999;
1288 error (g, "%s: internal error: reply callback called twice", "guestfs_lvs_full");
1292 ml->main_loop_quit (ml, g);
1294 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1295 error (g, "%s: failed to parse reply header", "guestfs_lvs_full");
1298 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1299 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1300 error (g, "%s: failed to parse reply error", "guestfs_lvs_full");
1305 if (!xdr_guestfs_lvs_full_ret (xdr, &ctx->ret)) {
1306 error (g, "%s: failed to parse reply", "guestfs_lvs_full");
1310 ctx->cb_sequence = 1;
1313 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
1315 struct lvs_full_ctx ctx;
1316 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1319 if (check_state (g, "guestfs_lvs_full") == -1) return NULL;
1320 guestfs_set_busy (g);
1322 memset (&ctx, 0, sizeof ctx);
1324 serial = guestfs__send_sync (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
1326 guestfs_end_busy (g);
1330 guestfs__switch_to_receiving (g);
1331 ctx.cb_sequence = 0;
1332 guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx);
1333 (void) ml->main_loop_run (ml, g);
1334 guestfs_set_reply_callback (g, NULL, NULL);
1335 if (ctx.cb_sequence != 1) {
1336 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs_full");
1337 guestfs_end_busy (g);
1341 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1) {
1342 guestfs_end_busy (g);
1346 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1347 error (g, "%s", ctx.err.error_message);
1348 free (ctx.err.error_message);
1349 guestfs_end_busy (g);
1353 guestfs_end_busy (g);
1354 /* caller will free this */
1355 return safe_memdup (g, &ctx.ret.logvols, sizeof (ctx.ret.logvols));
1358 struct read_lines_ctx {
1359 /* This flag is set by the callbacks, so we know we've done
1360 * the callbacks as expected, and in the right sequence.
1361 * 0 = not called, 1 = reply_cb called.
1364 struct guestfs_message_header hdr;
1365 struct guestfs_message_error err;
1366 struct guestfs_read_lines_ret ret;
1369 static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1371 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1372 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1374 /* This should definitely not happen. */
1375 if (ctx->cb_sequence != 0) {
1376 ctx->cb_sequence = 9999;
1377 error (g, "%s: internal error: reply callback called twice", "guestfs_read_lines");
1381 ml->main_loop_quit (ml, g);
1383 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1384 error (g, "%s: failed to parse reply header", "guestfs_read_lines");
1387 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1388 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1389 error (g, "%s: failed to parse reply error", "guestfs_read_lines");
1394 if (!xdr_guestfs_read_lines_ret (xdr, &ctx->ret)) {
1395 error (g, "%s: failed to parse reply", "guestfs_read_lines");
1399 ctx->cb_sequence = 1;
1402 char **guestfs_read_lines (guestfs_h *g,
1405 struct guestfs_read_lines_args args;
1406 struct read_lines_ctx ctx;
1407 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1410 if (check_state (g, "guestfs_read_lines") == -1) return NULL;
1411 guestfs_set_busy (g);
1413 memset (&ctx, 0, sizeof ctx);
1415 args.path = (char *) path;
1416 serial = guestfs__send_sync (g, GUESTFS_PROC_READ_LINES,
1417 (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
1419 guestfs_end_busy (g);
1423 guestfs__switch_to_receiving (g);
1424 ctx.cb_sequence = 0;
1425 guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx);
1426 (void) ml->main_loop_run (ml, g);
1427 guestfs_set_reply_callback (g, NULL, NULL);
1428 if (ctx.cb_sequence != 1) {
1429 error (g, "%s reply failed, see earlier error messages", "guestfs_read_lines");
1430 guestfs_end_busy (g);
1434 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_READ_LINES, serial) == -1) {
1435 guestfs_end_busy (g);
1439 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1440 error (g, "%s", ctx.err.error_message);
1441 free (ctx.err.error_message);
1442 guestfs_end_busy (g);
1446 guestfs_end_busy (g);
1447 /* caller will free this, but we need to add a NULL entry */
1448 ctx.ret.lines.lines_val =
1449 safe_realloc (g, ctx.ret.lines.lines_val,
1450 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
1451 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
1452 return ctx.ret.lines.lines_val;
1455 struct aug_init_ctx {
1456 /* This flag is set by the callbacks, so we know we've done
1457 * the callbacks as expected, and in the right sequence.
1458 * 0 = not called, 1 = reply_cb called.
1461 struct guestfs_message_header hdr;
1462 struct guestfs_message_error err;
1465 static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1467 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1468 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1470 /* This should definitely not happen. */
1471 if (ctx->cb_sequence != 0) {
1472 ctx->cb_sequence = 9999;
1473 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_init");
1477 ml->main_loop_quit (ml, g);
1479 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1480 error (g, "%s: failed to parse reply header", "guestfs_aug_init");
1483 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1484 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1485 error (g, "%s: failed to parse reply error", "guestfs_aug_init");
1491 ctx->cb_sequence = 1;
1494 int guestfs_aug_init (guestfs_h *g,
1498 struct guestfs_aug_init_args args;
1499 struct aug_init_ctx ctx;
1500 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1503 if (check_state (g, "guestfs_aug_init") == -1) return -1;
1504 guestfs_set_busy (g);
1506 memset (&ctx, 0, sizeof ctx);
1508 args.root = (char *) root;
1510 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INIT,
1511 (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
1513 guestfs_end_busy (g);
1517 guestfs__switch_to_receiving (g);
1518 ctx.cb_sequence = 0;
1519 guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx);
1520 (void) ml->main_loop_run (ml, g);
1521 guestfs_set_reply_callback (g, NULL, NULL);
1522 if (ctx.cb_sequence != 1) {
1523 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_init");
1524 guestfs_end_busy (g);
1528 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1) {
1529 guestfs_end_busy (g);
1533 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1534 error (g, "%s", ctx.err.error_message);
1535 free (ctx.err.error_message);
1536 guestfs_end_busy (g);
1540 guestfs_end_busy (g);
1544 struct aug_close_ctx {
1545 /* This flag is set by the callbacks, so we know we've done
1546 * the callbacks as expected, and in the right sequence.
1547 * 0 = not called, 1 = reply_cb called.
1550 struct guestfs_message_header hdr;
1551 struct guestfs_message_error err;
1554 static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1556 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1557 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1559 /* This should definitely not happen. */
1560 if (ctx->cb_sequence != 0) {
1561 ctx->cb_sequence = 9999;
1562 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_close");
1566 ml->main_loop_quit (ml, g);
1568 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1569 error (g, "%s: failed to parse reply header", "guestfs_aug_close");
1572 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1573 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1574 error (g, "%s: failed to parse reply error", "guestfs_aug_close");
1580 ctx->cb_sequence = 1;
1583 int guestfs_aug_close (guestfs_h *g)
1585 struct aug_close_ctx ctx;
1586 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1589 if (check_state (g, "guestfs_aug_close") == -1) return -1;
1590 guestfs_set_busy (g);
1592 memset (&ctx, 0, sizeof ctx);
1594 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
1596 guestfs_end_busy (g);
1600 guestfs__switch_to_receiving (g);
1601 ctx.cb_sequence = 0;
1602 guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx);
1603 (void) ml->main_loop_run (ml, g);
1604 guestfs_set_reply_callback (g, NULL, NULL);
1605 if (ctx.cb_sequence != 1) {
1606 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_close");
1607 guestfs_end_busy (g);
1611 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1) {
1612 guestfs_end_busy (g);
1616 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1617 error (g, "%s", ctx.err.error_message);
1618 free (ctx.err.error_message);
1619 guestfs_end_busy (g);
1623 guestfs_end_busy (g);
1627 struct aug_defvar_ctx {
1628 /* This flag is set by the callbacks, so we know we've done
1629 * the callbacks as expected, and in the right sequence.
1630 * 0 = not called, 1 = reply_cb called.
1633 struct guestfs_message_header hdr;
1634 struct guestfs_message_error err;
1635 struct guestfs_aug_defvar_ret ret;
1638 static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1640 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1641 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1643 /* This should definitely not happen. */
1644 if (ctx->cb_sequence != 0) {
1645 ctx->cb_sequence = 9999;
1646 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_defvar");
1650 ml->main_loop_quit (ml, g);
1652 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1653 error (g, "%s: failed to parse reply header", "guestfs_aug_defvar");
1656 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1657 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1658 error (g, "%s: failed to parse reply error", "guestfs_aug_defvar");
1663 if (!xdr_guestfs_aug_defvar_ret (xdr, &ctx->ret)) {
1664 error (g, "%s: failed to parse reply", "guestfs_aug_defvar");
1668 ctx->cb_sequence = 1;
1671 int guestfs_aug_defvar (guestfs_h *g,
1675 struct guestfs_aug_defvar_args args;
1676 struct aug_defvar_ctx ctx;
1677 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1680 if (check_state (g, "guestfs_aug_defvar") == -1) return -1;
1681 guestfs_set_busy (g);
1683 memset (&ctx, 0, sizeof ctx);
1685 args.name = (char *) name;
1686 args.expr = expr ? (char **) &expr : NULL;
1687 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFVAR,
1688 (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
1690 guestfs_end_busy (g);
1694 guestfs__switch_to_receiving (g);
1695 ctx.cb_sequence = 0;
1696 guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx);
1697 (void) ml->main_loop_run (ml, g);
1698 guestfs_set_reply_callback (g, NULL, NULL);
1699 if (ctx.cb_sequence != 1) {
1700 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defvar");
1701 guestfs_end_busy (g);
1705 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1) {
1706 guestfs_end_busy (g);
1710 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1711 error (g, "%s", ctx.err.error_message);
1712 free (ctx.err.error_message);
1713 guestfs_end_busy (g);
1717 guestfs_end_busy (g);
1718 return ctx.ret.nrnodes;
1721 struct aug_defnode_ctx {
1722 /* This flag is set by the callbacks, so we know we've done
1723 * the callbacks as expected, and in the right sequence.
1724 * 0 = not called, 1 = reply_cb called.
1727 struct guestfs_message_header hdr;
1728 struct guestfs_message_error err;
1729 struct guestfs_aug_defnode_ret ret;
1732 static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1734 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1735 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1737 /* This should definitely not happen. */
1738 if (ctx->cb_sequence != 0) {
1739 ctx->cb_sequence = 9999;
1740 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_defnode");
1744 ml->main_loop_quit (ml, g);
1746 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1747 error (g, "%s: failed to parse reply header", "guestfs_aug_defnode");
1750 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1751 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1752 error (g, "%s: failed to parse reply error", "guestfs_aug_defnode");
1757 if (!xdr_guestfs_aug_defnode_ret (xdr, &ctx->ret)) {
1758 error (g, "%s: failed to parse reply", "guestfs_aug_defnode");
1762 ctx->cb_sequence = 1;
1765 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
1770 struct guestfs_aug_defnode_args args;
1771 struct aug_defnode_ctx ctx;
1772 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1775 if (check_state (g, "guestfs_aug_defnode") == -1) return NULL;
1776 guestfs_set_busy (g);
1778 memset (&ctx, 0, sizeof ctx);
1780 args.name = (char *) name;
1781 args.expr = (char *) expr;
1782 args.val = (char *) val;
1783 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_DEFNODE,
1784 (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
1786 guestfs_end_busy (g);
1790 guestfs__switch_to_receiving (g);
1791 ctx.cb_sequence = 0;
1792 guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx);
1793 (void) ml->main_loop_run (ml, g);
1794 guestfs_set_reply_callback (g, NULL, NULL);
1795 if (ctx.cb_sequence != 1) {
1796 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defnode");
1797 guestfs_end_busy (g);
1801 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1) {
1802 guestfs_end_busy (g);
1806 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1807 error (g, "%s", ctx.err.error_message);
1808 free (ctx.err.error_message);
1809 guestfs_end_busy (g);
1813 guestfs_end_busy (g);
1814 /* caller with free this */
1815 return safe_memdup (g, &ctx.ret, sizeof (ctx.ret));
1818 struct aug_get_ctx {
1819 /* This flag is set by the callbacks, so we know we've done
1820 * the callbacks as expected, and in the right sequence.
1821 * 0 = not called, 1 = reply_cb called.
1824 struct guestfs_message_header hdr;
1825 struct guestfs_message_error err;
1826 struct guestfs_aug_get_ret ret;
1829 static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1831 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1832 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1834 /* This should definitely not happen. */
1835 if (ctx->cb_sequence != 0) {
1836 ctx->cb_sequence = 9999;
1837 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_get");
1841 ml->main_loop_quit (ml, g);
1843 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1844 error (g, "%s: failed to parse reply header", "guestfs_aug_get");
1847 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1848 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1849 error (g, "%s: failed to parse reply error", "guestfs_aug_get");
1854 if (!xdr_guestfs_aug_get_ret (xdr, &ctx->ret)) {
1855 error (g, "%s: failed to parse reply", "guestfs_aug_get");
1859 ctx->cb_sequence = 1;
1862 char *guestfs_aug_get (guestfs_h *g,
1865 struct guestfs_aug_get_args args;
1866 struct aug_get_ctx ctx;
1867 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1870 if (check_state (g, "guestfs_aug_get") == -1) return NULL;
1871 guestfs_set_busy (g);
1873 memset (&ctx, 0, sizeof ctx);
1875 args.path = (char *) path;
1876 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_GET,
1877 (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
1879 guestfs_end_busy (g);
1883 guestfs__switch_to_receiving (g);
1884 ctx.cb_sequence = 0;
1885 guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx);
1886 (void) ml->main_loop_run (ml, g);
1887 guestfs_set_reply_callback (g, NULL, NULL);
1888 if (ctx.cb_sequence != 1) {
1889 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_get");
1890 guestfs_end_busy (g);
1894 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_GET, serial) == -1) {
1895 guestfs_end_busy (g);
1899 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1900 error (g, "%s", ctx.err.error_message);
1901 free (ctx.err.error_message);
1902 guestfs_end_busy (g);
1906 guestfs_end_busy (g);
1907 return ctx.ret.val; /* caller will free */
1910 struct aug_set_ctx {
1911 /* This flag is set by the callbacks, so we know we've done
1912 * the callbacks as expected, and in the right sequence.
1913 * 0 = not called, 1 = reply_cb called.
1916 struct guestfs_message_header hdr;
1917 struct guestfs_message_error err;
1920 static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1922 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1923 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1925 /* This should definitely not happen. */
1926 if (ctx->cb_sequence != 0) {
1927 ctx->cb_sequence = 9999;
1928 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_set");
1932 ml->main_loop_quit (ml, g);
1934 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1935 error (g, "%s: failed to parse reply header", "guestfs_aug_set");
1938 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1939 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1940 error (g, "%s: failed to parse reply error", "guestfs_aug_set");
1946 ctx->cb_sequence = 1;
1949 int guestfs_aug_set (guestfs_h *g,
1953 struct guestfs_aug_set_args args;
1954 struct aug_set_ctx ctx;
1955 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1958 if (check_state (g, "guestfs_aug_set") == -1) return -1;
1959 guestfs_set_busy (g);
1961 memset (&ctx, 0, sizeof ctx);
1963 args.path = (char *) path;
1964 args.val = (char *) val;
1965 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SET,
1966 (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
1968 guestfs_end_busy (g);
1972 guestfs__switch_to_receiving (g);
1973 ctx.cb_sequence = 0;
1974 guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx);
1975 (void) ml->main_loop_run (ml, g);
1976 guestfs_set_reply_callback (g, NULL, NULL);
1977 if (ctx.cb_sequence != 1) {
1978 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_set");
1979 guestfs_end_busy (g);
1983 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SET, serial) == -1) {
1984 guestfs_end_busy (g);
1988 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1989 error (g, "%s", ctx.err.error_message);
1990 free (ctx.err.error_message);
1991 guestfs_end_busy (g);
1995 guestfs_end_busy (g);
1999 struct aug_insert_ctx {
2000 /* This flag is set by the callbacks, so we know we've done
2001 * the callbacks as expected, and in the right sequence.
2002 * 0 = not called, 1 = reply_cb called.
2005 struct guestfs_message_header hdr;
2006 struct guestfs_message_error err;
2009 static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2011 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2012 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
2014 /* This should definitely not happen. */
2015 if (ctx->cb_sequence != 0) {
2016 ctx->cb_sequence = 9999;
2017 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_insert");
2021 ml->main_loop_quit (ml, g);
2023 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2024 error (g, "%s: failed to parse reply header", "guestfs_aug_insert");
2027 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2028 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2029 error (g, "%s: failed to parse reply error", "guestfs_aug_insert");
2035 ctx->cb_sequence = 1;
2038 int guestfs_aug_insert (guestfs_h *g,
2043 struct guestfs_aug_insert_args args;
2044 struct aug_insert_ctx ctx;
2045 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2048 if (check_state (g, "guestfs_aug_insert") == -1) return -1;
2049 guestfs_set_busy (g);
2051 memset (&ctx, 0, sizeof ctx);
2053 args.path = (char *) path;
2054 args.label = (char *) label;
2055 args.before = before;
2056 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_INSERT,
2057 (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
2059 guestfs_end_busy (g);
2063 guestfs__switch_to_receiving (g);
2064 ctx.cb_sequence = 0;
2065 guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx);
2066 (void) ml->main_loop_run (ml, g);
2067 guestfs_set_reply_callback (g, NULL, NULL);
2068 if (ctx.cb_sequence != 1) {
2069 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_insert");
2070 guestfs_end_busy (g);
2074 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1) {
2075 guestfs_end_busy (g);
2079 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2080 error (g, "%s", ctx.err.error_message);
2081 free (ctx.err.error_message);
2082 guestfs_end_busy (g);
2086 guestfs_end_busy (g);
2091 /* This flag is set by the callbacks, so we know we've done
2092 * the callbacks as expected, and in the right sequence.
2093 * 0 = not called, 1 = reply_cb called.
2096 struct guestfs_message_header hdr;
2097 struct guestfs_message_error err;
2098 struct guestfs_aug_rm_ret ret;
2101 static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2103 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2104 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
2106 /* This should definitely not happen. */
2107 if (ctx->cb_sequence != 0) {
2108 ctx->cb_sequence = 9999;
2109 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_rm");
2113 ml->main_loop_quit (ml, g);
2115 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2116 error (g, "%s: failed to parse reply header", "guestfs_aug_rm");
2119 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2120 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2121 error (g, "%s: failed to parse reply error", "guestfs_aug_rm");
2126 if (!xdr_guestfs_aug_rm_ret (xdr, &ctx->ret)) {
2127 error (g, "%s: failed to parse reply", "guestfs_aug_rm");
2131 ctx->cb_sequence = 1;
2134 int guestfs_aug_rm (guestfs_h *g,
2137 struct guestfs_aug_rm_args args;
2138 struct aug_rm_ctx ctx;
2139 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2142 if (check_state (g, "guestfs_aug_rm") == -1) return -1;
2143 guestfs_set_busy (g);
2145 memset (&ctx, 0, sizeof ctx);
2147 args.path = (char *) path;
2148 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_RM,
2149 (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
2151 guestfs_end_busy (g);
2155 guestfs__switch_to_receiving (g);
2156 ctx.cb_sequence = 0;
2157 guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx);
2158 (void) ml->main_loop_run (ml, g);
2159 guestfs_set_reply_callback (g, NULL, NULL);
2160 if (ctx.cb_sequence != 1) {
2161 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_rm");
2162 guestfs_end_busy (g);
2166 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_RM, serial) == -1) {
2167 guestfs_end_busy (g);
2171 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2172 error (g, "%s", ctx.err.error_message);
2173 free (ctx.err.error_message);
2174 guestfs_end_busy (g);
2178 guestfs_end_busy (g);
2179 return ctx.ret.nrnodes;
2183 /* This flag is set by the callbacks, so we know we've done
2184 * the callbacks as expected, and in the right sequence.
2185 * 0 = not called, 1 = reply_cb called.
2188 struct guestfs_message_header hdr;
2189 struct guestfs_message_error err;
2192 static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2194 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2195 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
2197 /* This should definitely not happen. */
2198 if (ctx->cb_sequence != 0) {
2199 ctx->cb_sequence = 9999;
2200 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_mv");
2204 ml->main_loop_quit (ml, g);
2206 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2207 error (g, "%s: failed to parse reply header", "guestfs_aug_mv");
2210 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2211 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2212 error (g, "%s: failed to parse reply error", "guestfs_aug_mv");
2218 ctx->cb_sequence = 1;
2221 int guestfs_aug_mv (guestfs_h *g,
2225 struct guestfs_aug_mv_args args;
2226 struct aug_mv_ctx ctx;
2227 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2230 if (check_state (g, "guestfs_aug_mv") == -1) return -1;
2231 guestfs_set_busy (g);
2233 memset (&ctx, 0, sizeof ctx);
2235 args.src = (char *) src;
2236 args.dest = (char *) dest;
2237 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MV,
2238 (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
2240 guestfs_end_busy (g);
2244 guestfs__switch_to_receiving (g);
2245 ctx.cb_sequence = 0;
2246 guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx);
2247 (void) ml->main_loop_run (ml, g);
2248 guestfs_set_reply_callback (g, NULL, NULL);
2249 if (ctx.cb_sequence != 1) {
2250 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_mv");
2251 guestfs_end_busy (g);
2255 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MV, serial) == -1) {
2256 guestfs_end_busy (g);
2260 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2261 error (g, "%s", ctx.err.error_message);
2262 free (ctx.err.error_message);
2263 guestfs_end_busy (g);
2267 guestfs_end_busy (g);
2271 struct aug_match_ctx {
2272 /* This flag is set by the callbacks, so we know we've done
2273 * the callbacks as expected, and in the right sequence.
2274 * 0 = not called, 1 = reply_cb called.
2277 struct guestfs_message_header hdr;
2278 struct guestfs_message_error err;
2279 struct guestfs_aug_match_ret ret;
2282 static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2284 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2285 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
2287 /* This should definitely not happen. */
2288 if (ctx->cb_sequence != 0) {
2289 ctx->cb_sequence = 9999;
2290 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_match");
2294 ml->main_loop_quit (ml, g);
2296 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2297 error (g, "%s: failed to parse reply header", "guestfs_aug_match");
2300 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2301 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2302 error (g, "%s: failed to parse reply error", "guestfs_aug_match");
2307 if (!xdr_guestfs_aug_match_ret (xdr, &ctx->ret)) {
2308 error (g, "%s: failed to parse reply", "guestfs_aug_match");
2312 ctx->cb_sequence = 1;
2315 char **guestfs_aug_match (guestfs_h *g,
2318 struct guestfs_aug_match_args args;
2319 struct aug_match_ctx ctx;
2320 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2323 if (check_state (g, "guestfs_aug_match") == -1) return NULL;
2324 guestfs_set_busy (g);
2326 memset (&ctx, 0, sizeof ctx);
2328 args.path = (char *) path;
2329 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_MATCH,
2330 (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
2332 guestfs_end_busy (g);
2336 guestfs__switch_to_receiving (g);
2337 ctx.cb_sequence = 0;
2338 guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx);
2339 (void) ml->main_loop_run (ml, g);
2340 guestfs_set_reply_callback (g, NULL, NULL);
2341 if (ctx.cb_sequence != 1) {
2342 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_match");
2343 guestfs_end_busy (g);
2347 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1) {
2348 guestfs_end_busy (g);
2352 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2353 error (g, "%s", ctx.err.error_message);
2354 free (ctx.err.error_message);
2355 guestfs_end_busy (g);
2359 guestfs_end_busy (g);
2360 /* caller will free this, but we need to add a NULL entry */
2361 ctx.ret.matches.matches_val =
2362 safe_realloc (g, ctx.ret.matches.matches_val,
2363 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2364 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2365 return ctx.ret.matches.matches_val;
2368 struct aug_save_ctx {
2369 /* This flag is set by the callbacks, so we know we've done
2370 * the callbacks as expected, and in the right sequence.
2371 * 0 = not called, 1 = reply_cb called.
2374 struct guestfs_message_header hdr;
2375 struct guestfs_message_error err;
2378 static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2380 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2381 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2383 /* This should definitely not happen. */
2384 if (ctx->cb_sequence != 0) {
2385 ctx->cb_sequence = 9999;
2386 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_save");
2390 ml->main_loop_quit (ml, g);
2392 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2393 error (g, "%s: failed to parse reply header", "guestfs_aug_save");
2396 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2397 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2398 error (g, "%s: failed to parse reply error", "guestfs_aug_save");
2404 ctx->cb_sequence = 1;
2407 int guestfs_aug_save (guestfs_h *g)
2409 struct aug_save_ctx ctx;
2410 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2413 if (check_state (g, "guestfs_aug_save") == -1) return -1;
2414 guestfs_set_busy (g);
2416 memset (&ctx, 0, sizeof ctx);
2418 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
2420 guestfs_end_busy (g);
2424 guestfs__switch_to_receiving (g);
2425 ctx.cb_sequence = 0;
2426 guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx);
2427 (void) ml->main_loop_run (ml, g);
2428 guestfs_set_reply_callback (g, NULL, NULL);
2429 if (ctx.cb_sequence != 1) {
2430 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_save");
2431 guestfs_end_busy (g);
2435 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1) {
2436 guestfs_end_busy (g);
2440 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2441 error (g, "%s", ctx.err.error_message);
2442 free (ctx.err.error_message);
2443 guestfs_end_busy (g);
2447 guestfs_end_busy (g);
2451 struct aug_load_ctx {
2452 /* This flag is set by the callbacks, so we know we've done
2453 * the callbacks as expected, and in the right sequence.
2454 * 0 = not called, 1 = reply_cb called.
2457 struct guestfs_message_header hdr;
2458 struct guestfs_message_error err;
2461 static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2463 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2464 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2466 /* This should definitely not happen. */
2467 if (ctx->cb_sequence != 0) {
2468 ctx->cb_sequence = 9999;
2469 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_load");
2473 ml->main_loop_quit (ml, g);
2475 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2476 error (g, "%s: failed to parse reply header", "guestfs_aug_load");
2479 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2480 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2481 error (g, "%s: failed to parse reply error", "guestfs_aug_load");
2487 ctx->cb_sequence = 1;
2490 int guestfs_aug_load (guestfs_h *g)
2492 struct aug_load_ctx ctx;
2493 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2496 if (check_state (g, "guestfs_aug_load") == -1) return -1;
2497 guestfs_set_busy (g);
2499 memset (&ctx, 0, sizeof ctx);
2501 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
2503 guestfs_end_busy (g);
2507 guestfs__switch_to_receiving (g);
2508 ctx.cb_sequence = 0;
2509 guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx);
2510 (void) ml->main_loop_run (ml, g);
2511 guestfs_set_reply_callback (g, NULL, NULL);
2512 if (ctx.cb_sequence != 1) {
2513 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_load");
2514 guestfs_end_busy (g);
2518 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1) {
2519 guestfs_end_busy (g);
2523 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2524 error (g, "%s", ctx.err.error_message);
2525 free (ctx.err.error_message);
2526 guestfs_end_busy (g);
2530 guestfs_end_busy (g);
2535 /* This flag is set by the callbacks, so we know we've done
2536 * the callbacks as expected, and in the right sequence.
2537 * 0 = not called, 1 = reply_cb called.
2540 struct guestfs_message_header hdr;
2541 struct guestfs_message_error err;
2542 struct guestfs_aug_ls_ret ret;
2545 static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2547 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2548 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2550 /* This should definitely not happen. */
2551 if (ctx->cb_sequence != 0) {
2552 ctx->cb_sequence = 9999;
2553 error (g, "%s: internal error: reply callback called twice", "guestfs_aug_ls");
2557 ml->main_loop_quit (ml, g);
2559 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2560 error (g, "%s: failed to parse reply header", "guestfs_aug_ls");
2563 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2564 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2565 error (g, "%s: failed to parse reply error", "guestfs_aug_ls");
2570 if (!xdr_guestfs_aug_ls_ret (xdr, &ctx->ret)) {
2571 error (g, "%s: failed to parse reply", "guestfs_aug_ls");
2575 ctx->cb_sequence = 1;
2578 char **guestfs_aug_ls (guestfs_h *g,
2581 struct guestfs_aug_ls_args args;
2582 struct aug_ls_ctx ctx;
2583 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2586 if (check_state (g, "guestfs_aug_ls") == -1) return NULL;
2587 guestfs_set_busy (g);
2589 memset (&ctx, 0, sizeof ctx);
2591 args.path = (char *) path;
2592 serial = guestfs__send_sync (g, GUESTFS_PROC_AUG_LS,
2593 (xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
2595 guestfs_end_busy (g);
2599 guestfs__switch_to_receiving (g);
2600 ctx.cb_sequence = 0;
2601 guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx);
2602 (void) ml->main_loop_run (ml, g);
2603 guestfs_set_reply_callback (g, NULL, NULL);
2604 if (ctx.cb_sequence != 1) {
2605 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_ls");
2606 guestfs_end_busy (g);
2610 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LS, serial) == -1) {
2611 guestfs_end_busy (g);
2615 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2616 error (g, "%s", ctx.err.error_message);
2617 free (ctx.err.error_message);
2618 guestfs_end_busy (g);
2622 guestfs_end_busy (g);
2623 /* caller will free this, but we need to add a NULL entry */
2624 ctx.ret.matches.matches_val =
2625 safe_realloc (g, ctx.ret.matches.matches_val,
2626 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2627 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2628 return ctx.ret.matches.matches_val;
2632 /* This flag is set by the callbacks, so we know we've done
2633 * the callbacks as expected, and in the right sequence.
2634 * 0 = not called, 1 = reply_cb called.
2637 struct guestfs_message_header hdr;
2638 struct guestfs_message_error err;
2641 static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2643 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2644 struct rm_ctx *ctx = (struct rm_ctx *) data;
2646 /* This should definitely not happen. */
2647 if (ctx->cb_sequence != 0) {
2648 ctx->cb_sequence = 9999;
2649 error (g, "%s: internal error: reply callback called twice", "guestfs_rm");
2653 ml->main_loop_quit (ml, g);
2655 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2656 error (g, "%s: failed to parse reply header", "guestfs_rm");
2659 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2660 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2661 error (g, "%s: failed to parse reply error", "guestfs_rm");
2667 ctx->cb_sequence = 1;
2670 int guestfs_rm (guestfs_h *g,
2673 struct guestfs_rm_args args;
2675 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2678 if (check_state (g, "guestfs_rm") == -1) return -1;
2679 guestfs_set_busy (g);
2681 memset (&ctx, 0, sizeof ctx);
2683 args.path = (char *) path;
2684 serial = guestfs__send_sync (g, GUESTFS_PROC_RM,
2685 (xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
2687 guestfs_end_busy (g);
2691 guestfs__switch_to_receiving (g);
2692 ctx.cb_sequence = 0;
2693 guestfs_set_reply_callback (g, rm_reply_cb, &ctx);
2694 (void) ml->main_loop_run (ml, g);
2695 guestfs_set_reply_callback (g, NULL, NULL);
2696 if (ctx.cb_sequence != 1) {
2697 error (g, "%s reply failed, see earlier error messages", "guestfs_rm");
2698 guestfs_end_busy (g);
2702 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM, serial) == -1) {
2703 guestfs_end_busy (g);
2707 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2708 error (g, "%s", ctx.err.error_message);
2709 free (ctx.err.error_message);
2710 guestfs_end_busy (g);
2714 guestfs_end_busy (g);
2719 /* This flag is set by the callbacks, so we know we've done
2720 * the callbacks as expected, and in the right sequence.
2721 * 0 = not called, 1 = reply_cb called.
2724 struct guestfs_message_header hdr;
2725 struct guestfs_message_error err;
2728 static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2730 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2731 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2733 /* This should definitely not happen. */
2734 if (ctx->cb_sequence != 0) {
2735 ctx->cb_sequence = 9999;
2736 error (g, "%s: internal error: reply callback called twice", "guestfs_rmdir");
2740 ml->main_loop_quit (ml, g);
2742 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2743 error (g, "%s: failed to parse reply header", "guestfs_rmdir");
2746 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2747 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2748 error (g, "%s: failed to parse reply error", "guestfs_rmdir");
2754 ctx->cb_sequence = 1;
2757 int guestfs_rmdir (guestfs_h *g,
2760 struct guestfs_rmdir_args args;
2761 struct rmdir_ctx ctx;
2762 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2765 if (check_state (g, "guestfs_rmdir") == -1) return -1;
2766 guestfs_set_busy (g);
2768 memset (&ctx, 0, sizeof ctx);
2770 args.path = (char *) path;
2771 serial = guestfs__send_sync (g, GUESTFS_PROC_RMDIR,
2772 (xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
2774 guestfs_end_busy (g);
2778 guestfs__switch_to_receiving (g);
2779 ctx.cb_sequence = 0;
2780 guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx);
2781 (void) ml->main_loop_run (ml, g);
2782 guestfs_set_reply_callback (g, NULL, NULL);
2783 if (ctx.cb_sequence != 1) {
2784 error (g, "%s reply failed, see earlier error messages", "guestfs_rmdir");
2785 guestfs_end_busy (g);
2789 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RMDIR, serial) == -1) {
2790 guestfs_end_busy (g);
2794 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2795 error (g, "%s", ctx.err.error_message);
2796 free (ctx.err.error_message);
2797 guestfs_end_busy (g);
2801 guestfs_end_busy (g);
2806 /* This flag is set by the callbacks, so we know we've done
2807 * the callbacks as expected, and in the right sequence.
2808 * 0 = not called, 1 = reply_cb called.
2811 struct guestfs_message_header hdr;
2812 struct guestfs_message_error err;
2815 static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2817 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2818 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2820 /* This should definitely not happen. */
2821 if (ctx->cb_sequence != 0) {
2822 ctx->cb_sequence = 9999;
2823 error (g, "%s: internal error: reply callback called twice", "guestfs_rm_rf");
2827 ml->main_loop_quit (ml, g);
2829 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2830 error (g, "%s: failed to parse reply header", "guestfs_rm_rf");
2833 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2834 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2835 error (g, "%s: failed to parse reply error", "guestfs_rm_rf");
2841 ctx->cb_sequence = 1;
2844 int guestfs_rm_rf (guestfs_h *g,
2847 struct guestfs_rm_rf_args args;
2848 struct rm_rf_ctx ctx;
2849 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2852 if (check_state (g, "guestfs_rm_rf") == -1) return -1;
2853 guestfs_set_busy (g);
2855 memset (&ctx, 0, sizeof ctx);
2857 args.path = (char *) path;
2858 serial = guestfs__send_sync (g, GUESTFS_PROC_RM_RF,
2859 (xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
2861 guestfs_end_busy (g);
2865 guestfs__switch_to_receiving (g);
2866 ctx.cb_sequence = 0;
2867 guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx);
2868 (void) ml->main_loop_run (ml, g);
2869 guestfs_set_reply_callback (g, NULL, NULL);
2870 if (ctx.cb_sequence != 1) {
2871 error (g, "%s reply failed, see earlier error messages", "guestfs_rm_rf");
2872 guestfs_end_busy (g);
2876 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM_RF, serial) == -1) {
2877 guestfs_end_busy (g);
2881 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2882 error (g, "%s", ctx.err.error_message);
2883 free (ctx.err.error_message);
2884 guestfs_end_busy (g);
2888 guestfs_end_busy (g);
2893 /* This flag is set by the callbacks, so we know we've done
2894 * the callbacks as expected, and in the right sequence.
2895 * 0 = not called, 1 = reply_cb called.
2898 struct guestfs_message_header hdr;
2899 struct guestfs_message_error err;
2902 static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2904 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2905 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
2907 /* This should definitely not happen. */
2908 if (ctx->cb_sequence != 0) {
2909 ctx->cb_sequence = 9999;
2910 error (g, "%s: internal error: reply callback called twice", "guestfs_mkdir");
2914 ml->main_loop_quit (ml, g);
2916 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2917 error (g, "%s: failed to parse reply header", "guestfs_mkdir");
2920 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2921 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2922 error (g, "%s: failed to parse reply error", "guestfs_mkdir");
2928 ctx->cb_sequence = 1;
2931 int guestfs_mkdir (guestfs_h *g,
2934 struct guestfs_mkdir_args args;
2935 struct mkdir_ctx ctx;
2936 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2939 if (check_state (g, "guestfs_mkdir") == -1) return -1;
2940 guestfs_set_busy (g);
2942 memset (&ctx, 0, sizeof ctx);
2944 args.path = (char *) path;
2945 serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR,
2946 (xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
2948 guestfs_end_busy (g);
2952 guestfs__switch_to_receiving (g);
2953 ctx.cb_sequence = 0;
2954 guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx);
2955 (void) ml->main_loop_run (ml, g);
2956 guestfs_set_reply_callback (g, NULL, NULL);
2957 if (ctx.cb_sequence != 1) {
2958 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir");
2959 guestfs_end_busy (g);
2963 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR, serial) == -1) {
2964 guestfs_end_busy (g);
2968 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2969 error (g, "%s", ctx.err.error_message);
2970 free (ctx.err.error_message);
2971 guestfs_end_busy (g);
2975 guestfs_end_busy (g);
2979 struct mkdir_p_ctx {
2980 /* This flag is set by the callbacks, so we know we've done
2981 * the callbacks as expected, and in the right sequence.
2982 * 0 = not called, 1 = reply_cb called.
2985 struct guestfs_message_header hdr;
2986 struct guestfs_message_error err;
2989 static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2991 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2992 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
2994 /* This should definitely not happen. */
2995 if (ctx->cb_sequence != 0) {
2996 ctx->cb_sequence = 9999;
2997 error (g, "%s: internal error: reply callback called twice", "guestfs_mkdir_p");
3001 ml->main_loop_quit (ml, g);
3003 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3004 error (g, "%s: failed to parse reply header", "guestfs_mkdir_p");
3007 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3008 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3009 error (g, "%s: failed to parse reply error", "guestfs_mkdir_p");
3015 ctx->cb_sequence = 1;
3018 int guestfs_mkdir_p (guestfs_h *g,
3021 struct guestfs_mkdir_p_args args;
3022 struct mkdir_p_ctx ctx;
3023 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3026 if (check_state (g, "guestfs_mkdir_p") == -1) return -1;
3027 guestfs_set_busy (g);
3029 memset (&ctx, 0, sizeof ctx);
3031 args.path = (char *) path;
3032 serial = guestfs__send_sync (g, GUESTFS_PROC_MKDIR_P,
3033 (xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
3035 guestfs_end_busy (g);
3039 guestfs__switch_to_receiving (g);
3040 ctx.cb_sequence = 0;
3041 guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx);
3042 (void) ml->main_loop_run (ml, g);
3043 guestfs_set_reply_callback (g, NULL, NULL);
3044 if (ctx.cb_sequence != 1) {
3045 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir_p");
3046 guestfs_end_busy (g);
3050 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR_P, serial) == -1) {
3051 guestfs_end_busy (g);
3055 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3056 error (g, "%s", ctx.err.error_message);
3057 free (ctx.err.error_message);
3058 guestfs_end_busy (g);
3062 guestfs_end_busy (g);
3067 /* This flag is set by the callbacks, so we know we've done
3068 * the callbacks as expected, and in the right sequence.
3069 * 0 = not called, 1 = reply_cb called.
3072 struct guestfs_message_header hdr;
3073 struct guestfs_message_error err;
3076 static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3078 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3079 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
3081 /* This should definitely not happen. */
3082 if (ctx->cb_sequence != 0) {
3083 ctx->cb_sequence = 9999;
3084 error (g, "%s: internal error: reply callback called twice", "guestfs_chmod");
3088 ml->main_loop_quit (ml, g);
3090 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3091 error (g, "%s: failed to parse reply header", "guestfs_chmod");
3094 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3095 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3096 error (g, "%s: failed to parse reply error", "guestfs_chmod");
3102 ctx->cb_sequence = 1;
3105 int guestfs_chmod (guestfs_h *g,
3109 struct guestfs_chmod_args args;
3110 struct chmod_ctx ctx;
3111 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3114 if (check_state (g, "guestfs_chmod") == -1) return -1;
3115 guestfs_set_busy (g);
3117 memset (&ctx, 0, sizeof ctx);
3120 args.path = (char *) path;
3121 serial = guestfs__send_sync (g, GUESTFS_PROC_CHMOD,
3122 (xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
3124 guestfs_end_busy (g);
3128 guestfs__switch_to_receiving (g);
3129 ctx.cb_sequence = 0;
3130 guestfs_set_reply_callback (g, chmod_reply_cb, &ctx);
3131 (void) ml->main_loop_run (ml, g);
3132 guestfs_set_reply_callback (g, NULL, NULL);
3133 if (ctx.cb_sequence != 1) {
3134 error (g, "%s reply failed, see earlier error messages", "guestfs_chmod");
3135 guestfs_end_busy (g);
3139 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHMOD, serial) == -1) {
3140 guestfs_end_busy (g);
3144 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3145 error (g, "%s", ctx.err.error_message);
3146 free (ctx.err.error_message);
3147 guestfs_end_busy (g);
3151 guestfs_end_busy (g);
3156 /* This flag is set by the callbacks, so we know we've done
3157 * the callbacks as expected, and in the right sequence.
3158 * 0 = not called, 1 = reply_cb called.
3161 struct guestfs_message_header hdr;
3162 struct guestfs_message_error err;
3165 static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3167 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3168 struct chown_ctx *ctx = (struct chown_ctx *) data;
3170 /* This should definitely not happen. */
3171 if (ctx->cb_sequence != 0) {
3172 ctx->cb_sequence = 9999;
3173 error (g, "%s: internal error: reply callback called twice", "guestfs_chown");
3177 ml->main_loop_quit (ml, g);
3179 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3180 error (g, "%s: failed to parse reply header", "guestfs_chown");
3183 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3184 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3185 error (g, "%s: failed to parse reply error", "guestfs_chown");
3191 ctx->cb_sequence = 1;
3194 int guestfs_chown (guestfs_h *g,
3199 struct guestfs_chown_args args;
3200 struct chown_ctx ctx;
3201 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3204 if (check_state (g, "guestfs_chown") == -1) return -1;
3205 guestfs_set_busy (g);
3207 memset (&ctx, 0, sizeof ctx);
3211 args.path = (char *) path;
3212 serial = guestfs__send_sync (g, GUESTFS_PROC_CHOWN,
3213 (xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
3215 guestfs_end_busy (g);
3219 guestfs__switch_to_receiving (g);
3220 ctx.cb_sequence = 0;
3221 guestfs_set_reply_callback (g, chown_reply_cb, &ctx);
3222 (void) ml->main_loop_run (ml, g);
3223 guestfs_set_reply_callback (g, NULL, NULL);
3224 if (ctx.cb_sequence != 1) {
3225 error (g, "%s reply failed, see earlier error messages", "guestfs_chown");
3226 guestfs_end_busy (g);
3230 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHOWN, serial) == -1) {
3231 guestfs_end_busy (g);
3235 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3236 error (g, "%s", ctx.err.error_message);
3237 free (ctx.err.error_message);
3238 guestfs_end_busy (g);
3242 guestfs_end_busy (g);
3247 /* This flag is set by the callbacks, so we know we've done
3248 * the callbacks as expected, and in the right sequence.
3249 * 0 = not called, 1 = reply_cb called.
3252 struct guestfs_message_header hdr;
3253 struct guestfs_message_error err;
3254 struct guestfs_exists_ret ret;
3257 static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3259 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3260 struct exists_ctx *ctx = (struct exists_ctx *) data;
3262 /* This should definitely not happen. */
3263 if (ctx->cb_sequence != 0) {
3264 ctx->cb_sequence = 9999;
3265 error (g, "%s: internal error: reply callback called twice", "guestfs_exists");
3269 ml->main_loop_quit (ml, g);
3271 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3272 error (g, "%s: failed to parse reply header", "guestfs_exists");
3275 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3276 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3277 error (g, "%s: failed to parse reply error", "guestfs_exists");
3282 if (!xdr_guestfs_exists_ret (xdr, &ctx->ret)) {
3283 error (g, "%s: failed to parse reply", "guestfs_exists");
3287 ctx->cb_sequence = 1;
3290 int guestfs_exists (guestfs_h *g,
3293 struct guestfs_exists_args args;
3294 struct exists_ctx ctx;
3295 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3298 if (check_state (g, "guestfs_exists") == -1) return -1;
3299 guestfs_set_busy (g);
3301 memset (&ctx, 0, sizeof ctx);
3303 args.path = (char *) path;
3304 serial = guestfs__send_sync (g, GUESTFS_PROC_EXISTS,
3305 (xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
3307 guestfs_end_busy (g);
3311 guestfs__switch_to_receiving (g);
3312 ctx.cb_sequence = 0;
3313 guestfs_set_reply_callback (g, exists_reply_cb, &ctx);
3314 (void) ml->main_loop_run (ml, g);
3315 guestfs_set_reply_callback (g, NULL, NULL);
3316 if (ctx.cb_sequence != 1) {
3317 error (g, "%s reply failed, see earlier error messages", "guestfs_exists");
3318 guestfs_end_busy (g);
3322 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EXISTS, serial) == -1) {
3323 guestfs_end_busy (g);
3327 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3328 error (g, "%s", ctx.err.error_message);
3329 free (ctx.err.error_message);
3330 guestfs_end_busy (g);
3334 guestfs_end_busy (g);
3335 return ctx.ret.existsflag;
3338 struct is_file_ctx {
3339 /* This flag is set by the callbacks, so we know we've done
3340 * the callbacks as expected, and in the right sequence.
3341 * 0 = not called, 1 = reply_cb called.
3344 struct guestfs_message_header hdr;
3345 struct guestfs_message_error err;
3346 struct guestfs_is_file_ret ret;
3349 static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3351 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3352 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
3354 /* This should definitely not happen. */
3355 if (ctx->cb_sequence != 0) {
3356 ctx->cb_sequence = 9999;
3357 error (g, "%s: internal error: reply callback called twice", "guestfs_is_file");
3361 ml->main_loop_quit (ml, g);
3363 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3364 error (g, "%s: failed to parse reply header", "guestfs_is_file");
3367 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3368 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3369 error (g, "%s: failed to parse reply error", "guestfs_is_file");
3374 if (!xdr_guestfs_is_file_ret (xdr, &ctx->ret)) {
3375 error (g, "%s: failed to parse reply", "guestfs_is_file");
3379 ctx->cb_sequence = 1;
3382 int guestfs_is_file (guestfs_h *g,
3385 struct guestfs_is_file_args args;
3386 struct is_file_ctx ctx;
3387 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3390 if (check_state (g, "guestfs_is_file") == -1) return -1;
3391 guestfs_set_busy (g);
3393 memset (&ctx, 0, sizeof ctx);
3395 args.path = (char *) path;
3396 serial = guestfs__send_sync (g, GUESTFS_PROC_IS_FILE,
3397 (xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
3399 guestfs_end_busy (g);
3403 guestfs__switch_to_receiving (g);
3404 ctx.cb_sequence = 0;
3405 guestfs_set_reply_callback (g, is_file_reply_cb, &ctx);
3406 (void) ml->main_loop_run (ml, g);
3407 guestfs_set_reply_callback (g, NULL, NULL);
3408 if (ctx.cb_sequence != 1) {
3409 error (g, "%s reply failed, see earlier error messages", "guestfs_is_file");
3410 guestfs_end_busy (g);
3414 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_FILE, serial) == -1) {
3415 guestfs_end_busy (g);
3419 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3420 error (g, "%s", ctx.err.error_message);
3421 free (ctx.err.error_message);
3422 guestfs_end_busy (g);
3426 guestfs_end_busy (g);
3427 return ctx.ret.fileflag;
3431 /* This flag is set by the callbacks, so we know we've done
3432 * the callbacks as expected, and in the right sequence.
3433 * 0 = not called, 1 = reply_cb called.
3436 struct guestfs_message_header hdr;
3437 struct guestfs_message_error err;
3438 struct guestfs_is_dir_ret ret;
3441 static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3443 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3444 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
3446 /* This should definitely not happen. */
3447 if (ctx->cb_sequence != 0) {
3448 ctx->cb_sequence = 9999;
3449 error (g, "%s: internal error: reply callback called twice", "guestfs_is_dir");
3453 ml->main_loop_quit (ml, g);
3455 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3456 error (g, "%s: failed to parse reply header", "guestfs_is_dir");
3459 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3460 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3461 error (g, "%s: failed to parse reply error", "guestfs_is_dir");
3466 if (!xdr_guestfs_is_dir_ret (xdr, &ctx->ret)) {
3467 error (g, "%s: failed to parse reply", "guestfs_is_dir");
3471 ctx->cb_sequence = 1;
3474 int guestfs_is_dir (guestfs_h *g,
3477 struct guestfs_is_dir_args args;
3478 struct is_dir_ctx ctx;
3479 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3482 if (check_state (g, "guestfs_is_dir") == -1) return -1;
3483 guestfs_set_busy (g);
3485 memset (&ctx, 0, sizeof ctx);
3487 args.path = (char *) path;
3488 serial = guestfs__send_sync (g, GUESTFS_PROC_IS_DIR,
3489 (xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
3491 guestfs_end_busy (g);
3495 guestfs__switch_to_receiving (g);
3496 ctx.cb_sequence = 0;
3497 guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx);
3498 (void) ml->main_loop_run (ml, g);
3499 guestfs_set_reply_callback (g, NULL, NULL);
3500 if (ctx.cb_sequence != 1) {
3501 error (g, "%s reply failed, see earlier error messages", "guestfs_is_dir");
3502 guestfs_end_busy (g);
3506 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_DIR, serial) == -1) {
3507 guestfs_end_busy (g);
3511 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3512 error (g, "%s", ctx.err.error_message);
3513 free (ctx.err.error_message);
3514 guestfs_end_busy (g);
3518 guestfs_end_busy (g);
3519 return ctx.ret.dirflag;
3522 struct pvcreate_ctx {
3523 /* This flag is set by the callbacks, so we know we've done
3524 * the callbacks as expected, and in the right sequence.
3525 * 0 = not called, 1 = reply_cb called.
3528 struct guestfs_message_header hdr;
3529 struct guestfs_message_error err;
3532 static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3534 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3535 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
3537 /* This should definitely not happen. */
3538 if (ctx->cb_sequence != 0) {
3539 ctx->cb_sequence = 9999;
3540 error (g, "%s: internal error: reply callback called twice", "guestfs_pvcreate");
3544 ml->main_loop_quit (ml, g);
3546 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3547 error (g, "%s: failed to parse reply header", "guestfs_pvcreate");
3550 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3551 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3552 error (g, "%s: failed to parse reply error", "guestfs_pvcreate");
3558 ctx->cb_sequence = 1;
3561 int guestfs_pvcreate (guestfs_h *g,
3564 struct guestfs_pvcreate_args args;
3565 struct pvcreate_ctx ctx;
3566 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3569 if (check_state (g, "guestfs_pvcreate") == -1) return -1;
3570 guestfs_set_busy (g);
3572 memset (&ctx, 0, sizeof ctx);
3574 args.device = (char *) device;
3575 serial = guestfs__send_sync (g, GUESTFS_PROC_PVCREATE,
3576 (xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
3578 guestfs_end_busy (g);
3582 guestfs__switch_to_receiving (g);
3583 ctx.cb_sequence = 0;
3584 guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx);
3585 (void) ml->main_loop_run (ml, g);
3586 guestfs_set_reply_callback (g, NULL, NULL);
3587 if (ctx.cb_sequence != 1) {
3588 error (g, "%s reply failed, see earlier error messages", "guestfs_pvcreate");
3589 guestfs_end_busy (g);
3593 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVCREATE, serial) == -1) {
3594 guestfs_end_busy (g);
3598 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3599 error (g, "%s", ctx.err.error_message);
3600 free (ctx.err.error_message);
3601 guestfs_end_busy (g);
3605 guestfs_end_busy (g);
3609 struct vgcreate_ctx {
3610 /* This flag is set by the callbacks, so we know we've done
3611 * the callbacks as expected, and in the right sequence.
3612 * 0 = not called, 1 = reply_cb called.
3615 struct guestfs_message_header hdr;
3616 struct guestfs_message_error err;
3619 static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3621 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3622 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3624 /* This should definitely not happen. */
3625 if (ctx->cb_sequence != 0) {
3626 ctx->cb_sequence = 9999;
3627 error (g, "%s: internal error: reply callback called twice", "guestfs_vgcreate");
3631 ml->main_loop_quit (ml, g);
3633 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3634 error (g, "%s: failed to parse reply header", "guestfs_vgcreate");
3637 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3638 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3639 error (g, "%s: failed to parse reply error", "guestfs_vgcreate");
3645 ctx->cb_sequence = 1;
3648 int guestfs_vgcreate (guestfs_h *g,
3649 const char *volgroup,
3650 char * const* const physvols)
3652 struct guestfs_vgcreate_args args;
3653 struct vgcreate_ctx ctx;
3654 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3657 if (check_state (g, "guestfs_vgcreate") == -1) return -1;
3658 guestfs_set_busy (g);
3660 memset (&ctx, 0, sizeof ctx);
3662 args.volgroup = (char *) volgroup;
3663 args.physvols.physvols_val = (char **) physvols;
3664 for (args.physvols.physvols_len = 0; physvols[args.physvols.physvols_len]; args.physvols.physvols_len++) ;
3665 serial = guestfs__send_sync (g, GUESTFS_PROC_VGCREATE,
3666 (xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
3668 guestfs_end_busy (g);
3672 guestfs__switch_to_receiving (g);
3673 ctx.cb_sequence = 0;
3674 guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx);
3675 (void) ml->main_loop_run (ml, g);
3676 guestfs_set_reply_callback (g, NULL, NULL);
3677 if (ctx.cb_sequence != 1) {
3678 error (g, "%s reply failed, see earlier error messages", "guestfs_vgcreate");
3679 guestfs_end_busy (g);
3683 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGCREATE, serial) == -1) {
3684 guestfs_end_busy (g);
3688 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3689 error (g, "%s", ctx.err.error_message);
3690 free (ctx.err.error_message);
3691 guestfs_end_busy (g);
3695 guestfs_end_busy (g);
3699 struct lvcreate_ctx {
3700 /* This flag is set by the callbacks, so we know we've done
3701 * the callbacks as expected, and in the right sequence.
3702 * 0 = not called, 1 = reply_cb called.
3705 struct guestfs_message_header hdr;
3706 struct guestfs_message_error err;
3709 static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3711 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3712 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3714 /* This should definitely not happen. */
3715 if (ctx->cb_sequence != 0) {
3716 ctx->cb_sequence = 9999;
3717 error (g, "%s: internal error: reply callback called twice", "guestfs_lvcreate");
3721 ml->main_loop_quit (ml, g);
3723 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3724 error (g, "%s: failed to parse reply header", "guestfs_lvcreate");
3727 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3728 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3729 error (g, "%s: failed to parse reply error", "guestfs_lvcreate");
3735 ctx->cb_sequence = 1;
3738 int guestfs_lvcreate (guestfs_h *g,
3740 const char *volgroup,
3743 struct guestfs_lvcreate_args args;
3744 struct lvcreate_ctx ctx;
3745 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3748 if (check_state (g, "guestfs_lvcreate") == -1) return -1;
3749 guestfs_set_busy (g);
3751 memset (&ctx, 0, sizeof ctx);
3753 args.logvol = (char *) logvol;
3754 args.volgroup = (char *) volgroup;
3755 args.mbytes = mbytes;
3756 serial = guestfs__send_sync (g, GUESTFS_PROC_LVCREATE,
3757 (xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
3759 guestfs_end_busy (g);
3763 guestfs__switch_to_receiving (g);
3764 ctx.cb_sequence = 0;
3765 guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx);
3766 (void) ml->main_loop_run (ml, g);
3767 guestfs_set_reply_callback (g, NULL, NULL);
3768 if (ctx.cb_sequence != 1) {
3769 error (g, "%s reply failed, see earlier error messages", "guestfs_lvcreate");
3770 guestfs_end_busy (g);
3774 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVCREATE, serial) == -1) {
3775 guestfs_end_busy (g);
3779 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3780 error (g, "%s", ctx.err.error_message);
3781 free (ctx.err.error_message);
3782 guestfs_end_busy (g);
3786 guestfs_end_busy (g);
3791 /* This flag is set by the callbacks, so we know we've done
3792 * the callbacks as expected, and in the right sequence.
3793 * 0 = not called, 1 = reply_cb called.
3796 struct guestfs_message_header hdr;
3797 struct guestfs_message_error err;
3800 static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3802 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3803 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3805 /* This should definitely not happen. */
3806 if (ctx->cb_sequence != 0) {
3807 ctx->cb_sequence = 9999;
3808 error (g, "%s: internal error: reply callback called twice", "guestfs_mkfs");
3812 ml->main_loop_quit (ml, g);
3814 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3815 error (g, "%s: failed to parse reply header", "guestfs_mkfs");
3818 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3819 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3820 error (g, "%s: failed to parse reply error", "guestfs_mkfs");
3826 ctx->cb_sequence = 1;
3829 int guestfs_mkfs (guestfs_h *g,
3833 struct guestfs_mkfs_args args;
3834 struct mkfs_ctx ctx;
3835 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3838 if (check_state (g, "guestfs_mkfs") == -1) return -1;
3839 guestfs_set_busy (g);
3841 memset (&ctx, 0, sizeof ctx);
3843 args.fstype = (char *) fstype;
3844 args.device = (char *) device;
3845 serial = guestfs__send_sync (g, GUESTFS_PROC_MKFS,
3846 (xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
3848 guestfs_end_busy (g);
3852 guestfs__switch_to_receiving (g);
3853 ctx.cb_sequence = 0;
3854 guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx);
3855 (void) ml->main_loop_run (ml, g);
3856 guestfs_set_reply_callback (g, NULL, NULL);
3857 if (ctx.cb_sequence != 1) {
3858 error (g, "%s reply failed, see earlier error messages", "guestfs_mkfs");
3859 guestfs_end_busy (g);
3863 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFS, serial) == -1) {
3864 guestfs_end_busy (g);
3868 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3869 error (g, "%s", ctx.err.error_message);
3870 free (ctx.err.error_message);
3871 guestfs_end_busy (g);
3875 guestfs_end_busy (g);
3880 /* This flag is set by the callbacks, so we know we've done
3881 * the callbacks as expected, and in the right sequence.
3882 * 0 = not called, 1 = reply_cb called.
3885 struct guestfs_message_header hdr;
3886 struct guestfs_message_error err;
3889 static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3891 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3892 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
3894 /* This should definitely not happen. */
3895 if (ctx->cb_sequence != 0) {
3896 ctx->cb_sequence = 9999;
3897 error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk");
3901 ml->main_loop_quit (ml, g);
3903 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3904 error (g, "%s: failed to parse reply header", "guestfs_sfdisk");
3907 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3908 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3909 error (g, "%s: failed to parse reply error", "guestfs_sfdisk");
3915 ctx->cb_sequence = 1;
3918 int guestfs_sfdisk (guestfs_h *g,
3923 char * const* const lines)
3925 struct guestfs_sfdisk_args args;
3926 struct sfdisk_ctx ctx;
3927 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3930 if (check_state (g, "guestfs_sfdisk") == -1) return -1;
3931 guestfs_set_busy (g);
3933 memset (&ctx, 0, sizeof ctx);
3935 args.device = (char *) device;
3938 args.sectors = sectors;
3939 args.lines.lines_val = (char **) lines;
3940 for (args.lines.lines_len = 0; lines[args.lines.lines_len]; args.lines.lines_len++) ;
3941 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK,
3942 (xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
3944 guestfs_end_busy (g);
3948 guestfs__switch_to_receiving (g);
3949 ctx.cb_sequence = 0;
3950 guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx);
3951 (void) ml->main_loop_run (ml, g);
3952 guestfs_set_reply_callback (g, NULL, NULL);
3953 if (ctx.cb_sequence != 1) {
3954 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk");
3955 guestfs_end_busy (g);
3959 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK, serial) == -1) {
3960 guestfs_end_busy (g);
3964 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3965 error (g, "%s", ctx.err.error_message);
3966 free (ctx.err.error_message);
3967 guestfs_end_busy (g);
3971 guestfs_end_busy (g);
3975 struct write_file_ctx {
3976 /* This flag is set by the callbacks, so we know we've done
3977 * the callbacks as expected, and in the right sequence.
3978 * 0 = not called, 1 = reply_cb called.
3981 struct guestfs_message_header hdr;
3982 struct guestfs_message_error err;
3985 static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3987 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3988 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
3990 /* This should definitely not happen. */
3991 if (ctx->cb_sequence != 0) {
3992 ctx->cb_sequence = 9999;
3993 error (g, "%s: internal error: reply callback called twice", "guestfs_write_file");
3997 ml->main_loop_quit (ml, g);
3999 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4000 error (g, "%s: failed to parse reply header", "guestfs_write_file");
4003 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4004 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4005 error (g, "%s: failed to parse reply error", "guestfs_write_file");
4011 ctx->cb_sequence = 1;
4014 int guestfs_write_file (guestfs_h *g,
4016 const char *content,
4019 struct guestfs_write_file_args args;
4020 struct write_file_ctx ctx;
4021 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4024 if (check_state (g, "guestfs_write_file") == -1) return -1;
4025 guestfs_set_busy (g);
4027 memset (&ctx, 0, sizeof ctx);
4029 args.path = (char *) path;
4030 args.content = (char *) content;
4032 serial = guestfs__send_sync (g, GUESTFS_PROC_WRITE_FILE,
4033 (xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
4035 guestfs_end_busy (g);
4039 guestfs__switch_to_receiving (g);
4040 ctx.cb_sequence = 0;
4041 guestfs_set_reply_callback (g, write_file_reply_cb, &ctx);
4042 (void) ml->main_loop_run (ml, g);
4043 guestfs_set_reply_callback (g, NULL, NULL);
4044 if (ctx.cb_sequence != 1) {
4045 error (g, "%s reply failed, see earlier error messages", "guestfs_write_file");
4046 guestfs_end_busy (g);
4050 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WRITE_FILE, serial) == -1) {
4051 guestfs_end_busy (g);
4055 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4056 error (g, "%s", ctx.err.error_message);
4057 free (ctx.err.error_message);
4058 guestfs_end_busy (g);
4062 guestfs_end_busy (g);
4067 /* This flag is set by the callbacks, so we know we've done
4068 * the callbacks as expected, and in the right sequence.
4069 * 0 = not called, 1 = reply_cb called.
4072 struct guestfs_message_header hdr;
4073 struct guestfs_message_error err;
4076 static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4078 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4079 struct umount_ctx *ctx = (struct umount_ctx *) data;
4081 /* This should definitely not happen. */
4082 if (ctx->cb_sequence != 0) {
4083 ctx->cb_sequence = 9999;
4084 error (g, "%s: internal error: reply callback called twice", "guestfs_umount");
4088 ml->main_loop_quit (ml, g);
4090 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4091 error (g, "%s: failed to parse reply header", "guestfs_umount");
4094 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4095 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4096 error (g, "%s: failed to parse reply error", "guestfs_umount");
4102 ctx->cb_sequence = 1;
4105 int guestfs_umount (guestfs_h *g,
4106 const char *pathordevice)
4108 struct guestfs_umount_args args;
4109 struct umount_ctx ctx;
4110 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4113 if (check_state (g, "guestfs_umount") == -1) return -1;
4114 guestfs_set_busy (g);
4116 memset (&ctx, 0, sizeof ctx);
4118 args.pathordevice = (char *) pathordevice;
4119 serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT,
4120 (xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
4122 guestfs_end_busy (g);
4126 guestfs__switch_to_receiving (g);
4127 ctx.cb_sequence = 0;
4128 guestfs_set_reply_callback (g, umount_reply_cb, &ctx);
4129 (void) ml->main_loop_run (ml, g);
4130 guestfs_set_reply_callback (g, NULL, NULL);
4131 if (ctx.cb_sequence != 1) {
4132 error (g, "%s reply failed, see earlier error messages", "guestfs_umount");
4133 guestfs_end_busy (g);
4137 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT, serial) == -1) {
4138 guestfs_end_busy (g);
4142 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4143 error (g, "%s", ctx.err.error_message);
4144 free (ctx.err.error_message);
4145 guestfs_end_busy (g);
4149 guestfs_end_busy (g);
4154 /* This flag is set by the callbacks, so we know we've done
4155 * the callbacks as expected, and in the right sequence.
4156 * 0 = not called, 1 = reply_cb called.
4159 struct guestfs_message_header hdr;
4160 struct guestfs_message_error err;
4161 struct guestfs_mounts_ret ret;
4164 static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4166 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4167 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
4169 /* This should definitely not happen. */
4170 if (ctx->cb_sequence != 0) {
4171 ctx->cb_sequence = 9999;
4172 error (g, "%s: internal error: reply callback called twice", "guestfs_mounts");
4176 ml->main_loop_quit (ml, g);
4178 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4179 error (g, "%s: failed to parse reply header", "guestfs_mounts");
4182 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4183 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4184 error (g, "%s: failed to parse reply error", "guestfs_mounts");
4189 if (!xdr_guestfs_mounts_ret (xdr, &ctx->ret)) {
4190 error (g, "%s: failed to parse reply", "guestfs_mounts");
4194 ctx->cb_sequence = 1;
4197 char **guestfs_mounts (guestfs_h *g)
4199 struct mounts_ctx ctx;
4200 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4203 if (check_state (g, "guestfs_mounts") == -1) return NULL;
4204 guestfs_set_busy (g);
4206 memset (&ctx, 0, sizeof ctx);
4208 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNTS, NULL, NULL);
4210 guestfs_end_busy (g);
4214 guestfs__switch_to_receiving (g);
4215 ctx.cb_sequence = 0;
4216 guestfs_set_reply_callback (g, mounts_reply_cb, &ctx);
4217 (void) ml->main_loop_run (ml, g);
4218 guestfs_set_reply_callback (g, NULL, NULL);
4219 if (ctx.cb_sequence != 1) {
4220 error (g, "%s reply failed, see earlier error messages", "guestfs_mounts");
4221 guestfs_end_busy (g);
4225 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNTS, serial) == -1) {
4226 guestfs_end_busy (g);
4230 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4231 error (g, "%s", ctx.err.error_message);
4232 free (ctx.err.error_message);
4233 guestfs_end_busy (g);
4237 guestfs_end_busy (g);
4238 /* caller will free this, but we need to add a NULL entry */
4239 ctx.ret.devices.devices_val =
4240 safe_realloc (g, ctx.ret.devices.devices_val,
4241 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
4242 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
4243 return ctx.ret.devices.devices_val;
4246 struct umount_all_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 = reply_cb called.
4252 struct guestfs_message_header hdr;
4253 struct guestfs_message_error err;
4256 static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4258 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4259 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
4261 /* This should definitely not happen. */
4262 if (ctx->cb_sequence != 0) {
4263 ctx->cb_sequence = 9999;
4264 error (g, "%s: internal error: reply callback called twice", "guestfs_umount_all");
4268 ml->main_loop_quit (ml, g);
4270 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4271 error (g, "%s: failed to parse reply header", "guestfs_umount_all");
4274 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4275 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4276 error (g, "%s: failed to parse reply error", "guestfs_umount_all");
4282 ctx->cb_sequence = 1;
4285 int guestfs_umount_all (guestfs_h *g)
4287 struct umount_all_ctx ctx;
4288 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4291 if (check_state (g, "guestfs_umount_all") == -1) return -1;
4292 guestfs_set_busy (g);
4294 memset (&ctx, 0, sizeof ctx);
4296 serial = guestfs__send_sync (g, GUESTFS_PROC_UMOUNT_ALL, NULL, NULL);
4298 guestfs_end_busy (g);
4302 guestfs__switch_to_receiving (g);
4303 ctx.cb_sequence = 0;
4304 guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx);
4305 (void) ml->main_loop_run (ml, g);
4306 guestfs_set_reply_callback (g, NULL, NULL);
4307 if (ctx.cb_sequence != 1) {
4308 error (g, "%s reply failed, see earlier error messages", "guestfs_umount_all");
4309 guestfs_end_busy (g);
4313 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT_ALL, serial) == -1) {
4314 guestfs_end_busy (g);
4318 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4319 error (g, "%s", ctx.err.error_message);
4320 free (ctx.err.error_message);
4321 guestfs_end_busy (g);
4325 guestfs_end_busy (g);
4329 struct lvm_remove_all_ctx {
4330 /* This flag is set by the callbacks, so we know we've done
4331 * the callbacks as expected, and in the right sequence.
4332 * 0 = not called, 1 = reply_cb called.
4335 struct guestfs_message_header hdr;
4336 struct guestfs_message_error err;
4339 static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4341 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4342 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
4344 /* This should definitely not happen. */
4345 if (ctx->cb_sequence != 0) {
4346 ctx->cb_sequence = 9999;
4347 error (g, "%s: internal error: reply callback called twice", "guestfs_lvm_remove_all");
4351 ml->main_loop_quit (ml, g);
4353 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4354 error (g, "%s: failed to parse reply header", "guestfs_lvm_remove_all");
4357 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4358 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4359 error (g, "%s: failed to parse reply error", "guestfs_lvm_remove_all");
4365 ctx->cb_sequence = 1;
4368 int guestfs_lvm_remove_all (guestfs_h *g)
4370 struct lvm_remove_all_ctx ctx;
4371 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4374 if (check_state (g, "guestfs_lvm_remove_all") == -1) return -1;
4375 guestfs_set_busy (g);
4377 memset (&ctx, 0, sizeof ctx);
4379 serial = guestfs__send_sync (g, GUESTFS_PROC_LVM_REMOVE_ALL, NULL, NULL);
4381 guestfs_end_busy (g);
4385 guestfs__switch_to_receiving (g);
4386 ctx.cb_sequence = 0;
4387 guestfs_set_reply_callback (g, lvm_remove_all_reply_cb, &ctx);
4388 (void) ml->main_loop_run (ml, g);
4389 guestfs_set_reply_callback (g, NULL, NULL);
4390 if (ctx.cb_sequence != 1) {
4391 error (g, "%s reply failed, see earlier error messages", "guestfs_lvm_remove_all");
4392 guestfs_end_busy (g);
4396 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVM_REMOVE_ALL, serial) == -1) {
4397 guestfs_end_busy (g);
4401 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4402 error (g, "%s", ctx.err.error_message);
4403 free (ctx.err.error_message);
4404 guestfs_end_busy (g);
4408 guestfs_end_busy (g);
4413 /* This flag is set by the callbacks, so we know we've done
4414 * the callbacks as expected, and in the right sequence.
4415 * 0 = not called, 1 = reply_cb called.
4418 struct guestfs_message_header hdr;
4419 struct guestfs_message_error err;
4420 struct guestfs_file_ret ret;
4423 static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4425 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4426 struct file_ctx *ctx = (struct file_ctx *) data;
4428 /* This should definitely not happen. */
4429 if (ctx->cb_sequence != 0) {
4430 ctx->cb_sequence = 9999;
4431 error (g, "%s: internal error: reply callback called twice", "guestfs_file");
4435 ml->main_loop_quit (ml, g);
4437 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4438 error (g, "%s: failed to parse reply header", "guestfs_file");
4441 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4442 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4443 error (g, "%s: failed to parse reply error", "guestfs_file");
4448 if (!xdr_guestfs_file_ret (xdr, &ctx->ret)) {
4449 error (g, "%s: failed to parse reply", "guestfs_file");
4453 ctx->cb_sequence = 1;
4456 char *guestfs_file (guestfs_h *g,
4459 struct guestfs_file_args args;
4460 struct file_ctx ctx;
4461 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4464 if (check_state (g, "guestfs_file") == -1) return NULL;
4465 guestfs_set_busy (g);
4467 memset (&ctx, 0, sizeof ctx);
4469 args.path = (char *) path;
4470 serial = guestfs__send_sync (g, GUESTFS_PROC_FILE,
4471 (xdrproc_t) xdr_guestfs_file_args, (char *) &args);
4473 guestfs_end_busy (g);
4477 guestfs__switch_to_receiving (g);
4478 ctx.cb_sequence = 0;
4479 guestfs_set_reply_callback (g, file_reply_cb, &ctx);
4480 (void) ml->main_loop_run (ml, g);
4481 guestfs_set_reply_callback (g, NULL, NULL);
4482 if (ctx.cb_sequence != 1) {
4483 error (g, "%s reply failed, see earlier error messages", "guestfs_file");
4484 guestfs_end_busy (g);
4488 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FILE, serial) == -1) {
4489 guestfs_end_busy (g);
4493 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4494 error (g, "%s", ctx.err.error_message);
4495 free (ctx.err.error_message);
4496 guestfs_end_busy (g);
4500 guestfs_end_busy (g);
4501 return ctx.ret.description; /* caller will free */
4504 struct command_ctx {
4505 /* This flag is set by the callbacks, so we know we've done
4506 * the callbacks as expected, and in the right sequence.
4507 * 0 = not called, 1 = reply_cb called.
4510 struct guestfs_message_header hdr;
4511 struct guestfs_message_error err;
4512 struct guestfs_command_ret ret;
4515 static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4517 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4518 struct command_ctx *ctx = (struct command_ctx *) data;
4520 /* This should definitely not happen. */
4521 if (ctx->cb_sequence != 0) {
4522 ctx->cb_sequence = 9999;
4523 error (g, "%s: internal error: reply callback called twice", "guestfs_command");
4527 ml->main_loop_quit (ml, g);
4529 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4530 error (g, "%s: failed to parse reply header", "guestfs_command");
4533 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4534 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4535 error (g, "%s: failed to parse reply error", "guestfs_command");
4540 if (!xdr_guestfs_command_ret (xdr, &ctx->ret)) {
4541 error (g, "%s: failed to parse reply", "guestfs_command");
4545 ctx->cb_sequence = 1;
4548 char *guestfs_command (guestfs_h *g,
4549 char * const* const arguments)
4551 struct guestfs_command_args args;
4552 struct command_ctx ctx;
4553 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4556 if (check_state (g, "guestfs_command") == -1) return NULL;
4557 guestfs_set_busy (g);
4559 memset (&ctx, 0, sizeof ctx);
4561 args.arguments.arguments_val = (char **) arguments;
4562 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4563 serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND,
4564 (xdrproc_t) xdr_guestfs_command_args, (char *) &args);
4566 guestfs_end_busy (g);
4570 guestfs__switch_to_receiving (g);
4571 ctx.cb_sequence = 0;
4572 guestfs_set_reply_callback (g, command_reply_cb, &ctx);
4573 (void) ml->main_loop_run (ml, g);
4574 guestfs_set_reply_callback (g, NULL, NULL);
4575 if (ctx.cb_sequence != 1) {
4576 error (g, "%s reply failed, see earlier error messages", "guestfs_command");
4577 guestfs_end_busy (g);
4581 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND, serial) == -1) {
4582 guestfs_end_busy (g);
4586 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4587 error (g, "%s", ctx.err.error_message);
4588 free (ctx.err.error_message);
4589 guestfs_end_busy (g);
4593 guestfs_end_busy (g);
4594 return ctx.ret.output; /* caller will free */
4597 struct command_lines_ctx {
4598 /* This flag is set by the callbacks, so we know we've done
4599 * the callbacks as expected, and in the right sequence.
4600 * 0 = not called, 1 = reply_cb called.
4603 struct guestfs_message_header hdr;
4604 struct guestfs_message_error err;
4605 struct guestfs_command_lines_ret ret;
4608 static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4610 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4611 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
4613 /* This should definitely not happen. */
4614 if (ctx->cb_sequence != 0) {
4615 ctx->cb_sequence = 9999;
4616 error (g, "%s: internal error: reply callback called twice", "guestfs_command_lines");
4620 ml->main_loop_quit (ml, g);
4622 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4623 error (g, "%s: failed to parse reply header", "guestfs_command_lines");
4626 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4627 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4628 error (g, "%s: failed to parse reply error", "guestfs_command_lines");
4633 if (!xdr_guestfs_command_lines_ret (xdr, &ctx->ret)) {
4634 error (g, "%s: failed to parse reply", "guestfs_command_lines");
4638 ctx->cb_sequence = 1;
4641 char **guestfs_command_lines (guestfs_h *g,
4642 char * const* const arguments)
4644 struct guestfs_command_lines_args args;
4645 struct command_lines_ctx ctx;
4646 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4649 if (check_state (g, "guestfs_command_lines") == -1) return NULL;
4650 guestfs_set_busy (g);
4652 memset (&ctx, 0, sizeof ctx);
4654 args.arguments.arguments_val = (char **) arguments;
4655 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4656 serial = guestfs__send_sync (g, GUESTFS_PROC_COMMAND_LINES,
4657 (xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args);
4659 guestfs_end_busy (g);
4663 guestfs__switch_to_receiving (g);
4664 ctx.cb_sequence = 0;
4665 guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx);
4666 (void) ml->main_loop_run (ml, g);
4667 guestfs_set_reply_callback (g, NULL, NULL);
4668 if (ctx.cb_sequence != 1) {
4669 error (g, "%s reply failed, see earlier error messages", "guestfs_command_lines");
4670 guestfs_end_busy (g);
4674 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND_LINES, serial) == -1) {
4675 guestfs_end_busy (g);
4679 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4680 error (g, "%s", ctx.err.error_message);
4681 free (ctx.err.error_message);
4682 guestfs_end_busy (g);
4686 guestfs_end_busy (g);
4687 /* caller will free this, but we need to add a NULL entry */
4688 ctx.ret.lines.lines_val =
4689 safe_realloc (g, ctx.ret.lines.lines_val,
4690 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
4691 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
4692 return ctx.ret.lines.lines_val;
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 = reply_cb called.
4701 struct guestfs_message_header hdr;
4702 struct guestfs_message_error err;
4703 struct guestfs_stat_ret ret;
4706 static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4708 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4709 struct stat_ctx *ctx = (struct stat_ctx *) data;
4711 /* This should definitely not happen. */
4712 if (ctx->cb_sequence != 0) {
4713 ctx->cb_sequence = 9999;
4714 error (g, "%s: internal error: reply callback called twice", "guestfs_stat");
4718 ml->main_loop_quit (ml, g);
4720 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4721 error (g, "%s: failed to parse reply header", "guestfs_stat");
4724 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4725 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4726 error (g, "%s: failed to parse reply error", "guestfs_stat");
4731 if (!xdr_guestfs_stat_ret (xdr, &ctx->ret)) {
4732 error (g, "%s: failed to parse reply", "guestfs_stat");
4736 ctx->cb_sequence = 1;
4739 struct guestfs_stat *guestfs_stat (guestfs_h *g,
4742 struct guestfs_stat_args args;
4743 struct stat_ctx ctx;
4744 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4747 if (check_state (g, "guestfs_stat") == -1) return NULL;
4748 guestfs_set_busy (g);
4750 memset (&ctx, 0, sizeof ctx);
4752 args.path = (char *) path;
4753 serial = guestfs__send_sync (g, GUESTFS_PROC_STAT,
4754 (xdrproc_t) xdr_guestfs_stat_args, (char *) &args);
4756 guestfs_end_busy (g);
4760 guestfs__switch_to_receiving (g);
4761 ctx.cb_sequence = 0;
4762 guestfs_set_reply_callback (g, stat_reply_cb, &ctx);
4763 (void) ml->main_loop_run (ml, g);
4764 guestfs_set_reply_callback (g, NULL, NULL);
4765 if (ctx.cb_sequence != 1) {
4766 error (g, "%s reply failed, see earlier error messages", "guestfs_stat");
4767 guestfs_end_busy (g);
4771 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STAT, serial) == -1) {
4772 guestfs_end_busy (g);
4776 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4777 error (g, "%s", ctx.err.error_message);
4778 free (ctx.err.error_message);
4779 guestfs_end_busy (g);
4783 guestfs_end_busy (g);
4784 /* caller will free this */
4785 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4789 /* This flag is set by the callbacks, so we know we've done
4790 * the callbacks as expected, and in the right sequence.
4791 * 0 = not called, 1 = reply_cb called.
4794 struct guestfs_message_header hdr;
4795 struct guestfs_message_error err;
4796 struct guestfs_lstat_ret ret;
4799 static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4801 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4802 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4804 /* This should definitely not happen. */
4805 if (ctx->cb_sequence != 0) {
4806 ctx->cb_sequence = 9999;
4807 error (g, "%s: internal error: reply callback called twice", "guestfs_lstat");
4811 ml->main_loop_quit (ml, g);
4813 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4814 error (g, "%s: failed to parse reply header", "guestfs_lstat");
4817 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4818 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4819 error (g, "%s: failed to parse reply error", "guestfs_lstat");
4824 if (!xdr_guestfs_lstat_ret (xdr, &ctx->ret)) {
4825 error (g, "%s: failed to parse reply", "guestfs_lstat");
4829 ctx->cb_sequence = 1;
4832 struct guestfs_stat *guestfs_lstat (guestfs_h *g,
4835 struct guestfs_lstat_args args;
4836 struct lstat_ctx ctx;
4837 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4840 if (check_state (g, "guestfs_lstat") == -1) return NULL;
4841 guestfs_set_busy (g);
4843 memset (&ctx, 0, sizeof ctx);
4845 args.path = (char *) path;
4846 serial = guestfs__send_sync (g, GUESTFS_PROC_LSTAT,
4847 (xdrproc_t) xdr_guestfs_lstat_args, (char *) &args);
4849 guestfs_end_busy (g);
4853 guestfs__switch_to_receiving (g);
4854 ctx.cb_sequence = 0;
4855 guestfs_set_reply_callback (g, lstat_reply_cb, &ctx);
4856 (void) ml->main_loop_run (ml, g);
4857 guestfs_set_reply_callback (g, NULL, NULL);
4858 if (ctx.cb_sequence != 1) {
4859 error (g, "%s reply failed, see earlier error messages", "guestfs_lstat");
4860 guestfs_end_busy (g);
4864 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LSTAT, serial) == -1) {
4865 guestfs_end_busy (g);
4869 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4870 error (g, "%s", ctx.err.error_message);
4871 free (ctx.err.error_message);
4872 guestfs_end_busy (g);
4876 guestfs_end_busy (g);
4877 /* caller will free this */
4878 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4881 struct statvfs_ctx {
4882 /* This flag is set by the callbacks, so we know we've done
4883 * the callbacks as expected, and in the right sequence.
4884 * 0 = not called, 1 = reply_cb called.
4887 struct guestfs_message_header hdr;
4888 struct guestfs_message_error err;
4889 struct guestfs_statvfs_ret ret;
4892 static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4894 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4895 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
4897 /* This should definitely not happen. */
4898 if (ctx->cb_sequence != 0) {
4899 ctx->cb_sequence = 9999;
4900 error (g, "%s: internal error: reply callback called twice", "guestfs_statvfs");
4904 ml->main_loop_quit (ml, g);
4906 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4907 error (g, "%s: failed to parse reply header", "guestfs_statvfs");
4910 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4911 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4912 error (g, "%s: failed to parse reply error", "guestfs_statvfs");
4917 if (!xdr_guestfs_statvfs_ret (xdr, &ctx->ret)) {
4918 error (g, "%s: failed to parse reply", "guestfs_statvfs");
4922 ctx->cb_sequence = 1;
4925 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
4928 struct guestfs_statvfs_args args;
4929 struct statvfs_ctx ctx;
4930 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4933 if (check_state (g, "guestfs_statvfs") == -1) return NULL;
4934 guestfs_set_busy (g);
4936 memset (&ctx, 0, sizeof ctx);
4938 args.path = (char *) path;
4939 serial = guestfs__send_sync (g, GUESTFS_PROC_STATVFS,
4940 (xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args);
4942 guestfs_end_busy (g);
4946 guestfs__switch_to_receiving (g);
4947 ctx.cb_sequence = 0;
4948 guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx);
4949 (void) ml->main_loop_run (ml, g);
4950 guestfs_set_reply_callback (g, NULL, NULL);
4951 if (ctx.cb_sequence != 1) {
4952 error (g, "%s reply failed, see earlier error messages", "guestfs_statvfs");
4953 guestfs_end_busy (g);
4957 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STATVFS, serial) == -1) {
4958 guestfs_end_busy (g);
4962 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4963 error (g, "%s", ctx.err.error_message);
4964 free (ctx.err.error_message);
4965 guestfs_end_busy (g);
4969 guestfs_end_busy (g);
4970 /* caller will free this */
4971 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4974 struct tune2fs_l_ctx {
4975 /* This flag is set by the callbacks, so we know we've done
4976 * the callbacks as expected, and in the right sequence.
4977 * 0 = not called, 1 = reply_cb called.
4980 struct guestfs_message_header hdr;
4981 struct guestfs_message_error err;
4982 struct guestfs_tune2fs_l_ret ret;
4985 static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4987 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4988 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
4990 /* This should definitely not happen. */
4991 if (ctx->cb_sequence != 0) {
4992 ctx->cb_sequence = 9999;
4993 error (g, "%s: internal error: reply callback called twice", "guestfs_tune2fs_l");
4997 ml->main_loop_quit (ml, g);
4999 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5000 error (g, "%s: failed to parse reply header", "guestfs_tune2fs_l");
5003 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5004 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5005 error (g, "%s: failed to parse reply error", "guestfs_tune2fs_l");
5010 if (!xdr_guestfs_tune2fs_l_ret (xdr, &ctx->ret)) {
5011 error (g, "%s: failed to parse reply", "guestfs_tune2fs_l");
5015 ctx->cb_sequence = 1;
5018 char **guestfs_tune2fs_l (guestfs_h *g,
5021 struct guestfs_tune2fs_l_args args;
5022 struct tune2fs_l_ctx ctx;
5023 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5026 if (check_state (g, "guestfs_tune2fs_l") == -1) return NULL;
5027 guestfs_set_busy (g);
5029 memset (&ctx, 0, sizeof ctx);
5031 args.device = (char *) device;
5032 serial = guestfs__send_sync (g, GUESTFS_PROC_TUNE2FS_L,
5033 (xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args);
5035 guestfs_end_busy (g);
5039 guestfs__switch_to_receiving (g);
5040 ctx.cb_sequence = 0;
5041 guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx);
5042 (void) ml->main_loop_run (ml, g);
5043 guestfs_set_reply_callback (g, NULL, NULL);
5044 if (ctx.cb_sequence != 1) {
5045 error (g, "%s reply failed, see earlier error messages", "guestfs_tune2fs_l");
5046 guestfs_end_busy (g);
5050 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TUNE2FS_L, serial) == -1) {
5051 guestfs_end_busy (g);
5055 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5056 error (g, "%s", ctx.err.error_message);
5057 free (ctx.err.error_message);
5058 guestfs_end_busy (g);
5062 guestfs_end_busy (g);
5063 /* caller will free this, but we need to add a NULL entry */
5064 ctx.ret.superblock.superblock_val =
5065 safe_realloc (g, ctx.ret.superblock.superblock_val,
5066 sizeof (char *) * (ctx.ret.superblock.superblock_len + 1));
5067 ctx.ret.superblock.superblock_val[ctx.ret.superblock.superblock_len] = NULL;
5068 return ctx.ret.superblock.superblock_val;
5071 struct blockdev_setro_ctx {
5072 /* This flag is set by the callbacks, so we know we've done
5073 * the callbacks as expected, and in the right sequence.
5074 * 0 = not called, 1 = reply_cb called.
5077 struct guestfs_message_header hdr;
5078 struct guestfs_message_error err;
5081 static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5083 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5084 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
5086 /* This should definitely not happen. */
5087 if (ctx->cb_sequence != 0) {
5088 ctx->cb_sequence = 9999;
5089 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setro");
5093 ml->main_loop_quit (ml, g);
5095 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5096 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setro");
5099 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5100 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5101 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setro");
5107 ctx->cb_sequence = 1;
5110 int guestfs_blockdev_setro (guestfs_h *g,
5113 struct guestfs_blockdev_setro_args args;
5114 struct blockdev_setro_ctx ctx;
5115 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5118 if (check_state (g, "guestfs_blockdev_setro") == -1) return -1;
5119 guestfs_set_busy (g);
5121 memset (&ctx, 0, sizeof ctx);
5123 args.device = (char *) device;
5124 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRO,
5125 (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args);
5127 guestfs_end_busy (g);
5131 guestfs__switch_to_receiving (g);
5132 ctx.cb_sequence = 0;
5133 guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx);
5134 (void) ml->main_loop_run (ml, g);
5135 guestfs_set_reply_callback (g, NULL, NULL);
5136 if (ctx.cb_sequence != 1) {
5137 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setro");
5138 guestfs_end_busy (g);
5142 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1) {
5143 guestfs_end_busy (g);
5147 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5148 error (g, "%s", ctx.err.error_message);
5149 free (ctx.err.error_message);
5150 guestfs_end_busy (g);
5154 guestfs_end_busy (g);
5158 struct blockdev_setrw_ctx {
5159 /* This flag is set by the callbacks, so we know we've done
5160 * the callbacks as expected, and in the right sequence.
5161 * 0 = not called, 1 = reply_cb called.
5164 struct guestfs_message_header hdr;
5165 struct guestfs_message_error err;
5168 static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5170 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5171 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
5173 /* This should definitely not happen. */
5174 if (ctx->cb_sequence != 0) {
5175 ctx->cb_sequence = 9999;
5176 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setrw");
5180 ml->main_loop_quit (ml, g);
5182 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5183 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setrw");
5186 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5187 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5188 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setrw");
5194 ctx->cb_sequence = 1;
5197 int guestfs_blockdev_setrw (guestfs_h *g,
5200 struct guestfs_blockdev_setrw_args args;
5201 struct blockdev_setrw_ctx ctx;
5202 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5205 if (check_state (g, "guestfs_blockdev_setrw") == -1) return -1;
5206 guestfs_set_busy (g);
5208 memset (&ctx, 0, sizeof ctx);
5210 args.device = (char *) device;
5211 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETRW,
5212 (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args);
5214 guestfs_end_busy (g);
5218 guestfs__switch_to_receiving (g);
5219 ctx.cb_sequence = 0;
5220 guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx);
5221 (void) ml->main_loop_run (ml, g);
5222 guestfs_set_reply_callback (g, NULL, NULL);
5223 if (ctx.cb_sequence != 1) {
5224 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setrw");
5225 guestfs_end_busy (g);
5229 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1) {
5230 guestfs_end_busy (g);
5234 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5235 error (g, "%s", ctx.err.error_message);
5236 free (ctx.err.error_message);
5237 guestfs_end_busy (g);
5241 guestfs_end_busy (g);
5245 struct blockdev_getro_ctx {
5246 /* This flag is set by the callbacks, so we know we've done
5247 * the callbacks as expected, and in the right sequence.
5248 * 0 = not called, 1 = reply_cb called.
5251 struct guestfs_message_header hdr;
5252 struct guestfs_message_error err;
5253 struct guestfs_blockdev_getro_ret ret;
5256 static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5258 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5259 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
5261 /* This should definitely not happen. */
5262 if (ctx->cb_sequence != 0) {
5263 ctx->cb_sequence = 9999;
5264 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getro");
5268 ml->main_loop_quit (ml, g);
5270 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5271 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getro");
5274 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5275 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5276 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getro");
5281 if (!xdr_guestfs_blockdev_getro_ret (xdr, &ctx->ret)) {
5282 error (g, "%s: failed to parse reply", "guestfs_blockdev_getro");
5286 ctx->cb_sequence = 1;
5289 int guestfs_blockdev_getro (guestfs_h *g,
5292 struct guestfs_blockdev_getro_args args;
5293 struct blockdev_getro_ctx ctx;
5294 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5297 if (check_state (g, "guestfs_blockdev_getro") == -1) return -1;
5298 guestfs_set_busy (g);
5300 memset (&ctx, 0, sizeof ctx);
5302 args.device = (char *) device;
5303 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETRO,
5304 (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args);
5306 guestfs_end_busy (g);
5310 guestfs__switch_to_receiving (g);
5311 ctx.cb_sequence = 0;
5312 guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx);
5313 (void) ml->main_loop_run (ml, g);
5314 guestfs_set_reply_callback (g, NULL, NULL);
5315 if (ctx.cb_sequence != 1) {
5316 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getro");
5317 guestfs_end_busy (g);
5321 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1) {
5322 guestfs_end_busy (g);
5326 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5327 error (g, "%s", ctx.err.error_message);
5328 free (ctx.err.error_message);
5329 guestfs_end_busy (g);
5333 guestfs_end_busy (g);
5337 struct blockdev_getss_ctx {
5338 /* This flag is set by the callbacks, so we know we've done
5339 * the callbacks as expected, and in the right sequence.
5340 * 0 = not called, 1 = reply_cb called.
5343 struct guestfs_message_header hdr;
5344 struct guestfs_message_error err;
5345 struct guestfs_blockdev_getss_ret ret;
5348 static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5350 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5351 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
5353 /* This should definitely not happen. */
5354 if (ctx->cb_sequence != 0) {
5355 ctx->cb_sequence = 9999;
5356 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getss");
5360 ml->main_loop_quit (ml, g);
5362 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5363 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getss");
5366 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5367 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5368 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getss");
5373 if (!xdr_guestfs_blockdev_getss_ret (xdr, &ctx->ret)) {
5374 error (g, "%s: failed to parse reply", "guestfs_blockdev_getss");
5378 ctx->cb_sequence = 1;
5381 int guestfs_blockdev_getss (guestfs_h *g,
5384 struct guestfs_blockdev_getss_args args;
5385 struct blockdev_getss_ctx ctx;
5386 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5389 if (check_state (g, "guestfs_blockdev_getss") == -1) return -1;
5390 guestfs_set_busy (g);
5392 memset (&ctx, 0, sizeof ctx);
5394 args.device = (char *) device;
5395 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSS,
5396 (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args);
5398 guestfs_end_busy (g);
5402 guestfs__switch_to_receiving (g);
5403 ctx.cb_sequence = 0;
5404 guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx);
5405 (void) ml->main_loop_run (ml, g);
5406 guestfs_set_reply_callback (g, NULL, NULL);
5407 if (ctx.cb_sequence != 1) {
5408 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getss");
5409 guestfs_end_busy (g);
5413 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1) {
5414 guestfs_end_busy (g);
5418 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5419 error (g, "%s", ctx.err.error_message);
5420 free (ctx.err.error_message);
5421 guestfs_end_busy (g);
5425 guestfs_end_busy (g);
5426 return ctx.ret.sectorsize;
5429 struct blockdev_getbsz_ctx {
5430 /* This flag is set by the callbacks, so we know we've done
5431 * the callbacks as expected, and in the right sequence.
5432 * 0 = not called, 1 = reply_cb called.
5435 struct guestfs_message_header hdr;
5436 struct guestfs_message_error err;
5437 struct guestfs_blockdev_getbsz_ret ret;
5440 static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5442 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5443 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
5445 /* This should definitely not happen. */
5446 if (ctx->cb_sequence != 0) {
5447 ctx->cb_sequence = 9999;
5448 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getbsz");
5452 ml->main_loop_quit (ml, g);
5454 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5455 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getbsz");
5458 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5459 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5460 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getbsz");
5465 if (!xdr_guestfs_blockdev_getbsz_ret (xdr, &ctx->ret)) {
5466 error (g, "%s: failed to parse reply", "guestfs_blockdev_getbsz");
5470 ctx->cb_sequence = 1;
5473 int guestfs_blockdev_getbsz (guestfs_h *g,
5476 struct guestfs_blockdev_getbsz_args args;
5477 struct blockdev_getbsz_ctx ctx;
5478 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5481 if (check_state (g, "guestfs_blockdev_getbsz") == -1) return -1;
5482 guestfs_set_busy (g);
5484 memset (&ctx, 0, sizeof ctx);
5486 args.device = (char *) device;
5487 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETBSZ,
5488 (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args);
5490 guestfs_end_busy (g);
5494 guestfs__switch_to_receiving (g);
5495 ctx.cb_sequence = 0;
5496 guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx);
5497 (void) ml->main_loop_run (ml, g);
5498 guestfs_set_reply_callback (g, NULL, NULL);
5499 if (ctx.cb_sequence != 1) {
5500 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getbsz");
5501 guestfs_end_busy (g);
5505 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1) {
5506 guestfs_end_busy (g);
5510 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5511 error (g, "%s", ctx.err.error_message);
5512 free (ctx.err.error_message);
5513 guestfs_end_busy (g);
5517 guestfs_end_busy (g);
5518 return ctx.ret.blocksize;
5521 struct blockdev_setbsz_ctx {
5522 /* This flag is set by the callbacks, so we know we've done
5523 * the callbacks as expected, and in the right sequence.
5524 * 0 = not called, 1 = reply_cb called.
5527 struct guestfs_message_header hdr;
5528 struct guestfs_message_error err;
5531 static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5533 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5534 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
5536 /* This should definitely not happen. */
5537 if (ctx->cb_sequence != 0) {
5538 ctx->cb_sequence = 9999;
5539 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_setbsz");
5543 ml->main_loop_quit (ml, g);
5545 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5546 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setbsz");
5549 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5550 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5551 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setbsz");
5557 ctx->cb_sequence = 1;
5560 int guestfs_blockdev_setbsz (guestfs_h *g,
5564 struct guestfs_blockdev_setbsz_args args;
5565 struct blockdev_setbsz_ctx ctx;
5566 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5569 if (check_state (g, "guestfs_blockdev_setbsz") == -1) return -1;
5570 guestfs_set_busy (g);
5572 memset (&ctx, 0, sizeof ctx);
5574 args.device = (char *) device;
5575 args.blocksize = blocksize;
5576 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_SETBSZ,
5577 (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args);
5579 guestfs_end_busy (g);
5583 guestfs__switch_to_receiving (g);
5584 ctx.cb_sequence = 0;
5585 guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx);
5586 (void) ml->main_loop_run (ml, g);
5587 guestfs_set_reply_callback (g, NULL, NULL);
5588 if (ctx.cb_sequence != 1) {
5589 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setbsz");
5590 guestfs_end_busy (g);
5594 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1) {
5595 guestfs_end_busy (g);
5599 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5600 error (g, "%s", ctx.err.error_message);
5601 free (ctx.err.error_message);
5602 guestfs_end_busy (g);
5606 guestfs_end_busy (g);
5610 struct blockdev_getsz_ctx {
5611 /* This flag is set by the callbacks, so we know we've done
5612 * the callbacks as expected, and in the right sequence.
5613 * 0 = not called, 1 = reply_cb called.
5616 struct guestfs_message_header hdr;
5617 struct guestfs_message_error err;
5618 struct guestfs_blockdev_getsz_ret ret;
5621 static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5623 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5624 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
5626 /* This should definitely not happen. */
5627 if (ctx->cb_sequence != 0) {
5628 ctx->cb_sequence = 9999;
5629 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getsz");
5633 ml->main_loop_quit (ml, g);
5635 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5636 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsz");
5639 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5640 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5641 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsz");
5646 if (!xdr_guestfs_blockdev_getsz_ret (xdr, &ctx->ret)) {
5647 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsz");
5651 ctx->cb_sequence = 1;
5654 int64_t guestfs_blockdev_getsz (guestfs_h *g,
5657 struct guestfs_blockdev_getsz_args args;
5658 struct blockdev_getsz_ctx ctx;
5659 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5662 if (check_state (g, "guestfs_blockdev_getsz") == -1) return -1;
5663 guestfs_set_busy (g);
5665 memset (&ctx, 0, sizeof ctx);
5667 args.device = (char *) device;
5668 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSZ,
5669 (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args);
5671 guestfs_end_busy (g);
5675 guestfs__switch_to_receiving (g);
5676 ctx.cb_sequence = 0;
5677 guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx);
5678 (void) ml->main_loop_run (ml, g);
5679 guestfs_set_reply_callback (g, NULL, NULL);
5680 if (ctx.cb_sequence != 1) {
5681 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsz");
5682 guestfs_end_busy (g);
5686 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1) {
5687 guestfs_end_busy (g);
5691 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5692 error (g, "%s", ctx.err.error_message);
5693 free (ctx.err.error_message);
5694 guestfs_end_busy (g);
5698 guestfs_end_busy (g);
5699 return ctx.ret.sizeinsectors;
5702 struct blockdev_getsize64_ctx {
5703 /* This flag is set by the callbacks, so we know we've done
5704 * the callbacks as expected, and in the right sequence.
5705 * 0 = not called, 1 = reply_cb called.
5708 struct guestfs_message_header hdr;
5709 struct guestfs_message_error err;
5710 struct guestfs_blockdev_getsize64_ret ret;
5713 static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5715 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5716 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
5718 /* This should definitely not happen. */
5719 if (ctx->cb_sequence != 0) {
5720 ctx->cb_sequence = 9999;
5721 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_getsize64");
5725 ml->main_loop_quit (ml, g);
5727 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5728 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsize64");
5731 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5732 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5733 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsize64");
5738 if (!xdr_guestfs_blockdev_getsize64_ret (xdr, &ctx->ret)) {
5739 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsize64");
5743 ctx->cb_sequence = 1;
5746 int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
5749 struct guestfs_blockdev_getsize64_args args;
5750 struct blockdev_getsize64_ctx ctx;
5751 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5754 if (check_state (g, "guestfs_blockdev_getsize64") == -1) return -1;
5755 guestfs_set_busy (g);
5757 memset (&ctx, 0, sizeof ctx);
5759 args.device = (char *) device;
5760 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64,
5761 (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args);
5763 guestfs_end_busy (g);
5767 guestfs__switch_to_receiving (g);
5768 ctx.cb_sequence = 0;
5769 guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx);
5770 (void) ml->main_loop_run (ml, g);
5771 guestfs_set_reply_callback (g, NULL, NULL);
5772 if (ctx.cb_sequence != 1) {
5773 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsize64");
5774 guestfs_end_busy (g);
5778 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1) {
5779 guestfs_end_busy (g);
5783 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5784 error (g, "%s", ctx.err.error_message);
5785 free (ctx.err.error_message);
5786 guestfs_end_busy (g);
5790 guestfs_end_busy (g);
5791 return ctx.ret.sizeinbytes;
5794 struct blockdev_flushbufs_ctx {
5795 /* This flag is set by the callbacks, so we know we've done
5796 * the callbacks as expected, and in the right sequence.
5797 * 0 = not called, 1 = reply_cb called.
5800 struct guestfs_message_header hdr;
5801 struct guestfs_message_error err;
5804 static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5806 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5807 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
5809 /* This should definitely not happen. */
5810 if (ctx->cb_sequence != 0) {
5811 ctx->cb_sequence = 9999;
5812 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_flushbufs");
5816 ml->main_loop_quit (ml, g);
5818 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5819 error (g, "%s: failed to parse reply header", "guestfs_blockdev_flushbufs");
5822 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5823 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5824 error (g, "%s: failed to parse reply error", "guestfs_blockdev_flushbufs");
5830 ctx->cb_sequence = 1;
5833 int guestfs_blockdev_flushbufs (guestfs_h *g,
5836 struct guestfs_blockdev_flushbufs_args args;
5837 struct blockdev_flushbufs_ctx ctx;
5838 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5841 if (check_state (g, "guestfs_blockdev_flushbufs") == -1) return -1;
5842 guestfs_set_busy (g);
5844 memset (&ctx, 0, sizeof ctx);
5846 args.device = (char *) device;
5847 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS,
5848 (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args);
5850 guestfs_end_busy (g);
5854 guestfs__switch_to_receiving (g);
5855 ctx.cb_sequence = 0;
5856 guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx);
5857 (void) ml->main_loop_run (ml, g);
5858 guestfs_set_reply_callback (g, NULL, NULL);
5859 if (ctx.cb_sequence != 1) {
5860 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_flushbufs");
5861 guestfs_end_busy (g);
5865 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1) {
5866 guestfs_end_busy (g);
5870 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5871 error (g, "%s", ctx.err.error_message);
5872 free (ctx.err.error_message);
5873 guestfs_end_busy (g);
5877 guestfs_end_busy (g);
5881 struct blockdev_rereadpt_ctx {
5882 /* This flag is set by the callbacks, so we know we've done
5883 * the callbacks as expected, and in the right sequence.
5884 * 0 = not called, 1 = reply_cb called.
5887 struct guestfs_message_header hdr;
5888 struct guestfs_message_error err;
5891 static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5893 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5894 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
5896 /* This should definitely not happen. */
5897 if (ctx->cb_sequence != 0) {
5898 ctx->cb_sequence = 9999;
5899 error (g, "%s: internal error: reply callback called twice", "guestfs_blockdev_rereadpt");
5903 ml->main_loop_quit (ml, g);
5905 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5906 error (g, "%s: failed to parse reply header", "guestfs_blockdev_rereadpt");
5909 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5910 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5911 error (g, "%s: failed to parse reply error", "guestfs_blockdev_rereadpt");
5917 ctx->cb_sequence = 1;
5920 int guestfs_blockdev_rereadpt (guestfs_h *g,
5923 struct guestfs_blockdev_rereadpt_args args;
5924 struct blockdev_rereadpt_ctx ctx;
5925 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5928 if (check_state (g, "guestfs_blockdev_rereadpt") == -1) return -1;
5929 guestfs_set_busy (g);
5931 memset (&ctx, 0, sizeof ctx);
5933 args.device = (char *) device;
5934 serial = guestfs__send_sync (g, GUESTFS_PROC_BLOCKDEV_REREADPT,
5935 (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args);
5937 guestfs_end_busy (g);
5941 guestfs__switch_to_receiving (g);
5942 ctx.cb_sequence = 0;
5943 guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx);
5944 (void) ml->main_loop_run (ml, g);
5945 guestfs_set_reply_callback (g, NULL, NULL);
5946 if (ctx.cb_sequence != 1) {
5947 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_rereadpt");
5948 guestfs_end_busy (g);
5952 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1) {
5953 guestfs_end_busy (g);
5957 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5958 error (g, "%s", ctx.err.error_message);
5959 free (ctx.err.error_message);
5960 guestfs_end_busy (g);
5964 guestfs_end_busy (g);
5969 /* This flag is set by the callbacks, so we know we've done
5970 * the callbacks as expected, and in the right sequence.
5971 * 0 = not called, 1 = reply_cb called.
5974 struct guestfs_message_header hdr;
5975 struct guestfs_message_error err;
5978 static void upload_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5980 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5981 struct upload_ctx *ctx = (struct upload_ctx *) data;
5983 /* This should definitely not happen. */
5984 if (ctx->cb_sequence != 0) {
5985 ctx->cb_sequence = 9999;
5986 error (g, "%s: internal error: reply callback called twice", "guestfs_upload");
5990 ml->main_loop_quit (ml, g);
5992 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5993 error (g, "%s: failed to parse reply header", "guestfs_upload");
5996 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5997 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5998 error (g, "%s: failed to parse reply error", "guestfs_upload");
6004 ctx->cb_sequence = 1;
6007 int guestfs_upload (guestfs_h *g,
6008 const char *filename,
6009 const char *remotefilename)
6011 struct guestfs_upload_args args;
6012 struct upload_ctx ctx;
6013 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6016 if (check_state (g, "guestfs_upload") == -1) return -1;
6017 guestfs_set_busy (g);
6019 memset (&ctx, 0, sizeof ctx);
6021 args.remotefilename = (char *) remotefilename;
6022 serial = guestfs__send_sync (g, GUESTFS_PROC_UPLOAD,
6023 (xdrproc_t) xdr_guestfs_upload_args, (char *) &args);
6025 guestfs_end_busy (g);
6032 r = guestfs__send_file_sync (g, filename);
6034 guestfs_end_busy (g);
6037 if (r == -2) /* daemon cancelled */
6042 guestfs__switch_to_receiving (g);
6043 ctx.cb_sequence = 0;
6044 guestfs_set_reply_callback (g, upload_reply_cb, &ctx);
6045 (void) ml->main_loop_run (ml, g);
6046 guestfs_set_reply_callback (g, NULL, NULL);
6047 if (ctx.cb_sequence != 1) {
6048 error (g, "%s reply failed, see earlier error messages", "guestfs_upload");
6049 guestfs_end_busy (g);
6053 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UPLOAD, serial) == -1) {
6054 guestfs_end_busy (g);
6058 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6059 error (g, "%s", ctx.err.error_message);
6060 free (ctx.err.error_message);
6061 guestfs_end_busy (g);
6065 guestfs_end_busy (g);
6069 struct download_ctx {
6070 /* This flag is set by the callbacks, so we know we've done
6071 * the callbacks as expected, and in the right sequence.
6072 * 0 = not called, 1 = reply_cb called.
6075 struct guestfs_message_header hdr;
6076 struct guestfs_message_error err;
6079 static void download_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6081 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6082 struct download_ctx *ctx = (struct download_ctx *) data;
6084 /* This should definitely not happen. */
6085 if (ctx->cb_sequence != 0) {
6086 ctx->cb_sequence = 9999;
6087 error (g, "%s: internal error: reply callback called twice", "guestfs_download");
6091 ml->main_loop_quit (ml, g);
6093 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6094 error (g, "%s: failed to parse reply header", "guestfs_download");
6097 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6098 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6099 error (g, "%s: failed to parse reply error", "guestfs_download");
6105 ctx->cb_sequence = 1;
6108 int guestfs_download (guestfs_h *g,
6109 const char *remotefilename,
6110 const char *filename)
6112 struct guestfs_download_args args;
6113 struct download_ctx ctx;
6114 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6117 if (check_state (g, "guestfs_download") == -1) return -1;
6118 guestfs_set_busy (g);
6120 memset (&ctx, 0, sizeof ctx);
6122 args.remotefilename = (char *) remotefilename;
6123 serial = guestfs__send_sync (g, GUESTFS_PROC_DOWNLOAD,
6124 (xdrproc_t) xdr_guestfs_download_args, (char *) &args);
6126 guestfs_end_busy (g);
6130 guestfs__switch_to_receiving (g);
6131 ctx.cb_sequence = 0;
6132 guestfs_set_reply_callback (g, download_reply_cb, &ctx);
6133 (void) ml->main_loop_run (ml, g);
6134 guestfs_set_reply_callback (g, NULL, NULL);
6135 if (ctx.cb_sequence != 1) {
6136 error (g, "%s reply failed, see earlier error messages", "guestfs_download");
6137 guestfs_end_busy (g);
6141 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DOWNLOAD, serial) == -1) {
6142 guestfs_end_busy (g);
6146 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6147 error (g, "%s", ctx.err.error_message);
6148 free (ctx.err.error_message);
6149 guestfs_end_busy (g);
6153 if (guestfs__receive_file_sync (g, filename) == -1) {
6154 guestfs_end_busy (g);
6158 guestfs_end_busy (g);
6162 struct checksum_ctx {
6163 /* This flag is set by the callbacks, so we know we've done
6164 * the callbacks as expected, and in the right sequence.
6165 * 0 = not called, 1 = reply_cb called.
6168 struct guestfs_message_header hdr;
6169 struct guestfs_message_error err;
6170 struct guestfs_checksum_ret ret;
6173 static void checksum_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6175 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6176 struct checksum_ctx *ctx = (struct checksum_ctx *) data;
6178 /* This should definitely not happen. */
6179 if (ctx->cb_sequence != 0) {
6180 ctx->cb_sequence = 9999;
6181 error (g, "%s: internal error: reply callback called twice", "guestfs_checksum");
6185 ml->main_loop_quit (ml, g);
6187 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6188 error (g, "%s: failed to parse reply header", "guestfs_checksum");
6191 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6192 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6193 error (g, "%s: failed to parse reply error", "guestfs_checksum");
6198 if (!xdr_guestfs_checksum_ret (xdr, &ctx->ret)) {
6199 error (g, "%s: failed to parse reply", "guestfs_checksum");
6203 ctx->cb_sequence = 1;
6206 char *guestfs_checksum (guestfs_h *g,
6207 const char *csumtype,
6210 struct guestfs_checksum_args args;
6211 struct checksum_ctx ctx;
6212 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6215 if (check_state (g, "guestfs_checksum") == -1) return NULL;
6216 guestfs_set_busy (g);
6218 memset (&ctx, 0, sizeof ctx);
6220 args.csumtype = (char *) csumtype;
6221 args.path = (char *) path;
6222 serial = guestfs__send_sync (g, GUESTFS_PROC_CHECKSUM,
6223 (xdrproc_t) xdr_guestfs_checksum_args, (char *) &args);
6225 guestfs_end_busy (g);
6229 guestfs__switch_to_receiving (g);
6230 ctx.cb_sequence = 0;
6231 guestfs_set_reply_callback (g, checksum_reply_cb, &ctx);
6232 (void) ml->main_loop_run (ml, g);
6233 guestfs_set_reply_callback (g, NULL, NULL);
6234 if (ctx.cb_sequence != 1) {
6235 error (g, "%s reply failed, see earlier error messages", "guestfs_checksum");
6236 guestfs_end_busy (g);
6240 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHECKSUM, serial) == -1) {
6241 guestfs_end_busy (g);
6245 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6246 error (g, "%s", ctx.err.error_message);
6247 free (ctx.err.error_message);
6248 guestfs_end_busy (g);
6252 guestfs_end_busy (g);
6253 return ctx.ret.checksum; /* caller will free */
6257 /* This flag is set by the callbacks, so we know we've done
6258 * the callbacks as expected, and in the right sequence.
6259 * 0 = not called, 1 = reply_cb called.
6262 struct guestfs_message_header hdr;
6263 struct guestfs_message_error err;
6266 static void tar_in_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6268 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6269 struct tar_in_ctx *ctx = (struct tar_in_ctx *) data;
6271 /* This should definitely not happen. */
6272 if (ctx->cb_sequence != 0) {
6273 ctx->cb_sequence = 9999;
6274 error (g, "%s: internal error: reply callback called twice", "guestfs_tar_in");
6278 ml->main_loop_quit (ml, g);
6280 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6281 error (g, "%s: failed to parse reply header", "guestfs_tar_in");
6284 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6285 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6286 error (g, "%s: failed to parse reply error", "guestfs_tar_in");
6292 ctx->cb_sequence = 1;
6295 int guestfs_tar_in (guestfs_h *g,
6296 const char *tarfile,
6297 const char *directory)
6299 struct guestfs_tar_in_args args;
6300 struct tar_in_ctx ctx;
6301 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6304 if (check_state (g, "guestfs_tar_in") == -1) return -1;
6305 guestfs_set_busy (g);
6307 memset (&ctx, 0, sizeof ctx);
6309 args.directory = (char *) directory;
6310 serial = guestfs__send_sync (g, GUESTFS_PROC_TAR_IN,
6311 (xdrproc_t) xdr_guestfs_tar_in_args, (char *) &args);
6313 guestfs_end_busy (g);
6320 r = guestfs__send_file_sync (g, tarfile);
6322 guestfs_end_busy (g);
6325 if (r == -2) /* daemon cancelled */
6330 guestfs__switch_to_receiving (g);
6331 ctx.cb_sequence = 0;
6332 guestfs_set_reply_callback (g, tar_in_reply_cb, &ctx);
6333 (void) ml->main_loop_run (ml, g);
6334 guestfs_set_reply_callback (g, NULL, NULL);
6335 if (ctx.cb_sequence != 1) {
6336 error (g, "%s reply failed, see earlier error messages", "guestfs_tar_in");
6337 guestfs_end_busy (g);
6341 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_IN, serial) == -1) {
6342 guestfs_end_busy (g);
6346 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6347 error (g, "%s", ctx.err.error_message);
6348 free (ctx.err.error_message);
6349 guestfs_end_busy (g);
6353 guestfs_end_busy (g);
6357 struct tar_out_ctx {
6358 /* This flag is set by the callbacks, so we know we've done
6359 * the callbacks as expected, and in the right sequence.
6360 * 0 = not called, 1 = reply_cb called.
6363 struct guestfs_message_header hdr;
6364 struct guestfs_message_error err;
6367 static void tar_out_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6369 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6370 struct tar_out_ctx *ctx = (struct tar_out_ctx *) data;
6372 /* This should definitely not happen. */
6373 if (ctx->cb_sequence != 0) {
6374 ctx->cb_sequence = 9999;
6375 error (g, "%s: internal error: reply callback called twice", "guestfs_tar_out");
6379 ml->main_loop_quit (ml, g);
6381 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6382 error (g, "%s: failed to parse reply header", "guestfs_tar_out");
6385 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6386 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6387 error (g, "%s: failed to parse reply error", "guestfs_tar_out");
6393 ctx->cb_sequence = 1;
6396 int guestfs_tar_out (guestfs_h *g,
6397 const char *directory,
6398 const char *tarfile)
6400 struct guestfs_tar_out_args args;
6401 struct tar_out_ctx ctx;
6402 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6405 if (check_state (g, "guestfs_tar_out") == -1) return -1;
6406 guestfs_set_busy (g);
6408 memset (&ctx, 0, sizeof ctx);
6410 args.directory = (char *) directory;
6411 serial = guestfs__send_sync (g, GUESTFS_PROC_TAR_OUT,
6412 (xdrproc_t) xdr_guestfs_tar_out_args, (char *) &args);
6414 guestfs_end_busy (g);
6418 guestfs__switch_to_receiving (g);
6419 ctx.cb_sequence = 0;
6420 guestfs_set_reply_callback (g, tar_out_reply_cb, &ctx);
6421 (void) ml->main_loop_run (ml, g);
6422 guestfs_set_reply_callback (g, NULL, NULL);
6423 if (ctx.cb_sequence != 1) {
6424 error (g, "%s reply failed, see earlier error messages", "guestfs_tar_out");
6425 guestfs_end_busy (g);
6429 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TAR_OUT, serial) == -1) {
6430 guestfs_end_busy (g);
6434 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6435 error (g, "%s", ctx.err.error_message);
6436 free (ctx.err.error_message);
6437 guestfs_end_busy (g);
6441 if (guestfs__receive_file_sync (g, tarfile) == -1) {
6442 guestfs_end_busy (g);
6446 guestfs_end_busy (g);
6451 /* This flag is set by the callbacks, so we know we've done
6452 * the callbacks as expected, and in the right sequence.
6453 * 0 = not called, 1 = reply_cb called.
6456 struct guestfs_message_header hdr;
6457 struct guestfs_message_error err;
6460 static void tgz_in_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6462 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6463 struct tgz_in_ctx *ctx = (struct tgz_in_ctx *) data;
6465 /* This should definitely not happen. */
6466 if (ctx->cb_sequence != 0) {
6467 ctx->cb_sequence = 9999;
6468 error (g, "%s: internal error: reply callback called twice", "guestfs_tgz_in");
6472 ml->main_loop_quit (ml, g);
6474 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6475 error (g, "%s: failed to parse reply header", "guestfs_tgz_in");
6478 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6479 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6480 error (g, "%s: failed to parse reply error", "guestfs_tgz_in");
6486 ctx->cb_sequence = 1;
6489 int guestfs_tgz_in (guestfs_h *g,
6490 const char *tarball,
6491 const char *directory)
6493 struct guestfs_tgz_in_args args;
6494 struct tgz_in_ctx ctx;
6495 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6498 if (check_state (g, "guestfs_tgz_in") == -1) return -1;
6499 guestfs_set_busy (g);
6501 memset (&ctx, 0, sizeof ctx);
6503 args.directory = (char *) directory;
6504 serial = guestfs__send_sync (g, GUESTFS_PROC_TGZ_IN,
6505 (xdrproc_t) xdr_guestfs_tgz_in_args, (char *) &args);
6507 guestfs_end_busy (g);
6514 r = guestfs__send_file_sync (g, tarball);
6516 guestfs_end_busy (g);
6519 if (r == -2) /* daemon cancelled */
6524 guestfs__switch_to_receiving (g);
6525 ctx.cb_sequence = 0;
6526 guestfs_set_reply_callback (g, tgz_in_reply_cb, &ctx);
6527 (void) ml->main_loop_run (ml, g);
6528 guestfs_set_reply_callback (g, NULL, NULL);
6529 if (ctx.cb_sequence != 1) {
6530 error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_in");
6531 guestfs_end_busy (g);
6535 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_IN, serial) == -1) {
6536 guestfs_end_busy (g);
6540 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6541 error (g, "%s", ctx.err.error_message);
6542 free (ctx.err.error_message);
6543 guestfs_end_busy (g);
6547 guestfs_end_busy (g);
6551 struct tgz_out_ctx {
6552 /* This flag is set by the callbacks, so we know we've done
6553 * the callbacks as expected, and in the right sequence.
6554 * 0 = not called, 1 = reply_cb called.
6557 struct guestfs_message_header hdr;
6558 struct guestfs_message_error err;
6561 static void tgz_out_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6563 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6564 struct tgz_out_ctx *ctx = (struct tgz_out_ctx *) data;
6566 /* This should definitely not happen. */
6567 if (ctx->cb_sequence != 0) {
6568 ctx->cb_sequence = 9999;
6569 error (g, "%s: internal error: reply callback called twice", "guestfs_tgz_out");
6573 ml->main_loop_quit (ml, g);
6575 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6576 error (g, "%s: failed to parse reply header", "guestfs_tgz_out");
6579 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6580 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6581 error (g, "%s: failed to parse reply error", "guestfs_tgz_out");
6587 ctx->cb_sequence = 1;
6590 int guestfs_tgz_out (guestfs_h *g,
6591 const char *directory,
6592 const char *tarball)
6594 struct guestfs_tgz_out_args args;
6595 struct tgz_out_ctx ctx;
6596 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6599 if (check_state (g, "guestfs_tgz_out") == -1) return -1;
6600 guestfs_set_busy (g);
6602 memset (&ctx, 0, sizeof ctx);
6604 args.directory = (char *) directory;
6605 serial = guestfs__send_sync (g, GUESTFS_PROC_TGZ_OUT,
6606 (xdrproc_t) xdr_guestfs_tgz_out_args, (char *) &args);
6608 guestfs_end_busy (g);
6612 guestfs__switch_to_receiving (g);
6613 ctx.cb_sequence = 0;
6614 guestfs_set_reply_callback (g, tgz_out_reply_cb, &ctx);
6615 (void) ml->main_loop_run (ml, g);
6616 guestfs_set_reply_callback (g, NULL, NULL);
6617 if (ctx.cb_sequence != 1) {
6618 error (g, "%s reply failed, see earlier error messages", "guestfs_tgz_out");
6619 guestfs_end_busy (g);
6623 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TGZ_OUT, serial) == -1) {
6624 guestfs_end_busy (g);
6628 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6629 error (g, "%s", ctx.err.error_message);
6630 free (ctx.err.error_message);
6631 guestfs_end_busy (g);
6635 if (guestfs__receive_file_sync (g, tarball) == -1) {
6636 guestfs_end_busy (g);
6640 guestfs_end_busy (g);
6644 struct mount_ro_ctx {
6645 /* This flag is set by the callbacks, so we know we've done
6646 * the callbacks as expected, and in the right sequence.
6647 * 0 = not called, 1 = reply_cb called.
6650 struct guestfs_message_header hdr;
6651 struct guestfs_message_error err;
6654 static void mount_ro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6656 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6657 struct mount_ro_ctx *ctx = (struct mount_ro_ctx *) data;
6659 /* This should definitely not happen. */
6660 if (ctx->cb_sequence != 0) {
6661 ctx->cb_sequence = 9999;
6662 error (g, "%s: internal error: reply callback called twice", "guestfs_mount_ro");
6666 ml->main_loop_quit (ml, g);
6668 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6669 error (g, "%s: failed to parse reply header", "guestfs_mount_ro");
6672 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6673 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6674 error (g, "%s: failed to parse reply error", "guestfs_mount_ro");
6680 ctx->cb_sequence = 1;
6683 int guestfs_mount_ro (guestfs_h *g,
6685 const char *mountpoint)
6687 struct guestfs_mount_ro_args args;
6688 struct mount_ro_ctx ctx;
6689 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6692 if (check_state (g, "guestfs_mount_ro") == -1) return -1;
6693 guestfs_set_busy (g);
6695 memset (&ctx, 0, sizeof ctx);
6697 args.device = (char *) device;
6698 args.mountpoint = (char *) mountpoint;
6699 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_RO,
6700 (xdrproc_t) xdr_guestfs_mount_ro_args, (char *) &args);
6702 guestfs_end_busy (g);
6706 guestfs__switch_to_receiving (g);
6707 ctx.cb_sequence = 0;
6708 guestfs_set_reply_callback (g, mount_ro_reply_cb, &ctx);
6709 (void) ml->main_loop_run (ml, g);
6710 guestfs_set_reply_callback (g, NULL, NULL);
6711 if (ctx.cb_sequence != 1) {
6712 error (g, "%s reply failed, see earlier error messages", "guestfs_mount_ro");
6713 guestfs_end_busy (g);
6717 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_RO, serial) == -1) {
6718 guestfs_end_busy (g);
6722 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6723 error (g, "%s", ctx.err.error_message);
6724 free (ctx.err.error_message);
6725 guestfs_end_busy (g);
6729 guestfs_end_busy (g);
6733 struct mount_options_ctx {
6734 /* This flag is set by the callbacks, so we know we've done
6735 * the callbacks as expected, and in the right sequence.
6736 * 0 = not called, 1 = reply_cb called.
6739 struct guestfs_message_header hdr;
6740 struct guestfs_message_error err;
6743 static void mount_options_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6745 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6746 struct mount_options_ctx *ctx = (struct mount_options_ctx *) data;
6748 /* This should definitely not happen. */
6749 if (ctx->cb_sequence != 0) {
6750 ctx->cb_sequence = 9999;
6751 error (g, "%s: internal error: reply callback called twice", "guestfs_mount_options");
6755 ml->main_loop_quit (ml, g);
6757 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6758 error (g, "%s: failed to parse reply header", "guestfs_mount_options");
6761 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6762 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6763 error (g, "%s: failed to parse reply error", "guestfs_mount_options");
6769 ctx->cb_sequence = 1;
6772 int guestfs_mount_options (guestfs_h *g,
6773 const char *options,
6775 const char *mountpoint)
6777 struct guestfs_mount_options_args args;
6778 struct mount_options_ctx ctx;
6779 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6782 if (check_state (g, "guestfs_mount_options") == -1) return -1;
6783 guestfs_set_busy (g);
6785 memset (&ctx, 0, sizeof ctx);
6787 args.options = (char *) options;
6788 args.device = (char *) device;
6789 args.mountpoint = (char *) mountpoint;
6790 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_OPTIONS,
6791 (xdrproc_t) xdr_guestfs_mount_options_args, (char *) &args);
6793 guestfs_end_busy (g);
6797 guestfs__switch_to_receiving (g);
6798 ctx.cb_sequence = 0;
6799 guestfs_set_reply_callback (g, mount_options_reply_cb, &ctx);
6800 (void) ml->main_loop_run (ml, g);
6801 guestfs_set_reply_callback (g, NULL, NULL);
6802 if (ctx.cb_sequence != 1) {
6803 error (g, "%s reply failed, see earlier error messages", "guestfs_mount_options");
6804 guestfs_end_busy (g);
6808 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_OPTIONS, serial) == -1) {
6809 guestfs_end_busy (g);
6813 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6814 error (g, "%s", ctx.err.error_message);
6815 free (ctx.err.error_message);
6816 guestfs_end_busy (g);
6820 guestfs_end_busy (g);
6824 struct mount_vfs_ctx {
6825 /* This flag is set by the callbacks, so we know we've done
6826 * the callbacks as expected, and in the right sequence.
6827 * 0 = not called, 1 = reply_cb called.
6830 struct guestfs_message_header hdr;
6831 struct guestfs_message_error err;
6834 static void mount_vfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6836 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6837 struct mount_vfs_ctx *ctx = (struct mount_vfs_ctx *) data;
6839 /* This should definitely not happen. */
6840 if (ctx->cb_sequence != 0) {
6841 ctx->cb_sequence = 9999;
6842 error (g, "%s: internal error: reply callback called twice", "guestfs_mount_vfs");
6846 ml->main_loop_quit (ml, g);
6848 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6849 error (g, "%s: failed to parse reply header", "guestfs_mount_vfs");
6852 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6853 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6854 error (g, "%s: failed to parse reply error", "guestfs_mount_vfs");
6860 ctx->cb_sequence = 1;
6863 int guestfs_mount_vfs (guestfs_h *g,
6864 const char *options,
6865 const char *vfstype,
6867 const char *mountpoint)
6869 struct guestfs_mount_vfs_args args;
6870 struct mount_vfs_ctx ctx;
6871 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6874 if (check_state (g, "guestfs_mount_vfs") == -1) return -1;
6875 guestfs_set_busy (g);
6877 memset (&ctx, 0, sizeof ctx);
6879 args.options = (char *) options;
6880 args.vfstype = (char *) vfstype;
6881 args.device = (char *) device;
6882 args.mountpoint = (char *) mountpoint;
6883 serial = guestfs__send_sync (g, GUESTFS_PROC_MOUNT_VFS,
6884 (xdrproc_t) xdr_guestfs_mount_vfs_args, (char *) &args);
6886 guestfs_end_busy (g);
6890 guestfs__switch_to_receiving (g);
6891 ctx.cb_sequence = 0;
6892 guestfs_set_reply_callback (g, mount_vfs_reply_cb, &ctx);
6893 (void) ml->main_loop_run (ml, g);
6894 guestfs_set_reply_callback (g, NULL, NULL);
6895 if (ctx.cb_sequence != 1) {
6896 error (g, "%s reply failed, see earlier error messages", "guestfs_mount_vfs");
6897 guestfs_end_busy (g);
6901 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT_VFS, serial) == -1) {
6902 guestfs_end_busy (g);
6906 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6907 error (g, "%s", ctx.err.error_message);
6908 free (ctx.err.error_message);
6909 guestfs_end_busy (g);
6913 guestfs_end_busy (g);
6918 /* This flag is set by the callbacks, so we know we've done
6919 * the callbacks as expected, and in the right sequence.
6920 * 0 = not called, 1 = reply_cb called.
6923 struct guestfs_message_header hdr;
6924 struct guestfs_message_error err;
6925 struct guestfs_debug_ret ret;
6928 static void debug_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6930 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6931 struct debug_ctx *ctx = (struct debug_ctx *) data;
6933 /* This should definitely not happen. */
6934 if (ctx->cb_sequence != 0) {
6935 ctx->cb_sequence = 9999;
6936 error (g, "%s: internal error: reply callback called twice", "guestfs_debug");
6940 ml->main_loop_quit (ml, g);
6942 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6943 error (g, "%s: failed to parse reply header", "guestfs_debug");
6946 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6947 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6948 error (g, "%s: failed to parse reply error", "guestfs_debug");
6953 if (!xdr_guestfs_debug_ret (xdr, &ctx->ret)) {
6954 error (g, "%s: failed to parse reply", "guestfs_debug");
6958 ctx->cb_sequence = 1;
6961 char *guestfs_debug (guestfs_h *g,
6963 char * const* const extraargs)
6965 struct guestfs_debug_args args;
6966 struct debug_ctx ctx;
6967 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6970 if (check_state (g, "guestfs_debug") == -1) return NULL;
6971 guestfs_set_busy (g);
6973 memset (&ctx, 0, sizeof ctx);
6975 args.subcmd = (char *) subcmd;
6976 args.extraargs.extraargs_val = (char **) extraargs;
6977 for (args.extraargs.extraargs_len = 0; extraargs[args.extraargs.extraargs_len]; args.extraargs.extraargs_len++) ;
6978 serial = guestfs__send_sync (g, GUESTFS_PROC_DEBUG,
6979 (xdrproc_t) xdr_guestfs_debug_args, (char *) &args);
6981 guestfs_end_busy (g);
6985 guestfs__switch_to_receiving (g);
6986 ctx.cb_sequence = 0;
6987 guestfs_set_reply_callback (g, debug_reply_cb, &ctx);
6988 (void) ml->main_loop_run (ml, g);
6989 guestfs_set_reply_callback (g, NULL, NULL);
6990 if (ctx.cb_sequence != 1) {
6991 error (g, "%s reply failed, see earlier error messages", "guestfs_debug");
6992 guestfs_end_busy (g);
6996 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DEBUG, serial) == -1) {
6997 guestfs_end_busy (g);
7001 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7002 error (g, "%s", ctx.err.error_message);
7003 free (ctx.err.error_message);
7004 guestfs_end_busy (g);
7008 guestfs_end_busy (g);
7009 return ctx.ret.result; /* caller will free */
7012 struct lvremove_ctx {
7013 /* This flag is set by the callbacks, so we know we've done
7014 * the callbacks as expected, and in the right sequence.
7015 * 0 = not called, 1 = reply_cb called.
7018 struct guestfs_message_header hdr;
7019 struct guestfs_message_error err;
7022 static void lvremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7024 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7025 struct lvremove_ctx *ctx = (struct lvremove_ctx *) data;
7027 /* This should definitely not happen. */
7028 if (ctx->cb_sequence != 0) {
7029 ctx->cb_sequence = 9999;
7030 error (g, "%s: internal error: reply callback called twice", "guestfs_lvremove");
7034 ml->main_loop_quit (ml, g);
7036 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7037 error (g, "%s: failed to parse reply header", "guestfs_lvremove");
7040 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7041 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7042 error (g, "%s: failed to parse reply error", "guestfs_lvremove");
7048 ctx->cb_sequence = 1;
7051 int guestfs_lvremove (guestfs_h *g,
7054 struct guestfs_lvremove_args args;
7055 struct lvremove_ctx ctx;
7056 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7059 if (check_state (g, "guestfs_lvremove") == -1) return -1;
7060 guestfs_set_busy (g);
7062 memset (&ctx, 0, sizeof ctx);
7064 args.device = (char *) device;
7065 serial = guestfs__send_sync (g, GUESTFS_PROC_LVREMOVE,
7066 (xdrproc_t) xdr_guestfs_lvremove_args, (char *) &args);
7068 guestfs_end_busy (g);
7072 guestfs__switch_to_receiving (g);
7073 ctx.cb_sequence = 0;
7074 guestfs_set_reply_callback (g, lvremove_reply_cb, &ctx);
7075 (void) ml->main_loop_run (ml, g);
7076 guestfs_set_reply_callback (g, NULL, NULL);
7077 if (ctx.cb_sequence != 1) {
7078 error (g, "%s reply failed, see earlier error messages", "guestfs_lvremove");
7079 guestfs_end_busy (g);
7083 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVREMOVE, serial) == -1) {
7084 guestfs_end_busy (g);
7088 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7089 error (g, "%s", ctx.err.error_message);
7090 free (ctx.err.error_message);
7091 guestfs_end_busy (g);
7095 guestfs_end_busy (g);
7099 struct vgremove_ctx {
7100 /* This flag is set by the callbacks, so we know we've done
7101 * the callbacks as expected, and in the right sequence.
7102 * 0 = not called, 1 = reply_cb called.
7105 struct guestfs_message_header hdr;
7106 struct guestfs_message_error err;
7109 static void vgremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7111 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7112 struct vgremove_ctx *ctx = (struct vgremove_ctx *) data;
7114 /* This should definitely not happen. */
7115 if (ctx->cb_sequence != 0) {
7116 ctx->cb_sequence = 9999;
7117 error (g, "%s: internal error: reply callback called twice", "guestfs_vgremove");
7121 ml->main_loop_quit (ml, g);
7123 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7124 error (g, "%s: failed to parse reply header", "guestfs_vgremove");
7127 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7128 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7129 error (g, "%s: failed to parse reply error", "guestfs_vgremove");
7135 ctx->cb_sequence = 1;
7138 int guestfs_vgremove (guestfs_h *g,
7141 struct guestfs_vgremove_args args;
7142 struct vgremove_ctx ctx;
7143 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7146 if (check_state (g, "guestfs_vgremove") == -1) return -1;
7147 guestfs_set_busy (g);
7149 memset (&ctx, 0, sizeof ctx);
7151 args.vgname = (char *) vgname;
7152 serial = guestfs__send_sync (g, GUESTFS_PROC_VGREMOVE,
7153 (xdrproc_t) xdr_guestfs_vgremove_args, (char *) &args);
7155 guestfs_end_busy (g);
7159 guestfs__switch_to_receiving (g);
7160 ctx.cb_sequence = 0;
7161 guestfs_set_reply_callback (g, vgremove_reply_cb, &ctx);
7162 (void) ml->main_loop_run (ml, g);
7163 guestfs_set_reply_callback (g, NULL, NULL);
7164 if (ctx.cb_sequence != 1) {
7165 error (g, "%s reply failed, see earlier error messages", "guestfs_vgremove");
7166 guestfs_end_busy (g);
7170 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGREMOVE, serial) == -1) {
7171 guestfs_end_busy (g);
7175 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7176 error (g, "%s", ctx.err.error_message);
7177 free (ctx.err.error_message);
7178 guestfs_end_busy (g);
7182 guestfs_end_busy (g);
7186 struct pvremove_ctx {
7187 /* This flag is set by the callbacks, so we know we've done
7188 * the callbacks as expected, and in the right sequence.
7189 * 0 = not called, 1 = reply_cb called.
7192 struct guestfs_message_header hdr;
7193 struct guestfs_message_error err;
7196 static void pvremove_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7198 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7199 struct pvremove_ctx *ctx = (struct pvremove_ctx *) data;
7201 /* This should definitely not happen. */
7202 if (ctx->cb_sequence != 0) {
7203 ctx->cb_sequence = 9999;
7204 error (g, "%s: internal error: reply callback called twice", "guestfs_pvremove");
7208 ml->main_loop_quit (ml, g);
7210 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7211 error (g, "%s: failed to parse reply header", "guestfs_pvremove");
7214 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7215 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7216 error (g, "%s: failed to parse reply error", "guestfs_pvremove");
7222 ctx->cb_sequence = 1;
7225 int guestfs_pvremove (guestfs_h *g,
7228 struct guestfs_pvremove_args args;
7229 struct pvremove_ctx ctx;
7230 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7233 if (check_state (g, "guestfs_pvremove") == -1) return -1;
7234 guestfs_set_busy (g);
7236 memset (&ctx, 0, sizeof ctx);
7238 args.device = (char *) device;
7239 serial = guestfs__send_sync (g, GUESTFS_PROC_PVREMOVE,
7240 (xdrproc_t) xdr_guestfs_pvremove_args, (char *) &args);
7242 guestfs_end_busy (g);
7246 guestfs__switch_to_receiving (g);
7247 ctx.cb_sequence = 0;
7248 guestfs_set_reply_callback (g, pvremove_reply_cb, &ctx);
7249 (void) ml->main_loop_run (ml, g);
7250 guestfs_set_reply_callback (g, NULL, NULL);
7251 if (ctx.cb_sequence != 1) {
7252 error (g, "%s reply failed, see earlier error messages", "guestfs_pvremove");
7253 guestfs_end_busy (g);
7257 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVREMOVE, serial) == -1) {
7258 guestfs_end_busy (g);
7262 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7263 error (g, "%s", ctx.err.error_message);
7264 free (ctx.err.error_message);
7265 guestfs_end_busy (g);
7269 guestfs_end_busy (g);
7273 struct set_e2label_ctx {
7274 /* This flag is set by the callbacks, so we know we've done
7275 * the callbacks as expected, and in the right sequence.
7276 * 0 = not called, 1 = reply_cb called.
7279 struct guestfs_message_header hdr;
7280 struct guestfs_message_error err;
7283 static void set_e2label_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7285 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7286 struct set_e2label_ctx *ctx = (struct set_e2label_ctx *) data;
7288 /* This should definitely not happen. */
7289 if (ctx->cb_sequence != 0) {
7290 ctx->cb_sequence = 9999;
7291 error (g, "%s: internal error: reply callback called twice", "guestfs_set_e2label");
7295 ml->main_loop_quit (ml, g);
7297 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7298 error (g, "%s: failed to parse reply header", "guestfs_set_e2label");
7301 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7302 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7303 error (g, "%s: failed to parse reply error", "guestfs_set_e2label");
7309 ctx->cb_sequence = 1;
7312 int guestfs_set_e2label (guestfs_h *g,
7316 struct guestfs_set_e2label_args args;
7317 struct set_e2label_ctx ctx;
7318 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7321 if (check_state (g, "guestfs_set_e2label") == -1) return -1;
7322 guestfs_set_busy (g);
7324 memset (&ctx, 0, sizeof ctx);
7326 args.device = (char *) device;
7327 args.label = (char *) label;
7328 serial = guestfs__send_sync (g, GUESTFS_PROC_SET_E2LABEL,
7329 (xdrproc_t) xdr_guestfs_set_e2label_args, (char *) &args);
7331 guestfs_end_busy (g);
7335 guestfs__switch_to_receiving (g);
7336 ctx.cb_sequence = 0;
7337 guestfs_set_reply_callback (g, set_e2label_reply_cb, &ctx);
7338 (void) ml->main_loop_run (ml, g);
7339 guestfs_set_reply_callback (g, NULL, NULL);
7340 if (ctx.cb_sequence != 1) {
7341 error (g, "%s reply failed, see earlier error messages", "guestfs_set_e2label");
7342 guestfs_end_busy (g);
7346 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SET_E2LABEL, serial) == -1) {
7347 guestfs_end_busy (g);
7351 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7352 error (g, "%s", ctx.err.error_message);
7353 free (ctx.err.error_message);
7354 guestfs_end_busy (g);
7358 guestfs_end_busy (g);
7362 struct get_e2label_ctx {
7363 /* This flag is set by the callbacks, so we know we've done
7364 * the callbacks as expected, and in the right sequence.
7365 * 0 = not called, 1 = reply_cb called.
7368 struct guestfs_message_header hdr;
7369 struct guestfs_message_error err;
7370 struct guestfs_get_e2label_ret ret;
7373 static void get_e2label_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7375 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7376 struct get_e2label_ctx *ctx = (struct get_e2label_ctx *) data;
7378 /* This should definitely not happen. */
7379 if (ctx->cb_sequence != 0) {
7380 ctx->cb_sequence = 9999;
7381 error (g, "%s: internal error: reply callback called twice", "guestfs_get_e2label");
7385 ml->main_loop_quit (ml, g);
7387 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7388 error (g, "%s: failed to parse reply header", "guestfs_get_e2label");
7391 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7392 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7393 error (g, "%s: failed to parse reply error", "guestfs_get_e2label");
7398 if (!xdr_guestfs_get_e2label_ret (xdr, &ctx->ret)) {
7399 error (g, "%s: failed to parse reply", "guestfs_get_e2label");
7403 ctx->cb_sequence = 1;
7406 char *guestfs_get_e2label (guestfs_h *g,
7409 struct guestfs_get_e2label_args args;
7410 struct get_e2label_ctx ctx;
7411 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7414 if (check_state (g, "guestfs_get_e2label") == -1) return NULL;
7415 guestfs_set_busy (g);
7417 memset (&ctx, 0, sizeof ctx);
7419 args.device = (char *) device;
7420 serial = guestfs__send_sync (g, GUESTFS_PROC_GET_E2LABEL,
7421 (xdrproc_t) xdr_guestfs_get_e2label_args, (char *) &args);
7423 guestfs_end_busy (g);
7427 guestfs__switch_to_receiving (g);
7428 ctx.cb_sequence = 0;
7429 guestfs_set_reply_callback (g, get_e2label_reply_cb, &ctx);
7430 (void) ml->main_loop_run (ml, g);
7431 guestfs_set_reply_callback (g, NULL, NULL);
7432 if (ctx.cb_sequence != 1) {
7433 error (g, "%s reply failed, see earlier error messages", "guestfs_get_e2label");
7434 guestfs_end_busy (g);
7438 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GET_E2LABEL, serial) == -1) {
7439 guestfs_end_busy (g);
7443 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7444 error (g, "%s", ctx.err.error_message);
7445 free (ctx.err.error_message);
7446 guestfs_end_busy (g);
7450 guestfs_end_busy (g);
7451 return ctx.ret.label; /* caller will free */
7454 struct set_e2uuid_ctx {
7455 /* This flag is set by the callbacks, so we know we've done
7456 * the callbacks as expected, and in the right sequence.
7457 * 0 = not called, 1 = reply_cb called.
7460 struct guestfs_message_header hdr;
7461 struct guestfs_message_error err;
7464 static void set_e2uuid_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7466 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7467 struct set_e2uuid_ctx *ctx = (struct set_e2uuid_ctx *) data;
7469 /* This should definitely not happen. */
7470 if (ctx->cb_sequence != 0) {
7471 ctx->cb_sequence = 9999;
7472 error (g, "%s: internal error: reply callback called twice", "guestfs_set_e2uuid");
7476 ml->main_loop_quit (ml, g);
7478 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7479 error (g, "%s: failed to parse reply header", "guestfs_set_e2uuid");
7482 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7483 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7484 error (g, "%s: failed to parse reply error", "guestfs_set_e2uuid");
7490 ctx->cb_sequence = 1;
7493 int guestfs_set_e2uuid (guestfs_h *g,
7497 struct guestfs_set_e2uuid_args args;
7498 struct set_e2uuid_ctx ctx;
7499 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7502 if (check_state (g, "guestfs_set_e2uuid") == -1) return -1;
7503 guestfs_set_busy (g);
7505 memset (&ctx, 0, sizeof ctx);
7507 args.device = (char *) device;
7508 args.uuid = (char *) uuid;
7509 serial = guestfs__send_sync (g, GUESTFS_PROC_SET_E2UUID,
7510 (xdrproc_t) xdr_guestfs_set_e2uuid_args, (char *) &args);
7512 guestfs_end_busy (g);
7516 guestfs__switch_to_receiving (g);
7517 ctx.cb_sequence = 0;
7518 guestfs_set_reply_callback (g, set_e2uuid_reply_cb, &ctx);
7519 (void) ml->main_loop_run (ml, g);
7520 guestfs_set_reply_callback (g, NULL, NULL);
7521 if (ctx.cb_sequence != 1) {
7522 error (g, "%s reply failed, see earlier error messages", "guestfs_set_e2uuid");
7523 guestfs_end_busy (g);
7527 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SET_E2UUID, serial) == -1) {
7528 guestfs_end_busy (g);
7532 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7533 error (g, "%s", ctx.err.error_message);
7534 free (ctx.err.error_message);
7535 guestfs_end_busy (g);
7539 guestfs_end_busy (g);
7543 struct get_e2uuid_ctx {
7544 /* This flag is set by the callbacks, so we know we've done
7545 * the callbacks as expected, and in the right sequence.
7546 * 0 = not called, 1 = reply_cb called.
7549 struct guestfs_message_header hdr;
7550 struct guestfs_message_error err;
7551 struct guestfs_get_e2uuid_ret ret;
7554 static void get_e2uuid_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7556 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7557 struct get_e2uuid_ctx *ctx = (struct get_e2uuid_ctx *) data;
7559 /* This should definitely not happen. */
7560 if (ctx->cb_sequence != 0) {
7561 ctx->cb_sequence = 9999;
7562 error (g, "%s: internal error: reply callback called twice", "guestfs_get_e2uuid");
7566 ml->main_loop_quit (ml, g);
7568 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7569 error (g, "%s: failed to parse reply header", "guestfs_get_e2uuid");
7572 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7573 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7574 error (g, "%s: failed to parse reply error", "guestfs_get_e2uuid");
7579 if (!xdr_guestfs_get_e2uuid_ret (xdr, &ctx->ret)) {
7580 error (g, "%s: failed to parse reply", "guestfs_get_e2uuid");
7584 ctx->cb_sequence = 1;
7587 char *guestfs_get_e2uuid (guestfs_h *g,
7590 struct guestfs_get_e2uuid_args args;
7591 struct get_e2uuid_ctx ctx;
7592 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7595 if (check_state (g, "guestfs_get_e2uuid") == -1) return NULL;
7596 guestfs_set_busy (g);
7598 memset (&ctx, 0, sizeof ctx);
7600 args.device = (char *) device;
7601 serial = guestfs__send_sync (g, GUESTFS_PROC_GET_E2UUID,
7602 (xdrproc_t) xdr_guestfs_get_e2uuid_args, (char *) &args);
7604 guestfs_end_busy (g);
7608 guestfs__switch_to_receiving (g);
7609 ctx.cb_sequence = 0;
7610 guestfs_set_reply_callback (g, get_e2uuid_reply_cb, &ctx);
7611 (void) ml->main_loop_run (ml, g);
7612 guestfs_set_reply_callback (g, NULL, NULL);
7613 if (ctx.cb_sequence != 1) {
7614 error (g, "%s reply failed, see earlier error messages", "guestfs_get_e2uuid");
7615 guestfs_end_busy (g);
7619 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GET_E2UUID, serial) == -1) {
7620 guestfs_end_busy (g);
7624 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7625 error (g, "%s", ctx.err.error_message);
7626 free (ctx.err.error_message);
7627 guestfs_end_busy (g);
7631 guestfs_end_busy (g);
7632 return ctx.ret.uuid; /* caller will free */
7636 /* This flag is set by the callbacks, so we know we've done
7637 * the callbacks as expected, and in the right sequence.
7638 * 0 = not called, 1 = reply_cb called.
7641 struct guestfs_message_header hdr;
7642 struct guestfs_message_error err;
7643 struct guestfs_fsck_ret ret;
7646 static void fsck_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7648 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7649 struct fsck_ctx *ctx = (struct fsck_ctx *) data;
7651 /* This should definitely not happen. */
7652 if (ctx->cb_sequence != 0) {
7653 ctx->cb_sequence = 9999;
7654 error (g, "%s: internal error: reply callback called twice", "guestfs_fsck");
7658 ml->main_loop_quit (ml, g);
7660 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7661 error (g, "%s: failed to parse reply header", "guestfs_fsck");
7664 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7665 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7666 error (g, "%s: failed to parse reply error", "guestfs_fsck");
7671 if (!xdr_guestfs_fsck_ret (xdr, &ctx->ret)) {
7672 error (g, "%s: failed to parse reply", "guestfs_fsck");
7676 ctx->cb_sequence = 1;
7679 int guestfs_fsck (guestfs_h *g,
7683 struct guestfs_fsck_args args;
7684 struct fsck_ctx ctx;
7685 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7688 if (check_state (g, "guestfs_fsck") == -1) return -1;
7689 guestfs_set_busy (g);
7691 memset (&ctx, 0, sizeof ctx);
7693 args.fstype = (char *) fstype;
7694 args.device = (char *) device;
7695 serial = guestfs__send_sync (g, GUESTFS_PROC_FSCK,
7696 (xdrproc_t) xdr_guestfs_fsck_args, (char *) &args);
7698 guestfs_end_busy (g);
7702 guestfs__switch_to_receiving (g);
7703 ctx.cb_sequence = 0;
7704 guestfs_set_reply_callback (g, fsck_reply_cb, &ctx);
7705 (void) ml->main_loop_run (ml, g);
7706 guestfs_set_reply_callback (g, NULL, NULL);
7707 if (ctx.cb_sequence != 1) {
7708 error (g, "%s reply failed, see earlier error messages", "guestfs_fsck");
7709 guestfs_end_busy (g);
7713 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FSCK, serial) == -1) {
7714 guestfs_end_busy (g);
7718 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7719 error (g, "%s", ctx.err.error_message);
7720 free (ctx.err.error_message);
7721 guestfs_end_busy (g);
7725 guestfs_end_busy (g);
7726 return ctx.ret.status;
7730 /* This flag is set by the callbacks, so we know we've done
7731 * the callbacks as expected, and in the right sequence.
7732 * 0 = not called, 1 = reply_cb called.
7735 struct guestfs_message_header hdr;
7736 struct guestfs_message_error err;
7739 static void zero_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7741 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7742 struct zero_ctx *ctx = (struct zero_ctx *) data;
7744 /* This should definitely not happen. */
7745 if (ctx->cb_sequence != 0) {
7746 ctx->cb_sequence = 9999;
7747 error (g, "%s: internal error: reply callback called twice", "guestfs_zero");
7751 ml->main_loop_quit (ml, g);
7753 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7754 error (g, "%s: failed to parse reply header", "guestfs_zero");
7757 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7758 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7759 error (g, "%s: failed to parse reply error", "guestfs_zero");
7765 ctx->cb_sequence = 1;
7768 int guestfs_zero (guestfs_h *g,
7771 struct guestfs_zero_args args;
7772 struct zero_ctx ctx;
7773 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7776 if (check_state (g, "guestfs_zero") == -1) return -1;
7777 guestfs_set_busy (g);
7779 memset (&ctx, 0, sizeof ctx);
7781 args.device = (char *) device;
7782 serial = guestfs__send_sync (g, GUESTFS_PROC_ZERO,
7783 (xdrproc_t) xdr_guestfs_zero_args, (char *) &args);
7785 guestfs_end_busy (g);
7789 guestfs__switch_to_receiving (g);
7790 ctx.cb_sequence = 0;
7791 guestfs_set_reply_callback (g, zero_reply_cb, &ctx);
7792 (void) ml->main_loop_run (ml, g);
7793 guestfs_set_reply_callback (g, NULL, NULL);
7794 if (ctx.cb_sequence != 1) {
7795 error (g, "%s reply failed, see earlier error messages", "guestfs_zero");
7796 guestfs_end_busy (g);
7800 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_ZERO, serial) == -1) {
7801 guestfs_end_busy (g);
7805 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7806 error (g, "%s", ctx.err.error_message);
7807 free (ctx.err.error_message);
7808 guestfs_end_busy (g);
7812 guestfs_end_busy (g);
7816 struct grub_install_ctx {
7817 /* This flag is set by the callbacks, so we know we've done
7818 * the callbacks as expected, and in the right sequence.
7819 * 0 = not called, 1 = reply_cb called.
7822 struct guestfs_message_header hdr;
7823 struct guestfs_message_error err;
7826 static void grub_install_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7828 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7829 struct grub_install_ctx *ctx = (struct grub_install_ctx *) data;
7831 /* This should definitely not happen. */
7832 if (ctx->cb_sequence != 0) {
7833 ctx->cb_sequence = 9999;
7834 error (g, "%s: internal error: reply callback called twice", "guestfs_grub_install");
7838 ml->main_loop_quit (ml, g);
7840 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7841 error (g, "%s: failed to parse reply header", "guestfs_grub_install");
7844 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7845 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7846 error (g, "%s: failed to parse reply error", "guestfs_grub_install");
7852 ctx->cb_sequence = 1;
7855 int guestfs_grub_install (guestfs_h *g,
7859 struct guestfs_grub_install_args args;
7860 struct grub_install_ctx ctx;
7861 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7864 if (check_state (g, "guestfs_grub_install") == -1) return -1;
7865 guestfs_set_busy (g);
7867 memset (&ctx, 0, sizeof ctx);
7869 args.root = (char *) root;
7870 args.device = (char *) device;
7871 serial = guestfs__send_sync (g, GUESTFS_PROC_GRUB_INSTALL,
7872 (xdrproc_t) xdr_guestfs_grub_install_args, (char *) &args);
7874 guestfs_end_busy (g);
7878 guestfs__switch_to_receiving (g);
7879 ctx.cb_sequence = 0;
7880 guestfs_set_reply_callback (g, grub_install_reply_cb, &ctx);
7881 (void) ml->main_loop_run (ml, g);
7882 guestfs_set_reply_callback (g, NULL, NULL);
7883 if (ctx.cb_sequence != 1) {
7884 error (g, "%s reply failed, see earlier error messages", "guestfs_grub_install");
7885 guestfs_end_busy (g);
7889 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_GRUB_INSTALL, serial) == -1) {
7890 guestfs_end_busy (g);
7894 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7895 error (g, "%s", ctx.err.error_message);
7896 free (ctx.err.error_message);
7897 guestfs_end_busy (g);
7901 guestfs_end_busy (g);
7906 /* This flag is set by the callbacks, so we know we've done
7907 * the callbacks as expected, and in the right sequence.
7908 * 0 = not called, 1 = reply_cb called.
7911 struct guestfs_message_header hdr;
7912 struct guestfs_message_error err;
7915 static void cp_reply_cb (guestfs_h *g, void *data, XDR *xdr)
7917 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7918 struct cp_ctx *ctx = (struct cp_ctx *) data;
7920 /* This should definitely not happen. */
7921 if (ctx->cb_sequence != 0) {
7922 ctx->cb_sequence = 9999;
7923 error (g, "%s: internal error: reply callback called twice", "guestfs_cp");
7927 ml->main_loop_quit (ml, g);
7929 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
7930 error (g, "%s: failed to parse reply header", "guestfs_cp");
7933 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
7934 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
7935 error (g, "%s: failed to parse reply error", "guestfs_cp");
7941 ctx->cb_sequence = 1;
7944 int guestfs_cp (guestfs_h *g,
7948 struct guestfs_cp_args args;
7950 guestfs_main_loop *ml = guestfs_get_main_loop (g);
7953 if (check_state (g, "guestfs_cp") == -1) return -1;
7954 guestfs_set_busy (g);
7956 memset (&ctx, 0, sizeof ctx);
7958 args.src = (char *) src;
7959 args.dest = (char *) dest;
7960 serial = guestfs__send_sync (g, GUESTFS_PROC_CP,
7961 (xdrproc_t) xdr_guestfs_cp_args, (char *) &args);
7963 guestfs_end_busy (g);
7967 guestfs__switch_to_receiving (g);
7968 ctx.cb_sequence = 0;
7969 guestfs_set_reply_callback (g, cp_reply_cb, &ctx);
7970 (void) ml->main_loop_run (ml, g);
7971 guestfs_set_reply_callback (g, NULL, NULL);
7972 if (ctx.cb_sequence != 1) {
7973 error (g, "%s reply failed, see earlier error messages", "guestfs_cp");
7974 guestfs_end_busy (g);
7978 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CP, serial) == -1) {
7979 guestfs_end_busy (g);
7983 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
7984 error (g, "%s", ctx.err.error_message);
7985 free (ctx.err.error_message);
7986 guestfs_end_busy (g);
7990 guestfs_end_busy (g);
7995 /* This flag is set by the callbacks, so we know we've done
7996 * the callbacks as expected, and in the right sequence.
7997 * 0 = not called, 1 = reply_cb called.
8000 struct guestfs_message_header hdr;
8001 struct guestfs_message_error err;
8004 static void cp_a_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8006 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8007 struct cp_a_ctx *ctx = (struct cp_a_ctx *) data;
8009 /* This should definitely not happen. */
8010 if (ctx->cb_sequence != 0) {
8011 ctx->cb_sequence = 9999;
8012 error (g, "%s: internal error: reply callback called twice", "guestfs_cp_a");
8016 ml->main_loop_quit (ml, g);
8018 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8019 error (g, "%s: failed to parse reply header", "guestfs_cp_a");
8022 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8023 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8024 error (g, "%s: failed to parse reply error", "guestfs_cp_a");
8030 ctx->cb_sequence = 1;
8033 int guestfs_cp_a (guestfs_h *g,
8037 struct guestfs_cp_a_args args;
8038 struct cp_a_ctx ctx;
8039 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8042 if (check_state (g, "guestfs_cp_a") == -1) return -1;
8043 guestfs_set_busy (g);
8045 memset (&ctx, 0, sizeof ctx);
8047 args.src = (char *) src;
8048 args.dest = (char *) dest;
8049 serial = guestfs__send_sync (g, GUESTFS_PROC_CP_A,
8050 (xdrproc_t) xdr_guestfs_cp_a_args, (char *) &args);
8052 guestfs_end_busy (g);
8056 guestfs__switch_to_receiving (g);
8057 ctx.cb_sequence = 0;
8058 guestfs_set_reply_callback (g, cp_a_reply_cb, &ctx);
8059 (void) ml->main_loop_run (ml, g);
8060 guestfs_set_reply_callback (g, NULL, NULL);
8061 if (ctx.cb_sequence != 1) {
8062 error (g, "%s reply failed, see earlier error messages", "guestfs_cp_a");
8063 guestfs_end_busy (g);
8067 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CP_A, serial) == -1) {
8068 guestfs_end_busy (g);
8072 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8073 error (g, "%s", ctx.err.error_message);
8074 free (ctx.err.error_message);
8075 guestfs_end_busy (g);
8079 guestfs_end_busy (g);
8084 /* This flag is set by the callbacks, so we know we've done
8085 * the callbacks as expected, and in the right sequence.
8086 * 0 = not called, 1 = reply_cb called.
8089 struct guestfs_message_header hdr;
8090 struct guestfs_message_error err;
8093 static void mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8095 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8096 struct mv_ctx *ctx = (struct mv_ctx *) data;
8098 /* This should definitely not happen. */
8099 if (ctx->cb_sequence != 0) {
8100 ctx->cb_sequence = 9999;
8101 error (g, "%s: internal error: reply callback called twice", "guestfs_mv");
8105 ml->main_loop_quit (ml, g);
8107 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8108 error (g, "%s: failed to parse reply header", "guestfs_mv");
8111 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8112 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8113 error (g, "%s: failed to parse reply error", "guestfs_mv");
8119 ctx->cb_sequence = 1;
8122 int guestfs_mv (guestfs_h *g,
8126 struct guestfs_mv_args args;
8128 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8131 if (check_state (g, "guestfs_mv") == -1) return -1;
8132 guestfs_set_busy (g);
8134 memset (&ctx, 0, sizeof ctx);
8136 args.src = (char *) src;
8137 args.dest = (char *) dest;
8138 serial = guestfs__send_sync (g, GUESTFS_PROC_MV,
8139 (xdrproc_t) xdr_guestfs_mv_args, (char *) &args);
8141 guestfs_end_busy (g);
8145 guestfs__switch_to_receiving (g);
8146 ctx.cb_sequence = 0;
8147 guestfs_set_reply_callback (g, mv_reply_cb, &ctx);
8148 (void) ml->main_loop_run (ml, g);
8149 guestfs_set_reply_callback (g, NULL, NULL);
8150 if (ctx.cb_sequence != 1) {
8151 error (g, "%s reply failed, see earlier error messages", "guestfs_mv");
8152 guestfs_end_busy (g);
8156 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MV, serial) == -1) {
8157 guestfs_end_busy (g);
8161 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8162 error (g, "%s", ctx.err.error_message);
8163 free (ctx.err.error_message);
8164 guestfs_end_busy (g);
8168 guestfs_end_busy (g);
8172 struct drop_caches_ctx {
8173 /* This flag is set by the callbacks, so we know we've done
8174 * the callbacks as expected, and in the right sequence.
8175 * 0 = not called, 1 = reply_cb called.
8178 struct guestfs_message_header hdr;
8179 struct guestfs_message_error err;
8182 static void drop_caches_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8184 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8185 struct drop_caches_ctx *ctx = (struct drop_caches_ctx *) data;
8187 /* This should definitely not happen. */
8188 if (ctx->cb_sequence != 0) {
8189 ctx->cb_sequence = 9999;
8190 error (g, "%s: internal error: reply callback called twice", "guestfs_drop_caches");
8194 ml->main_loop_quit (ml, g);
8196 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8197 error (g, "%s: failed to parse reply header", "guestfs_drop_caches");
8200 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8201 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8202 error (g, "%s: failed to parse reply error", "guestfs_drop_caches");
8208 ctx->cb_sequence = 1;
8211 int guestfs_drop_caches (guestfs_h *g,
8214 struct guestfs_drop_caches_args args;
8215 struct drop_caches_ctx ctx;
8216 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8219 if (check_state (g, "guestfs_drop_caches") == -1) return -1;
8220 guestfs_set_busy (g);
8222 memset (&ctx, 0, sizeof ctx);
8224 args.whattodrop = whattodrop;
8225 serial = guestfs__send_sync (g, GUESTFS_PROC_DROP_CACHES,
8226 (xdrproc_t) xdr_guestfs_drop_caches_args, (char *) &args);
8228 guestfs_end_busy (g);
8232 guestfs__switch_to_receiving (g);
8233 ctx.cb_sequence = 0;
8234 guestfs_set_reply_callback (g, drop_caches_reply_cb, &ctx);
8235 (void) ml->main_loop_run (ml, g);
8236 guestfs_set_reply_callback (g, NULL, NULL);
8237 if (ctx.cb_sequence != 1) {
8238 error (g, "%s reply failed, see earlier error messages", "guestfs_drop_caches");
8239 guestfs_end_busy (g);
8243 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DROP_CACHES, serial) == -1) {
8244 guestfs_end_busy (g);
8248 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8249 error (g, "%s", ctx.err.error_message);
8250 free (ctx.err.error_message);
8251 guestfs_end_busy (g);
8255 guestfs_end_busy (g);
8260 /* This flag is set by the callbacks, so we know we've done
8261 * the callbacks as expected, and in the right sequence.
8262 * 0 = not called, 1 = reply_cb called.
8265 struct guestfs_message_header hdr;
8266 struct guestfs_message_error err;
8267 struct guestfs_dmesg_ret ret;
8270 static void dmesg_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8272 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8273 struct dmesg_ctx *ctx = (struct dmesg_ctx *) data;
8275 /* This should definitely not happen. */
8276 if (ctx->cb_sequence != 0) {
8277 ctx->cb_sequence = 9999;
8278 error (g, "%s: internal error: reply callback called twice", "guestfs_dmesg");
8282 ml->main_loop_quit (ml, g);
8284 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8285 error (g, "%s: failed to parse reply header", "guestfs_dmesg");
8288 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8289 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8290 error (g, "%s: failed to parse reply error", "guestfs_dmesg");
8295 if (!xdr_guestfs_dmesg_ret (xdr, &ctx->ret)) {
8296 error (g, "%s: failed to parse reply", "guestfs_dmesg");
8300 ctx->cb_sequence = 1;
8303 char *guestfs_dmesg (guestfs_h *g)
8305 struct dmesg_ctx ctx;
8306 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8309 if (check_state (g, "guestfs_dmesg") == -1) return NULL;
8310 guestfs_set_busy (g);
8312 memset (&ctx, 0, sizeof ctx);
8314 serial = guestfs__send_sync (g, GUESTFS_PROC_DMESG, NULL, NULL);
8316 guestfs_end_busy (g);
8320 guestfs__switch_to_receiving (g);
8321 ctx.cb_sequence = 0;
8322 guestfs_set_reply_callback (g, dmesg_reply_cb, &ctx);
8323 (void) ml->main_loop_run (ml, g);
8324 guestfs_set_reply_callback (g, NULL, NULL);
8325 if (ctx.cb_sequence != 1) {
8326 error (g, "%s reply failed, see earlier error messages", "guestfs_dmesg");
8327 guestfs_end_busy (g);
8331 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DMESG, serial) == -1) {
8332 guestfs_end_busy (g);
8336 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8337 error (g, "%s", ctx.err.error_message);
8338 free (ctx.err.error_message);
8339 guestfs_end_busy (g);
8343 guestfs_end_busy (g);
8344 return ctx.ret.kmsgs; /* caller will free */
8347 struct ping_daemon_ctx {
8348 /* This flag is set by the callbacks, so we know we've done
8349 * the callbacks as expected, and in the right sequence.
8350 * 0 = not called, 1 = reply_cb called.
8353 struct guestfs_message_header hdr;
8354 struct guestfs_message_error err;
8357 static void ping_daemon_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8359 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8360 struct ping_daemon_ctx *ctx = (struct ping_daemon_ctx *) data;
8362 /* This should definitely not happen. */
8363 if (ctx->cb_sequence != 0) {
8364 ctx->cb_sequence = 9999;
8365 error (g, "%s: internal error: reply callback called twice", "guestfs_ping_daemon");
8369 ml->main_loop_quit (ml, g);
8371 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8372 error (g, "%s: failed to parse reply header", "guestfs_ping_daemon");
8375 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8376 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8377 error (g, "%s: failed to parse reply error", "guestfs_ping_daemon");
8383 ctx->cb_sequence = 1;
8386 int guestfs_ping_daemon (guestfs_h *g)
8388 struct ping_daemon_ctx ctx;
8389 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8392 if (check_state (g, "guestfs_ping_daemon") == -1) return -1;
8393 guestfs_set_busy (g);
8395 memset (&ctx, 0, sizeof ctx);
8397 serial = guestfs__send_sync (g, GUESTFS_PROC_PING_DAEMON, NULL, NULL);
8399 guestfs_end_busy (g);
8403 guestfs__switch_to_receiving (g);
8404 ctx.cb_sequence = 0;
8405 guestfs_set_reply_callback (g, ping_daemon_reply_cb, &ctx);
8406 (void) ml->main_loop_run (ml, g);
8407 guestfs_set_reply_callback (g, NULL, NULL);
8408 if (ctx.cb_sequence != 1) {
8409 error (g, "%s reply failed, see earlier error messages", "guestfs_ping_daemon");
8410 guestfs_end_busy (g);
8414 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PING_DAEMON, serial) == -1) {
8415 guestfs_end_busy (g);
8419 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8420 error (g, "%s", ctx.err.error_message);
8421 free (ctx.err.error_message);
8422 guestfs_end_busy (g);
8426 guestfs_end_busy (g);
8431 /* This flag is set by the callbacks, so we know we've done
8432 * the callbacks as expected, and in the right sequence.
8433 * 0 = not called, 1 = reply_cb called.
8436 struct guestfs_message_header hdr;
8437 struct guestfs_message_error err;
8438 struct guestfs_equal_ret ret;
8441 static void equal_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8443 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8444 struct equal_ctx *ctx = (struct equal_ctx *) data;
8446 /* This should definitely not happen. */
8447 if (ctx->cb_sequence != 0) {
8448 ctx->cb_sequence = 9999;
8449 error (g, "%s: internal error: reply callback called twice", "guestfs_equal");
8453 ml->main_loop_quit (ml, g);
8455 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8456 error (g, "%s: failed to parse reply header", "guestfs_equal");
8459 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8460 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8461 error (g, "%s: failed to parse reply error", "guestfs_equal");
8466 if (!xdr_guestfs_equal_ret (xdr, &ctx->ret)) {
8467 error (g, "%s: failed to parse reply", "guestfs_equal");
8471 ctx->cb_sequence = 1;
8474 int guestfs_equal (guestfs_h *g,
8478 struct guestfs_equal_args args;
8479 struct equal_ctx ctx;
8480 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8483 if (check_state (g, "guestfs_equal") == -1) return -1;
8484 guestfs_set_busy (g);
8486 memset (&ctx, 0, sizeof ctx);
8488 args.file1 = (char *) file1;
8489 args.file2 = (char *) file2;
8490 serial = guestfs__send_sync (g, GUESTFS_PROC_EQUAL,
8491 (xdrproc_t) xdr_guestfs_equal_args, (char *) &args);
8493 guestfs_end_busy (g);
8497 guestfs__switch_to_receiving (g);
8498 ctx.cb_sequence = 0;
8499 guestfs_set_reply_callback (g, equal_reply_cb, &ctx);
8500 (void) ml->main_loop_run (ml, g);
8501 guestfs_set_reply_callback (g, NULL, NULL);
8502 if (ctx.cb_sequence != 1) {
8503 error (g, "%s reply failed, see earlier error messages", "guestfs_equal");
8504 guestfs_end_busy (g);
8508 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EQUAL, serial) == -1) {
8509 guestfs_end_busy (g);
8513 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8514 error (g, "%s", ctx.err.error_message);
8515 free (ctx.err.error_message);
8516 guestfs_end_busy (g);
8520 guestfs_end_busy (g);
8521 return ctx.ret.equality;
8524 struct strings_ctx {
8525 /* This flag is set by the callbacks, so we know we've done
8526 * the callbacks as expected, and in the right sequence.
8527 * 0 = not called, 1 = reply_cb called.
8530 struct guestfs_message_header hdr;
8531 struct guestfs_message_error err;
8532 struct guestfs_strings_ret ret;
8535 static void strings_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8537 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8538 struct strings_ctx *ctx = (struct strings_ctx *) data;
8540 /* This should definitely not happen. */
8541 if (ctx->cb_sequence != 0) {
8542 ctx->cb_sequence = 9999;
8543 error (g, "%s: internal error: reply callback called twice", "guestfs_strings");
8547 ml->main_loop_quit (ml, g);
8549 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8550 error (g, "%s: failed to parse reply header", "guestfs_strings");
8553 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8554 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8555 error (g, "%s: failed to parse reply error", "guestfs_strings");
8560 if (!xdr_guestfs_strings_ret (xdr, &ctx->ret)) {
8561 error (g, "%s: failed to parse reply", "guestfs_strings");
8565 ctx->cb_sequence = 1;
8568 char **guestfs_strings (guestfs_h *g,
8571 struct guestfs_strings_args args;
8572 struct strings_ctx ctx;
8573 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8576 if (check_state (g, "guestfs_strings") == -1) return NULL;
8577 guestfs_set_busy (g);
8579 memset (&ctx, 0, sizeof ctx);
8581 args.path = (char *) path;
8582 serial = guestfs__send_sync (g, GUESTFS_PROC_STRINGS,
8583 (xdrproc_t) xdr_guestfs_strings_args, (char *) &args);
8585 guestfs_end_busy (g);
8589 guestfs__switch_to_receiving (g);
8590 ctx.cb_sequence = 0;
8591 guestfs_set_reply_callback (g, strings_reply_cb, &ctx);
8592 (void) ml->main_loop_run (ml, g);
8593 guestfs_set_reply_callback (g, NULL, NULL);
8594 if (ctx.cb_sequence != 1) {
8595 error (g, "%s reply failed, see earlier error messages", "guestfs_strings");
8596 guestfs_end_busy (g);
8600 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STRINGS, serial) == -1) {
8601 guestfs_end_busy (g);
8605 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8606 error (g, "%s", ctx.err.error_message);
8607 free (ctx.err.error_message);
8608 guestfs_end_busy (g);
8612 guestfs_end_busy (g);
8613 /* caller will free this, but we need to add a NULL entry */
8614 ctx.ret.stringsout.stringsout_val =
8615 safe_realloc (g, ctx.ret.stringsout.stringsout_val,
8616 sizeof (char *) * (ctx.ret.stringsout.stringsout_len + 1));
8617 ctx.ret.stringsout.stringsout_val[ctx.ret.stringsout.stringsout_len] = NULL;
8618 return ctx.ret.stringsout.stringsout_val;
8621 struct strings_e_ctx {
8622 /* This flag is set by the callbacks, so we know we've done
8623 * the callbacks as expected, and in the right sequence.
8624 * 0 = not called, 1 = reply_cb called.
8627 struct guestfs_message_header hdr;
8628 struct guestfs_message_error err;
8629 struct guestfs_strings_e_ret ret;
8632 static void strings_e_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8634 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8635 struct strings_e_ctx *ctx = (struct strings_e_ctx *) data;
8637 /* This should definitely not happen. */
8638 if (ctx->cb_sequence != 0) {
8639 ctx->cb_sequence = 9999;
8640 error (g, "%s: internal error: reply callback called twice", "guestfs_strings_e");
8644 ml->main_loop_quit (ml, g);
8646 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8647 error (g, "%s: failed to parse reply header", "guestfs_strings_e");
8650 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8651 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8652 error (g, "%s: failed to parse reply error", "guestfs_strings_e");
8657 if (!xdr_guestfs_strings_e_ret (xdr, &ctx->ret)) {
8658 error (g, "%s: failed to parse reply", "guestfs_strings_e");
8662 ctx->cb_sequence = 1;
8665 char **guestfs_strings_e (guestfs_h *g,
8666 const char *encoding,
8669 struct guestfs_strings_e_args args;
8670 struct strings_e_ctx ctx;
8671 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8674 if (check_state (g, "guestfs_strings_e") == -1) return NULL;
8675 guestfs_set_busy (g);
8677 memset (&ctx, 0, sizeof ctx);
8679 args.encoding = (char *) encoding;
8680 args.path = (char *) path;
8681 serial = guestfs__send_sync (g, GUESTFS_PROC_STRINGS_E,
8682 (xdrproc_t) xdr_guestfs_strings_e_args, (char *) &args);
8684 guestfs_end_busy (g);
8688 guestfs__switch_to_receiving (g);
8689 ctx.cb_sequence = 0;
8690 guestfs_set_reply_callback (g, strings_e_reply_cb, &ctx);
8691 (void) ml->main_loop_run (ml, g);
8692 guestfs_set_reply_callback (g, NULL, NULL);
8693 if (ctx.cb_sequence != 1) {
8694 error (g, "%s reply failed, see earlier error messages", "guestfs_strings_e");
8695 guestfs_end_busy (g);
8699 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STRINGS_E, serial) == -1) {
8700 guestfs_end_busy (g);
8704 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8705 error (g, "%s", ctx.err.error_message);
8706 free (ctx.err.error_message);
8707 guestfs_end_busy (g);
8711 guestfs_end_busy (g);
8712 /* caller will free this, but we need to add a NULL entry */
8713 ctx.ret.stringsout.stringsout_val =
8714 safe_realloc (g, ctx.ret.stringsout.stringsout_val,
8715 sizeof (char *) * (ctx.ret.stringsout.stringsout_len + 1));
8716 ctx.ret.stringsout.stringsout_val[ctx.ret.stringsout.stringsout_len] = NULL;
8717 return ctx.ret.stringsout.stringsout_val;
8720 struct hexdump_ctx {
8721 /* This flag is set by the callbacks, so we know we've done
8722 * the callbacks as expected, and in the right sequence.
8723 * 0 = not called, 1 = reply_cb called.
8726 struct guestfs_message_header hdr;
8727 struct guestfs_message_error err;
8728 struct guestfs_hexdump_ret ret;
8731 static void hexdump_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8733 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8734 struct hexdump_ctx *ctx = (struct hexdump_ctx *) data;
8736 /* This should definitely not happen. */
8737 if (ctx->cb_sequence != 0) {
8738 ctx->cb_sequence = 9999;
8739 error (g, "%s: internal error: reply callback called twice", "guestfs_hexdump");
8743 ml->main_loop_quit (ml, g);
8745 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8746 error (g, "%s: failed to parse reply header", "guestfs_hexdump");
8749 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8750 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8751 error (g, "%s: failed to parse reply error", "guestfs_hexdump");
8756 if (!xdr_guestfs_hexdump_ret (xdr, &ctx->ret)) {
8757 error (g, "%s: failed to parse reply", "guestfs_hexdump");
8761 ctx->cb_sequence = 1;
8764 char *guestfs_hexdump (guestfs_h *g,
8767 struct guestfs_hexdump_args args;
8768 struct hexdump_ctx ctx;
8769 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8772 if (check_state (g, "guestfs_hexdump") == -1) return NULL;
8773 guestfs_set_busy (g);
8775 memset (&ctx, 0, sizeof ctx);
8777 args.path = (char *) path;
8778 serial = guestfs__send_sync (g, GUESTFS_PROC_HEXDUMP,
8779 (xdrproc_t) xdr_guestfs_hexdump_args, (char *) &args);
8781 guestfs_end_busy (g);
8785 guestfs__switch_to_receiving (g);
8786 ctx.cb_sequence = 0;
8787 guestfs_set_reply_callback (g, hexdump_reply_cb, &ctx);
8788 (void) ml->main_loop_run (ml, g);
8789 guestfs_set_reply_callback (g, NULL, NULL);
8790 if (ctx.cb_sequence != 1) {
8791 error (g, "%s reply failed, see earlier error messages", "guestfs_hexdump");
8792 guestfs_end_busy (g);
8796 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_HEXDUMP, serial) == -1) {
8797 guestfs_end_busy (g);
8801 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8802 error (g, "%s", ctx.err.error_message);
8803 free (ctx.err.error_message);
8804 guestfs_end_busy (g);
8808 guestfs_end_busy (g);
8809 return ctx.ret.dump; /* caller will free */
8812 struct zerofree_ctx {
8813 /* This flag is set by the callbacks, so we know we've done
8814 * the callbacks as expected, and in the right sequence.
8815 * 0 = not called, 1 = reply_cb called.
8818 struct guestfs_message_header hdr;
8819 struct guestfs_message_error err;
8822 static void zerofree_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8824 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8825 struct zerofree_ctx *ctx = (struct zerofree_ctx *) data;
8827 /* This should definitely not happen. */
8828 if (ctx->cb_sequence != 0) {
8829 ctx->cb_sequence = 9999;
8830 error (g, "%s: internal error: reply callback called twice", "guestfs_zerofree");
8834 ml->main_loop_quit (ml, g);
8836 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8837 error (g, "%s: failed to parse reply header", "guestfs_zerofree");
8840 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8841 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8842 error (g, "%s: failed to parse reply error", "guestfs_zerofree");
8848 ctx->cb_sequence = 1;
8851 int guestfs_zerofree (guestfs_h *g,
8854 struct guestfs_zerofree_args args;
8855 struct zerofree_ctx ctx;
8856 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8859 if (check_state (g, "guestfs_zerofree") == -1) return -1;
8860 guestfs_set_busy (g);
8862 memset (&ctx, 0, sizeof ctx);
8864 args.device = (char *) device;
8865 serial = guestfs__send_sync (g, GUESTFS_PROC_ZEROFREE,
8866 (xdrproc_t) xdr_guestfs_zerofree_args, (char *) &args);
8868 guestfs_end_busy (g);
8872 guestfs__switch_to_receiving (g);
8873 ctx.cb_sequence = 0;
8874 guestfs_set_reply_callback (g, zerofree_reply_cb, &ctx);
8875 (void) ml->main_loop_run (ml, g);
8876 guestfs_set_reply_callback (g, NULL, NULL);
8877 if (ctx.cb_sequence != 1) {
8878 error (g, "%s reply failed, see earlier error messages", "guestfs_zerofree");
8879 guestfs_end_busy (g);
8883 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_ZEROFREE, serial) == -1) {
8884 guestfs_end_busy (g);
8888 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8889 error (g, "%s", ctx.err.error_message);
8890 free (ctx.err.error_message);
8891 guestfs_end_busy (g);
8895 guestfs_end_busy (g);
8899 struct pvresize_ctx {
8900 /* This flag is set by the callbacks, so we know we've done
8901 * the callbacks as expected, and in the right sequence.
8902 * 0 = not called, 1 = reply_cb called.
8905 struct guestfs_message_header hdr;
8906 struct guestfs_message_error err;
8909 static void pvresize_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8911 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8912 struct pvresize_ctx *ctx = (struct pvresize_ctx *) data;
8914 /* This should definitely not happen. */
8915 if (ctx->cb_sequence != 0) {
8916 ctx->cb_sequence = 9999;
8917 error (g, "%s: internal error: reply callback called twice", "guestfs_pvresize");
8921 ml->main_loop_quit (ml, g);
8923 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
8924 error (g, "%s: failed to parse reply header", "guestfs_pvresize");
8927 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
8928 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
8929 error (g, "%s: failed to parse reply error", "guestfs_pvresize");
8935 ctx->cb_sequence = 1;
8938 int guestfs_pvresize (guestfs_h *g,
8941 struct guestfs_pvresize_args args;
8942 struct pvresize_ctx ctx;
8943 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8946 if (check_state (g, "guestfs_pvresize") == -1) return -1;
8947 guestfs_set_busy (g);
8949 memset (&ctx, 0, sizeof ctx);
8951 args.device = (char *) device;
8952 serial = guestfs__send_sync (g, GUESTFS_PROC_PVRESIZE,
8953 (xdrproc_t) xdr_guestfs_pvresize_args, (char *) &args);
8955 guestfs_end_busy (g);
8959 guestfs__switch_to_receiving (g);
8960 ctx.cb_sequence = 0;
8961 guestfs_set_reply_callback (g, pvresize_reply_cb, &ctx);
8962 (void) ml->main_loop_run (ml, g);
8963 guestfs_set_reply_callback (g, NULL, NULL);
8964 if (ctx.cb_sequence != 1) {
8965 error (g, "%s reply failed, see earlier error messages", "guestfs_pvresize");
8966 guestfs_end_busy (g);
8970 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVRESIZE, serial) == -1) {
8971 guestfs_end_busy (g);
8975 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
8976 error (g, "%s", ctx.err.error_message);
8977 free (ctx.err.error_message);
8978 guestfs_end_busy (g);
8982 guestfs_end_busy (g);
8986 struct sfdisk_N_ctx {
8987 /* This flag is set by the callbacks, so we know we've done
8988 * the callbacks as expected, and in the right sequence.
8989 * 0 = not called, 1 = reply_cb called.
8992 struct guestfs_message_header hdr;
8993 struct guestfs_message_error err;
8996 static void sfdisk_N_reply_cb (guestfs_h *g, void *data, XDR *xdr)
8998 guestfs_main_loop *ml = guestfs_get_main_loop (g);
8999 struct sfdisk_N_ctx *ctx = (struct sfdisk_N_ctx *) data;
9001 /* This should definitely not happen. */
9002 if (ctx->cb_sequence != 0) {
9003 ctx->cb_sequence = 9999;
9004 error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_N");
9008 ml->main_loop_quit (ml, g);
9010 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9011 error (g, "%s: failed to parse reply header", "guestfs_sfdisk_N");
9014 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9015 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9016 error (g, "%s: failed to parse reply error", "guestfs_sfdisk_N");
9022 ctx->cb_sequence = 1;
9025 int guestfs_sfdisk_N (guestfs_h *g,
9033 struct guestfs_sfdisk_N_args args;
9034 struct sfdisk_N_ctx ctx;
9035 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9038 if (check_state (g, "guestfs_sfdisk_N") == -1) return -1;
9039 guestfs_set_busy (g);
9041 memset (&ctx, 0, sizeof ctx);
9043 args.device = (char *) device;
9047 args.sectors = sectors;
9048 args.line = (char *) line;
9049 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_N,
9050 (xdrproc_t) xdr_guestfs_sfdisk_N_args, (char *) &args);
9052 guestfs_end_busy (g);
9056 guestfs__switch_to_receiving (g);
9057 ctx.cb_sequence = 0;
9058 guestfs_set_reply_callback (g, sfdisk_N_reply_cb, &ctx);
9059 (void) ml->main_loop_run (ml, g);
9060 guestfs_set_reply_callback (g, NULL, NULL);
9061 if (ctx.cb_sequence != 1) {
9062 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_N");
9063 guestfs_end_busy (g);
9067 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_N, serial) == -1) {
9068 guestfs_end_busy (g);
9072 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9073 error (g, "%s", ctx.err.error_message);
9074 free (ctx.err.error_message);
9075 guestfs_end_busy (g);
9079 guestfs_end_busy (g);
9083 struct sfdisk_l_ctx {
9084 /* This flag is set by the callbacks, so we know we've done
9085 * the callbacks as expected, and in the right sequence.
9086 * 0 = not called, 1 = reply_cb called.
9089 struct guestfs_message_header hdr;
9090 struct guestfs_message_error err;
9091 struct guestfs_sfdisk_l_ret ret;
9094 static void sfdisk_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9096 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9097 struct sfdisk_l_ctx *ctx = (struct sfdisk_l_ctx *) data;
9099 /* This should definitely not happen. */
9100 if (ctx->cb_sequence != 0) {
9101 ctx->cb_sequence = 9999;
9102 error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_l");
9106 ml->main_loop_quit (ml, g);
9108 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9109 error (g, "%s: failed to parse reply header", "guestfs_sfdisk_l");
9112 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9113 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9114 error (g, "%s: failed to parse reply error", "guestfs_sfdisk_l");
9119 if (!xdr_guestfs_sfdisk_l_ret (xdr, &ctx->ret)) {
9120 error (g, "%s: failed to parse reply", "guestfs_sfdisk_l");
9124 ctx->cb_sequence = 1;
9127 char *guestfs_sfdisk_l (guestfs_h *g,
9130 struct guestfs_sfdisk_l_args args;
9131 struct sfdisk_l_ctx ctx;
9132 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9135 if (check_state (g, "guestfs_sfdisk_l") == -1) return NULL;
9136 guestfs_set_busy (g);
9138 memset (&ctx, 0, sizeof ctx);
9140 args.device = (char *) device;
9141 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_L,
9142 (xdrproc_t) xdr_guestfs_sfdisk_l_args, (char *) &args);
9144 guestfs_end_busy (g);
9148 guestfs__switch_to_receiving (g);
9149 ctx.cb_sequence = 0;
9150 guestfs_set_reply_callback (g, sfdisk_l_reply_cb, &ctx);
9151 (void) ml->main_loop_run (ml, g);
9152 guestfs_set_reply_callback (g, NULL, NULL);
9153 if (ctx.cb_sequence != 1) {
9154 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_l");
9155 guestfs_end_busy (g);
9159 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_L, serial) == -1) {
9160 guestfs_end_busy (g);
9164 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9165 error (g, "%s", ctx.err.error_message);
9166 free (ctx.err.error_message);
9167 guestfs_end_busy (g);
9171 guestfs_end_busy (g);
9172 return ctx.ret.partitions; /* caller will free */
9175 struct sfdisk_kernel_geometry_ctx {
9176 /* This flag is set by the callbacks, so we know we've done
9177 * the callbacks as expected, and in the right sequence.
9178 * 0 = not called, 1 = reply_cb called.
9181 struct guestfs_message_header hdr;
9182 struct guestfs_message_error err;
9183 struct guestfs_sfdisk_kernel_geometry_ret ret;
9186 static void sfdisk_kernel_geometry_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9188 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9189 struct sfdisk_kernel_geometry_ctx *ctx = (struct sfdisk_kernel_geometry_ctx *) data;
9191 /* This should definitely not happen. */
9192 if (ctx->cb_sequence != 0) {
9193 ctx->cb_sequence = 9999;
9194 error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_kernel_geometry");
9198 ml->main_loop_quit (ml, g);
9200 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9201 error (g, "%s: failed to parse reply header", "guestfs_sfdisk_kernel_geometry");
9204 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9205 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9206 error (g, "%s: failed to parse reply error", "guestfs_sfdisk_kernel_geometry");
9211 if (!xdr_guestfs_sfdisk_kernel_geometry_ret (xdr, &ctx->ret)) {
9212 error (g, "%s: failed to parse reply", "guestfs_sfdisk_kernel_geometry");
9216 ctx->cb_sequence = 1;
9219 char *guestfs_sfdisk_kernel_geometry (guestfs_h *g,
9222 struct guestfs_sfdisk_kernel_geometry_args args;
9223 struct sfdisk_kernel_geometry_ctx ctx;
9224 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9227 if (check_state (g, "guestfs_sfdisk_kernel_geometry") == -1) return NULL;
9228 guestfs_set_busy (g);
9230 memset (&ctx, 0, sizeof ctx);
9232 args.device = (char *) device;
9233 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY,
9234 (xdrproc_t) xdr_guestfs_sfdisk_kernel_geometry_args, (char *) &args);
9236 guestfs_end_busy (g);
9240 guestfs__switch_to_receiving (g);
9241 ctx.cb_sequence = 0;
9242 guestfs_set_reply_callback (g, sfdisk_kernel_geometry_reply_cb, &ctx);
9243 (void) ml->main_loop_run (ml, g);
9244 guestfs_set_reply_callback (g, NULL, NULL);
9245 if (ctx.cb_sequence != 1) {
9246 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_kernel_geometry");
9247 guestfs_end_busy (g);
9251 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_KERNEL_GEOMETRY, serial) == -1) {
9252 guestfs_end_busy (g);
9256 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9257 error (g, "%s", ctx.err.error_message);
9258 free (ctx.err.error_message);
9259 guestfs_end_busy (g);
9263 guestfs_end_busy (g);
9264 return ctx.ret.partitions; /* caller will free */
9267 struct sfdisk_disk_geometry_ctx {
9268 /* This flag is set by the callbacks, so we know we've done
9269 * the callbacks as expected, and in the right sequence.
9270 * 0 = not called, 1 = reply_cb called.
9273 struct guestfs_message_header hdr;
9274 struct guestfs_message_error err;
9275 struct guestfs_sfdisk_disk_geometry_ret ret;
9278 static void sfdisk_disk_geometry_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9280 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9281 struct sfdisk_disk_geometry_ctx *ctx = (struct sfdisk_disk_geometry_ctx *) data;
9283 /* This should definitely not happen. */
9284 if (ctx->cb_sequence != 0) {
9285 ctx->cb_sequence = 9999;
9286 error (g, "%s: internal error: reply callback called twice", "guestfs_sfdisk_disk_geometry");
9290 ml->main_loop_quit (ml, g);
9292 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9293 error (g, "%s: failed to parse reply header", "guestfs_sfdisk_disk_geometry");
9296 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9297 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9298 error (g, "%s: failed to parse reply error", "guestfs_sfdisk_disk_geometry");
9303 if (!xdr_guestfs_sfdisk_disk_geometry_ret (xdr, &ctx->ret)) {
9304 error (g, "%s: failed to parse reply", "guestfs_sfdisk_disk_geometry");
9308 ctx->cb_sequence = 1;
9311 char *guestfs_sfdisk_disk_geometry (guestfs_h *g,
9314 struct guestfs_sfdisk_disk_geometry_args args;
9315 struct sfdisk_disk_geometry_ctx ctx;
9316 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9319 if (check_state (g, "guestfs_sfdisk_disk_geometry") == -1) return NULL;
9320 guestfs_set_busy (g);
9322 memset (&ctx, 0, sizeof ctx);
9324 args.device = (char *) device;
9325 serial = guestfs__send_sync (g, GUESTFS_PROC_SFDISK_DISK_GEOMETRY,
9326 (xdrproc_t) xdr_guestfs_sfdisk_disk_geometry_args, (char *) &args);
9328 guestfs_end_busy (g);
9332 guestfs__switch_to_receiving (g);
9333 ctx.cb_sequence = 0;
9334 guestfs_set_reply_callback (g, sfdisk_disk_geometry_reply_cb, &ctx);
9335 (void) ml->main_loop_run (ml, g);
9336 guestfs_set_reply_callback (g, NULL, NULL);
9337 if (ctx.cb_sequence != 1) {
9338 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk_disk_geometry");
9339 guestfs_end_busy (g);
9343 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK_DISK_GEOMETRY, serial) == -1) {
9344 guestfs_end_busy (g);
9348 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9349 error (g, "%s", ctx.err.error_message);
9350 free (ctx.err.error_message);
9351 guestfs_end_busy (g);
9355 guestfs_end_busy (g);
9356 return ctx.ret.partitions; /* caller will free */
9359 struct vg_activate_all_ctx {
9360 /* This flag is set by the callbacks, so we know we've done
9361 * the callbacks as expected, and in the right sequence.
9362 * 0 = not called, 1 = reply_cb called.
9365 struct guestfs_message_header hdr;
9366 struct guestfs_message_error err;
9369 static void vg_activate_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9371 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9372 struct vg_activate_all_ctx *ctx = (struct vg_activate_all_ctx *) data;
9374 /* This should definitely not happen. */
9375 if (ctx->cb_sequence != 0) {
9376 ctx->cb_sequence = 9999;
9377 error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate_all");
9381 ml->main_loop_quit (ml, g);
9383 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9384 error (g, "%s: failed to parse reply header", "guestfs_vg_activate_all");
9387 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9388 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9389 error (g, "%s: failed to parse reply error", "guestfs_vg_activate_all");
9395 ctx->cb_sequence = 1;
9398 int guestfs_vg_activate_all (guestfs_h *g,
9401 struct guestfs_vg_activate_all_args args;
9402 struct vg_activate_all_ctx ctx;
9403 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9406 if (check_state (g, "guestfs_vg_activate_all") == -1) return -1;
9407 guestfs_set_busy (g);
9409 memset (&ctx, 0, sizeof ctx);
9411 args.activate = activate;
9412 serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE_ALL,
9413 (xdrproc_t) xdr_guestfs_vg_activate_all_args, (char *) &args);
9415 guestfs_end_busy (g);
9419 guestfs__switch_to_receiving (g);
9420 ctx.cb_sequence = 0;
9421 guestfs_set_reply_callback (g, vg_activate_all_reply_cb, &ctx);
9422 (void) ml->main_loop_run (ml, g);
9423 guestfs_set_reply_callback (g, NULL, NULL);
9424 if (ctx.cb_sequence != 1) {
9425 error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate_all");
9426 guestfs_end_busy (g);
9430 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE_ALL, serial) == -1) {
9431 guestfs_end_busy (g);
9435 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9436 error (g, "%s", ctx.err.error_message);
9437 free (ctx.err.error_message);
9438 guestfs_end_busy (g);
9442 guestfs_end_busy (g);
9446 struct vg_activate_ctx {
9447 /* This flag is set by the callbacks, so we know we've done
9448 * the callbacks as expected, and in the right sequence.
9449 * 0 = not called, 1 = reply_cb called.
9452 struct guestfs_message_header hdr;
9453 struct guestfs_message_error err;
9456 static void vg_activate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9458 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9459 struct vg_activate_ctx *ctx = (struct vg_activate_ctx *) data;
9461 /* This should definitely not happen. */
9462 if (ctx->cb_sequence != 0) {
9463 ctx->cb_sequence = 9999;
9464 error (g, "%s: internal error: reply callback called twice", "guestfs_vg_activate");
9468 ml->main_loop_quit (ml, g);
9470 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9471 error (g, "%s: failed to parse reply header", "guestfs_vg_activate");
9474 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9475 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9476 error (g, "%s: failed to parse reply error", "guestfs_vg_activate");
9482 ctx->cb_sequence = 1;
9485 int guestfs_vg_activate (guestfs_h *g,
9487 char * const* const volgroups)
9489 struct guestfs_vg_activate_args args;
9490 struct vg_activate_ctx ctx;
9491 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9494 if (check_state (g, "guestfs_vg_activate") == -1) return -1;
9495 guestfs_set_busy (g);
9497 memset (&ctx, 0, sizeof ctx);
9499 args.activate = activate;
9500 args.volgroups.volgroups_val = (char **) volgroups;
9501 for (args.volgroups.volgroups_len = 0; volgroups[args.volgroups.volgroups_len]; args.volgroups.volgroups_len++) ;
9502 serial = guestfs__send_sync (g, GUESTFS_PROC_VG_ACTIVATE,
9503 (xdrproc_t) xdr_guestfs_vg_activate_args, (char *) &args);
9505 guestfs_end_busy (g);
9509 guestfs__switch_to_receiving (g);
9510 ctx.cb_sequence = 0;
9511 guestfs_set_reply_callback (g, vg_activate_reply_cb, &ctx);
9512 (void) ml->main_loop_run (ml, g);
9513 guestfs_set_reply_callback (g, NULL, NULL);
9514 if (ctx.cb_sequence != 1) {
9515 error (g, "%s reply failed, see earlier error messages", "guestfs_vg_activate");
9516 guestfs_end_busy (g);
9520 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VG_ACTIVATE, serial) == -1) {
9521 guestfs_end_busy (g);
9525 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9526 error (g, "%s", ctx.err.error_message);
9527 free (ctx.err.error_message);
9528 guestfs_end_busy (g);
9532 guestfs_end_busy (g);
9536 struct lvresize_ctx {
9537 /* This flag is set by the callbacks, so we know we've done
9538 * the callbacks as expected, and in the right sequence.
9539 * 0 = not called, 1 = reply_cb called.
9542 struct guestfs_message_header hdr;
9543 struct guestfs_message_error err;
9546 static void lvresize_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9548 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9549 struct lvresize_ctx *ctx = (struct lvresize_ctx *) data;
9551 /* This should definitely not happen. */
9552 if (ctx->cb_sequence != 0) {
9553 ctx->cb_sequence = 9999;
9554 error (g, "%s: internal error: reply callback called twice", "guestfs_lvresize");
9558 ml->main_loop_quit (ml, g);
9560 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9561 error (g, "%s: failed to parse reply header", "guestfs_lvresize");
9564 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9565 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9566 error (g, "%s: failed to parse reply error", "guestfs_lvresize");
9572 ctx->cb_sequence = 1;
9575 int guestfs_lvresize (guestfs_h *g,
9579 struct guestfs_lvresize_args args;
9580 struct lvresize_ctx ctx;
9581 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9584 if (check_state (g, "guestfs_lvresize") == -1) return -1;
9585 guestfs_set_busy (g);
9587 memset (&ctx, 0, sizeof ctx);
9589 args.device = (char *) device;
9590 args.mbytes = mbytes;
9591 serial = guestfs__send_sync (g, GUESTFS_PROC_LVRESIZE,
9592 (xdrproc_t) xdr_guestfs_lvresize_args, (char *) &args);
9594 guestfs_end_busy (g);
9598 guestfs__switch_to_receiving (g);
9599 ctx.cb_sequence = 0;
9600 guestfs_set_reply_callback (g, lvresize_reply_cb, &ctx);
9601 (void) ml->main_loop_run (ml, g);
9602 guestfs_set_reply_callback (g, NULL, NULL);
9603 if (ctx.cb_sequence != 1) {
9604 error (g, "%s reply failed, see earlier error messages", "guestfs_lvresize");
9605 guestfs_end_busy (g);
9609 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVRESIZE, serial) == -1) {
9610 guestfs_end_busy (g);
9614 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9615 error (g, "%s", ctx.err.error_message);
9616 free (ctx.err.error_message);
9617 guestfs_end_busy (g);
9621 guestfs_end_busy (g);
9625 struct resize2fs_ctx {
9626 /* This flag is set by the callbacks, so we know we've done
9627 * the callbacks as expected, and in the right sequence.
9628 * 0 = not called, 1 = reply_cb called.
9631 struct guestfs_message_header hdr;
9632 struct guestfs_message_error err;
9635 static void resize2fs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9637 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9638 struct resize2fs_ctx *ctx = (struct resize2fs_ctx *) data;
9640 /* This should definitely not happen. */
9641 if (ctx->cb_sequence != 0) {
9642 ctx->cb_sequence = 9999;
9643 error (g, "%s: internal error: reply callback called twice", "guestfs_resize2fs");
9647 ml->main_loop_quit (ml, g);
9649 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9650 error (g, "%s: failed to parse reply header", "guestfs_resize2fs");
9653 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9654 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9655 error (g, "%s: failed to parse reply error", "guestfs_resize2fs");
9661 ctx->cb_sequence = 1;
9664 int guestfs_resize2fs (guestfs_h *g,
9667 struct guestfs_resize2fs_args args;
9668 struct resize2fs_ctx ctx;
9669 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9672 if (check_state (g, "guestfs_resize2fs") == -1) return -1;
9673 guestfs_set_busy (g);
9675 memset (&ctx, 0, sizeof ctx);
9677 args.device = (char *) device;
9678 serial = guestfs__send_sync (g, GUESTFS_PROC_RESIZE2FS,
9679 (xdrproc_t) xdr_guestfs_resize2fs_args, (char *) &args);
9681 guestfs_end_busy (g);
9685 guestfs__switch_to_receiving (g);
9686 ctx.cb_sequence = 0;
9687 guestfs_set_reply_callback (g, resize2fs_reply_cb, &ctx);
9688 (void) ml->main_loop_run (ml, g);
9689 guestfs_set_reply_callback (g, NULL, NULL);
9690 if (ctx.cb_sequence != 1) {
9691 error (g, "%s reply failed, see earlier error messages", "guestfs_resize2fs");
9692 guestfs_end_busy (g);
9696 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RESIZE2FS, serial) == -1) {
9697 guestfs_end_busy (g);
9701 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9702 error (g, "%s", ctx.err.error_message);
9703 free (ctx.err.error_message);
9704 guestfs_end_busy (g);
9708 guestfs_end_busy (g);
9713 /* This flag is set by the callbacks, so we know we've done
9714 * the callbacks as expected, and in the right sequence.
9715 * 0 = not called, 1 = reply_cb called.
9718 struct guestfs_message_header hdr;
9719 struct guestfs_message_error err;
9720 struct guestfs_find_ret ret;
9723 static void find_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9725 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9726 struct find_ctx *ctx = (struct find_ctx *) data;
9728 /* This should definitely not happen. */
9729 if (ctx->cb_sequence != 0) {
9730 ctx->cb_sequence = 9999;
9731 error (g, "%s: internal error: reply callback called twice", "guestfs_find");
9735 ml->main_loop_quit (ml, g);
9737 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9738 error (g, "%s: failed to parse reply header", "guestfs_find");
9741 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9742 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9743 error (g, "%s: failed to parse reply error", "guestfs_find");
9748 if (!xdr_guestfs_find_ret (xdr, &ctx->ret)) {
9749 error (g, "%s: failed to parse reply", "guestfs_find");
9753 ctx->cb_sequence = 1;
9756 char **guestfs_find (guestfs_h *g,
9757 const char *directory)
9759 struct guestfs_find_args args;
9760 struct find_ctx ctx;
9761 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9764 if (check_state (g, "guestfs_find") == -1) return NULL;
9765 guestfs_set_busy (g);
9767 memset (&ctx, 0, sizeof ctx);
9769 args.directory = (char *) directory;
9770 serial = guestfs__send_sync (g, GUESTFS_PROC_FIND,
9771 (xdrproc_t) xdr_guestfs_find_args, (char *) &args);
9773 guestfs_end_busy (g);
9777 guestfs__switch_to_receiving (g);
9778 ctx.cb_sequence = 0;
9779 guestfs_set_reply_callback (g, find_reply_cb, &ctx);
9780 (void) ml->main_loop_run (ml, g);
9781 guestfs_set_reply_callback (g, NULL, NULL);
9782 if (ctx.cb_sequence != 1) {
9783 error (g, "%s reply failed, see earlier error messages", "guestfs_find");
9784 guestfs_end_busy (g);
9788 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FIND, serial) == -1) {
9789 guestfs_end_busy (g);
9793 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9794 error (g, "%s", ctx.err.error_message);
9795 free (ctx.err.error_message);
9796 guestfs_end_busy (g);
9800 guestfs_end_busy (g);
9801 /* caller will free this, but we need to add a NULL entry */
9802 ctx.ret.names.names_val =
9803 safe_realloc (g, ctx.ret.names.names_val,
9804 sizeof (char *) * (ctx.ret.names.names_len + 1));
9805 ctx.ret.names.names_val[ctx.ret.names.names_len] = NULL;
9806 return ctx.ret.names.names_val;
9809 struct e2fsck_f_ctx {
9810 /* This flag is set by the callbacks, so we know we've done
9811 * the callbacks as expected, and in the right sequence.
9812 * 0 = not called, 1 = reply_cb called.
9815 struct guestfs_message_header hdr;
9816 struct guestfs_message_error err;
9819 static void e2fsck_f_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9821 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9822 struct e2fsck_f_ctx *ctx = (struct e2fsck_f_ctx *) data;
9824 /* This should definitely not happen. */
9825 if (ctx->cb_sequence != 0) {
9826 ctx->cb_sequence = 9999;
9827 error (g, "%s: internal error: reply callback called twice", "guestfs_e2fsck_f");
9831 ml->main_loop_quit (ml, g);
9833 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9834 error (g, "%s: failed to parse reply header", "guestfs_e2fsck_f");
9837 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9838 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9839 error (g, "%s: failed to parse reply error", "guestfs_e2fsck_f");
9845 ctx->cb_sequence = 1;
9848 int guestfs_e2fsck_f (guestfs_h *g,
9851 struct guestfs_e2fsck_f_args args;
9852 struct e2fsck_f_ctx ctx;
9853 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9856 if (check_state (g, "guestfs_e2fsck_f") == -1) return -1;
9857 guestfs_set_busy (g);
9859 memset (&ctx, 0, sizeof ctx);
9861 args.device = (char *) device;
9862 serial = guestfs__send_sync (g, GUESTFS_PROC_E2FSCK_F,
9863 (xdrproc_t) xdr_guestfs_e2fsck_f_args, (char *) &args);
9865 guestfs_end_busy (g);
9869 guestfs__switch_to_receiving (g);
9870 ctx.cb_sequence = 0;
9871 guestfs_set_reply_callback (g, e2fsck_f_reply_cb, &ctx);
9872 (void) ml->main_loop_run (ml, g);
9873 guestfs_set_reply_callback (g, NULL, NULL);
9874 if (ctx.cb_sequence != 1) {
9875 error (g, "%s reply failed, see earlier error messages", "guestfs_e2fsck_f");
9876 guestfs_end_busy (g);
9880 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_E2FSCK_F, serial) == -1) {
9881 guestfs_end_busy (g);
9885 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9886 error (g, "%s", ctx.err.error_message);
9887 free (ctx.err.error_message);
9888 guestfs_end_busy (g);
9892 guestfs_end_busy (g);
9897 /* This flag is set by the callbacks, so we know we've done
9898 * the callbacks as expected, and in the right sequence.
9899 * 0 = not called, 1 = reply_cb called.
9902 struct guestfs_message_header hdr;
9903 struct guestfs_message_error err;
9906 static void sleep_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9908 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9909 struct sleep_ctx *ctx = (struct sleep_ctx *) data;
9911 /* This should definitely not happen. */
9912 if (ctx->cb_sequence != 0) {
9913 ctx->cb_sequence = 9999;
9914 error (g, "%s: internal error: reply callback called twice", "guestfs_sleep");
9918 ml->main_loop_quit (ml, g);
9920 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
9921 error (g, "%s: failed to parse reply header", "guestfs_sleep");
9924 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
9925 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
9926 error (g, "%s: failed to parse reply error", "guestfs_sleep");
9932 ctx->cb_sequence = 1;
9935 int guestfs_sleep (guestfs_h *g,
9938 struct guestfs_sleep_args args;
9939 struct sleep_ctx ctx;
9940 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9943 if (check_state (g, "guestfs_sleep") == -1) return -1;
9944 guestfs_set_busy (g);
9946 memset (&ctx, 0, sizeof ctx);
9949 serial = guestfs__send_sync (g, GUESTFS_PROC_SLEEP,
9950 (xdrproc_t) xdr_guestfs_sleep_args, (char *) &args);
9952 guestfs_end_busy (g);
9956 guestfs__switch_to_receiving (g);
9957 ctx.cb_sequence = 0;
9958 guestfs_set_reply_callback (g, sleep_reply_cb, &ctx);
9959 (void) ml->main_loop_run (ml, g);
9960 guestfs_set_reply_callback (g, NULL, NULL);
9961 if (ctx.cb_sequence != 1) {
9962 error (g, "%s reply failed, see earlier error messages", "guestfs_sleep");
9963 guestfs_end_busy (g);
9967 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SLEEP, serial) == -1) {
9968 guestfs_end_busy (g);
9972 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
9973 error (g, "%s", ctx.err.error_message);
9974 free (ctx.err.error_message);
9975 guestfs_end_busy (g);
9979 guestfs_end_busy (g);
9983 struct ntfs_3g_probe_ctx {
9984 /* This flag is set by the callbacks, so we know we've done
9985 * the callbacks as expected, and in the right sequence.
9986 * 0 = not called, 1 = reply_cb called.
9989 struct guestfs_message_header hdr;
9990 struct guestfs_message_error err;
9991 struct guestfs_ntfs_3g_probe_ret ret;
9994 static void ntfs_3g_probe_reply_cb (guestfs_h *g, void *data, XDR *xdr)
9996 guestfs_main_loop *ml = guestfs_get_main_loop (g);
9997 struct ntfs_3g_probe_ctx *ctx = (struct ntfs_3g_probe_ctx *) data;
9999 /* This should definitely not happen. */
10000 if (ctx->cb_sequence != 0) {
10001 ctx->cb_sequence = 9999;
10002 error (g, "%s: internal error: reply callback called twice", "guestfs_ntfs_3g_probe");
10006 ml->main_loop_quit (ml, g);
10008 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
10009 error (g, "%s: failed to parse reply header", "guestfs_ntfs_3g_probe");
10012 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
10013 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
10014 error (g, "%s: failed to parse reply error", "guestfs_ntfs_3g_probe");
10019 if (!xdr_guestfs_ntfs_3g_probe_ret (xdr, &ctx->ret)) {
10020 error (g, "%s: failed to parse reply", "guestfs_ntfs_3g_probe");
10024 ctx->cb_sequence = 1;
10027 int guestfs_ntfs_3g_probe (guestfs_h *g,
10029 const char *device)
10031 struct guestfs_ntfs_3g_probe_args args;
10032 struct ntfs_3g_probe_ctx ctx;
10033 guestfs_main_loop *ml = guestfs_get_main_loop (g);
10036 if (check_state (g, "guestfs_ntfs_3g_probe") == -1) return -1;
10037 guestfs_set_busy (g);
10039 memset (&ctx, 0, sizeof ctx);
10042 args.device = (char *) device;
10043 serial = guestfs__send_sync (g, GUESTFS_PROC_NTFS_3G_PROBE,
10044 (xdrproc_t) xdr_guestfs_ntfs_3g_probe_args, (char *) &args);
10045 if (serial == -1) {
10046 guestfs_end_busy (g);
10050 guestfs__switch_to_receiving (g);
10051 ctx.cb_sequence = 0;
10052 guestfs_set_reply_callback (g, ntfs_3g_probe_reply_cb, &ctx);
10053 (void) ml->main_loop_run (ml, g);
10054 guestfs_set_reply_callback (g, NULL, NULL);
10055 if (ctx.cb_sequence != 1) {
10056 error (g, "%s reply failed, see earlier error messages", "guestfs_ntfs_3g_probe");
10057 guestfs_end_busy (g);
10061 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_NTFS_3G_PROBE, serial) == -1) {
10062 guestfs_end_busy (g);
10066 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
10067 error (g, "%s", ctx.err.error_message);
10068 free (ctx.err.error_message);
10069 guestfs_end_busy (g);
10073 guestfs_end_busy (g);
10074 return ctx.ret.status;