1 /* libguestfs generated file
2 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
5 * Copyright (C) 2009 Red Hat Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "guestfs_protocol.h"
28 #define error guestfs_error
29 #define perrorf guestfs_perrorf
30 #define safe_malloc guestfs_safe_malloc
31 #define safe_realloc guestfs_safe_realloc
32 #define safe_strdup guestfs_safe_strdup
33 #define safe_memdup guestfs_safe_memdup
35 /* Check the return message from a call for validity. */
37 check_reply_header (guestfs_h *g,
38 const struct guestfs_message_header *hdr,
39 int proc_nr, int serial)
41 if (hdr->prog != GUESTFS_PROGRAM) {
42 error (g, "wrong program (%d/%d)", hdr->prog, GUESTFS_PROGRAM);
45 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
46 error (g, "wrong protocol version (%d/%d)",
47 hdr->vers, GUESTFS_PROTOCOL_VERSION);
50 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
51 error (g, "unexpected message direction (%d/%d)",
52 hdr->direction, GUESTFS_DIRECTION_REPLY);
55 if (hdr->proc != proc_nr) {
56 error (g, "unexpected procedure number (%d/%d)", hdr->proc, proc_nr);
59 if (hdr->serial != serial) {
60 error (g, "unexpected serial (%d/%d)", hdr->serial, serial);
67 /* Check we are in the right state to run a high-level action. */
69 check_state (guestfs_h *g, const char *caller)
71 if (!guestfs_is_ready (g)) {
72 if (guestfs_is_config (g))
73 error (g, "%s: call launch() before using this function",
75 else if (guestfs_is_launching (g))
76 error (g, "%s: call wait_ready() before using this function",
79 error (g, "%s called from the wrong state, %d != READY",
80 caller, guestfs_get_state (g));
87 /* This flag is set by the callbacks, so we know we've done
88 * the callbacks as expected, and in the right sequence.
89 * 0 = not called, 1 = send called,
90 * 2.. = send_file called,
91 * 1000 = reply called.
94 struct guestfs_message_header hdr;
95 struct guestfs_message_error err;
98 static void mount_send_cb (guestfs_h *g, void *data)
100 guestfs_main_loop *ml = guestfs_get_main_loop (g);
101 struct mount_ctx *ctx = (struct mount_ctx *) data;
103 guestfs__switch_to_receiving (g);
104 ctx->cb_sequence = 1;
105 ml->main_loop_quit (ml, g);
108 static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
110 guestfs_main_loop *ml = guestfs_get_main_loop (g);
111 struct mount_ctx *ctx = (struct mount_ctx *) data;
113 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
114 error (g, "%s: failed to parse reply header", "guestfs_mount");
117 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
118 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
119 error (g, "%s: failed to parse reply error", "guestfs_mount");
125 ctx->cb_sequence = 1000;
126 ml->main_loop_quit (ml, g);
129 int guestfs_mount (guestfs_h *g,
131 const char *mountpoint)
133 struct guestfs_mount_args args;
134 struct mount_ctx ctx;
135 guestfs_main_loop *ml = guestfs_get_main_loop (g);
138 if (check_state (g, "guestfs_mount") == -1) return -1;
140 memset (&ctx, 0, sizeof ctx);
142 args.device = (char *) device;
143 args.mountpoint = (char *) mountpoint;
144 serial = guestfs__send (g, GUESTFS_PROC_MOUNT,
145 (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
150 guestfs_set_send_callback (g, mount_send_cb, &ctx);
151 (void) ml->main_loop_run (ml, g);
152 guestfs_set_send_callback (g, NULL, NULL);
153 if (ctx.cb_sequence != 1) {
154 error (g, "%s send failed, see earlier error messages", "guestfs_mount");
159 guestfs_set_reply_callback (g, mount_reply_cb, &ctx);
160 (void) ml->main_loop_run (ml, g);
161 guestfs_set_reply_callback (g, NULL, NULL);
162 if (ctx.cb_sequence != 1000) {
163 error (g, "%s reply failed, see earlier error messages", "guestfs_mount");
167 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
170 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
171 error (g, "%s", ctx.err.error_message);
179 /* This flag is set by the callbacks, so we know we've done
180 * the callbacks as expected, and in the right sequence.
181 * 0 = not called, 1 = send called,
182 * 2.. = send_file called,
183 * 1000 = reply called.
186 struct guestfs_message_header hdr;
187 struct guestfs_message_error err;
190 static void sync_send_cb (guestfs_h *g, void *data)
192 guestfs_main_loop *ml = guestfs_get_main_loop (g);
193 struct sync_ctx *ctx = (struct sync_ctx *) data;
195 guestfs__switch_to_receiving (g);
196 ctx->cb_sequence = 1;
197 ml->main_loop_quit (ml, g);
200 static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
202 guestfs_main_loop *ml = guestfs_get_main_loop (g);
203 struct sync_ctx *ctx = (struct sync_ctx *) data;
205 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
206 error (g, "%s: failed to parse reply header", "guestfs_sync");
209 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
210 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
211 error (g, "%s: failed to parse reply error", "guestfs_sync");
217 ctx->cb_sequence = 1000;
218 ml->main_loop_quit (ml, g);
221 int guestfs_sync (guestfs_h *g)
224 guestfs_main_loop *ml = guestfs_get_main_loop (g);
227 if (check_state (g, "guestfs_sync") == -1) return -1;
229 memset (&ctx, 0, sizeof ctx);
231 serial = guestfs__send (g, GUESTFS_PROC_SYNC, NULL, NULL);
236 guestfs_set_send_callback (g, sync_send_cb, &ctx);
237 (void) ml->main_loop_run (ml, g);
238 guestfs_set_send_callback (g, NULL, NULL);
239 if (ctx.cb_sequence != 1) {
240 error (g, "%s send failed, see earlier error messages", "guestfs_sync");
245 guestfs_set_reply_callback (g, sync_reply_cb, &ctx);
246 (void) ml->main_loop_run (ml, g);
247 guestfs_set_reply_callback (g, NULL, NULL);
248 if (ctx.cb_sequence != 1000) {
249 error (g, "%s reply failed, see earlier error messages", "guestfs_sync");
253 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SYNC, serial) == -1)
256 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
257 error (g, "%s", ctx.err.error_message);
265 /* This flag is set by the callbacks, so we know we've done
266 * the callbacks as expected, and in the right sequence.
267 * 0 = not called, 1 = send called,
268 * 2.. = send_file called,
269 * 1000 = reply called.
272 struct guestfs_message_header hdr;
273 struct guestfs_message_error err;
276 static void touch_send_cb (guestfs_h *g, void *data)
278 guestfs_main_loop *ml = guestfs_get_main_loop (g);
279 struct touch_ctx *ctx = (struct touch_ctx *) data;
281 guestfs__switch_to_receiving (g);
282 ctx->cb_sequence = 1;
283 ml->main_loop_quit (ml, g);
286 static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
288 guestfs_main_loop *ml = guestfs_get_main_loop (g);
289 struct touch_ctx *ctx = (struct touch_ctx *) data;
291 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
292 error (g, "%s: failed to parse reply header", "guestfs_touch");
295 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
296 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
297 error (g, "%s: failed to parse reply error", "guestfs_touch");
303 ctx->cb_sequence = 1000;
304 ml->main_loop_quit (ml, g);
307 int guestfs_touch (guestfs_h *g,
310 struct guestfs_touch_args args;
311 struct touch_ctx ctx;
312 guestfs_main_loop *ml = guestfs_get_main_loop (g);
315 if (check_state (g, "guestfs_touch") == -1) return -1;
317 memset (&ctx, 0, sizeof ctx);
319 args.path = (char *) path;
320 serial = guestfs__send (g, GUESTFS_PROC_TOUCH,
321 (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
326 guestfs_set_send_callback (g, touch_send_cb, &ctx);
327 (void) ml->main_loop_run (ml, g);
328 guestfs_set_send_callback (g, NULL, NULL);
329 if (ctx.cb_sequence != 1) {
330 error (g, "%s send failed, see earlier error messages", "guestfs_touch");
335 guestfs_set_reply_callback (g, touch_reply_cb, &ctx);
336 (void) ml->main_loop_run (ml, g);
337 guestfs_set_reply_callback (g, NULL, NULL);
338 if (ctx.cb_sequence != 1000) {
339 error (g, "%s reply failed, see earlier error messages", "guestfs_touch");
343 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
346 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
347 error (g, "%s", ctx.err.error_message);
355 /* This flag is set by the callbacks, so we know we've done
356 * the callbacks as expected, and in the right sequence.
357 * 0 = not called, 1 = send called,
358 * 2.. = send_file called,
359 * 1000 = reply called.
362 struct guestfs_message_header hdr;
363 struct guestfs_message_error err;
364 struct guestfs_cat_ret ret;
367 static void cat_send_cb (guestfs_h *g, void *data)
369 guestfs_main_loop *ml = guestfs_get_main_loop (g);
370 struct cat_ctx *ctx = (struct cat_ctx *) data;
372 guestfs__switch_to_receiving (g);
373 ctx->cb_sequence = 1;
374 ml->main_loop_quit (ml, g);
377 static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
379 guestfs_main_loop *ml = guestfs_get_main_loop (g);
380 struct cat_ctx *ctx = (struct cat_ctx *) data;
382 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
383 error (g, "%s: failed to parse reply header", "guestfs_cat");
386 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
387 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
388 error (g, "%s: failed to parse reply error", "guestfs_cat");
393 if (!xdr_guestfs_cat_ret (xdr, &ctx->ret)) {
394 error (g, "%s: failed to parse reply", "guestfs_cat");
398 ctx->cb_sequence = 1000;
399 ml->main_loop_quit (ml, g);
402 char *guestfs_cat (guestfs_h *g,
405 struct guestfs_cat_args args;
407 guestfs_main_loop *ml = guestfs_get_main_loop (g);
410 if (check_state (g, "guestfs_cat") == -1) return NULL;
412 memset (&ctx, 0, sizeof ctx);
414 args.path = (char *) path;
415 serial = guestfs__send (g, GUESTFS_PROC_CAT,
416 (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
421 guestfs_set_send_callback (g, cat_send_cb, &ctx);
422 (void) ml->main_loop_run (ml, g);
423 guestfs_set_send_callback (g, NULL, NULL);
424 if (ctx.cb_sequence != 1) {
425 error (g, "%s send failed, see earlier error messages", "guestfs_cat");
430 guestfs_set_reply_callback (g, cat_reply_cb, &ctx);
431 (void) ml->main_loop_run (ml, g);
432 guestfs_set_reply_callback (g, NULL, NULL);
433 if (ctx.cb_sequence != 1000) {
434 error (g, "%s reply failed, see earlier error messages", "guestfs_cat");
438 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CAT, serial) == -1)
441 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
442 error (g, "%s", ctx.err.error_message);
446 return ctx.ret.content; /* caller will free */
450 /* This flag is set by the callbacks, so we know we've done
451 * the callbacks as expected, and in the right sequence.
452 * 0 = not called, 1 = send called,
453 * 2.. = send_file called,
454 * 1000 = reply called.
457 struct guestfs_message_header hdr;
458 struct guestfs_message_error err;
459 struct guestfs_ll_ret ret;
462 static void ll_send_cb (guestfs_h *g, void *data)
464 guestfs_main_loop *ml = guestfs_get_main_loop (g);
465 struct ll_ctx *ctx = (struct ll_ctx *) data;
467 guestfs__switch_to_receiving (g);
468 ctx->cb_sequence = 1;
469 ml->main_loop_quit (ml, g);
472 static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
474 guestfs_main_loop *ml = guestfs_get_main_loop (g);
475 struct ll_ctx *ctx = (struct ll_ctx *) data;
477 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
478 error (g, "%s: failed to parse reply header", "guestfs_ll");
481 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
482 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
483 error (g, "%s: failed to parse reply error", "guestfs_ll");
488 if (!xdr_guestfs_ll_ret (xdr, &ctx->ret)) {
489 error (g, "%s: failed to parse reply", "guestfs_ll");
493 ctx->cb_sequence = 1000;
494 ml->main_loop_quit (ml, g);
497 char *guestfs_ll (guestfs_h *g,
498 const char *directory)
500 struct guestfs_ll_args args;
502 guestfs_main_loop *ml = guestfs_get_main_loop (g);
505 if (check_state (g, "guestfs_ll") == -1) return NULL;
507 memset (&ctx, 0, sizeof ctx);
509 args.directory = (char *) directory;
510 serial = guestfs__send (g, GUESTFS_PROC_LL,
511 (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
516 guestfs_set_send_callback (g, ll_send_cb, &ctx);
517 (void) ml->main_loop_run (ml, g);
518 guestfs_set_send_callback (g, NULL, NULL);
519 if (ctx.cb_sequence != 1) {
520 error (g, "%s send failed, see earlier error messages", "guestfs_ll");
525 guestfs_set_reply_callback (g, ll_reply_cb, &ctx);
526 (void) ml->main_loop_run (ml, g);
527 guestfs_set_reply_callback (g, NULL, NULL);
528 if (ctx.cb_sequence != 1000) {
529 error (g, "%s reply failed, see earlier error messages", "guestfs_ll");
533 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LL, serial) == -1)
536 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
537 error (g, "%s", ctx.err.error_message);
541 return ctx.ret.listing; /* caller will free */
545 /* This flag is set by the callbacks, so we know we've done
546 * the callbacks as expected, and in the right sequence.
547 * 0 = not called, 1 = send called,
548 * 2.. = send_file called,
549 * 1000 = reply called.
552 struct guestfs_message_header hdr;
553 struct guestfs_message_error err;
554 struct guestfs_ls_ret ret;
557 static void ls_send_cb (guestfs_h *g, void *data)
559 guestfs_main_loop *ml = guestfs_get_main_loop (g);
560 struct ls_ctx *ctx = (struct ls_ctx *) data;
562 guestfs__switch_to_receiving (g);
563 ctx->cb_sequence = 1;
564 ml->main_loop_quit (ml, g);
567 static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
569 guestfs_main_loop *ml = guestfs_get_main_loop (g);
570 struct ls_ctx *ctx = (struct ls_ctx *) data;
572 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
573 error (g, "%s: failed to parse reply header", "guestfs_ls");
576 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
577 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
578 error (g, "%s: failed to parse reply error", "guestfs_ls");
583 if (!xdr_guestfs_ls_ret (xdr, &ctx->ret)) {
584 error (g, "%s: failed to parse reply", "guestfs_ls");
588 ctx->cb_sequence = 1000;
589 ml->main_loop_quit (ml, g);
592 char **guestfs_ls (guestfs_h *g,
593 const char *directory)
595 struct guestfs_ls_args args;
597 guestfs_main_loop *ml = guestfs_get_main_loop (g);
600 if (check_state (g, "guestfs_ls") == -1) return NULL;
602 memset (&ctx, 0, sizeof ctx);
604 args.directory = (char *) directory;
605 serial = guestfs__send (g, GUESTFS_PROC_LS,
606 (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
611 guestfs_set_send_callback (g, ls_send_cb, &ctx);
612 (void) ml->main_loop_run (ml, g);
613 guestfs_set_send_callback (g, NULL, NULL);
614 if (ctx.cb_sequence != 1) {
615 error (g, "%s send failed, see earlier error messages", "guestfs_ls");
620 guestfs_set_reply_callback (g, ls_reply_cb, &ctx);
621 (void) ml->main_loop_run (ml, g);
622 guestfs_set_reply_callback (g, NULL, NULL);
623 if (ctx.cb_sequence != 1000) {
624 error (g, "%s reply failed, see earlier error messages", "guestfs_ls");
628 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LS, serial) == -1)
631 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
632 error (g, "%s", ctx.err.error_message);
636 /* caller will free this, but we need to add a NULL entry */
637 ctx.ret.listing.listing_val =
638 safe_realloc (g, ctx.ret.listing.listing_val,
639 sizeof (char *) * (ctx.ret.listing.listing_len + 1));
640 ctx.ret.listing.listing_val[ctx.ret.listing.listing_len] = NULL;
641 return ctx.ret.listing.listing_val;
644 struct list_devices_ctx {
645 /* This flag is set by the callbacks, so we know we've done
646 * the callbacks as expected, and in the right sequence.
647 * 0 = not called, 1 = send called,
648 * 2.. = send_file called,
649 * 1000 = reply called.
652 struct guestfs_message_header hdr;
653 struct guestfs_message_error err;
654 struct guestfs_list_devices_ret ret;
657 static void list_devices_send_cb (guestfs_h *g, void *data)
659 guestfs_main_loop *ml = guestfs_get_main_loop (g);
660 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
662 guestfs__switch_to_receiving (g);
663 ctx->cb_sequence = 1;
664 ml->main_loop_quit (ml, g);
667 static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
669 guestfs_main_loop *ml = guestfs_get_main_loop (g);
670 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
672 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
673 error (g, "%s: failed to parse reply header", "guestfs_list_devices");
676 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
677 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
678 error (g, "%s: failed to parse reply error", "guestfs_list_devices");
683 if (!xdr_guestfs_list_devices_ret (xdr, &ctx->ret)) {
684 error (g, "%s: failed to parse reply", "guestfs_list_devices");
688 ctx->cb_sequence = 1000;
689 ml->main_loop_quit (ml, g);
692 char **guestfs_list_devices (guestfs_h *g)
694 struct list_devices_ctx ctx;
695 guestfs_main_loop *ml = guestfs_get_main_loop (g);
698 if (check_state (g, "guestfs_list_devices") == -1) return NULL;
700 memset (&ctx, 0, sizeof ctx);
702 serial = guestfs__send (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
707 guestfs_set_send_callback (g, list_devices_send_cb, &ctx);
708 (void) ml->main_loop_run (ml, g);
709 guestfs_set_send_callback (g, NULL, NULL);
710 if (ctx.cb_sequence != 1) {
711 error (g, "%s send failed, see earlier error messages", "guestfs_list_devices");
716 guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx);
717 (void) ml->main_loop_run (ml, g);
718 guestfs_set_reply_callback (g, NULL, NULL);
719 if (ctx.cb_sequence != 1000) {
720 error (g, "%s reply failed, see earlier error messages", "guestfs_list_devices");
724 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1)
727 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
728 error (g, "%s", ctx.err.error_message);
732 /* caller will free this, but we need to add a NULL entry */
733 ctx.ret.devices.devices_val =
734 safe_realloc (g, ctx.ret.devices.devices_val,
735 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
736 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
737 return ctx.ret.devices.devices_val;
740 struct list_partitions_ctx {
741 /* This flag is set by the callbacks, so we know we've done
742 * the callbacks as expected, and in the right sequence.
743 * 0 = not called, 1 = send called,
744 * 2.. = send_file called,
745 * 1000 = reply called.
748 struct guestfs_message_header hdr;
749 struct guestfs_message_error err;
750 struct guestfs_list_partitions_ret ret;
753 static void list_partitions_send_cb (guestfs_h *g, void *data)
755 guestfs_main_loop *ml = guestfs_get_main_loop (g);
756 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
758 guestfs__switch_to_receiving (g);
759 ctx->cb_sequence = 1;
760 ml->main_loop_quit (ml, g);
763 static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
765 guestfs_main_loop *ml = guestfs_get_main_loop (g);
766 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
768 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
769 error (g, "%s: failed to parse reply header", "guestfs_list_partitions");
772 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
773 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
774 error (g, "%s: failed to parse reply error", "guestfs_list_partitions");
779 if (!xdr_guestfs_list_partitions_ret (xdr, &ctx->ret)) {
780 error (g, "%s: failed to parse reply", "guestfs_list_partitions");
784 ctx->cb_sequence = 1000;
785 ml->main_loop_quit (ml, g);
788 char **guestfs_list_partitions (guestfs_h *g)
790 struct list_partitions_ctx ctx;
791 guestfs_main_loop *ml = guestfs_get_main_loop (g);
794 if (check_state (g, "guestfs_list_partitions") == -1) return NULL;
796 memset (&ctx, 0, sizeof ctx);
798 serial = guestfs__send (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
803 guestfs_set_send_callback (g, list_partitions_send_cb, &ctx);
804 (void) ml->main_loop_run (ml, g);
805 guestfs_set_send_callback (g, NULL, NULL);
806 if (ctx.cb_sequence != 1) {
807 error (g, "%s send failed, see earlier error messages", "guestfs_list_partitions");
812 guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx);
813 (void) ml->main_loop_run (ml, g);
814 guestfs_set_reply_callback (g, NULL, NULL);
815 if (ctx.cb_sequence != 1000) {
816 error (g, "%s reply failed, see earlier error messages", "guestfs_list_partitions");
820 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1)
823 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
824 error (g, "%s", ctx.err.error_message);
828 /* caller will free this, but we need to add a NULL entry */
829 ctx.ret.partitions.partitions_val =
830 safe_realloc (g, ctx.ret.partitions.partitions_val,
831 sizeof (char *) * (ctx.ret.partitions.partitions_len + 1));
832 ctx.ret.partitions.partitions_val[ctx.ret.partitions.partitions_len] = NULL;
833 return ctx.ret.partitions.partitions_val;
837 /* This flag is set by the callbacks, so we know we've done
838 * the callbacks as expected, and in the right sequence.
839 * 0 = not called, 1 = send called,
840 * 2.. = send_file called,
841 * 1000 = reply called.
844 struct guestfs_message_header hdr;
845 struct guestfs_message_error err;
846 struct guestfs_pvs_ret ret;
849 static void pvs_send_cb (guestfs_h *g, void *data)
851 guestfs_main_loop *ml = guestfs_get_main_loop (g);
852 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
854 guestfs__switch_to_receiving (g);
855 ctx->cb_sequence = 1;
856 ml->main_loop_quit (ml, g);
859 static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
861 guestfs_main_loop *ml = guestfs_get_main_loop (g);
862 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
864 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
865 error (g, "%s: failed to parse reply header", "guestfs_pvs");
868 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
869 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
870 error (g, "%s: failed to parse reply error", "guestfs_pvs");
875 if (!xdr_guestfs_pvs_ret (xdr, &ctx->ret)) {
876 error (g, "%s: failed to parse reply", "guestfs_pvs");
880 ctx->cb_sequence = 1000;
881 ml->main_loop_quit (ml, g);
884 char **guestfs_pvs (guestfs_h *g)
887 guestfs_main_loop *ml = guestfs_get_main_loop (g);
890 if (check_state (g, "guestfs_pvs") == -1) return NULL;
892 memset (&ctx, 0, sizeof ctx);
894 serial = guestfs__send (g, GUESTFS_PROC_PVS, NULL, NULL);
899 guestfs_set_send_callback (g, pvs_send_cb, &ctx);
900 (void) ml->main_loop_run (ml, g);
901 guestfs_set_send_callback (g, NULL, NULL);
902 if (ctx.cb_sequence != 1) {
903 error (g, "%s send failed, see earlier error messages", "guestfs_pvs");
908 guestfs_set_reply_callback (g, pvs_reply_cb, &ctx);
909 (void) ml->main_loop_run (ml, g);
910 guestfs_set_reply_callback (g, NULL, NULL);
911 if (ctx.cb_sequence != 1000) {
912 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs");
916 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS, serial) == -1)
919 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
920 error (g, "%s", ctx.err.error_message);
924 /* caller will free this, but we need to add a NULL entry */
925 ctx.ret.physvols.physvols_val =
926 safe_realloc (g, ctx.ret.physvols.physvols_val,
927 sizeof (char *) * (ctx.ret.physvols.physvols_len + 1));
928 ctx.ret.physvols.physvols_val[ctx.ret.physvols.physvols_len] = NULL;
929 return ctx.ret.physvols.physvols_val;
933 /* This flag is set by the callbacks, so we know we've done
934 * the callbacks as expected, and in the right sequence.
935 * 0 = not called, 1 = send called,
936 * 2.. = send_file called,
937 * 1000 = reply called.
940 struct guestfs_message_header hdr;
941 struct guestfs_message_error err;
942 struct guestfs_vgs_ret ret;
945 static void vgs_send_cb (guestfs_h *g, void *data)
947 guestfs_main_loop *ml = guestfs_get_main_loop (g);
948 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
950 guestfs__switch_to_receiving (g);
951 ctx->cb_sequence = 1;
952 ml->main_loop_quit (ml, g);
955 static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
957 guestfs_main_loop *ml = guestfs_get_main_loop (g);
958 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
960 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
961 error (g, "%s: failed to parse reply header", "guestfs_vgs");
964 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
965 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
966 error (g, "%s: failed to parse reply error", "guestfs_vgs");
971 if (!xdr_guestfs_vgs_ret (xdr, &ctx->ret)) {
972 error (g, "%s: failed to parse reply", "guestfs_vgs");
976 ctx->cb_sequence = 1000;
977 ml->main_loop_quit (ml, g);
980 char **guestfs_vgs (guestfs_h *g)
983 guestfs_main_loop *ml = guestfs_get_main_loop (g);
986 if (check_state (g, "guestfs_vgs") == -1) return NULL;
988 memset (&ctx, 0, sizeof ctx);
990 serial = guestfs__send (g, GUESTFS_PROC_VGS, NULL, NULL);
995 guestfs_set_send_callback (g, vgs_send_cb, &ctx);
996 (void) ml->main_loop_run (ml, g);
997 guestfs_set_send_callback (g, NULL, NULL);
998 if (ctx.cb_sequence != 1) {
999 error (g, "%s send failed, see earlier error messages", "guestfs_vgs");
1003 ctx.cb_sequence = 0;
1004 guestfs_set_reply_callback (g, vgs_reply_cb, &ctx);
1005 (void) ml->main_loop_run (ml, g);
1006 guestfs_set_reply_callback (g, NULL, NULL);
1007 if (ctx.cb_sequence != 1000) {
1008 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs");
1012 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS, serial) == -1)
1015 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1016 error (g, "%s", ctx.err.error_message);
1020 /* caller will free this, but we need to add a NULL entry */
1021 ctx.ret.volgroups.volgroups_val =
1022 safe_realloc (g, ctx.ret.volgroups.volgroups_val,
1023 sizeof (char *) * (ctx.ret.volgroups.volgroups_len + 1));
1024 ctx.ret.volgroups.volgroups_val[ctx.ret.volgroups.volgroups_len] = NULL;
1025 return ctx.ret.volgroups.volgroups_val;
1029 /* This flag is set by the callbacks, so we know we've done
1030 * the callbacks as expected, and in the right sequence.
1031 * 0 = not called, 1 = send called,
1032 * 2.. = send_file called,
1033 * 1000 = reply called.
1036 struct guestfs_message_header hdr;
1037 struct guestfs_message_error err;
1038 struct guestfs_lvs_ret ret;
1041 static void lvs_send_cb (guestfs_h *g, void *data)
1043 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1044 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
1046 guestfs__switch_to_receiving (g);
1047 ctx->cb_sequence = 1;
1048 ml->main_loop_quit (ml, g);
1051 static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1053 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1054 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
1056 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1057 error (g, "%s: failed to parse reply header", "guestfs_lvs");
1060 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1061 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1062 error (g, "%s: failed to parse reply error", "guestfs_lvs");
1067 if (!xdr_guestfs_lvs_ret (xdr, &ctx->ret)) {
1068 error (g, "%s: failed to parse reply", "guestfs_lvs");
1072 ctx->cb_sequence = 1000;
1073 ml->main_loop_quit (ml, g);
1076 char **guestfs_lvs (guestfs_h *g)
1079 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1082 if (check_state (g, "guestfs_lvs") == -1) return NULL;
1084 memset (&ctx, 0, sizeof ctx);
1086 serial = guestfs__send (g, GUESTFS_PROC_LVS, NULL, NULL);
1090 ctx.cb_sequence = 0;
1091 guestfs_set_send_callback (g, lvs_send_cb, &ctx);
1092 (void) ml->main_loop_run (ml, g);
1093 guestfs_set_send_callback (g, NULL, NULL);
1094 if (ctx.cb_sequence != 1) {
1095 error (g, "%s send failed, see earlier error messages", "guestfs_lvs");
1099 ctx.cb_sequence = 0;
1100 guestfs_set_reply_callback (g, lvs_reply_cb, &ctx);
1101 (void) ml->main_loop_run (ml, g);
1102 guestfs_set_reply_callback (g, NULL, NULL);
1103 if (ctx.cb_sequence != 1000) {
1104 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs");
1108 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS, serial) == -1)
1111 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1112 error (g, "%s", ctx.err.error_message);
1116 /* caller will free this, but we need to add a NULL entry */
1117 ctx.ret.logvols.logvols_val =
1118 safe_realloc (g, ctx.ret.logvols.logvols_val,
1119 sizeof (char *) * (ctx.ret.logvols.logvols_len + 1));
1120 ctx.ret.logvols.logvols_val[ctx.ret.logvols.logvols_len] = NULL;
1121 return ctx.ret.logvols.logvols_val;
1124 struct pvs_full_ctx {
1125 /* This flag is set by the callbacks, so we know we've done
1126 * the callbacks as expected, and in the right sequence.
1127 * 0 = not called, 1 = send called,
1128 * 2.. = send_file called,
1129 * 1000 = reply called.
1132 struct guestfs_message_header hdr;
1133 struct guestfs_message_error err;
1134 struct guestfs_pvs_full_ret ret;
1137 static void pvs_full_send_cb (guestfs_h *g, void *data)
1139 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1140 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
1142 guestfs__switch_to_receiving (g);
1143 ctx->cb_sequence = 1;
1144 ml->main_loop_quit (ml, g);
1147 static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1149 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1150 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
1152 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1153 error (g, "%s: failed to parse reply header", "guestfs_pvs_full");
1156 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1157 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1158 error (g, "%s: failed to parse reply error", "guestfs_pvs_full");
1163 if (!xdr_guestfs_pvs_full_ret (xdr, &ctx->ret)) {
1164 error (g, "%s: failed to parse reply", "guestfs_pvs_full");
1168 ctx->cb_sequence = 1000;
1169 ml->main_loop_quit (ml, g);
1172 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
1174 struct pvs_full_ctx ctx;
1175 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1178 if (check_state (g, "guestfs_pvs_full") == -1) return NULL;
1180 memset (&ctx, 0, sizeof ctx);
1182 serial = guestfs__send (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
1186 ctx.cb_sequence = 0;
1187 guestfs_set_send_callback (g, pvs_full_send_cb, &ctx);
1188 (void) ml->main_loop_run (ml, g);
1189 guestfs_set_send_callback (g, NULL, NULL);
1190 if (ctx.cb_sequence != 1) {
1191 error (g, "%s send failed, see earlier error messages", "guestfs_pvs_full");
1195 ctx.cb_sequence = 0;
1196 guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx);
1197 (void) ml->main_loop_run (ml, g);
1198 guestfs_set_reply_callback (g, NULL, NULL);
1199 if (ctx.cb_sequence != 1000) {
1200 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs_full");
1204 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1)
1207 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1208 error (g, "%s", ctx.err.error_message);
1212 /* caller will free this */
1213 return safe_memdup (g, &ctx.ret.physvols, sizeof (ctx.ret.physvols));
1216 struct vgs_full_ctx {
1217 /* This flag is set by the callbacks, so we know we've done
1218 * the callbacks as expected, and in the right sequence.
1219 * 0 = not called, 1 = send called,
1220 * 2.. = send_file called,
1221 * 1000 = reply called.
1224 struct guestfs_message_header hdr;
1225 struct guestfs_message_error err;
1226 struct guestfs_vgs_full_ret ret;
1229 static void vgs_full_send_cb (guestfs_h *g, void *data)
1231 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1232 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1234 guestfs__switch_to_receiving (g);
1235 ctx->cb_sequence = 1;
1236 ml->main_loop_quit (ml, g);
1239 static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1241 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1242 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1244 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1245 error (g, "%s: failed to parse reply header", "guestfs_vgs_full");
1248 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1249 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1250 error (g, "%s: failed to parse reply error", "guestfs_vgs_full");
1255 if (!xdr_guestfs_vgs_full_ret (xdr, &ctx->ret)) {
1256 error (g, "%s: failed to parse reply", "guestfs_vgs_full");
1260 ctx->cb_sequence = 1000;
1261 ml->main_loop_quit (ml, g);
1264 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
1266 struct vgs_full_ctx ctx;
1267 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1270 if (check_state (g, "guestfs_vgs_full") == -1) return NULL;
1272 memset (&ctx, 0, sizeof ctx);
1274 serial = guestfs__send (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
1278 ctx.cb_sequence = 0;
1279 guestfs_set_send_callback (g, vgs_full_send_cb, &ctx);
1280 (void) ml->main_loop_run (ml, g);
1281 guestfs_set_send_callback (g, NULL, NULL);
1282 if (ctx.cb_sequence != 1) {
1283 error (g, "%s send failed, see earlier error messages", "guestfs_vgs_full");
1287 ctx.cb_sequence = 0;
1288 guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx);
1289 (void) ml->main_loop_run (ml, g);
1290 guestfs_set_reply_callback (g, NULL, NULL);
1291 if (ctx.cb_sequence != 1000) {
1292 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs_full");
1296 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1)
1299 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1300 error (g, "%s", ctx.err.error_message);
1304 /* caller will free this */
1305 return safe_memdup (g, &ctx.ret.volgroups, sizeof (ctx.ret.volgroups));
1308 struct lvs_full_ctx {
1309 /* This flag is set by the callbacks, so we know we've done
1310 * the callbacks as expected, and in the right sequence.
1311 * 0 = not called, 1 = send called,
1312 * 2.. = send_file called,
1313 * 1000 = reply called.
1316 struct guestfs_message_header hdr;
1317 struct guestfs_message_error err;
1318 struct guestfs_lvs_full_ret ret;
1321 static void lvs_full_send_cb (guestfs_h *g, void *data)
1323 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1324 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1326 guestfs__switch_to_receiving (g);
1327 ctx->cb_sequence = 1;
1328 ml->main_loop_quit (ml, g);
1331 static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1333 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1334 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1336 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1337 error (g, "%s: failed to parse reply header", "guestfs_lvs_full");
1340 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1341 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1342 error (g, "%s: failed to parse reply error", "guestfs_lvs_full");
1347 if (!xdr_guestfs_lvs_full_ret (xdr, &ctx->ret)) {
1348 error (g, "%s: failed to parse reply", "guestfs_lvs_full");
1352 ctx->cb_sequence = 1000;
1353 ml->main_loop_quit (ml, g);
1356 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
1358 struct lvs_full_ctx ctx;
1359 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1362 if (check_state (g, "guestfs_lvs_full") == -1) return NULL;
1364 memset (&ctx, 0, sizeof ctx);
1366 serial = guestfs__send (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
1370 ctx.cb_sequence = 0;
1371 guestfs_set_send_callback (g, lvs_full_send_cb, &ctx);
1372 (void) ml->main_loop_run (ml, g);
1373 guestfs_set_send_callback (g, NULL, NULL);
1374 if (ctx.cb_sequence != 1) {
1375 error (g, "%s send failed, see earlier error messages", "guestfs_lvs_full");
1379 ctx.cb_sequence = 0;
1380 guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx);
1381 (void) ml->main_loop_run (ml, g);
1382 guestfs_set_reply_callback (g, NULL, NULL);
1383 if (ctx.cb_sequence != 1000) {
1384 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs_full");
1388 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1)
1391 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1392 error (g, "%s", ctx.err.error_message);
1396 /* caller will free this */
1397 return safe_memdup (g, &ctx.ret.logvols, sizeof (ctx.ret.logvols));
1400 struct read_lines_ctx {
1401 /* This flag is set by the callbacks, so we know we've done
1402 * the callbacks as expected, and in the right sequence.
1403 * 0 = not called, 1 = send called,
1404 * 2.. = send_file called,
1405 * 1000 = reply called.
1408 struct guestfs_message_header hdr;
1409 struct guestfs_message_error err;
1410 struct guestfs_read_lines_ret ret;
1413 static void read_lines_send_cb (guestfs_h *g, void *data)
1415 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1416 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1418 guestfs__switch_to_receiving (g);
1419 ctx->cb_sequence = 1;
1420 ml->main_loop_quit (ml, g);
1423 static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1425 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1426 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1428 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1429 error (g, "%s: failed to parse reply header", "guestfs_read_lines");
1432 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1433 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1434 error (g, "%s: failed to parse reply error", "guestfs_read_lines");
1439 if (!xdr_guestfs_read_lines_ret (xdr, &ctx->ret)) {
1440 error (g, "%s: failed to parse reply", "guestfs_read_lines");
1444 ctx->cb_sequence = 1000;
1445 ml->main_loop_quit (ml, g);
1448 char **guestfs_read_lines (guestfs_h *g,
1451 struct guestfs_read_lines_args args;
1452 struct read_lines_ctx ctx;
1453 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1456 if (check_state (g, "guestfs_read_lines") == -1) return NULL;
1458 memset (&ctx, 0, sizeof ctx);
1460 args.path = (char *) path;
1461 serial = guestfs__send (g, GUESTFS_PROC_READ_LINES,
1462 (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
1466 ctx.cb_sequence = 0;
1467 guestfs_set_send_callback (g, read_lines_send_cb, &ctx);
1468 (void) ml->main_loop_run (ml, g);
1469 guestfs_set_send_callback (g, NULL, NULL);
1470 if (ctx.cb_sequence != 1) {
1471 error (g, "%s send failed, see earlier error messages", "guestfs_read_lines");
1475 ctx.cb_sequence = 0;
1476 guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx);
1477 (void) ml->main_loop_run (ml, g);
1478 guestfs_set_reply_callback (g, NULL, NULL);
1479 if (ctx.cb_sequence != 1000) {
1480 error (g, "%s reply failed, see earlier error messages", "guestfs_read_lines");
1484 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_READ_LINES, serial) == -1)
1487 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1488 error (g, "%s", ctx.err.error_message);
1492 /* caller will free this, but we need to add a NULL entry */
1493 ctx.ret.lines.lines_val =
1494 safe_realloc (g, ctx.ret.lines.lines_val,
1495 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
1496 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
1497 return ctx.ret.lines.lines_val;
1500 struct aug_init_ctx {
1501 /* This flag is set by the callbacks, so we know we've done
1502 * the callbacks as expected, and in the right sequence.
1503 * 0 = not called, 1 = send called,
1504 * 2.. = send_file called,
1505 * 1000 = reply called.
1508 struct guestfs_message_header hdr;
1509 struct guestfs_message_error err;
1512 static void aug_init_send_cb (guestfs_h *g, void *data)
1514 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1515 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1517 guestfs__switch_to_receiving (g);
1518 ctx->cb_sequence = 1;
1519 ml->main_loop_quit (ml, g);
1522 static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1524 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1525 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1527 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1528 error (g, "%s: failed to parse reply header", "guestfs_aug_init");
1531 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1532 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1533 error (g, "%s: failed to parse reply error", "guestfs_aug_init");
1539 ctx->cb_sequence = 1000;
1540 ml->main_loop_quit (ml, g);
1543 int guestfs_aug_init (guestfs_h *g,
1547 struct guestfs_aug_init_args args;
1548 struct aug_init_ctx ctx;
1549 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1552 if (check_state (g, "guestfs_aug_init") == -1) return -1;
1554 memset (&ctx, 0, sizeof ctx);
1556 args.root = (char *) root;
1558 serial = guestfs__send (g, GUESTFS_PROC_AUG_INIT,
1559 (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
1563 ctx.cb_sequence = 0;
1564 guestfs_set_send_callback (g, aug_init_send_cb, &ctx);
1565 (void) ml->main_loop_run (ml, g);
1566 guestfs_set_send_callback (g, NULL, NULL);
1567 if (ctx.cb_sequence != 1) {
1568 error (g, "%s send failed, see earlier error messages", "guestfs_aug_init");
1572 ctx.cb_sequence = 0;
1573 guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx);
1574 (void) ml->main_loop_run (ml, g);
1575 guestfs_set_reply_callback (g, NULL, NULL);
1576 if (ctx.cb_sequence != 1000) {
1577 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_init");
1581 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1)
1584 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1585 error (g, "%s", ctx.err.error_message);
1592 struct aug_close_ctx {
1593 /* This flag is set by the callbacks, so we know we've done
1594 * the callbacks as expected, and in the right sequence.
1595 * 0 = not called, 1 = send called,
1596 * 2.. = send_file called,
1597 * 1000 = reply called.
1600 struct guestfs_message_header hdr;
1601 struct guestfs_message_error err;
1604 static void aug_close_send_cb (guestfs_h *g, void *data)
1606 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1607 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1609 guestfs__switch_to_receiving (g);
1610 ctx->cb_sequence = 1;
1611 ml->main_loop_quit (ml, g);
1614 static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1616 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1617 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1619 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1620 error (g, "%s: failed to parse reply header", "guestfs_aug_close");
1623 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1624 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1625 error (g, "%s: failed to parse reply error", "guestfs_aug_close");
1631 ctx->cb_sequence = 1000;
1632 ml->main_loop_quit (ml, g);
1635 int guestfs_aug_close (guestfs_h *g)
1637 struct aug_close_ctx ctx;
1638 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1641 if (check_state (g, "guestfs_aug_close") == -1) return -1;
1643 memset (&ctx, 0, sizeof ctx);
1645 serial = guestfs__send (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
1649 ctx.cb_sequence = 0;
1650 guestfs_set_send_callback (g, aug_close_send_cb, &ctx);
1651 (void) ml->main_loop_run (ml, g);
1652 guestfs_set_send_callback (g, NULL, NULL);
1653 if (ctx.cb_sequence != 1) {
1654 error (g, "%s send failed, see earlier error messages", "guestfs_aug_close");
1658 ctx.cb_sequence = 0;
1659 guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx);
1660 (void) ml->main_loop_run (ml, g);
1661 guestfs_set_reply_callback (g, NULL, NULL);
1662 if (ctx.cb_sequence != 1000) {
1663 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_close");
1667 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1)
1670 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1671 error (g, "%s", ctx.err.error_message);
1678 struct aug_defvar_ctx {
1679 /* This flag is set by the callbacks, so we know we've done
1680 * the callbacks as expected, and in the right sequence.
1681 * 0 = not called, 1 = send called,
1682 * 2.. = send_file called,
1683 * 1000 = reply called.
1686 struct guestfs_message_header hdr;
1687 struct guestfs_message_error err;
1688 struct guestfs_aug_defvar_ret ret;
1691 static void aug_defvar_send_cb (guestfs_h *g, void *data)
1693 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1694 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1696 guestfs__switch_to_receiving (g);
1697 ctx->cb_sequence = 1;
1698 ml->main_loop_quit (ml, g);
1701 static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1703 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1704 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1706 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1707 error (g, "%s: failed to parse reply header", "guestfs_aug_defvar");
1710 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1711 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1712 error (g, "%s: failed to parse reply error", "guestfs_aug_defvar");
1717 if (!xdr_guestfs_aug_defvar_ret (xdr, &ctx->ret)) {
1718 error (g, "%s: failed to parse reply", "guestfs_aug_defvar");
1722 ctx->cb_sequence = 1000;
1723 ml->main_loop_quit (ml, g);
1726 int guestfs_aug_defvar (guestfs_h *g,
1730 struct guestfs_aug_defvar_args args;
1731 struct aug_defvar_ctx ctx;
1732 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1735 if (check_state (g, "guestfs_aug_defvar") == -1) return -1;
1737 memset (&ctx, 0, sizeof ctx);
1739 args.name = (char *) name;
1740 args.expr = expr ? (char **) &expr : NULL;
1741 serial = guestfs__send (g, GUESTFS_PROC_AUG_DEFVAR,
1742 (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
1746 ctx.cb_sequence = 0;
1747 guestfs_set_send_callback (g, aug_defvar_send_cb, &ctx);
1748 (void) ml->main_loop_run (ml, g);
1749 guestfs_set_send_callback (g, NULL, NULL);
1750 if (ctx.cb_sequence != 1) {
1751 error (g, "%s send failed, see earlier error messages", "guestfs_aug_defvar");
1755 ctx.cb_sequence = 0;
1756 guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx);
1757 (void) ml->main_loop_run (ml, g);
1758 guestfs_set_reply_callback (g, NULL, NULL);
1759 if (ctx.cb_sequence != 1000) {
1760 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defvar");
1764 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1)
1767 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1768 error (g, "%s", ctx.err.error_message);
1772 return ctx.ret.nrnodes;
1775 struct aug_defnode_ctx {
1776 /* This flag is set by the callbacks, so we know we've done
1777 * the callbacks as expected, and in the right sequence.
1778 * 0 = not called, 1 = send called,
1779 * 2.. = send_file called,
1780 * 1000 = reply called.
1783 struct guestfs_message_header hdr;
1784 struct guestfs_message_error err;
1785 struct guestfs_aug_defnode_ret ret;
1788 static void aug_defnode_send_cb (guestfs_h *g, void *data)
1790 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1791 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1793 guestfs__switch_to_receiving (g);
1794 ctx->cb_sequence = 1;
1795 ml->main_loop_quit (ml, g);
1798 static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1800 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1801 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1803 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1804 error (g, "%s: failed to parse reply header", "guestfs_aug_defnode");
1807 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1808 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1809 error (g, "%s: failed to parse reply error", "guestfs_aug_defnode");
1814 if (!xdr_guestfs_aug_defnode_ret (xdr, &ctx->ret)) {
1815 error (g, "%s: failed to parse reply", "guestfs_aug_defnode");
1819 ctx->cb_sequence = 1000;
1820 ml->main_loop_quit (ml, g);
1823 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
1828 struct guestfs_aug_defnode_args args;
1829 struct aug_defnode_ctx ctx;
1830 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1833 if (check_state (g, "guestfs_aug_defnode") == -1) return NULL;
1835 memset (&ctx, 0, sizeof ctx);
1837 args.name = (char *) name;
1838 args.expr = (char *) expr;
1839 args.val = (char *) val;
1840 serial = guestfs__send (g, GUESTFS_PROC_AUG_DEFNODE,
1841 (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
1845 ctx.cb_sequence = 0;
1846 guestfs_set_send_callback (g, aug_defnode_send_cb, &ctx);
1847 (void) ml->main_loop_run (ml, g);
1848 guestfs_set_send_callback (g, NULL, NULL);
1849 if (ctx.cb_sequence != 1) {
1850 error (g, "%s send failed, see earlier error messages", "guestfs_aug_defnode");
1854 ctx.cb_sequence = 0;
1855 guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx);
1856 (void) ml->main_loop_run (ml, g);
1857 guestfs_set_reply_callback (g, NULL, NULL);
1858 if (ctx.cb_sequence != 1000) {
1859 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defnode");
1863 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1)
1866 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1867 error (g, "%s", ctx.err.error_message);
1871 /* caller with free this */
1872 return safe_memdup (g, &ctx.ret, sizeof (ctx.ret));
1875 struct aug_get_ctx {
1876 /* This flag is set by the callbacks, so we know we've done
1877 * the callbacks as expected, and in the right sequence.
1878 * 0 = not called, 1 = send called,
1879 * 2.. = send_file called,
1880 * 1000 = reply called.
1883 struct guestfs_message_header hdr;
1884 struct guestfs_message_error err;
1885 struct guestfs_aug_get_ret ret;
1888 static void aug_get_send_cb (guestfs_h *g, void *data)
1890 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1891 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1893 guestfs__switch_to_receiving (g);
1894 ctx->cb_sequence = 1;
1895 ml->main_loop_quit (ml, g);
1898 static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1900 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1901 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1903 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1904 error (g, "%s: failed to parse reply header", "guestfs_aug_get");
1907 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1908 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1909 error (g, "%s: failed to parse reply error", "guestfs_aug_get");
1914 if (!xdr_guestfs_aug_get_ret (xdr, &ctx->ret)) {
1915 error (g, "%s: failed to parse reply", "guestfs_aug_get");
1919 ctx->cb_sequence = 1000;
1920 ml->main_loop_quit (ml, g);
1923 char *guestfs_aug_get (guestfs_h *g,
1926 struct guestfs_aug_get_args args;
1927 struct aug_get_ctx ctx;
1928 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1931 if (check_state (g, "guestfs_aug_get") == -1) return NULL;
1933 memset (&ctx, 0, sizeof ctx);
1935 args.path = (char *) path;
1936 serial = guestfs__send (g, GUESTFS_PROC_AUG_GET,
1937 (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
1941 ctx.cb_sequence = 0;
1942 guestfs_set_send_callback (g, aug_get_send_cb, &ctx);
1943 (void) ml->main_loop_run (ml, g);
1944 guestfs_set_send_callback (g, NULL, NULL);
1945 if (ctx.cb_sequence != 1) {
1946 error (g, "%s send failed, see earlier error messages", "guestfs_aug_get");
1950 ctx.cb_sequence = 0;
1951 guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx);
1952 (void) ml->main_loop_run (ml, g);
1953 guestfs_set_reply_callback (g, NULL, NULL);
1954 if (ctx.cb_sequence != 1000) {
1955 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_get");
1959 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_GET, serial) == -1)
1962 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1963 error (g, "%s", ctx.err.error_message);
1967 return ctx.ret.val; /* caller will free */
1970 struct aug_set_ctx {
1971 /* This flag is set by the callbacks, so we know we've done
1972 * the callbacks as expected, and in the right sequence.
1973 * 0 = not called, 1 = send called,
1974 * 2.. = send_file called,
1975 * 1000 = reply called.
1978 struct guestfs_message_header hdr;
1979 struct guestfs_message_error err;
1982 static void aug_set_send_cb (guestfs_h *g, void *data)
1984 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1985 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1987 guestfs__switch_to_receiving (g);
1988 ctx->cb_sequence = 1;
1989 ml->main_loop_quit (ml, g);
1992 static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1994 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1995 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1997 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1998 error (g, "%s: failed to parse reply header", "guestfs_aug_set");
2001 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2002 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2003 error (g, "%s: failed to parse reply error", "guestfs_aug_set");
2009 ctx->cb_sequence = 1000;
2010 ml->main_loop_quit (ml, g);
2013 int guestfs_aug_set (guestfs_h *g,
2017 struct guestfs_aug_set_args args;
2018 struct aug_set_ctx ctx;
2019 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2022 if (check_state (g, "guestfs_aug_set") == -1) return -1;
2024 memset (&ctx, 0, sizeof ctx);
2026 args.path = (char *) path;
2027 args.val = (char *) val;
2028 serial = guestfs__send (g, GUESTFS_PROC_AUG_SET,
2029 (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
2033 ctx.cb_sequence = 0;
2034 guestfs_set_send_callback (g, aug_set_send_cb, &ctx);
2035 (void) ml->main_loop_run (ml, g);
2036 guestfs_set_send_callback (g, NULL, NULL);
2037 if (ctx.cb_sequence != 1) {
2038 error (g, "%s send failed, see earlier error messages", "guestfs_aug_set");
2042 ctx.cb_sequence = 0;
2043 guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx);
2044 (void) ml->main_loop_run (ml, g);
2045 guestfs_set_reply_callback (g, NULL, NULL);
2046 if (ctx.cb_sequence != 1000) {
2047 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_set");
2051 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SET, serial) == -1)
2054 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2055 error (g, "%s", ctx.err.error_message);
2062 struct aug_insert_ctx {
2063 /* This flag is set by the callbacks, so we know we've done
2064 * the callbacks as expected, and in the right sequence.
2065 * 0 = not called, 1 = send called,
2066 * 2.. = send_file called,
2067 * 1000 = reply called.
2070 struct guestfs_message_header hdr;
2071 struct guestfs_message_error err;
2074 static void aug_insert_send_cb (guestfs_h *g, void *data)
2076 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2077 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
2079 guestfs__switch_to_receiving (g);
2080 ctx->cb_sequence = 1;
2081 ml->main_loop_quit (ml, g);
2084 static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2086 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2087 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
2089 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2090 error (g, "%s: failed to parse reply header", "guestfs_aug_insert");
2093 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2094 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2095 error (g, "%s: failed to parse reply error", "guestfs_aug_insert");
2101 ctx->cb_sequence = 1000;
2102 ml->main_loop_quit (ml, g);
2105 int guestfs_aug_insert (guestfs_h *g,
2110 struct guestfs_aug_insert_args args;
2111 struct aug_insert_ctx ctx;
2112 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2115 if (check_state (g, "guestfs_aug_insert") == -1) return -1;
2117 memset (&ctx, 0, sizeof ctx);
2119 args.path = (char *) path;
2120 args.label = (char *) label;
2121 args.before = before;
2122 serial = guestfs__send (g, GUESTFS_PROC_AUG_INSERT,
2123 (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
2127 ctx.cb_sequence = 0;
2128 guestfs_set_send_callback (g, aug_insert_send_cb, &ctx);
2129 (void) ml->main_loop_run (ml, g);
2130 guestfs_set_send_callback (g, NULL, NULL);
2131 if (ctx.cb_sequence != 1) {
2132 error (g, "%s send failed, see earlier error messages", "guestfs_aug_insert");
2136 ctx.cb_sequence = 0;
2137 guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx);
2138 (void) ml->main_loop_run (ml, g);
2139 guestfs_set_reply_callback (g, NULL, NULL);
2140 if (ctx.cb_sequence != 1000) {
2141 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_insert");
2145 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1)
2148 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2149 error (g, "%s", ctx.err.error_message);
2157 /* This flag is set by the callbacks, so we know we've done
2158 * the callbacks as expected, and in the right sequence.
2159 * 0 = not called, 1 = send called,
2160 * 2.. = send_file called,
2161 * 1000 = reply called.
2164 struct guestfs_message_header hdr;
2165 struct guestfs_message_error err;
2166 struct guestfs_aug_rm_ret ret;
2169 static void aug_rm_send_cb (guestfs_h *g, void *data)
2171 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2172 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
2174 guestfs__switch_to_receiving (g);
2175 ctx->cb_sequence = 1;
2176 ml->main_loop_quit (ml, g);
2179 static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2181 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2182 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
2184 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2185 error (g, "%s: failed to parse reply header", "guestfs_aug_rm");
2188 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2189 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2190 error (g, "%s: failed to parse reply error", "guestfs_aug_rm");
2195 if (!xdr_guestfs_aug_rm_ret (xdr, &ctx->ret)) {
2196 error (g, "%s: failed to parse reply", "guestfs_aug_rm");
2200 ctx->cb_sequence = 1000;
2201 ml->main_loop_quit (ml, g);
2204 int guestfs_aug_rm (guestfs_h *g,
2207 struct guestfs_aug_rm_args args;
2208 struct aug_rm_ctx ctx;
2209 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2212 if (check_state (g, "guestfs_aug_rm") == -1) return -1;
2214 memset (&ctx, 0, sizeof ctx);
2216 args.path = (char *) path;
2217 serial = guestfs__send (g, GUESTFS_PROC_AUG_RM,
2218 (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
2222 ctx.cb_sequence = 0;
2223 guestfs_set_send_callback (g, aug_rm_send_cb, &ctx);
2224 (void) ml->main_loop_run (ml, g);
2225 guestfs_set_send_callback (g, NULL, NULL);
2226 if (ctx.cb_sequence != 1) {
2227 error (g, "%s send failed, see earlier error messages", "guestfs_aug_rm");
2231 ctx.cb_sequence = 0;
2232 guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx);
2233 (void) ml->main_loop_run (ml, g);
2234 guestfs_set_reply_callback (g, NULL, NULL);
2235 if (ctx.cb_sequence != 1000) {
2236 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_rm");
2240 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_RM, serial) == -1)
2243 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2244 error (g, "%s", ctx.err.error_message);
2248 return ctx.ret.nrnodes;
2252 /* This flag is set by the callbacks, so we know we've done
2253 * the callbacks as expected, and in the right sequence.
2254 * 0 = not called, 1 = send called,
2255 * 2.. = send_file called,
2256 * 1000 = reply called.
2259 struct guestfs_message_header hdr;
2260 struct guestfs_message_error err;
2263 static void aug_mv_send_cb (guestfs_h *g, void *data)
2265 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2266 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
2268 guestfs__switch_to_receiving (g);
2269 ctx->cb_sequence = 1;
2270 ml->main_loop_quit (ml, g);
2273 static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2275 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2276 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
2278 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2279 error (g, "%s: failed to parse reply header", "guestfs_aug_mv");
2282 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2283 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2284 error (g, "%s: failed to parse reply error", "guestfs_aug_mv");
2290 ctx->cb_sequence = 1000;
2291 ml->main_loop_quit (ml, g);
2294 int guestfs_aug_mv (guestfs_h *g,
2298 struct guestfs_aug_mv_args args;
2299 struct aug_mv_ctx ctx;
2300 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2303 if (check_state (g, "guestfs_aug_mv") == -1) return -1;
2305 memset (&ctx, 0, sizeof ctx);
2307 args.src = (char *) src;
2308 args.dest = (char *) dest;
2309 serial = guestfs__send (g, GUESTFS_PROC_AUG_MV,
2310 (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
2314 ctx.cb_sequence = 0;
2315 guestfs_set_send_callback (g, aug_mv_send_cb, &ctx);
2316 (void) ml->main_loop_run (ml, g);
2317 guestfs_set_send_callback (g, NULL, NULL);
2318 if (ctx.cb_sequence != 1) {
2319 error (g, "%s send failed, see earlier error messages", "guestfs_aug_mv");
2323 ctx.cb_sequence = 0;
2324 guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx);
2325 (void) ml->main_loop_run (ml, g);
2326 guestfs_set_reply_callback (g, NULL, NULL);
2327 if (ctx.cb_sequence != 1000) {
2328 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_mv");
2332 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MV, serial) == -1)
2335 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2336 error (g, "%s", ctx.err.error_message);
2343 struct aug_match_ctx {
2344 /* This flag is set by the callbacks, so we know we've done
2345 * the callbacks as expected, and in the right sequence.
2346 * 0 = not called, 1 = send called,
2347 * 2.. = send_file called,
2348 * 1000 = reply called.
2351 struct guestfs_message_header hdr;
2352 struct guestfs_message_error err;
2353 struct guestfs_aug_match_ret ret;
2356 static void aug_match_send_cb (guestfs_h *g, void *data)
2358 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2359 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
2361 guestfs__switch_to_receiving (g);
2362 ctx->cb_sequence = 1;
2363 ml->main_loop_quit (ml, g);
2366 static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2368 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2369 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
2371 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2372 error (g, "%s: failed to parse reply header", "guestfs_aug_match");
2375 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2376 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2377 error (g, "%s: failed to parse reply error", "guestfs_aug_match");
2382 if (!xdr_guestfs_aug_match_ret (xdr, &ctx->ret)) {
2383 error (g, "%s: failed to parse reply", "guestfs_aug_match");
2387 ctx->cb_sequence = 1000;
2388 ml->main_loop_quit (ml, g);
2391 char **guestfs_aug_match (guestfs_h *g,
2394 struct guestfs_aug_match_args args;
2395 struct aug_match_ctx ctx;
2396 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2399 if (check_state (g, "guestfs_aug_match") == -1) return NULL;
2401 memset (&ctx, 0, sizeof ctx);
2403 args.path = (char *) path;
2404 serial = guestfs__send (g, GUESTFS_PROC_AUG_MATCH,
2405 (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
2409 ctx.cb_sequence = 0;
2410 guestfs_set_send_callback (g, aug_match_send_cb, &ctx);
2411 (void) ml->main_loop_run (ml, g);
2412 guestfs_set_send_callback (g, NULL, NULL);
2413 if (ctx.cb_sequence != 1) {
2414 error (g, "%s send failed, see earlier error messages", "guestfs_aug_match");
2418 ctx.cb_sequence = 0;
2419 guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx);
2420 (void) ml->main_loop_run (ml, g);
2421 guestfs_set_reply_callback (g, NULL, NULL);
2422 if (ctx.cb_sequence != 1000) {
2423 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_match");
2427 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1)
2430 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2431 error (g, "%s", ctx.err.error_message);
2435 /* caller will free this, but we need to add a NULL entry */
2436 ctx.ret.matches.matches_val =
2437 safe_realloc (g, ctx.ret.matches.matches_val,
2438 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2439 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2440 return ctx.ret.matches.matches_val;
2443 struct aug_save_ctx {
2444 /* This flag is set by the callbacks, so we know we've done
2445 * the callbacks as expected, and in the right sequence.
2446 * 0 = not called, 1 = send called,
2447 * 2.. = send_file called,
2448 * 1000 = reply called.
2451 struct guestfs_message_header hdr;
2452 struct guestfs_message_error err;
2455 static void aug_save_send_cb (guestfs_h *g, void *data)
2457 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2458 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2460 guestfs__switch_to_receiving (g);
2461 ctx->cb_sequence = 1;
2462 ml->main_loop_quit (ml, g);
2465 static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2467 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2468 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2470 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2471 error (g, "%s: failed to parse reply header", "guestfs_aug_save");
2474 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2475 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2476 error (g, "%s: failed to parse reply error", "guestfs_aug_save");
2482 ctx->cb_sequence = 1000;
2483 ml->main_loop_quit (ml, g);
2486 int guestfs_aug_save (guestfs_h *g)
2488 struct aug_save_ctx ctx;
2489 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2492 if (check_state (g, "guestfs_aug_save") == -1) return -1;
2494 memset (&ctx, 0, sizeof ctx);
2496 serial = guestfs__send (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
2500 ctx.cb_sequence = 0;
2501 guestfs_set_send_callback (g, aug_save_send_cb, &ctx);
2502 (void) ml->main_loop_run (ml, g);
2503 guestfs_set_send_callback (g, NULL, NULL);
2504 if (ctx.cb_sequence != 1) {
2505 error (g, "%s send failed, see earlier error messages", "guestfs_aug_save");
2509 ctx.cb_sequence = 0;
2510 guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx);
2511 (void) ml->main_loop_run (ml, g);
2512 guestfs_set_reply_callback (g, NULL, NULL);
2513 if (ctx.cb_sequence != 1000) {
2514 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_save");
2518 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1)
2521 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2522 error (g, "%s", ctx.err.error_message);
2529 struct aug_load_ctx {
2530 /* This flag is set by the callbacks, so we know we've done
2531 * the callbacks as expected, and in the right sequence.
2532 * 0 = not called, 1 = send called,
2533 * 2.. = send_file called,
2534 * 1000 = reply called.
2537 struct guestfs_message_header hdr;
2538 struct guestfs_message_error err;
2541 static void aug_load_send_cb (guestfs_h *g, void *data)
2543 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2544 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2546 guestfs__switch_to_receiving (g);
2547 ctx->cb_sequence = 1;
2548 ml->main_loop_quit (ml, g);
2551 static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2553 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2554 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2556 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2557 error (g, "%s: failed to parse reply header", "guestfs_aug_load");
2560 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2561 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2562 error (g, "%s: failed to parse reply error", "guestfs_aug_load");
2568 ctx->cb_sequence = 1000;
2569 ml->main_loop_quit (ml, g);
2572 int guestfs_aug_load (guestfs_h *g)
2574 struct aug_load_ctx ctx;
2575 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2578 if (check_state (g, "guestfs_aug_load") == -1) return -1;
2580 memset (&ctx, 0, sizeof ctx);
2582 serial = guestfs__send (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
2586 ctx.cb_sequence = 0;
2587 guestfs_set_send_callback (g, aug_load_send_cb, &ctx);
2588 (void) ml->main_loop_run (ml, g);
2589 guestfs_set_send_callback (g, NULL, NULL);
2590 if (ctx.cb_sequence != 1) {
2591 error (g, "%s send failed, see earlier error messages", "guestfs_aug_load");
2595 ctx.cb_sequence = 0;
2596 guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx);
2597 (void) ml->main_loop_run (ml, g);
2598 guestfs_set_reply_callback (g, NULL, NULL);
2599 if (ctx.cb_sequence != 1000) {
2600 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_load");
2604 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1)
2607 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2608 error (g, "%s", ctx.err.error_message);
2616 /* This flag is set by the callbacks, so we know we've done
2617 * the callbacks as expected, and in the right sequence.
2618 * 0 = not called, 1 = send called,
2619 * 2.. = send_file called,
2620 * 1000 = reply called.
2623 struct guestfs_message_header hdr;
2624 struct guestfs_message_error err;
2625 struct guestfs_aug_ls_ret ret;
2628 static void aug_ls_send_cb (guestfs_h *g, void *data)
2630 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2631 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2633 guestfs__switch_to_receiving (g);
2634 ctx->cb_sequence = 1;
2635 ml->main_loop_quit (ml, g);
2638 static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2640 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2641 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2643 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2644 error (g, "%s: failed to parse reply header", "guestfs_aug_ls");
2647 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2648 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2649 error (g, "%s: failed to parse reply error", "guestfs_aug_ls");
2654 if (!xdr_guestfs_aug_ls_ret (xdr, &ctx->ret)) {
2655 error (g, "%s: failed to parse reply", "guestfs_aug_ls");
2659 ctx->cb_sequence = 1000;
2660 ml->main_loop_quit (ml, g);
2663 char **guestfs_aug_ls (guestfs_h *g,
2666 struct guestfs_aug_ls_args args;
2667 struct aug_ls_ctx ctx;
2668 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2671 if (check_state (g, "guestfs_aug_ls") == -1) return NULL;
2673 memset (&ctx, 0, sizeof ctx);
2675 args.path = (char *) path;
2676 serial = guestfs__send (g, GUESTFS_PROC_AUG_LS,
2677 (xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
2681 ctx.cb_sequence = 0;
2682 guestfs_set_send_callback (g, aug_ls_send_cb, &ctx);
2683 (void) ml->main_loop_run (ml, g);
2684 guestfs_set_send_callback (g, NULL, NULL);
2685 if (ctx.cb_sequence != 1) {
2686 error (g, "%s send failed, see earlier error messages", "guestfs_aug_ls");
2690 ctx.cb_sequence = 0;
2691 guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx);
2692 (void) ml->main_loop_run (ml, g);
2693 guestfs_set_reply_callback (g, NULL, NULL);
2694 if (ctx.cb_sequence != 1000) {
2695 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_ls");
2699 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LS, serial) == -1)
2702 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2703 error (g, "%s", ctx.err.error_message);
2707 /* caller will free this, but we need to add a NULL entry */
2708 ctx.ret.matches.matches_val =
2709 safe_realloc (g, ctx.ret.matches.matches_val,
2710 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2711 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2712 return ctx.ret.matches.matches_val;
2716 /* This flag is set by the callbacks, so we know we've done
2717 * the callbacks as expected, and in the right sequence.
2718 * 0 = not called, 1 = send called,
2719 * 2.. = send_file called,
2720 * 1000 = reply called.
2723 struct guestfs_message_header hdr;
2724 struct guestfs_message_error err;
2727 static void rm_send_cb (guestfs_h *g, void *data)
2729 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2730 struct rm_ctx *ctx = (struct rm_ctx *) data;
2732 guestfs__switch_to_receiving (g);
2733 ctx->cb_sequence = 1;
2734 ml->main_loop_quit (ml, g);
2737 static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2739 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2740 struct rm_ctx *ctx = (struct rm_ctx *) data;
2742 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2743 error (g, "%s: failed to parse reply header", "guestfs_rm");
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_rm");
2754 ctx->cb_sequence = 1000;
2755 ml->main_loop_quit (ml, g);
2758 int guestfs_rm (guestfs_h *g,
2761 struct guestfs_rm_args args;
2763 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2766 if (check_state (g, "guestfs_rm") == -1) return -1;
2768 memset (&ctx, 0, sizeof ctx);
2770 args.path = (char *) path;
2771 serial = guestfs__send (g, GUESTFS_PROC_RM,
2772 (xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
2776 ctx.cb_sequence = 0;
2777 guestfs_set_send_callback (g, rm_send_cb, &ctx);
2778 (void) ml->main_loop_run (ml, g);
2779 guestfs_set_send_callback (g, NULL, NULL);
2780 if (ctx.cb_sequence != 1) {
2781 error (g, "%s send failed, see earlier error messages", "guestfs_rm");
2785 ctx.cb_sequence = 0;
2786 guestfs_set_reply_callback (g, rm_reply_cb, &ctx);
2787 (void) ml->main_loop_run (ml, g);
2788 guestfs_set_reply_callback (g, NULL, NULL);
2789 if (ctx.cb_sequence != 1000) {
2790 error (g, "%s reply failed, see earlier error messages", "guestfs_rm");
2794 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM, serial) == -1)
2797 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2798 error (g, "%s", ctx.err.error_message);
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 = send called,
2809 * 2.. = send_file called,
2810 * 1000 = reply called.
2813 struct guestfs_message_header hdr;
2814 struct guestfs_message_error err;
2817 static void rmdir_send_cb (guestfs_h *g, void *data)
2819 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2820 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2822 guestfs__switch_to_receiving (g);
2823 ctx->cb_sequence = 1;
2824 ml->main_loop_quit (ml, g);
2827 static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2829 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2830 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2832 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2833 error (g, "%s: failed to parse reply header", "guestfs_rmdir");
2836 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2837 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2838 error (g, "%s: failed to parse reply error", "guestfs_rmdir");
2844 ctx->cb_sequence = 1000;
2845 ml->main_loop_quit (ml, g);
2848 int guestfs_rmdir (guestfs_h *g,
2851 struct guestfs_rmdir_args args;
2852 struct rmdir_ctx ctx;
2853 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2856 if (check_state (g, "guestfs_rmdir") == -1) return -1;
2858 memset (&ctx, 0, sizeof ctx);
2860 args.path = (char *) path;
2861 serial = guestfs__send (g, GUESTFS_PROC_RMDIR,
2862 (xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
2866 ctx.cb_sequence = 0;
2867 guestfs_set_send_callback (g, rmdir_send_cb, &ctx);
2868 (void) ml->main_loop_run (ml, g);
2869 guestfs_set_send_callback (g, NULL, NULL);
2870 if (ctx.cb_sequence != 1) {
2871 error (g, "%s send failed, see earlier error messages", "guestfs_rmdir");
2875 ctx.cb_sequence = 0;
2876 guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx);
2877 (void) ml->main_loop_run (ml, g);
2878 guestfs_set_reply_callback (g, NULL, NULL);
2879 if (ctx.cb_sequence != 1000) {
2880 error (g, "%s reply failed, see earlier error messages", "guestfs_rmdir");
2884 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RMDIR, serial) == -1)
2887 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2888 error (g, "%s", ctx.err.error_message);
2896 /* This flag is set by the callbacks, so we know we've done
2897 * the callbacks as expected, and in the right sequence.
2898 * 0 = not called, 1 = send called,
2899 * 2.. = send_file called,
2900 * 1000 = reply called.
2903 struct guestfs_message_header hdr;
2904 struct guestfs_message_error err;
2907 static void rm_rf_send_cb (guestfs_h *g, void *data)
2909 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2910 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2912 guestfs__switch_to_receiving (g);
2913 ctx->cb_sequence = 1;
2914 ml->main_loop_quit (ml, g);
2917 static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2919 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2920 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2922 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2923 error (g, "%s: failed to parse reply header", "guestfs_rm_rf");
2926 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2927 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2928 error (g, "%s: failed to parse reply error", "guestfs_rm_rf");
2934 ctx->cb_sequence = 1000;
2935 ml->main_loop_quit (ml, g);
2938 int guestfs_rm_rf (guestfs_h *g,
2941 struct guestfs_rm_rf_args args;
2942 struct rm_rf_ctx ctx;
2943 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2946 if (check_state (g, "guestfs_rm_rf") == -1) return -1;
2948 memset (&ctx, 0, sizeof ctx);
2950 args.path = (char *) path;
2951 serial = guestfs__send (g, GUESTFS_PROC_RM_RF,
2952 (xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
2956 ctx.cb_sequence = 0;
2957 guestfs_set_send_callback (g, rm_rf_send_cb, &ctx);
2958 (void) ml->main_loop_run (ml, g);
2959 guestfs_set_send_callback (g, NULL, NULL);
2960 if (ctx.cb_sequence != 1) {
2961 error (g, "%s send failed, see earlier error messages", "guestfs_rm_rf");
2965 ctx.cb_sequence = 0;
2966 guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx);
2967 (void) ml->main_loop_run (ml, g);
2968 guestfs_set_reply_callback (g, NULL, NULL);
2969 if (ctx.cb_sequence != 1000) {
2970 error (g, "%s reply failed, see earlier error messages", "guestfs_rm_rf");
2974 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM_RF, serial) == -1)
2977 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2978 error (g, "%s", ctx.err.error_message);
2986 /* This flag is set by the callbacks, so we know we've done
2987 * the callbacks as expected, and in the right sequence.
2988 * 0 = not called, 1 = send called,
2989 * 2.. = send_file called,
2990 * 1000 = reply called.
2993 struct guestfs_message_header hdr;
2994 struct guestfs_message_error err;
2997 static void mkdir_send_cb (guestfs_h *g, void *data)
2999 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3000 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
3002 guestfs__switch_to_receiving (g);
3003 ctx->cb_sequence = 1;
3004 ml->main_loop_quit (ml, g);
3007 static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3009 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3010 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
3012 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3013 error (g, "%s: failed to parse reply header", "guestfs_mkdir");
3016 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3017 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3018 error (g, "%s: failed to parse reply error", "guestfs_mkdir");
3024 ctx->cb_sequence = 1000;
3025 ml->main_loop_quit (ml, g);
3028 int guestfs_mkdir (guestfs_h *g,
3031 struct guestfs_mkdir_args args;
3032 struct mkdir_ctx ctx;
3033 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3036 if (check_state (g, "guestfs_mkdir") == -1) return -1;
3038 memset (&ctx, 0, sizeof ctx);
3040 args.path = (char *) path;
3041 serial = guestfs__send (g, GUESTFS_PROC_MKDIR,
3042 (xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
3046 ctx.cb_sequence = 0;
3047 guestfs_set_send_callback (g, mkdir_send_cb, &ctx);
3048 (void) ml->main_loop_run (ml, g);
3049 guestfs_set_send_callback (g, NULL, NULL);
3050 if (ctx.cb_sequence != 1) {
3051 error (g, "%s send failed, see earlier error messages", "guestfs_mkdir");
3055 ctx.cb_sequence = 0;
3056 guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx);
3057 (void) ml->main_loop_run (ml, g);
3058 guestfs_set_reply_callback (g, NULL, NULL);
3059 if (ctx.cb_sequence != 1000) {
3060 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir");
3064 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR, serial) == -1)
3067 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3068 error (g, "%s", ctx.err.error_message);
3075 struct mkdir_p_ctx {
3076 /* This flag is set by the callbacks, so we know we've done
3077 * the callbacks as expected, and in the right sequence.
3078 * 0 = not called, 1 = send called,
3079 * 2.. = send_file called,
3080 * 1000 = reply called.
3083 struct guestfs_message_header hdr;
3084 struct guestfs_message_error err;
3087 static void mkdir_p_send_cb (guestfs_h *g, void *data)
3089 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3090 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
3092 guestfs__switch_to_receiving (g);
3093 ctx->cb_sequence = 1;
3094 ml->main_loop_quit (ml, g);
3097 static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3099 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3100 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
3102 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3103 error (g, "%s: failed to parse reply header", "guestfs_mkdir_p");
3106 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3107 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3108 error (g, "%s: failed to parse reply error", "guestfs_mkdir_p");
3114 ctx->cb_sequence = 1000;
3115 ml->main_loop_quit (ml, g);
3118 int guestfs_mkdir_p (guestfs_h *g,
3121 struct guestfs_mkdir_p_args args;
3122 struct mkdir_p_ctx ctx;
3123 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3126 if (check_state (g, "guestfs_mkdir_p") == -1) return -1;
3128 memset (&ctx, 0, sizeof ctx);
3130 args.path = (char *) path;
3131 serial = guestfs__send (g, GUESTFS_PROC_MKDIR_P,
3132 (xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
3136 ctx.cb_sequence = 0;
3137 guestfs_set_send_callback (g, mkdir_p_send_cb, &ctx);
3138 (void) ml->main_loop_run (ml, g);
3139 guestfs_set_send_callback (g, NULL, NULL);
3140 if (ctx.cb_sequence != 1) {
3141 error (g, "%s send failed, see earlier error messages", "guestfs_mkdir_p");
3145 ctx.cb_sequence = 0;
3146 guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx);
3147 (void) ml->main_loop_run (ml, g);
3148 guestfs_set_reply_callback (g, NULL, NULL);
3149 if (ctx.cb_sequence != 1000) {
3150 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir_p");
3154 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR_P, serial) == -1)
3157 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3158 error (g, "%s", ctx.err.error_message);
3166 /* This flag is set by the callbacks, so we know we've done
3167 * the callbacks as expected, and in the right sequence.
3168 * 0 = not called, 1 = send called,
3169 * 2.. = send_file called,
3170 * 1000 = reply called.
3173 struct guestfs_message_header hdr;
3174 struct guestfs_message_error err;
3177 static void chmod_send_cb (guestfs_h *g, void *data)
3179 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3180 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
3182 guestfs__switch_to_receiving (g);
3183 ctx->cb_sequence = 1;
3184 ml->main_loop_quit (ml, g);
3187 static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3189 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3190 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
3192 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3193 error (g, "%s: failed to parse reply header", "guestfs_chmod");
3196 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3197 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3198 error (g, "%s: failed to parse reply error", "guestfs_chmod");
3204 ctx->cb_sequence = 1000;
3205 ml->main_loop_quit (ml, g);
3208 int guestfs_chmod (guestfs_h *g,
3212 struct guestfs_chmod_args args;
3213 struct chmod_ctx ctx;
3214 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3217 if (check_state (g, "guestfs_chmod") == -1) return -1;
3219 memset (&ctx, 0, sizeof ctx);
3222 args.path = (char *) path;
3223 serial = guestfs__send (g, GUESTFS_PROC_CHMOD,
3224 (xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
3228 ctx.cb_sequence = 0;
3229 guestfs_set_send_callback (g, chmod_send_cb, &ctx);
3230 (void) ml->main_loop_run (ml, g);
3231 guestfs_set_send_callback (g, NULL, NULL);
3232 if (ctx.cb_sequence != 1) {
3233 error (g, "%s send failed, see earlier error messages", "guestfs_chmod");
3237 ctx.cb_sequence = 0;
3238 guestfs_set_reply_callback (g, chmod_reply_cb, &ctx);
3239 (void) ml->main_loop_run (ml, g);
3240 guestfs_set_reply_callback (g, NULL, NULL);
3241 if (ctx.cb_sequence != 1000) {
3242 error (g, "%s reply failed, see earlier error messages", "guestfs_chmod");
3246 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHMOD, serial) == -1)
3249 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3250 error (g, "%s", ctx.err.error_message);
3258 /* This flag is set by the callbacks, so we know we've done
3259 * the callbacks as expected, and in the right sequence.
3260 * 0 = not called, 1 = send called,
3261 * 2.. = send_file called,
3262 * 1000 = reply called.
3265 struct guestfs_message_header hdr;
3266 struct guestfs_message_error err;
3269 static void chown_send_cb (guestfs_h *g, void *data)
3271 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3272 struct chown_ctx *ctx = (struct chown_ctx *) data;
3274 guestfs__switch_to_receiving (g);
3275 ctx->cb_sequence = 1;
3276 ml->main_loop_quit (ml, g);
3279 static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3281 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3282 struct chown_ctx *ctx = (struct chown_ctx *) data;
3284 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3285 error (g, "%s: failed to parse reply header", "guestfs_chown");
3288 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3289 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3290 error (g, "%s: failed to parse reply error", "guestfs_chown");
3296 ctx->cb_sequence = 1000;
3297 ml->main_loop_quit (ml, g);
3300 int guestfs_chown (guestfs_h *g,
3305 struct guestfs_chown_args args;
3306 struct chown_ctx ctx;
3307 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3310 if (check_state (g, "guestfs_chown") == -1) return -1;
3312 memset (&ctx, 0, sizeof ctx);
3316 args.path = (char *) path;
3317 serial = guestfs__send (g, GUESTFS_PROC_CHOWN,
3318 (xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
3322 ctx.cb_sequence = 0;
3323 guestfs_set_send_callback (g, chown_send_cb, &ctx);
3324 (void) ml->main_loop_run (ml, g);
3325 guestfs_set_send_callback (g, NULL, NULL);
3326 if (ctx.cb_sequence != 1) {
3327 error (g, "%s send failed, see earlier error messages", "guestfs_chown");
3331 ctx.cb_sequence = 0;
3332 guestfs_set_reply_callback (g, chown_reply_cb, &ctx);
3333 (void) ml->main_loop_run (ml, g);
3334 guestfs_set_reply_callback (g, NULL, NULL);
3335 if (ctx.cb_sequence != 1000) {
3336 error (g, "%s reply failed, see earlier error messages", "guestfs_chown");
3340 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHOWN, serial) == -1)
3343 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3344 error (g, "%s", ctx.err.error_message);
3352 /* This flag is set by the callbacks, so we know we've done
3353 * the callbacks as expected, and in the right sequence.
3354 * 0 = not called, 1 = send called,
3355 * 2.. = send_file called,
3356 * 1000 = reply called.
3359 struct guestfs_message_header hdr;
3360 struct guestfs_message_error err;
3361 struct guestfs_exists_ret ret;
3364 static void exists_send_cb (guestfs_h *g, void *data)
3366 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3367 struct exists_ctx *ctx = (struct exists_ctx *) data;
3369 guestfs__switch_to_receiving (g);
3370 ctx->cb_sequence = 1;
3371 ml->main_loop_quit (ml, g);
3374 static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3376 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3377 struct exists_ctx *ctx = (struct exists_ctx *) data;
3379 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3380 error (g, "%s: failed to parse reply header", "guestfs_exists");
3383 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3384 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3385 error (g, "%s: failed to parse reply error", "guestfs_exists");
3390 if (!xdr_guestfs_exists_ret (xdr, &ctx->ret)) {
3391 error (g, "%s: failed to parse reply", "guestfs_exists");
3395 ctx->cb_sequence = 1000;
3396 ml->main_loop_quit (ml, g);
3399 int guestfs_exists (guestfs_h *g,
3402 struct guestfs_exists_args args;
3403 struct exists_ctx ctx;
3404 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3407 if (check_state (g, "guestfs_exists") == -1) return -1;
3409 memset (&ctx, 0, sizeof ctx);
3411 args.path = (char *) path;
3412 serial = guestfs__send (g, GUESTFS_PROC_EXISTS,
3413 (xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
3417 ctx.cb_sequence = 0;
3418 guestfs_set_send_callback (g, exists_send_cb, &ctx);
3419 (void) ml->main_loop_run (ml, g);
3420 guestfs_set_send_callback (g, NULL, NULL);
3421 if (ctx.cb_sequence != 1) {
3422 error (g, "%s send failed, see earlier error messages", "guestfs_exists");
3426 ctx.cb_sequence = 0;
3427 guestfs_set_reply_callback (g, exists_reply_cb, &ctx);
3428 (void) ml->main_loop_run (ml, g);
3429 guestfs_set_reply_callback (g, NULL, NULL);
3430 if (ctx.cb_sequence != 1000) {
3431 error (g, "%s reply failed, see earlier error messages", "guestfs_exists");
3435 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EXISTS, serial) == -1)
3438 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3439 error (g, "%s", ctx.err.error_message);
3443 return ctx.ret.existsflag;
3446 struct is_file_ctx {
3447 /* This flag is set by the callbacks, so we know we've done
3448 * the callbacks as expected, and in the right sequence.
3449 * 0 = not called, 1 = send called,
3450 * 2.. = send_file called,
3451 * 1000 = reply called.
3454 struct guestfs_message_header hdr;
3455 struct guestfs_message_error err;
3456 struct guestfs_is_file_ret ret;
3459 static void is_file_send_cb (guestfs_h *g, void *data)
3461 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3462 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
3464 guestfs__switch_to_receiving (g);
3465 ctx->cb_sequence = 1;
3466 ml->main_loop_quit (ml, g);
3469 static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3471 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3472 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
3474 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3475 error (g, "%s: failed to parse reply header", "guestfs_is_file");
3478 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3479 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3480 error (g, "%s: failed to parse reply error", "guestfs_is_file");
3485 if (!xdr_guestfs_is_file_ret (xdr, &ctx->ret)) {
3486 error (g, "%s: failed to parse reply", "guestfs_is_file");
3490 ctx->cb_sequence = 1000;
3491 ml->main_loop_quit (ml, g);
3494 int guestfs_is_file (guestfs_h *g,
3497 struct guestfs_is_file_args args;
3498 struct is_file_ctx ctx;
3499 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3502 if (check_state (g, "guestfs_is_file") == -1) return -1;
3504 memset (&ctx, 0, sizeof ctx);
3506 args.path = (char *) path;
3507 serial = guestfs__send (g, GUESTFS_PROC_IS_FILE,
3508 (xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
3512 ctx.cb_sequence = 0;
3513 guestfs_set_send_callback (g, is_file_send_cb, &ctx);
3514 (void) ml->main_loop_run (ml, g);
3515 guestfs_set_send_callback (g, NULL, NULL);
3516 if (ctx.cb_sequence != 1) {
3517 error (g, "%s send failed, see earlier error messages", "guestfs_is_file");
3521 ctx.cb_sequence = 0;
3522 guestfs_set_reply_callback (g, is_file_reply_cb, &ctx);
3523 (void) ml->main_loop_run (ml, g);
3524 guestfs_set_reply_callback (g, NULL, NULL);
3525 if (ctx.cb_sequence != 1000) {
3526 error (g, "%s reply failed, see earlier error messages", "guestfs_is_file");
3530 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_FILE, serial) == -1)
3533 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3534 error (g, "%s", ctx.err.error_message);
3538 return ctx.ret.fileflag;
3542 /* This flag is set by the callbacks, so we know we've done
3543 * the callbacks as expected, and in the right sequence.
3544 * 0 = not called, 1 = send called,
3545 * 2.. = send_file called,
3546 * 1000 = reply called.
3549 struct guestfs_message_header hdr;
3550 struct guestfs_message_error err;
3551 struct guestfs_is_dir_ret ret;
3554 static void is_dir_send_cb (guestfs_h *g, void *data)
3556 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3557 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
3559 guestfs__switch_to_receiving (g);
3560 ctx->cb_sequence = 1;
3561 ml->main_loop_quit (ml, g);
3564 static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3566 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3567 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
3569 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3570 error (g, "%s: failed to parse reply header", "guestfs_is_dir");
3573 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3574 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3575 error (g, "%s: failed to parse reply error", "guestfs_is_dir");
3580 if (!xdr_guestfs_is_dir_ret (xdr, &ctx->ret)) {
3581 error (g, "%s: failed to parse reply", "guestfs_is_dir");
3585 ctx->cb_sequence = 1000;
3586 ml->main_loop_quit (ml, g);
3589 int guestfs_is_dir (guestfs_h *g,
3592 struct guestfs_is_dir_args args;
3593 struct is_dir_ctx ctx;
3594 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3597 if (check_state (g, "guestfs_is_dir") == -1) return -1;
3599 memset (&ctx, 0, sizeof ctx);
3601 args.path = (char *) path;
3602 serial = guestfs__send (g, GUESTFS_PROC_IS_DIR,
3603 (xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
3607 ctx.cb_sequence = 0;
3608 guestfs_set_send_callback (g, is_dir_send_cb, &ctx);
3609 (void) ml->main_loop_run (ml, g);
3610 guestfs_set_send_callback (g, NULL, NULL);
3611 if (ctx.cb_sequence != 1) {
3612 error (g, "%s send failed, see earlier error messages", "guestfs_is_dir");
3616 ctx.cb_sequence = 0;
3617 guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx);
3618 (void) ml->main_loop_run (ml, g);
3619 guestfs_set_reply_callback (g, NULL, NULL);
3620 if (ctx.cb_sequence != 1000) {
3621 error (g, "%s reply failed, see earlier error messages", "guestfs_is_dir");
3625 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_DIR, serial) == -1)
3628 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3629 error (g, "%s", ctx.err.error_message);
3633 return ctx.ret.dirflag;
3636 struct pvcreate_ctx {
3637 /* This flag is set by the callbacks, so we know we've done
3638 * the callbacks as expected, and in the right sequence.
3639 * 0 = not called, 1 = send called,
3640 * 2.. = send_file called,
3641 * 1000 = reply called.
3644 struct guestfs_message_header hdr;
3645 struct guestfs_message_error err;
3648 static void pvcreate_send_cb (guestfs_h *g, void *data)
3650 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3651 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
3653 guestfs__switch_to_receiving (g);
3654 ctx->cb_sequence = 1;
3655 ml->main_loop_quit (ml, g);
3658 static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3660 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3661 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
3663 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3664 error (g, "%s: failed to parse reply header", "guestfs_pvcreate");
3667 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3668 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3669 error (g, "%s: failed to parse reply error", "guestfs_pvcreate");
3675 ctx->cb_sequence = 1000;
3676 ml->main_loop_quit (ml, g);
3679 int guestfs_pvcreate (guestfs_h *g,
3682 struct guestfs_pvcreate_args args;
3683 struct pvcreate_ctx ctx;
3684 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3687 if (check_state (g, "guestfs_pvcreate") == -1) return -1;
3689 memset (&ctx, 0, sizeof ctx);
3691 args.device = (char *) device;
3692 serial = guestfs__send (g, GUESTFS_PROC_PVCREATE,
3693 (xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
3697 ctx.cb_sequence = 0;
3698 guestfs_set_send_callback (g, pvcreate_send_cb, &ctx);
3699 (void) ml->main_loop_run (ml, g);
3700 guestfs_set_send_callback (g, NULL, NULL);
3701 if (ctx.cb_sequence != 1) {
3702 error (g, "%s send failed, see earlier error messages", "guestfs_pvcreate");
3706 ctx.cb_sequence = 0;
3707 guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx);
3708 (void) ml->main_loop_run (ml, g);
3709 guestfs_set_reply_callback (g, NULL, NULL);
3710 if (ctx.cb_sequence != 1000) {
3711 error (g, "%s reply failed, see earlier error messages", "guestfs_pvcreate");
3715 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVCREATE, serial) == -1)
3718 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3719 error (g, "%s", ctx.err.error_message);
3726 struct vgcreate_ctx {
3727 /* This flag is set by the callbacks, so we know we've done
3728 * the callbacks as expected, and in the right sequence.
3729 * 0 = not called, 1 = send called,
3730 * 2.. = send_file called,
3731 * 1000 = reply called.
3734 struct guestfs_message_header hdr;
3735 struct guestfs_message_error err;
3738 static void vgcreate_send_cb (guestfs_h *g, void *data)
3740 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3741 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3743 guestfs__switch_to_receiving (g);
3744 ctx->cb_sequence = 1;
3745 ml->main_loop_quit (ml, g);
3748 static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3750 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3751 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3753 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3754 error (g, "%s: failed to parse reply header", "guestfs_vgcreate");
3757 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3758 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3759 error (g, "%s: failed to parse reply error", "guestfs_vgcreate");
3765 ctx->cb_sequence = 1000;
3766 ml->main_loop_quit (ml, g);
3769 int guestfs_vgcreate (guestfs_h *g,
3770 const char *volgroup,
3771 char * const* const physvols)
3773 struct guestfs_vgcreate_args args;
3774 struct vgcreate_ctx ctx;
3775 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3778 if (check_state (g, "guestfs_vgcreate") == -1) return -1;
3780 memset (&ctx, 0, sizeof ctx);
3782 args.volgroup = (char *) volgroup;
3783 args.physvols.physvols_val = (char **) physvols;
3784 for (args.physvols.physvols_len = 0; physvols[args.physvols.physvols_len]; args.physvols.physvols_len++) ;
3785 serial = guestfs__send (g, GUESTFS_PROC_VGCREATE,
3786 (xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
3790 ctx.cb_sequence = 0;
3791 guestfs_set_send_callback (g, vgcreate_send_cb, &ctx);
3792 (void) ml->main_loop_run (ml, g);
3793 guestfs_set_send_callback (g, NULL, NULL);
3794 if (ctx.cb_sequence != 1) {
3795 error (g, "%s send failed, see earlier error messages", "guestfs_vgcreate");
3799 ctx.cb_sequence = 0;
3800 guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx);
3801 (void) ml->main_loop_run (ml, g);
3802 guestfs_set_reply_callback (g, NULL, NULL);
3803 if (ctx.cb_sequence != 1000) {
3804 error (g, "%s reply failed, see earlier error messages", "guestfs_vgcreate");
3808 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGCREATE, serial) == -1)
3811 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3812 error (g, "%s", ctx.err.error_message);
3819 struct lvcreate_ctx {
3820 /* This flag is set by the callbacks, so we know we've done
3821 * the callbacks as expected, and in the right sequence.
3822 * 0 = not called, 1 = send called,
3823 * 2.. = send_file called,
3824 * 1000 = reply called.
3827 struct guestfs_message_header hdr;
3828 struct guestfs_message_error err;
3831 static void lvcreate_send_cb (guestfs_h *g, void *data)
3833 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3834 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3836 guestfs__switch_to_receiving (g);
3837 ctx->cb_sequence = 1;
3838 ml->main_loop_quit (ml, g);
3841 static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3843 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3844 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3846 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3847 error (g, "%s: failed to parse reply header", "guestfs_lvcreate");
3850 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3851 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3852 error (g, "%s: failed to parse reply error", "guestfs_lvcreate");
3858 ctx->cb_sequence = 1000;
3859 ml->main_loop_quit (ml, g);
3862 int guestfs_lvcreate (guestfs_h *g,
3864 const char *volgroup,
3867 struct guestfs_lvcreate_args args;
3868 struct lvcreate_ctx ctx;
3869 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3872 if (check_state (g, "guestfs_lvcreate") == -1) return -1;
3874 memset (&ctx, 0, sizeof ctx);
3876 args.logvol = (char *) logvol;
3877 args.volgroup = (char *) volgroup;
3878 args.mbytes = mbytes;
3879 serial = guestfs__send (g, GUESTFS_PROC_LVCREATE,
3880 (xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
3884 ctx.cb_sequence = 0;
3885 guestfs_set_send_callback (g, lvcreate_send_cb, &ctx);
3886 (void) ml->main_loop_run (ml, g);
3887 guestfs_set_send_callback (g, NULL, NULL);
3888 if (ctx.cb_sequence != 1) {
3889 error (g, "%s send failed, see earlier error messages", "guestfs_lvcreate");
3893 ctx.cb_sequence = 0;
3894 guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx);
3895 (void) ml->main_loop_run (ml, g);
3896 guestfs_set_reply_callback (g, NULL, NULL);
3897 if (ctx.cb_sequence != 1000) {
3898 error (g, "%s reply failed, see earlier error messages", "guestfs_lvcreate");
3902 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVCREATE, serial) == -1)
3905 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3906 error (g, "%s", ctx.err.error_message);
3914 /* This flag is set by the callbacks, so we know we've done
3915 * the callbacks as expected, and in the right sequence.
3916 * 0 = not called, 1 = send called,
3917 * 2.. = send_file called,
3918 * 1000 = reply called.
3921 struct guestfs_message_header hdr;
3922 struct guestfs_message_error err;
3925 static void mkfs_send_cb (guestfs_h *g, void *data)
3927 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3928 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3930 guestfs__switch_to_receiving (g);
3931 ctx->cb_sequence = 1;
3932 ml->main_loop_quit (ml, g);
3935 static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3937 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3938 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3940 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3941 error (g, "%s: failed to parse reply header", "guestfs_mkfs");
3944 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3945 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3946 error (g, "%s: failed to parse reply error", "guestfs_mkfs");
3952 ctx->cb_sequence = 1000;
3953 ml->main_loop_quit (ml, g);
3956 int guestfs_mkfs (guestfs_h *g,
3960 struct guestfs_mkfs_args args;
3961 struct mkfs_ctx ctx;
3962 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3965 if (check_state (g, "guestfs_mkfs") == -1) return -1;
3967 memset (&ctx, 0, sizeof ctx);
3969 args.fstype = (char *) fstype;
3970 args.device = (char *) device;
3971 serial = guestfs__send (g, GUESTFS_PROC_MKFS,
3972 (xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
3976 ctx.cb_sequence = 0;
3977 guestfs_set_send_callback (g, mkfs_send_cb, &ctx);
3978 (void) ml->main_loop_run (ml, g);
3979 guestfs_set_send_callback (g, NULL, NULL);
3980 if (ctx.cb_sequence != 1) {
3981 error (g, "%s send failed, see earlier error messages", "guestfs_mkfs");
3985 ctx.cb_sequence = 0;
3986 guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx);
3987 (void) ml->main_loop_run (ml, g);
3988 guestfs_set_reply_callback (g, NULL, NULL);
3989 if (ctx.cb_sequence != 1000) {
3990 error (g, "%s reply failed, see earlier error messages", "guestfs_mkfs");
3994 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFS, serial) == -1)
3997 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3998 error (g, "%s", ctx.err.error_message);
4006 /* This flag is set by the callbacks, so we know we've done
4007 * the callbacks as expected, and in the right sequence.
4008 * 0 = not called, 1 = send called,
4009 * 2.. = send_file called,
4010 * 1000 = reply called.
4013 struct guestfs_message_header hdr;
4014 struct guestfs_message_error err;
4017 static void sfdisk_send_cb (guestfs_h *g, void *data)
4019 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4020 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
4022 guestfs__switch_to_receiving (g);
4023 ctx->cb_sequence = 1;
4024 ml->main_loop_quit (ml, g);
4027 static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4029 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4030 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
4032 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4033 error (g, "%s: failed to parse reply header", "guestfs_sfdisk");
4036 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4037 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4038 error (g, "%s: failed to parse reply error", "guestfs_sfdisk");
4044 ctx->cb_sequence = 1000;
4045 ml->main_loop_quit (ml, g);
4048 int guestfs_sfdisk (guestfs_h *g,
4053 char * const* const lines)
4055 struct guestfs_sfdisk_args args;
4056 struct sfdisk_ctx ctx;
4057 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4060 if (check_state (g, "guestfs_sfdisk") == -1) return -1;
4062 memset (&ctx, 0, sizeof ctx);
4064 args.device = (char *) device;
4067 args.sectors = sectors;
4068 args.lines.lines_val = (char **) lines;
4069 for (args.lines.lines_len = 0; lines[args.lines.lines_len]; args.lines.lines_len++) ;
4070 serial = guestfs__send (g, GUESTFS_PROC_SFDISK,
4071 (xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
4075 ctx.cb_sequence = 0;
4076 guestfs_set_send_callback (g, sfdisk_send_cb, &ctx);
4077 (void) ml->main_loop_run (ml, g);
4078 guestfs_set_send_callback (g, NULL, NULL);
4079 if (ctx.cb_sequence != 1) {
4080 error (g, "%s send failed, see earlier error messages", "guestfs_sfdisk");
4084 ctx.cb_sequence = 0;
4085 guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx);
4086 (void) ml->main_loop_run (ml, g);
4087 guestfs_set_reply_callback (g, NULL, NULL);
4088 if (ctx.cb_sequence != 1000) {
4089 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk");
4093 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK, serial) == -1)
4096 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4097 error (g, "%s", ctx.err.error_message);
4104 struct write_file_ctx {
4105 /* This flag is set by the callbacks, so we know we've done
4106 * the callbacks as expected, and in the right sequence.
4107 * 0 = not called, 1 = send called,
4108 * 2.. = send_file called,
4109 * 1000 = reply called.
4112 struct guestfs_message_header hdr;
4113 struct guestfs_message_error err;
4116 static void write_file_send_cb (guestfs_h *g, void *data)
4118 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4119 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
4121 guestfs__switch_to_receiving (g);
4122 ctx->cb_sequence = 1;
4123 ml->main_loop_quit (ml, g);
4126 static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4128 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4129 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
4131 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4132 error (g, "%s: failed to parse reply header", "guestfs_write_file");
4135 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4136 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4137 error (g, "%s: failed to parse reply error", "guestfs_write_file");
4143 ctx->cb_sequence = 1000;
4144 ml->main_loop_quit (ml, g);
4147 int guestfs_write_file (guestfs_h *g,
4149 const char *content,
4152 struct guestfs_write_file_args args;
4153 struct write_file_ctx ctx;
4154 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4157 if (check_state (g, "guestfs_write_file") == -1) return -1;
4159 memset (&ctx, 0, sizeof ctx);
4161 args.path = (char *) path;
4162 args.content = (char *) content;
4164 serial = guestfs__send (g, GUESTFS_PROC_WRITE_FILE,
4165 (xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
4169 ctx.cb_sequence = 0;
4170 guestfs_set_send_callback (g, write_file_send_cb, &ctx);
4171 (void) ml->main_loop_run (ml, g);
4172 guestfs_set_send_callback (g, NULL, NULL);
4173 if (ctx.cb_sequence != 1) {
4174 error (g, "%s send failed, see earlier error messages", "guestfs_write_file");
4178 ctx.cb_sequence = 0;
4179 guestfs_set_reply_callback (g, write_file_reply_cb, &ctx);
4180 (void) ml->main_loop_run (ml, g);
4181 guestfs_set_reply_callback (g, NULL, NULL);
4182 if (ctx.cb_sequence != 1000) {
4183 error (g, "%s reply failed, see earlier error messages", "guestfs_write_file");
4187 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WRITE_FILE, serial) == -1)
4190 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4191 error (g, "%s", ctx.err.error_message);
4199 /* This flag is set by the callbacks, so we know we've done
4200 * the callbacks as expected, and in the right sequence.
4201 * 0 = not called, 1 = send called,
4202 * 2.. = send_file called,
4203 * 1000 = reply called.
4206 struct guestfs_message_header hdr;
4207 struct guestfs_message_error err;
4210 static void umount_send_cb (guestfs_h *g, void *data)
4212 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4213 struct umount_ctx *ctx = (struct umount_ctx *) data;
4215 guestfs__switch_to_receiving (g);
4216 ctx->cb_sequence = 1;
4217 ml->main_loop_quit (ml, g);
4220 static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4222 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4223 struct umount_ctx *ctx = (struct umount_ctx *) data;
4225 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4226 error (g, "%s: failed to parse reply header", "guestfs_umount");
4229 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4230 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4231 error (g, "%s: failed to parse reply error", "guestfs_umount");
4237 ctx->cb_sequence = 1000;
4238 ml->main_loop_quit (ml, g);
4241 int guestfs_umount (guestfs_h *g,
4242 const char *pathordevice)
4244 struct guestfs_umount_args args;
4245 struct umount_ctx ctx;
4246 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4249 if (check_state (g, "guestfs_umount") == -1) return -1;
4251 memset (&ctx, 0, sizeof ctx);
4253 args.pathordevice = (char *) pathordevice;
4254 serial = guestfs__send (g, GUESTFS_PROC_UMOUNT,
4255 (xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
4259 ctx.cb_sequence = 0;
4260 guestfs_set_send_callback (g, umount_send_cb, &ctx);
4261 (void) ml->main_loop_run (ml, g);
4262 guestfs_set_send_callback (g, NULL, NULL);
4263 if (ctx.cb_sequence != 1) {
4264 error (g, "%s send failed, see earlier error messages", "guestfs_umount");
4268 ctx.cb_sequence = 0;
4269 guestfs_set_reply_callback (g, umount_reply_cb, &ctx);
4270 (void) ml->main_loop_run (ml, g);
4271 guestfs_set_reply_callback (g, NULL, NULL);
4272 if (ctx.cb_sequence != 1000) {
4273 error (g, "%s reply failed, see earlier error messages", "guestfs_umount");
4277 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT, serial) == -1)
4280 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4281 error (g, "%s", ctx.err.error_message);
4289 /* This flag is set by the callbacks, so we know we've done
4290 * the callbacks as expected, and in the right sequence.
4291 * 0 = not called, 1 = send called,
4292 * 2.. = send_file called,
4293 * 1000 = reply called.
4296 struct guestfs_message_header hdr;
4297 struct guestfs_message_error err;
4298 struct guestfs_mounts_ret ret;
4301 static void mounts_send_cb (guestfs_h *g, void *data)
4303 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4304 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
4306 guestfs__switch_to_receiving (g);
4307 ctx->cb_sequence = 1;
4308 ml->main_loop_quit (ml, g);
4311 static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4313 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4314 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
4316 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4317 error (g, "%s: failed to parse reply header", "guestfs_mounts");
4320 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4321 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4322 error (g, "%s: failed to parse reply error", "guestfs_mounts");
4327 if (!xdr_guestfs_mounts_ret (xdr, &ctx->ret)) {
4328 error (g, "%s: failed to parse reply", "guestfs_mounts");
4332 ctx->cb_sequence = 1000;
4333 ml->main_loop_quit (ml, g);
4336 char **guestfs_mounts (guestfs_h *g)
4338 struct mounts_ctx ctx;
4339 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4342 if (check_state (g, "guestfs_mounts") == -1) return NULL;
4344 memset (&ctx, 0, sizeof ctx);
4346 serial = guestfs__send (g, GUESTFS_PROC_MOUNTS, NULL, NULL);
4350 ctx.cb_sequence = 0;
4351 guestfs_set_send_callback (g, mounts_send_cb, &ctx);
4352 (void) ml->main_loop_run (ml, g);
4353 guestfs_set_send_callback (g, NULL, NULL);
4354 if (ctx.cb_sequence != 1) {
4355 error (g, "%s send failed, see earlier error messages", "guestfs_mounts");
4359 ctx.cb_sequence = 0;
4360 guestfs_set_reply_callback (g, mounts_reply_cb, &ctx);
4361 (void) ml->main_loop_run (ml, g);
4362 guestfs_set_reply_callback (g, NULL, NULL);
4363 if (ctx.cb_sequence != 1000) {
4364 error (g, "%s reply failed, see earlier error messages", "guestfs_mounts");
4368 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNTS, serial) == -1)
4371 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4372 error (g, "%s", ctx.err.error_message);
4376 /* caller will free this, but we need to add a NULL entry */
4377 ctx.ret.devices.devices_val =
4378 safe_realloc (g, ctx.ret.devices.devices_val,
4379 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
4380 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
4381 return ctx.ret.devices.devices_val;
4384 struct umount_all_ctx {
4385 /* This flag is set by the callbacks, so we know we've done
4386 * the callbacks as expected, and in the right sequence.
4387 * 0 = not called, 1 = send called,
4388 * 2.. = send_file called,
4389 * 1000 = reply called.
4392 struct guestfs_message_header hdr;
4393 struct guestfs_message_error err;
4396 static void umount_all_send_cb (guestfs_h *g, void *data)
4398 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4399 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
4401 guestfs__switch_to_receiving (g);
4402 ctx->cb_sequence = 1;
4403 ml->main_loop_quit (ml, g);
4406 static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4408 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4409 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
4411 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4412 error (g, "%s: failed to parse reply header", "guestfs_umount_all");
4415 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4416 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4417 error (g, "%s: failed to parse reply error", "guestfs_umount_all");
4423 ctx->cb_sequence = 1000;
4424 ml->main_loop_quit (ml, g);
4427 int guestfs_umount_all (guestfs_h *g)
4429 struct umount_all_ctx ctx;
4430 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4433 if (check_state (g, "guestfs_umount_all") == -1) return -1;
4435 memset (&ctx, 0, sizeof ctx);
4437 serial = guestfs__send (g, GUESTFS_PROC_UMOUNT_ALL, NULL, NULL);
4441 ctx.cb_sequence = 0;
4442 guestfs_set_send_callback (g, umount_all_send_cb, &ctx);
4443 (void) ml->main_loop_run (ml, g);
4444 guestfs_set_send_callback (g, NULL, NULL);
4445 if (ctx.cb_sequence != 1) {
4446 error (g, "%s send failed, see earlier error messages", "guestfs_umount_all");
4450 ctx.cb_sequence = 0;
4451 guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx);
4452 (void) ml->main_loop_run (ml, g);
4453 guestfs_set_reply_callback (g, NULL, NULL);
4454 if (ctx.cb_sequence != 1000) {
4455 error (g, "%s reply failed, see earlier error messages", "guestfs_umount_all");
4459 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT_ALL, serial) == -1)
4462 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4463 error (g, "%s", ctx.err.error_message);
4470 struct lvm_remove_all_ctx {
4471 /* This flag is set by the callbacks, so we know we've done
4472 * the callbacks as expected, and in the right sequence.
4473 * 0 = not called, 1 = send called,
4474 * 2.. = send_file called,
4475 * 1000 = reply called.
4478 struct guestfs_message_header hdr;
4479 struct guestfs_message_error err;
4482 static void lvm_remove_all_send_cb (guestfs_h *g, void *data)
4484 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4485 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
4487 guestfs__switch_to_receiving (g);
4488 ctx->cb_sequence = 1;
4489 ml->main_loop_quit (ml, g);
4492 static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4494 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4495 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
4497 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4498 error (g, "%s: failed to parse reply header", "guestfs_lvm_remove_all");
4501 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4502 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4503 error (g, "%s: failed to parse reply error", "guestfs_lvm_remove_all");
4509 ctx->cb_sequence = 1000;
4510 ml->main_loop_quit (ml, g);
4513 int guestfs_lvm_remove_all (guestfs_h *g)
4515 struct lvm_remove_all_ctx ctx;
4516 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4519 if (check_state (g, "guestfs_lvm_remove_all") == -1) return -1;
4521 memset (&ctx, 0, sizeof ctx);
4523 serial = guestfs__send (g, GUESTFS_PROC_LVM_REMOVE_ALL, NULL, NULL);
4527 ctx.cb_sequence = 0;
4528 guestfs_set_send_callback (g, lvm_remove_all_send_cb, &ctx);
4529 (void) ml->main_loop_run (ml, g);
4530 guestfs_set_send_callback (g, NULL, NULL);
4531 if (ctx.cb_sequence != 1) {
4532 error (g, "%s send failed, see earlier error messages", "guestfs_lvm_remove_all");
4536 ctx.cb_sequence = 0;
4537 guestfs_set_reply_callback (g, lvm_remove_all_reply_cb, &ctx);
4538 (void) ml->main_loop_run (ml, g);
4539 guestfs_set_reply_callback (g, NULL, NULL);
4540 if (ctx.cb_sequence != 1000) {
4541 error (g, "%s reply failed, see earlier error messages", "guestfs_lvm_remove_all");
4545 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVM_REMOVE_ALL, serial) == -1)
4548 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4549 error (g, "%s", ctx.err.error_message);
4557 /* This flag is set by the callbacks, so we know we've done
4558 * the callbacks as expected, and in the right sequence.
4559 * 0 = not called, 1 = send called,
4560 * 2.. = send_file called,
4561 * 1000 = reply called.
4564 struct guestfs_message_header hdr;
4565 struct guestfs_message_error err;
4566 struct guestfs_file_ret ret;
4569 static void file_send_cb (guestfs_h *g, void *data)
4571 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4572 struct file_ctx *ctx = (struct file_ctx *) data;
4574 guestfs__switch_to_receiving (g);
4575 ctx->cb_sequence = 1;
4576 ml->main_loop_quit (ml, g);
4579 static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4581 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4582 struct file_ctx *ctx = (struct file_ctx *) data;
4584 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4585 error (g, "%s: failed to parse reply header", "guestfs_file");
4588 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4589 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4590 error (g, "%s: failed to parse reply error", "guestfs_file");
4595 if (!xdr_guestfs_file_ret (xdr, &ctx->ret)) {
4596 error (g, "%s: failed to parse reply", "guestfs_file");
4600 ctx->cb_sequence = 1000;
4601 ml->main_loop_quit (ml, g);
4604 char *guestfs_file (guestfs_h *g,
4607 struct guestfs_file_args args;
4608 struct file_ctx ctx;
4609 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4612 if (check_state (g, "guestfs_file") == -1) return NULL;
4614 memset (&ctx, 0, sizeof ctx);
4616 args.path = (char *) path;
4617 serial = guestfs__send (g, GUESTFS_PROC_FILE,
4618 (xdrproc_t) xdr_guestfs_file_args, (char *) &args);
4622 ctx.cb_sequence = 0;
4623 guestfs_set_send_callback (g, file_send_cb, &ctx);
4624 (void) ml->main_loop_run (ml, g);
4625 guestfs_set_send_callback (g, NULL, NULL);
4626 if (ctx.cb_sequence != 1) {
4627 error (g, "%s send failed, see earlier error messages", "guestfs_file");
4631 ctx.cb_sequence = 0;
4632 guestfs_set_reply_callback (g, file_reply_cb, &ctx);
4633 (void) ml->main_loop_run (ml, g);
4634 guestfs_set_reply_callback (g, NULL, NULL);
4635 if (ctx.cb_sequence != 1000) {
4636 error (g, "%s reply failed, see earlier error messages", "guestfs_file");
4640 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FILE, serial) == -1)
4643 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4644 error (g, "%s", ctx.err.error_message);
4648 return ctx.ret.description; /* caller will free */
4651 struct command_ctx {
4652 /* This flag is set by the callbacks, so we know we've done
4653 * the callbacks as expected, and in the right sequence.
4654 * 0 = not called, 1 = send called,
4655 * 2.. = send_file called,
4656 * 1000 = reply called.
4659 struct guestfs_message_header hdr;
4660 struct guestfs_message_error err;
4661 struct guestfs_command_ret ret;
4664 static void command_send_cb (guestfs_h *g, void *data)
4666 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4667 struct command_ctx *ctx = (struct command_ctx *) data;
4669 guestfs__switch_to_receiving (g);
4670 ctx->cb_sequence = 1;
4671 ml->main_loop_quit (ml, g);
4674 static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4676 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4677 struct command_ctx *ctx = (struct command_ctx *) data;
4679 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4680 error (g, "%s: failed to parse reply header", "guestfs_command");
4683 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4684 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4685 error (g, "%s: failed to parse reply error", "guestfs_command");
4690 if (!xdr_guestfs_command_ret (xdr, &ctx->ret)) {
4691 error (g, "%s: failed to parse reply", "guestfs_command");
4695 ctx->cb_sequence = 1000;
4696 ml->main_loop_quit (ml, g);
4699 char *guestfs_command (guestfs_h *g,
4700 char * const* const arguments)
4702 struct guestfs_command_args args;
4703 struct command_ctx ctx;
4704 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4707 if (check_state (g, "guestfs_command") == -1) return NULL;
4709 memset (&ctx, 0, sizeof ctx);
4711 args.arguments.arguments_val = (char **) arguments;
4712 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4713 serial = guestfs__send (g, GUESTFS_PROC_COMMAND,
4714 (xdrproc_t) xdr_guestfs_command_args, (char *) &args);
4718 ctx.cb_sequence = 0;
4719 guestfs_set_send_callback (g, command_send_cb, &ctx);
4720 (void) ml->main_loop_run (ml, g);
4721 guestfs_set_send_callback (g, NULL, NULL);
4722 if (ctx.cb_sequence != 1) {
4723 error (g, "%s send failed, see earlier error messages", "guestfs_command");
4727 ctx.cb_sequence = 0;
4728 guestfs_set_reply_callback (g, command_reply_cb, &ctx);
4729 (void) ml->main_loop_run (ml, g);
4730 guestfs_set_reply_callback (g, NULL, NULL);
4731 if (ctx.cb_sequence != 1000) {
4732 error (g, "%s reply failed, see earlier error messages", "guestfs_command");
4736 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND, serial) == -1)
4739 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4740 error (g, "%s", ctx.err.error_message);
4744 return ctx.ret.output; /* caller will free */
4747 struct command_lines_ctx {
4748 /* This flag is set by the callbacks, so we know we've done
4749 * the callbacks as expected, and in the right sequence.
4750 * 0 = not called, 1 = send called,
4751 * 2.. = send_file called,
4752 * 1000 = reply called.
4755 struct guestfs_message_header hdr;
4756 struct guestfs_message_error err;
4757 struct guestfs_command_lines_ret ret;
4760 static void command_lines_send_cb (guestfs_h *g, void *data)
4762 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4763 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
4765 guestfs__switch_to_receiving (g);
4766 ctx->cb_sequence = 1;
4767 ml->main_loop_quit (ml, g);
4770 static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4772 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4773 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
4775 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4776 error (g, "%s: failed to parse reply header", "guestfs_command_lines");
4779 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4780 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4781 error (g, "%s: failed to parse reply error", "guestfs_command_lines");
4786 if (!xdr_guestfs_command_lines_ret (xdr, &ctx->ret)) {
4787 error (g, "%s: failed to parse reply", "guestfs_command_lines");
4791 ctx->cb_sequence = 1000;
4792 ml->main_loop_quit (ml, g);
4795 char **guestfs_command_lines (guestfs_h *g,
4796 char * const* const arguments)
4798 struct guestfs_command_lines_args args;
4799 struct command_lines_ctx ctx;
4800 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4803 if (check_state (g, "guestfs_command_lines") == -1) return NULL;
4805 memset (&ctx, 0, sizeof ctx);
4807 args.arguments.arguments_val = (char **) arguments;
4808 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4809 serial = guestfs__send (g, GUESTFS_PROC_COMMAND_LINES,
4810 (xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args);
4814 ctx.cb_sequence = 0;
4815 guestfs_set_send_callback (g, command_lines_send_cb, &ctx);
4816 (void) ml->main_loop_run (ml, g);
4817 guestfs_set_send_callback (g, NULL, NULL);
4818 if (ctx.cb_sequence != 1) {
4819 error (g, "%s send failed, see earlier error messages", "guestfs_command_lines");
4823 ctx.cb_sequence = 0;
4824 guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx);
4825 (void) ml->main_loop_run (ml, g);
4826 guestfs_set_reply_callback (g, NULL, NULL);
4827 if (ctx.cb_sequence != 1000) {
4828 error (g, "%s reply failed, see earlier error messages", "guestfs_command_lines");
4832 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND_LINES, serial) == -1)
4835 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4836 error (g, "%s", ctx.err.error_message);
4840 /* caller will free this, but we need to add a NULL entry */
4841 ctx.ret.lines.lines_val =
4842 safe_realloc (g, ctx.ret.lines.lines_val,
4843 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
4844 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
4845 return ctx.ret.lines.lines_val;
4849 /* This flag is set by the callbacks, so we know we've done
4850 * the callbacks as expected, and in the right sequence.
4851 * 0 = not called, 1 = send called,
4852 * 2.. = send_file called,
4853 * 1000 = reply called.
4856 struct guestfs_message_header hdr;
4857 struct guestfs_message_error err;
4858 struct guestfs_stat_ret ret;
4861 static void stat_send_cb (guestfs_h *g, void *data)
4863 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4864 struct stat_ctx *ctx = (struct stat_ctx *) data;
4866 guestfs__switch_to_receiving (g);
4867 ctx->cb_sequence = 1;
4868 ml->main_loop_quit (ml, g);
4871 static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4873 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4874 struct stat_ctx *ctx = (struct stat_ctx *) data;
4876 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4877 error (g, "%s: failed to parse reply header", "guestfs_stat");
4880 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4881 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4882 error (g, "%s: failed to parse reply error", "guestfs_stat");
4887 if (!xdr_guestfs_stat_ret (xdr, &ctx->ret)) {
4888 error (g, "%s: failed to parse reply", "guestfs_stat");
4892 ctx->cb_sequence = 1000;
4893 ml->main_loop_quit (ml, g);
4896 struct guestfs_stat *guestfs_stat (guestfs_h *g,
4899 struct guestfs_stat_args args;
4900 struct stat_ctx ctx;
4901 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4904 if (check_state (g, "guestfs_stat") == -1) return NULL;
4906 memset (&ctx, 0, sizeof ctx);
4908 args.path = (char *) path;
4909 serial = guestfs__send (g, GUESTFS_PROC_STAT,
4910 (xdrproc_t) xdr_guestfs_stat_args, (char *) &args);
4914 ctx.cb_sequence = 0;
4915 guestfs_set_send_callback (g, stat_send_cb, &ctx);
4916 (void) ml->main_loop_run (ml, g);
4917 guestfs_set_send_callback (g, NULL, NULL);
4918 if (ctx.cb_sequence != 1) {
4919 error (g, "%s send failed, see earlier error messages", "guestfs_stat");
4923 ctx.cb_sequence = 0;
4924 guestfs_set_reply_callback (g, stat_reply_cb, &ctx);
4925 (void) ml->main_loop_run (ml, g);
4926 guestfs_set_reply_callback (g, NULL, NULL);
4927 if (ctx.cb_sequence != 1000) {
4928 error (g, "%s reply failed, see earlier error messages", "guestfs_stat");
4932 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STAT, serial) == -1)
4935 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4936 error (g, "%s", ctx.err.error_message);
4940 /* caller will free this */
4941 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4945 /* This flag is set by the callbacks, so we know we've done
4946 * the callbacks as expected, and in the right sequence.
4947 * 0 = not called, 1 = send called,
4948 * 2.. = send_file called,
4949 * 1000 = reply called.
4952 struct guestfs_message_header hdr;
4953 struct guestfs_message_error err;
4954 struct guestfs_lstat_ret ret;
4957 static void lstat_send_cb (guestfs_h *g, void *data)
4959 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4960 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4962 guestfs__switch_to_receiving (g);
4963 ctx->cb_sequence = 1;
4964 ml->main_loop_quit (ml, g);
4967 static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4969 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4970 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4972 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4973 error (g, "%s: failed to parse reply header", "guestfs_lstat");
4976 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4977 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4978 error (g, "%s: failed to parse reply error", "guestfs_lstat");
4983 if (!xdr_guestfs_lstat_ret (xdr, &ctx->ret)) {
4984 error (g, "%s: failed to parse reply", "guestfs_lstat");
4988 ctx->cb_sequence = 1000;
4989 ml->main_loop_quit (ml, g);
4992 struct guestfs_stat *guestfs_lstat (guestfs_h *g,
4995 struct guestfs_lstat_args args;
4996 struct lstat_ctx ctx;
4997 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5000 if (check_state (g, "guestfs_lstat") == -1) return NULL;
5002 memset (&ctx, 0, sizeof ctx);
5004 args.path = (char *) path;
5005 serial = guestfs__send (g, GUESTFS_PROC_LSTAT,
5006 (xdrproc_t) xdr_guestfs_lstat_args, (char *) &args);
5010 ctx.cb_sequence = 0;
5011 guestfs_set_send_callback (g, lstat_send_cb, &ctx);
5012 (void) ml->main_loop_run (ml, g);
5013 guestfs_set_send_callback (g, NULL, NULL);
5014 if (ctx.cb_sequence != 1) {
5015 error (g, "%s send failed, see earlier error messages", "guestfs_lstat");
5019 ctx.cb_sequence = 0;
5020 guestfs_set_reply_callback (g, lstat_reply_cb, &ctx);
5021 (void) ml->main_loop_run (ml, g);
5022 guestfs_set_reply_callback (g, NULL, NULL);
5023 if (ctx.cb_sequence != 1000) {
5024 error (g, "%s reply failed, see earlier error messages", "guestfs_lstat");
5028 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LSTAT, serial) == -1)
5031 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5032 error (g, "%s", ctx.err.error_message);
5036 /* caller will free this */
5037 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
5040 struct statvfs_ctx {
5041 /* This flag is set by the callbacks, so we know we've done
5042 * the callbacks as expected, and in the right sequence.
5043 * 0 = not called, 1 = send called,
5044 * 2.. = send_file called,
5045 * 1000 = reply called.
5048 struct guestfs_message_header hdr;
5049 struct guestfs_message_error err;
5050 struct guestfs_statvfs_ret ret;
5053 static void statvfs_send_cb (guestfs_h *g, void *data)
5055 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5056 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
5058 guestfs__switch_to_receiving (g);
5059 ctx->cb_sequence = 1;
5060 ml->main_loop_quit (ml, g);
5063 static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5065 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5066 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
5068 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5069 error (g, "%s: failed to parse reply header", "guestfs_statvfs");
5072 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5073 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5074 error (g, "%s: failed to parse reply error", "guestfs_statvfs");
5079 if (!xdr_guestfs_statvfs_ret (xdr, &ctx->ret)) {
5080 error (g, "%s: failed to parse reply", "guestfs_statvfs");
5084 ctx->cb_sequence = 1000;
5085 ml->main_loop_quit (ml, g);
5088 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
5091 struct guestfs_statvfs_args args;
5092 struct statvfs_ctx ctx;
5093 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5096 if (check_state (g, "guestfs_statvfs") == -1) return NULL;
5098 memset (&ctx, 0, sizeof ctx);
5100 args.path = (char *) path;
5101 serial = guestfs__send (g, GUESTFS_PROC_STATVFS,
5102 (xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args);
5106 ctx.cb_sequence = 0;
5107 guestfs_set_send_callback (g, statvfs_send_cb, &ctx);
5108 (void) ml->main_loop_run (ml, g);
5109 guestfs_set_send_callback (g, NULL, NULL);
5110 if (ctx.cb_sequence != 1) {
5111 error (g, "%s send failed, see earlier error messages", "guestfs_statvfs");
5115 ctx.cb_sequence = 0;
5116 guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx);
5117 (void) ml->main_loop_run (ml, g);
5118 guestfs_set_reply_callback (g, NULL, NULL);
5119 if (ctx.cb_sequence != 1000) {
5120 error (g, "%s reply failed, see earlier error messages", "guestfs_statvfs");
5124 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STATVFS, serial) == -1)
5127 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5128 error (g, "%s", ctx.err.error_message);
5132 /* caller will free this */
5133 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
5136 struct tune2fs_l_ctx {
5137 /* This flag is set by the callbacks, so we know we've done
5138 * the callbacks as expected, and in the right sequence.
5139 * 0 = not called, 1 = send called,
5140 * 2.. = send_file called,
5141 * 1000 = reply called.
5144 struct guestfs_message_header hdr;
5145 struct guestfs_message_error err;
5146 struct guestfs_tune2fs_l_ret ret;
5149 static void tune2fs_l_send_cb (guestfs_h *g, void *data)
5151 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5152 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
5154 guestfs__switch_to_receiving (g);
5155 ctx->cb_sequence = 1;
5156 ml->main_loop_quit (ml, g);
5159 static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5161 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5162 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
5164 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5165 error (g, "%s: failed to parse reply header", "guestfs_tune2fs_l");
5168 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5169 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5170 error (g, "%s: failed to parse reply error", "guestfs_tune2fs_l");
5175 if (!xdr_guestfs_tune2fs_l_ret (xdr, &ctx->ret)) {
5176 error (g, "%s: failed to parse reply", "guestfs_tune2fs_l");
5180 ctx->cb_sequence = 1000;
5181 ml->main_loop_quit (ml, g);
5184 char **guestfs_tune2fs_l (guestfs_h *g,
5187 struct guestfs_tune2fs_l_args args;
5188 struct tune2fs_l_ctx ctx;
5189 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5192 if (check_state (g, "guestfs_tune2fs_l") == -1) return NULL;
5194 memset (&ctx, 0, sizeof ctx);
5196 args.device = (char *) device;
5197 serial = guestfs__send (g, GUESTFS_PROC_TUNE2FS_L,
5198 (xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args);
5202 ctx.cb_sequence = 0;
5203 guestfs_set_send_callback (g, tune2fs_l_send_cb, &ctx);
5204 (void) ml->main_loop_run (ml, g);
5205 guestfs_set_send_callback (g, NULL, NULL);
5206 if (ctx.cb_sequence != 1) {
5207 error (g, "%s send failed, see earlier error messages", "guestfs_tune2fs_l");
5211 ctx.cb_sequence = 0;
5212 guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx);
5213 (void) ml->main_loop_run (ml, g);
5214 guestfs_set_reply_callback (g, NULL, NULL);
5215 if (ctx.cb_sequence != 1000) {
5216 error (g, "%s reply failed, see earlier error messages", "guestfs_tune2fs_l");
5220 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TUNE2FS_L, serial) == -1)
5223 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5224 error (g, "%s", ctx.err.error_message);
5228 /* caller will free this, but we need to add a NULL entry */
5229 ctx.ret.superblock.superblock_val =
5230 safe_realloc (g, ctx.ret.superblock.superblock_val,
5231 sizeof (char *) * (ctx.ret.superblock.superblock_len + 1));
5232 ctx.ret.superblock.superblock_val[ctx.ret.superblock.superblock_len] = NULL;
5233 return ctx.ret.superblock.superblock_val;
5236 struct blockdev_setro_ctx {
5237 /* This flag is set by the callbacks, so we know we've done
5238 * the callbacks as expected, and in the right sequence.
5239 * 0 = not called, 1 = send called,
5240 * 2.. = send_file called,
5241 * 1000 = reply called.
5244 struct guestfs_message_header hdr;
5245 struct guestfs_message_error err;
5248 static void blockdev_setro_send_cb (guestfs_h *g, void *data)
5250 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5251 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
5253 guestfs__switch_to_receiving (g);
5254 ctx->cb_sequence = 1;
5255 ml->main_loop_quit (ml, g);
5258 static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5260 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5261 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
5263 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5264 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setro");
5267 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5268 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5269 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setro");
5275 ctx->cb_sequence = 1000;
5276 ml->main_loop_quit (ml, g);
5279 int guestfs_blockdev_setro (guestfs_h *g,
5282 struct guestfs_blockdev_setro_args args;
5283 struct blockdev_setro_ctx ctx;
5284 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5287 if (check_state (g, "guestfs_blockdev_setro") == -1) return -1;
5289 memset (&ctx, 0, sizeof ctx);
5291 args.device = (char *) device;
5292 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETRO,
5293 (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args);
5297 ctx.cb_sequence = 0;
5298 guestfs_set_send_callback (g, blockdev_setro_send_cb, &ctx);
5299 (void) ml->main_loop_run (ml, g);
5300 guestfs_set_send_callback (g, NULL, NULL);
5301 if (ctx.cb_sequence != 1) {
5302 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setro");
5306 ctx.cb_sequence = 0;
5307 guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx);
5308 (void) ml->main_loop_run (ml, g);
5309 guestfs_set_reply_callback (g, NULL, NULL);
5310 if (ctx.cb_sequence != 1000) {
5311 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setro");
5315 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1)
5318 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5319 error (g, "%s", ctx.err.error_message);
5326 struct blockdev_setrw_ctx {
5327 /* This flag is set by the callbacks, so we know we've done
5328 * the callbacks as expected, and in the right sequence.
5329 * 0 = not called, 1 = send called,
5330 * 2.. = send_file called,
5331 * 1000 = reply called.
5334 struct guestfs_message_header hdr;
5335 struct guestfs_message_error err;
5338 static void blockdev_setrw_send_cb (guestfs_h *g, void *data)
5340 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5341 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
5343 guestfs__switch_to_receiving (g);
5344 ctx->cb_sequence = 1;
5345 ml->main_loop_quit (ml, g);
5348 static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5350 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5351 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
5353 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5354 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setrw");
5357 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5358 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5359 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setrw");
5365 ctx->cb_sequence = 1000;
5366 ml->main_loop_quit (ml, g);
5369 int guestfs_blockdev_setrw (guestfs_h *g,
5372 struct guestfs_blockdev_setrw_args args;
5373 struct blockdev_setrw_ctx ctx;
5374 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5377 if (check_state (g, "guestfs_blockdev_setrw") == -1) return -1;
5379 memset (&ctx, 0, sizeof ctx);
5381 args.device = (char *) device;
5382 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETRW,
5383 (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args);
5387 ctx.cb_sequence = 0;
5388 guestfs_set_send_callback (g, blockdev_setrw_send_cb, &ctx);
5389 (void) ml->main_loop_run (ml, g);
5390 guestfs_set_send_callback (g, NULL, NULL);
5391 if (ctx.cb_sequence != 1) {
5392 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setrw");
5396 ctx.cb_sequence = 0;
5397 guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx);
5398 (void) ml->main_loop_run (ml, g);
5399 guestfs_set_reply_callback (g, NULL, NULL);
5400 if (ctx.cb_sequence != 1000) {
5401 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setrw");
5405 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1)
5408 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5409 error (g, "%s", ctx.err.error_message);
5416 struct blockdev_getro_ctx {
5417 /* This flag is set by the callbacks, so we know we've done
5418 * the callbacks as expected, and in the right sequence.
5419 * 0 = not called, 1 = send called,
5420 * 2.. = send_file called,
5421 * 1000 = reply called.
5424 struct guestfs_message_header hdr;
5425 struct guestfs_message_error err;
5426 struct guestfs_blockdev_getro_ret ret;
5429 static void blockdev_getro_send_cb (guestfs_h *g, void *data)
5431 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5432 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
5434 guestfs__switch_to_receiving (g);
5435 ctx->cb_sequence = 1;
5436 ml->main_loop_quit (ml, g);
5439 static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5441 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5442 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
5444 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5445 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getro");
5448 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5449 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5450 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getro");
5455 if (!xdr_guestfs_blockdev_getro_ret (xdr, &ctx->ret)) {
5456 error (g, "%s: failed to parse reply", "guestfs_blockdev_getro");
5460 ctx->cb_sequence = 1000;
5461 ml->main_loop_quit (ml, g);
5464 int guestfs_blockdev_getro (guestfs_h *g,
5467 struct guestfs_blockdev_getro_args args;
5468 struct blockdev_getro_ctx ctx;
5469 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5472 if (check_state (g, "guestfs_blockdev_getro") == -1) return -1;
5474 memset (&ctx, 0, sizeof ctx);
5476 args.device = (char *) device;
5477 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETRO,
5478 (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args);
5482 ctx.cb_sequence = 0;
5483 guestfs_set_send_callback (g, blockdev_getro_send_cb, &ctx);
5484 (void) ml->main_loop_run (ml, g);
5485 guestfs_set_send_callback (g, NULL, NULL);
5486 if (ctx.cb_sequence != 1) {
5487 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getro");
5491 ctx.cb_sequence = 0;
5492 guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx);
5493 (void) ml->main_loop_run (ml, g);
5494 guestfs_set_reply_callback (g, NULL, NULL);
5495 if (ctx.cb_sequence != 1000) {
5496 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getro");
5500 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1)
5503 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5504 error (g, "%s", ctx.err.error_message);
5511 struct blockdev_getss_ctx {
5512 /* This flag is set by the callbacks, so we know we've done
5513 * the callbacks as expected, and in the right sequence.
5514 * 0 = not called, 1 = send called,
5515 * 2.. = send_file called,
5516 * 1000 = reply called.
5519 struct guestfs_message_header hdr;
5520 struct guestfs_message_error err;
5521 struct guestfs_blockdev_getss_ret ret;
5524 static void blockdev_getss_send_cb (guestfs_h *g, void *data)
5526 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5527 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
5529 guestfs__switch_to_receiving (g);
5530 ctx->cb_sequence = 1;
5531 ml->main_loop_quit (ml, g);
5534 static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5536 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5537 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
5539 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5540 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getss");
5543 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5544 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5545 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getss");
5550 if (!xdr_guestfs_blockdev_getss_ret (xdr, &ctx->ret)) {
5551 error (g, "%s: failed to parse reply", "guestfs_blockdev_getss");
5555 ctx->cb_sequence = 1000;
5556 ml->main_loop_quit (ml, g);
5559 int guestfs_blockdev_getss (guestfs_h *g,
5562 struct guestfs_blockdev_getss_args args;
5563 struct blockdev_getss_ctx ctx;
5564 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5567 if (check_state (g, "guestfs_blockdev_getss") == -1) return -1;
5569 memset (&ctx, 0, sizeof ctx);
5571 args.device = (char *) device;
5572 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSS,
5573 (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args);
5577 ctx.cb_sequence = 0;
5578 guestfs_set_send_callback (g, blockdev_getss_send_cb, &ctx);
5579 (void) ml->main_loop_run (ml, g);
5580 guestfs_set_send_callback (g, NULL, NULL);
5581 if (ctx.cb_sequence != 1) {
5582 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getss");
5586 ctx.cb_sequence = 0;
5587 guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx);
5588 (void) ml->main_loop_run (ml, g);
5589 guestfs_set_reply_callback (g, NULL, NULL);
5590 if (ctx.cb_sequence != 1000) {
5591 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getss");
5595 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1)
5598 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5599 error (g, "%s", ctx.err.error_message);
5603 return ctx.ret.sectorsize;
5606 struct blockdev_getbsz_ctx {
5607 /* This flag is set by the callbacks, so we know we've done
5608 * the callbacks as expected, and in the right sequence.
5609 * 0 = not called, 1 = send called,
5610 * 2.. = send_file called,
5611 * 1000 = reply called.
5614 struct guestfs_message_header hdr;
5615 struct guestfs_message_error err;
5616 struct guestfs_blockdev_getbsz_ret ret;
5619 static void blockdev_getbsz_send_cb (guestfs_h *g, void *data)
5621 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5622 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
5624 guestfs__switch_to_receiving (g);
5625 ctx->cb_sequence = 1;
5626 ml->main_loop_quit (ml, g);
5629 static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5631 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5632 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
5634 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5635 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getbsz");
5638 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5639 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5640 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getbsz");
5645 if (!xdr_guestfs_blockdev_getbsz_ret (xdr, &ctx->ret)) {
5646 error (g, "%s: failed to parse reply", "guestfs_blockdev_getbsz");
5650 ctx->cb_sequence = 1000;
5651 ml->main_loop_quit (ml, g);
5654 int guestfs_blockdev_getbsz (guestfs_h *g,
5657 struct guestfs_blockdev_getbsz_args args;
5658 struct blockdev_getbsz_ctx ctx;
5659 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5662 if (check_state (g, "guestfs_blockdev_getbsz") == -1) return -1;
5664 memset (&ctx, 0, sizeof ctx);
5666 args.device = (char *) device;
5667 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETBSZ,
5668 (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args);
5672 ctx.cb_sequence = 0;
5673 guestfs_set_send_callback (g, blockdev_getbsz_send_cb, &ctx);
5674 (void) ml->main_loop_run (ml, g);
5675 guestfs_set_send_callback (g, NULL, NULL);
5676 if (ctx.cb_sequence != 1) {
5677 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getbsz");
5681 ctx.cb_sequence = 0;
5682 guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx);
5683 (void) ml->main_loop_run (ml, g);
5684 guestfs_set_reply_callback (g, NULL, NULL);
5685 if (ctx.cb_sequence != 1000) {
5686 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getbsz");
5690 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1)
5693 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5694 error (g, "%s", ctx.err.error_message);
5698 return ctx.ret.blocksize;
5701 struct blockdev_setbsz_ctx {
5702 /* This flag is set by the callbacks, so we know we've done
5703 * the callbacks as expected, and in the right sequence.
5704 * 0 = not called, 1 = send called,
5705 * 2.. = send_file called,
5706 * 1000 = reply called.
5709 struct guestfs_message_header hdr;
5710 struct guestfs_message_error err;
5713 static void blockdev_setbsz_send_cb (guestfs_h *g, void *data)
5715 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5716 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
5718 guestfs__switch_to_receiving (g);
5719 ctx->cb_sequence = 1;
5720 ml->main_loop_quit (ml, g);
5723 static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5725 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5726 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
5728 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5729 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setbsz");
5732 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5733 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5734 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setbsz");
5740 ctx->cb_sequence = 1000;
5741 ml->main_loop_quit (ml, g);
5744 int guestfs_blockdev_setbsz (guestfs_h *g,
5748 struct guestfs_blockdev_setbsz_args args;
5749 struct blockdev_setbsz_ctx ctx;
5750 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5753 if (check_state (g, "guestfs_blockdev_setbsz") == -1) return -1;
5755 memset (&ctx, 0, sizeof ctx);
5757 args.device = (char *) device;
5758 args.blocksize = blocksize;
5759 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETBSZ,
5760 (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args);
5764 ctx.cb_sequence = 0;
5765 guestfs_set_send_callback (g, blockdev_setbsz_send_cb, &ctx);
5766 (void) ml->main_loop_run (ml, g);
5767 guestfs_set_send_callback (g, NULL, NULL);
5768 if (ctx.cb_sequence != 1) {
5769 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setbsz");
5773 ctx.cb_sequence = 0;
5774 guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx);
5775 (void) ml->main_loop_run (ml, g);
5776 guestfs_set_reply_callback (g, NULL, NULL);
5777 if (ctx.cb_sequence != 1000) {
5778 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setbsz");
5782 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1)
5785 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5786 error (g, "%s", ctx.err.error_message);
5793 struct blockdev_getsz_ctx {
5794 /* This flag is set by the callbacks, so we know we've done
5795 * the callbacks as expected, and in the right sequence.
5796 * 0 = not called, 1 = send called,
5797 * 2.. = send_file called,
5798 * 1000 = reply called.
5801 struct guestfs_message_header hdr;
5802 struct guestfs_message_error err;
5803 struct guestfs_blockdev_getsz_ret ret;
5806 static void blockdev_getsz_send_cb (guestfs_h *g, void *data)
5808 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5809 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
5811 guestfs__switch_to_receiving (g);
5812 ctx->cb_sequence = 1;
5813 ml->main_loop_quit (ml, g);
5816 static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5818 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5819 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
5821 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5822 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsz");
5825 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5826 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5827 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsz");
5832 if (!xdr_guestfs_blockdev_getsz_ret (xdr, &ctx->ret)) {
5833 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsz");
5837 ctx->cb_sequence = 1000;
5838 ml->main_loop_quit (ml, g);
5841 int64_t guestfs_blockdev_getsz (guestfs_h *g,
5844 struct guestfs_blockdev_getsz_args args;
5845 struct blockdev_getsz_ctx ctx;
5846 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5849 if (check_state (g, "guestfs_blockdev_getsz") == -1) return -1;
5851 memset (&ctx, 0, sizeof ctx);
5853 args.device = (char *) device;
5854 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSZ,
5855 (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args);
5859 ctx.cb_sequence = 0;
5860 guestfs_set_send_callback (g, blockdev_getsz_send_cb, &ctx);
5861 (void) ml->main_loop_run (ml, g);
5862 guestfs_set_send_callback (g, NULL, NULL);
5863 if (ctx.cb_sequence != 1) {
5864 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getsz");
5868 ctx.cb_sequence = 0;
5869 guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx);
5870 (void) ml->main_loop_run (ml, g);
5871 guestfs_set_reply_callback (g, NULL, NULL);
5872 if (ctx.cb_sequence != 1000) {
5873 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsz");
5877 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1)
5880 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5881 error (g, "%s", ctx.err.error_message);
5885 return ctx.ret.sizeinsectors;
5888 struct blockdev_getsize64_ctx {
5889 /* This flag is set by the callbacks, so we know we've done
5890 * the callbacks as expected, and in the right sequence.
5891 * 0 = not called, 1 = send called,
5892 * 2.. = send_file called,
5893 * 1000 = reply called.
5896 struct guestfs_message_header hdr;
5897 struct guestfs_message_error err;
5898 struct guestfs_blockdev_getsize64_ret ret;
5901 static void blockdev_getsize64_send_cb (guestfs_h *g, void *data)
5903 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5904 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
5906 guestfs__switch_to_receiving (g);
5907 ctx->cb_sequence = 1;
5908 ml->main_loop_quit (ml, g);
5911 static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5913 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5914 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
5916 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5917 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsize64");
5920 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5921 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5922 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsize64");
5927 if (!xdr_guestfs_blockdev_getsize64_ret (xdr, &ctx->ret)) {
5928 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsize64");
5932 ctx->cb_sequence = 1000;
5933 ml->main_loop_quit (ml, g);
5936 int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
5939 struct guestfs_blockdev_getsize64_args args;
5940 struct blockdev_getsize64_ctx ctx;
5941 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5944 if (check_state (g, "guestfs_blockdev_getsize64") == -1) return -1;
5946 memset (&ctx, 0, sizeof ctx);
5948 args.device = (char *) device;
5949 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64,
5950 (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args);
5954 ctx.cb_sequence = 0;
5955 guestfs_set_send_callback (g, blockdev_getsize64_send_cb, &ctx);
5956 (void) ml->main_loop_run (ml, g);
5957 guestfs_set_send_callback (g, NULL, NULL);
5958 if (ctx.cb_sequence != 1) {
5959 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getsize64");
5963 ctx.cb_sequence = 0;
5964 guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx);
5965 (void) ml->main_loop_run (ml, g);
5966 guestfs_set_reply_callback (g, NULL, NULL);
5967 if (ctx.cb_sequence != 1000) {
5968 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsize64");
5972 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1)
5975 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5976 error (g, "%s", ctx.err.error_message);
5980 return ctx.ret.sizeinbytes;
5983 struct blockdev_flushbufs_ctx {
5984 /* This flag is set by the callbacks, so we know we've done
5985 * the callbacks as expected, and in the right sequence.
5986 * 0 = not called, 1 = send called,
5987 * 2.. = send_file called,
5988 * 1000 = reply called.
5991 struct guestfs_message_header hdr;
5992 struct guestfs_message_error err;
5995 static void blockdev_flushbufs_send_cb (guestfs_h *g, void *data)
5997 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5998 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
6000 guestfs__switch_to_receiving (g);
6001 ctx->cb_sequence = 1;
6002 ml->main_loop_quit (ml, g);
6005 static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6007 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6008 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
6010 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6011 error (g, "%s: failed to parse reply header", "guestfs_blockdev_flushbufs");
6014 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6015 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6016 error (g, "%s: failed to parse reply error", "guestfs_blockdev_flushbufs");
6022 ctx->cb_sequence = 1000;
6023 ml->main_loop_quit (ml, g);
6026 int guestfs_blockdev_flushbufs (guestfs_h *g,
6029 struct guestfs_blockdev_flushbufs_args args;
6030 struct blockdev_flushbufs_ctx ctx;
6031 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6034 if (check_state (g, "guestfs_blockdev_flushbufs") == -1) return -1;
6036 memset (&ctx, 0, sizeof ctx);
6038 args.device = (char *) device;
6039 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS,
6040 (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args);
6044 ctx.cb_sequence = 0;
6045 guestfs_set_send_callback (g, blockdev_flushbufs_send_cb, &ctx);
6046 (void) ml->main_loop_run (ml, g);
6047 guestfs_set_send_callback (g, NULL, NULL);
6048 if (ctx.cb_sequence != 1) {
6049 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_flushbufs");
6053 ctx.cb_sequence = 0;
6054 guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx);
6055 (void) ml->main_loop_run (ml, g);
6056 guestfs_set_reply_callback (g, NULL, NULL);
6057 if (ctx.cb_sequence != 1000) {
6058 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_flushbufs");
6062 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1)
6065 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6066 error (g, "%s", ctx.err.error_message);
6073 struct blockdev_rereadpt_ctx {
6074 /* This flag is set by the callbacks, so we know we've done
6075 * the callbacks as expected, and in the right sequence.
6076 * 0 = not called, 1 = send called,
6077 * 2.. = send_file called,
6078 * 1000 = reply called.
6081 struct guestfs_message_header hdr;
6082 struct guestfs_message_error err;
6085 static void blockdev_rereadpt_send_cb (guestfs_h *g, void *data)
6087 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6088 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
6090 guestfs__switch_to_receiving (g);
6091 ctx->cb_sequence = 1;
6092 ml->main_loop_quit (ml, g);
6095 static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6097 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6098 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
6100 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6101 error (g, "%s: failed to parse reply header", "guestfs_blockdev_rereadpt");
6104 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6105 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6106 error (g, "%s: failed to parse reply error", "guestfs_blockdev_rereadpt");
6112 ctx->cb_sequence = 1000;
6113 ml->main_loop_quit (ml, g);
6116 int guestfs_blockdev_rereadpt (guestfs_h *g,
6119 struct guestfs_blockdev_rereadpt_args args;
6120 struct blockdev_rereadpt_ctx ctx;
6121 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6124 if (check_state (g, "guestfs_blockdev_rereadpt") == -1) return -1;
6126 memset (&ctx, 0, sizeof ctx);
6128 args.device = (char *) device;
6129 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_REREADPT,
6130 (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args);
6134 ctx.cb_sequence = 0;
6135 guestfs_set_send_callback (g, blockdev_rereadpt_send_cb, &ctx);
6136 (void) ml->main_loop_run (ml, g);
6137 guestfs_set_send_callback (g, NULL, NULL);
6138 if (ctx.cb_sequence != 1) {
6139 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_rereadpt");
6143 ctx.cb_sequence = 0;
6144 guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx);
6145 (void) ml->main_loop_run (ml, g);
6146 guestfs_set_reply_callback (g, NULL, NULL);
6147 if (ctx.cb_sequence != 1000) {
6148 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_rereadpt");
6152 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1)
6155 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6156 error (g, "%s", ctx.err.error_message);