1 /* libguestfs generated file
2 * WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 * ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
5 * Copyright (C) 2009 Red Hat Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "guestfs_protocol.h"
28 #define error guestfs_error
29 #define perrorf guestfs_perrorf
30 #define safe_malloc guestfs_safe_malloc
31 #define safe_realloc guestfs_safe_realloc
32 #define safe_strdup guestfs_safe_strdup
33 #define safe_memdup guestfs_safe_memdup
35 /* Check the return message from a call for validity. */
37 check_reply_header (guestfs_h *g,
38 const struct guestfs_message_header *hdr,
39 int proc_nr, int serial)
41 if (hdr->prog != GUESTFS_PROGRAM) {
42 error (g, "wrong program (%d/%d)", hdr->prog, GUESTFS_PROGRAM);
45 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
46 error (g, "wrong protocol version (%d/%d)",
47 hdr->vers, GUESTFS_PROTOCOL_VERSION);
50 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
51 error (g, "unexpected message direction (%d/%d)",
52 hdr->direction, GUESTFS_DIRECTION_REPLY);
55 if (hdr->proc != proc_nr) {
56 error (g, "unexpected procedure number (%d/%d)", hdr->proc, proc_nr);
59 if (hdr->serial != serial) {
60 error (g, "unexpected serial (%d/%d)", hdr->serial, serial);
67 /* Check we are in the right state to run a high-level action. */
69 check_state (guestfs_h *g, const char *caller)
71 if (!guestfs_is_ready (g)) {
72 if (guestfs_is_config (g))
73 error (g, "%s: call launch() before using this function",
75 else if (guestfs_is_launching (g))
76 error (g, "%s: call wait_ready() before using this function",
79 error (g, "%s called from the wrong state, %d != READY",
80 caller, guestfs_get_state (g));
87 /* This flag is set by the callbacks, so we know we've done
88 * the callbacks as expected, and in the right sequence.
89 * 0 = not called, 1 = send called,
90 * 1001 = reply called.
93 struct guestfs_message_header hdr;
94 struct guestfs_message_error err;
97 static void mount_send_cb (guestfs_h *g, void *data)
99 guestfs_main_loop *ml = guestfs_get_main_loop (g);
100 struct mount_ctx *ctx = (struct mount_ctx *) data;
102 ctx->cb_sequence = 1;
103 ml->main_loop_quit (ml, g);
106 static void mount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
108 guestfs_main_loop *ml = guestfs_get_main_loop (g);
109 struct mount_ctx *ctx = (struct mount_ctx *) data;
111 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
112 error (g, "%s: failed to parse reply header", "guestfs_mount");
115 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
116 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
117 error (g, "%s: failed to parse reply error", "guestfs_mount");
123 ctx->cb_sequence = 1001;
124 ml->main_loop_quit (ml, g);
127 int guestfs_mount (guestfs_h *g,
129 const char *mountpoint)
131 struct guestfs_mount_args args;
132 struct mount_ctx ctx;
133 guestfs_main_loop *ml = guestfs_get_main_loop (g);
136 if (check_state (g, "guestfs_mount") == -1) return -1;
138 memset (&ctx, 0, sizeof ctx);
140 args.device = (char *) device;
141 args.mountpoint = (char *) mountpoint;
142 serial = guestfs__send (g, GUESTFS_PROC_MOUNT,
143 (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
148 guestfs_set_send_callback (g, mount_send_cb, &ctx);
149 (void) ml->main_loop_run (ml, g);
150 guestfs_set_send_callback (g, NULL, NULL);
151 if (ctx.cb_sequence != 1) {
152 error (g, "%s send failed, see earlier error messages", "guestfs_mount");
156 guestfs__switch_to_receiving (g);
158 guestfs_set_reply_callback (g, mount_reply_cb, &ctx);
159 (void) ml->main_loop_run (ml, g);
160 guestfs_set_reply_callback (g, NULL, NULL);
161 if (ctx.cb_sequence != 1001) {
162 error (g, "%s reply failed, see earlier error messages", "guestfs_mount");
166 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
169 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
170 error (g, "%s", ctx.err.error_message);
178 /* This flag is set by the callbacks, so we know we've done
179 * the callbacks as expected, and in the right sequence.
180 * 0 = not called, 1 = send called,
181 * 1001 = reply called.
184 struct guestfs_message_header hdr;
185 struct guestfs_message_error err;
188 static void sync_send_cb (guestfs_h *g, void *data)
190 guestfs_main_loop *ml = guestfs_get_main_loop (g);
191 struct sync_ctx *ctx = (struct sync_ctx *) data;
193 ctx->cb_sequence = 1;
194 ml->main_loop_quit (ml, g);
197 static void sync_reply_cb (guestfs_h *g, void *data, XDR *xdr)
199 guestfs_main_loop *ml = guestfs_get_main_loop (g);
200 struct sync_ctx *ctx = (struct sync_ctx *) data;
202 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
203 error (g, "%s: failed to parse reply header", "guestfs_sync");
206 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
207 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
208 error (g, "%s: failed to parse reply error", "guestfs_sync");
214 ctx->cb_sequence = 1001;
215 ml->main_loop_quit (ml, g);
218 int guestfs_sync (guestfs_h *g)
221 guestfs_main_loop *ml = guestfs_get_main_loop (g);
224 if (check_state (g, "guestfs_sync") == -1) return -1;
226 memset (&ctx, 0, sizeof ctx);
228 serial = guestfs__send (g, GUESTFS_PROC_SYNC, NULL, NULL);
233 guestfs_set_send_callback (g, sync_send_cb, &ctx);
234 (void) ml->main_loop_run (ml, g);
235 guestfs_set_send_callback (g, NULL, NULL);
236 if (ctx.cb_sequence != 1) {
237 error (g, "%s send failed, see earlier error messages", "guestfs_sync");
241 guestfs__switch_to_receiving (g);
243 guestfs_set_reply_callback (g, sync_reply_cb, &ctx);
244 (void) ml->main_loop_run (ml, g);
245 guestfs_set_reply_callback (g, NULL, NULL);
246 if (ctx.cb_sequence != 1001) {
247 error (g, "%s reply failed, see earlier error messages", "guestfs_sync");
251 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SYNC, serial) == -1)
254 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
255 error (g, "%s", ctx.err.error_message);
263 /* This flag is set by the callbacks, so we know we've done
264 * the callbacks as expected, and in the right sequence.
265 * 0 = not called, 1 = send called,
266 * 1001 = reply called.
269 struct guestfs_message_header hdr;
270 struct guestfs_message_error err;
273 static void touch_send_cb (guestfs_h *g, void *data)
275 guestfs_main_loop *ml = guestfs_get_main_loop (g);
276 struct touch_ctx *ctx = (struct touch_ctx *) data;
278 ctx->cb_sequence = 1;
279 ml->main_loop_quit (ml, g);
282 static void touch_reply_cb (guestfs_h *g, void *data, XDR *xdr)
284 guestfs_main_loop *ml = guestfs_get_main_loop (g);
285 struct touch_ctx *ctx = (struct touch_ctx *) data;
287 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
288 error (g, "%s: failed to parse reply header", "guestfs_touch");
291 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
292 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
293 error (g, "%s: failed to parse reply error", "guestfs_touch");
299 ctx->cb_sequence = 1001;
300 ml->main_loop_quit (ml, g);
303 int guestfs_touch (guestfs_h *g,
306 struct guestfs_touch_args args;
307 struct touch_ctx ctx;
308 guestfs_main_loop *ml = guestfs_get_main_loop (g);
311 if (check_state (g, "guestfs_touch") == -1) return -1;
313 memset (&ctx, 0, sizeof ctx);
315 args.path = (char *) path;
316 serial = guestfs__send (g, GUESTFS_PROC_TOUCH,
317 (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
322 guestfs_set_send_callback (g, touch_send_cb, &ctx);
323 (void) ml->main_loop_run (ml, g);
324 guestfs_set_send_callback (g, NULL, NULL);
325 if (ctx.cb_sequence != 1) {
326 error (g, "%s send failed, see earlier error messages", "guestfs_touch");
330 guestfs__switch_to_receiving (g);
332 guestfs_set_reply_callback (g, touch_reply_cb, &ctx);
333 (void) ml->main_loop_run (ml, g);
334 guestfs_set_reply_callback (g, NULL, NULL);
335 if (ctx.cb_sequence != 1001) {
336 error (g, "%s reply failed, see earlier error messages", "guestfs_touch");
340 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
343 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
344 error (g, "%s", ctx.err.error_message);
352 /* This flag is set by the callbacks, so we know we've done
353 * the callbacks as expected, and in the right sequence.
354 * 0 = not called, 1 = send called,
355 * 1001 = reply called.
358 struct guestfs_message_header hdr;
359 struct guestfs_message_error err;
360 struct guestfs_cat_ret ret;
363 static void cat_send_cb (guestfs_h *g, void *data)
365 guestfs_main_loop *ml = guestfs_get_main_loop (g);
366 struct cat_ctx *ctx = (struct cat_ctx *) data;
368 ctx->cb_sequence = 1;
369 ml->main_loop_quit (ml, g);
372 static void cat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
374 guestfs_main_loop *ml = guestfs_get_main_loop (g);
375 struct cat_ctx *ctx = (struct cat_ctx *) data;
377 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
378 error (g, "%s: failed to parse reply header", "guestfs_cat");
381 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
382 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
383 error (g, "%s: failed to parse reply error", "guestfs_cat");
388 if (!xdr_guestfs_cat_ret (xdr, &ctx->ret)) {
389 error (g, "%s: failed to parse reply", "guestfs_cat");
393 ctx->cb_sequence = 1001;
394 ml->main_loop_quit (ml, g);
397 char *guestfs_cat (guestfs_h *g,
400 struct guestfs_cat_args args;
402 guestfs_main_loop *ml = guestfs_get_main_loop (g);
405 if (check_state (g, "guestfs_cat") == -1) return NULL;
407 memset (&ctx, 0, sizeof ctx);
409 args.path = (char *) path;
410 serial = guestfs__send (g, GUESTFS_PROC_CAT,
411 (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
416 guestfs_set_send_callback (g, cat_send_cb, &ctx);
417 (void) ml->main_loop_run (ml, g);
418 guestfs_set_send_callback (g, NULL, NULL);
419 if (ctx.cb_sequence != 1) {
420 error (g, "%s send failed, see earlier error messages", "guestfs_cat");
424 guestfs__switch_to_receiving (g);
426 guestfs_set_reply_callback (g, cat_reply_cb, &ctx);
427 (void) ml->main_loop_run (ml, g);
428 guestfs_set_reply_callback (g, NULL, NULL);
429 if (ctx.cb_sequence != 1001) {
430 error (g, "%s reply failed, see earlier error messages", "guestfs_cat");
434 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CAT, serial) == -1)
437 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
438 error (g, "%s", ctx.err.error_message);
442 return ctx.ret.content; /* caller will free */
446 /* This flag is set by the callbacks, so we know we've done
447 * the callbacks as expected, and in the right sequence.
448 * 0 = not called, 1 = send called,
449 * 1001 = reply called.
452 struct guestfs_message_header hdr;
453 struct guestfs_message_error err;
454 struct guestfs_ll_ret ret;
457 static void ll_send_cb (guestfs_h *g, void *data)
459 guestfs_main_loop *ml = guestfs_get_main_loop (g);
460 struct ll_ctx *ctx = (struct ll_ctx *) data;
462 ctx->cb_sequence = 1;
463 ml->main_loop_quit (ml, g);
466 static void ll_reply_cb (guestfs_h *g, void *data, XDR *xdr)
468 guestfs_main_loop *ml = guestfs_get_main_loop (g);
469 struct ll_ctx *ctx = (struct ll_ctx *) data;
471 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
472 error (g, "%s: failed to parse reply header", "guestfs_ll");
475 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
476 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
477 error (g, "%s: failed to parse reply error", "guestfs_ll");
482 if (!xdr_guestfs_ll_ret (xdr, &ctx->ret)) {
483 error (g, "%s: failed to parse reply", "guestfs_ll");
487 ctx->cb_sequence = 1001;
488 ml->main_loop_quit (ml, g);
491 char *guestfs_ll (guestfs_h *g,
492 const char *directory)
494 struct guestfs_ll_args args;
496 guestfs_main_loop *ml = guestfs_get_main_loop (g);
499 if (check_state (g, "guestfs_ll") == -1) return NULL;
501 memset (&ctx, 0, sizeof ctx);
503 args.directory = (char *) directory;
504 serial = guestfs__send (g, GUESTFS_PROC_LL,
505 (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
510 guestfs_set_send_callback (g, ll_send_cb, &ctx);
511 (void) ml->main_loop_run (ml, g);
512 guestfs_set_send_callback (g, NULL, NULL);
513 if (ctx.cb_sequence != 1) {
514 error (g, "%s send failed, see earlier error messages", "guestfs_ll");
518 guestfs__switch_to_receiving (g);
520 guestfs_set_reply_callback (g, ll_reply_cb, &ctx);
521 (void) ml->main_loop_run (ml, g);
522 guestfs_set_reply_callback (g, NULL, NULL);
523 if (ctx.cb_sequence != 1001) {
524 error (g, "%s reply failed, see earlier error messages", "guestfs_ll");
528 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LL, serial) == -1)
531 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
532 error (g, "%s", ctx.err.error_message);
536 return ctx.ret.listing; /* caller will free */
540 /* This flag is set by the callbacks, so we know we've done
541 * the callbacks as expected, and in the right sequence.
542 * 0 = not called, 1 = send called,
543 * 1001 = reply called.
546 struct guestfs_message_header hdr;
547 struct guestfs_message_error err;
548 struct guestfs_ls_ret ret;
551 static void ls_send_cb (guestfs_h *g, void *data)
553 guestfs_main_loop *ml = guestfs_get_main_loop (g);
554 struct ls_ctx *ctx = (struct ls_ctx *) data;
556 ctx->cb_sequence = 1;
557 ml->main_loop_quit (ml, g);
560 static void ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
562 guestfs_main_loop *ml = guestfs_get_main_loop (g);
563 struct ls_ctx *ctx = (struct ls_ctx *) data;
565 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
566 error (g, "%s: failed to parse reply header", "guestfs_ls");
569 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
570 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
571 error (g, "%s: failed to parse reply error", "guestfs_ls");
576 if (!xdr_guestfs_ls_ret (xdr, &ctx->ret)) {
577 error (g, "%s: failed to parse reply", "guestfs_ls");
581 ctx->cb_sequence = 1001;
582 ml->main_loop_quit (ml, g);
585 char **guestfs_ls (guestfs_h *g,
586 const char *directory)
588 struct guestfs_ls_args args;
590 guestfs_main_loop *ml = guestfs_get_main_loop (g);
593 if (check_state (g, "guestfs_ls") == -1) return NULL;
595 memset (&ctx, 0, sizeof ctx);
597 args.directory = (char *) directory;
598 serial = guestfs__send (g, GUESTFS_PROC_LS,
599 (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
604 guestfs_set_send_callback (g, ls_send_cb, &ctx);
605 (void) ml->main_loop_run (ml, g);
606 guestfs_set_send_callback (g, NULL, NULL);
607 if (ctx.cb_sequence != 1) {
608 error (g, "%s send failed, see earlier error messages", "guestfs_ls");
612 guestfs__switch_to_receiving (g);
614 guestfs_set_reply_callback (g, ls_reply_cb, &ctx);
615 (void) ml->main_loop_run (ml, g);
616 guestfs_set_reply_callback (g, NULL, NULL);
617 if (ctx.cb_sequence != 1001) {
618 error (g, "%s reply failed, see earlier error messages", "guestfs_ls");
622 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LS, serial) == -1)
625 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
626 error (g, "%s", ctx.err.error_message);
630 /* caller will free this, but we need to add a NULL entry */
631 ctx.ret.listing.listing_val =
632 safe_realloc (g, ctx.ret.listing.listing_val,
633 sizeof (char *) * (ctx.ret.listing.listing_len + 1));
634 ctx.ret.listing.listing_val[ctx.ret.listing.listing_len] = NULL;
635 return ctx.ret.listing.listing_val;
638 struct list_devices_ctx {
639 /* This flag is set by the callbacks, so we know we've done
640 * the callbacks as expected, and in the right sequence.
641 * 0 = not called, 1 = send called,
642 * 1001 = reply called.
645 struct guestfs_message_header hdr;
646 struct guestfs_message_error err;
647 struct guestfs_list_devices_ret ret;
650 static void list_devices_send_cb (guestfs_h *g, void *data)
652 guestfs_main_loop *ml = guestfs_get_main_loop (g);
653 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
655 ctx->cb_sequence = 1;
656 ml->main_loop_quit (ml, g);
659 static void list_devices_reply_cb (guestfs_h *g, void *data, XDR *xdr)
661 guestfs_main_loop *ml = guestfs_get_main_loop (g);
662 struct list_devices_ctx *ctx = (struct list_devices_ctx *) data;
664 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
665 error (g, "%s: failed to parse reply header", "guestfs_list_devices");
668 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
669 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
670 error (g, "%s: failed to parse reply error", "guestfs_list_devices");
675 if (!xdr_guestfs_list_devices_ret (xdr, &ctx->ret)) {
676 error (g, "%s: failed to parse reply", "guestfs_list_devices");
680 ctx->cb_sequence = 1001;
681 ml->main_loop_quit (ml, g);
684 char **guestfs_list_devices (guestfs_h *g)
686 struct list_devices_ctx ctx;
687 guestfs_main_loop *ml = guestfs_get_main_loop (g);
690 if (check_state (g, "guestfs_list_devices") == -1) return NULL;
692 memset (&ctx, 0, sizeof ctx);
694 serial = guestfs__send (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
699 guestfs_set_send_callback (g, list_devices_send_cb, &ctx);
700 (void) ml->main_loop_run (ml, g);
701 guestfs_set_send_callback (g, NULL, NULL);
702 if (ctx.cb_sequence != 1) {
703 error (g, "%s send failed, see earlier error messages", "guestfs_list_devices");
707 guestfs__switch_to_receiving (g);
709 guestfs_set_reply_callback (g, list_devices_reply_cb, &ctx);
710 (void) ml->main_loop_run (ml, g);
711 guestfs_set_reply_callback (g, NULL, NULL);
712 if (ctx.cb_sequence != 1001) {
713 error (g, "%s reply failed, see earlier error messages", "guestfs_list_devices");
717 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1)
720 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
721 error (g, "%s", ctx.err.error_message);
725 /* caller will free this, but we need to add a NULL entry */
726 ctx.ret.devices.devices_val =
727 safe_realloc (g, ctx.ret.devices.devices_val,
728 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
729 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
730 return ctx.ret.devices.devices_val;
733 struct list_partitions_ctx {
734 /* This flag is set by the callbacks, so we know we've done
735 * the callbacks as expected, and in the right sequence.
736 * 0 = not called, 1 = send called,
737 * 1001 = reply called.
740 struct guestfs_message_header hdr;
741 struct guestfs_message_error err;
742 struct guestfs_list_partitions_ret ret;
745 static void list_partitions_send_cb (guestfs_h *g, void *data)
747 guestfs_main_loop *ml = guestfs_get_main_loop (g);
748 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
750 ctx->cb_sequence = 1;
751 ml->main_loop_quit (ml, g);
754 static void list_partitions_reply_cb (guestfs_h *g, void *data, XDR *xdr)
756 guestfs_main_loop *ml = guestfs_get_main_loop (g);
757 struct list_partitions_ctx *ctx = (struct list_partitions_ctx *) data;
759 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
760 error (g, "%s: failed to parse reply header", "guestfs_list_partitions");
763 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
764 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
765 error (g, "%s: failed to parse reply error", "guestfs_list_partitions");
770 if (!xdr_guestfs_list_partitions_ret (xdr, &ctx->ret)) {
771 error (g, "%s: failed to parse reply", "guestfs_list_partitions");
775 ctx->cb_sequence = 1001;
776 ml->main_loop_quit (ml, g);
779 char **guestfs_list_partitions (guestfs_h *g)
781 struct list_partitions_ctx ctx;
782 guestfs_main_loop *ml = guestfs_get_main_loop (g);
785 if (check_state (g, "guestfs_list_partitions") == -1) return NULL;
787 memset (&ctx, 0, sizeof ctx);
789 serial = guestfs__send (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
794 guestfs_set_send_callback (g, list_partitions_send_cb, &ctx);
795 (void) ml->main_loop_run (ml, g);
796 guestfs_set_send_callback (g, NULL, NULL);
797 if (ctx.cb_sequence != 1) {
798 error (g, "%s send failed, see earlier error messages", "guestfs_list_partitions");
802 guestfs__switch_to_receiving (g);
804 guestfs_set_reply_callback (g, list_partitions_reply_cb, &ctx);
805 (void) ml->main_loop_run (ml, g);
806 guestfs_set_reply_callback (g, NULL, NULL);
807 if (ctx.cb_sequence != 1001) {
808 error (g, "%s reply failed, see earlier error messages", "guestfs_list_partitions");
812 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1)
815 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
816 error (g, "%s", ctx.err.error_message);
820 /* caller will free this, but we need to add a NULL entry */
821 ctx.ret.partitions.partitions_val =
822 safe_realloc (g, ctx.ret.partitions.partitions_val,
823 sizeof (char *) * (ctx.ret.partitions.partitions_len + 1));
824 ctx.ret.partitions.partitions_val[ctx.ret.partitions.partitions_len] = NULL;
825 return ctx.ret.partitions.partitions_val;
829 /* This flag is set by the callbacks, so we know we've done
830 * the callbacks as expected, and in the right sequence.
831 * 0 = not called, 1 = send called,
832 * 1001 = reply called.
835 struct guestfs_message_header hdr;
836 struct guestfs_message_error err;
837 struct guestfs_pvs_ret ret;
840 static void pvs_send_cb (guestfs_h *g, void *data)
842 guestfs_main_loop *ml = guestfs_get_main_loop (g);
843 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
845 ctx->cb_sequence = 1;
846 ml->main_loop_quit (ml, g);
849 static void pvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
851 guestfs_main_loop *ml = guestfs_get_main_loop (g);
852 struct pvs_ctx *ctx = (struct pvs_ctx *) data;
854 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
855 error (g, "%s: failed to parse reply header", "guestfs_pvs");
858 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
859 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
860 error (g, "%s: failed to parse reply error", "guestfs_pvs");
865 if (!xdr_guestfs_pvs_ret (xdr, &ctx->ret)) {
866 error (g, "%s: failed to parse reply", "guestfs_pvs");
870 ctx->cb_sequence = 1001;
871 ml->main_loop_quit (ml, g);
874 char **guestfs_pvs (guestfs_h *g)
877 guestfs_main_loop *ml = guestfs_get_main_loop (g);
880 if (check_state (g, "guestfs_pvs") == -1) return NULL;
882 memset (&ctx, 0, sizeof ctx);
884 serial = guestfs__send (g, GUESTFS_PROC_PVS, NULL, NULL);
889 guestfs_set_send_callback (g, pvs_send_cb, &ctx);
890 (void) ml->main_loop_run (ml, g);
891 guestfs_set_send_callback (g, NULL, NULL);
892 if (ctx.cb_sequence != 1) {
893 error (g, "%s send failed, see earlier error messages", "guestfs_pvs");
897 guestfs__switch_to_receiving (g);
899 guestfs_set_reply_callback (g, pvs_reply_cb, &ctx);
900 (void) ml->main_loop_run (ml, g);
901 guestfs_set_reply_callback (g, NULL, NULL);
902 if (ctx.cb_sequence != 1001) {
903 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs");
907 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS, serial) == -1)
910 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
911 error (g, "%s", ctx.err.error_message);
915 /* caller will free this, but we need to add a NULL entry */
916 ctx.ret.physvols.physvols_val =
917 safe_realloc (g, ctx.ret.physvols.physvols_val,
918 sizeof (char *) * (ctx.ret.physvols.physvols_len + 1));
919 ctx.ret.physvols.physvols_val[ctx.ret.physvols.physvols_len] = NULL;
920 return ctx.ret.physvols.physvols_val;
924 /* This flag is set by the callbacks, so we know we've done
925 * the callbacks as expected, and in the right sequence.
926 * 0 = not called, 1 = send called,
927 * 1001 = reply called.
930 struct guestfs_message_header hdr;
931 struct guestfs_message_error err;
932 struct guestfs_vgs_ret ret;
935 static void vgs_send_cb (guestfs_h *g, void *data)
937 guestfs_main_loop *ml = guestfs_get_main_loop (g);
938 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
940 ctx->cb_sequence = 1;
941 ml->main_loop_quit (ml, g);
944 static void vgs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
946 guestfs_main_loop *ml = guestfs_get_main_loop (g);
947 struct vgs_ctx *ctx = (struct vgs_ctx *) data;
949 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
950 error (g, "%s: failed to parse reply header", "guestfs_vgs");
953 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
954 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
955 error (g, "%s: failed to parse reply error", "guestfs_vgs");
960 if (!xdr_guestfs_vgs_ret (xdr, &ctx->ret)) {
961 error (g, "%s: failed to parse reply", "guestfs_vgs");
965 ctx->cb_sequence = 1001;
966 ml->main_loop_quit (ml, g);
969 char **guestfs_vgs (guestfs_h *g)
972 guestfs_main_loop *ml = guestfs_get_main_loop (g);
975 if (check_state (g, "guestfs_vgs") == -1) return NULL;
977 memset (&ctx, 0, sizeof ctx);
979 serial = guestfs__send (g, GUESTFS_PROC_VGS, NULL, NULL);
984 guestfs_set_send_callback (g, vgs_send_cb, &ctx);
985 (void) ml->main_loop_run (ml, g);
986 guestfs_set_send_callback (g, NULL, NULL);
987 if (ctx.cb_sequence != 1) {
988 error (g, "%s send failed, see earlier error messages", "guestfs_vgs");
992 guestfs__switch_to_receiving (g);
994 guestfs_set_reply_callback (g, vgs_reply_cb, &ctx);
995 (void) ml->main_loop_run (ml, g);
996 guestfs_set_reply_callback (g, NULL, NULL);
997 if (ctx.cb_sequence != 1001) {
998 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs");
1002 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS, serial) == -1)
1005 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1006 error (g, "%s", ctx.err.error_message);
1010 /* caller will free this, but we need to add a NULL entry */
1011 ctx.ret.volgroups.volgroups_val =
1012 safe_realloc (g, ctx.ret.volgroups.volgroups_val,
1013 sizeof (char *) * (ctx.ret.volgroups.volgroups_len + 1));
1014 ctx.ret.volgroups.volgroups_val[ctx.ret.volgroups.volgroups_len] = NULL;
1015 return ctx.ret.volgroups.volgroups_val;
1019 /* This flag is set by the callbacks, so we know we've done
1020 * the callbacks as expected, and in the right sequence.
1021 * 0 = not called, 1 = send called,
1022 * 1001 = reply called.
1025 struct guestfs_message_header hdr;
1026 struct guestfs_message_error err;
1027 struct guestfs_lvs_ret ret;
1030 static void lvs_send_cb (guestfs_h *g, void *data)
1032 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1033 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
1035 ctx->cb_sequence = 1;
1036 ml->main_loop_quit (ml, g);
1039 static void lvs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1041 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1042 struct lvs_ctx *ctx = (struct lvs_ctx *) data;
1044 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1045 error (g, "%s: failed to parse reply header", "guestfs_lvs");
1048 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1049 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1050 error (g, "%s: failed to parse reply error", "guestfs_lvs");
1055 if (!xdr_guestfs_lvs_ret (xdr, &ctx->ret)) {
1056 error (g, "%s: failed to parse reply", "guestfs_lvs");
1060 ctx->cb_sequence = 1001;
1061 ml->main_loop_quit (ml, g);
1064 char **guestfs_lvs (guestfs_h *g)
1067 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1070 if (check_state (g, "guestfs_lvs") == -1) return NULL;
1072 memset (&ctx, 0, sizeof ctx);
1074 serial = guestfs__send (g, GUESTFS_PROC_LVS, NULL, NULL);
1078 ctx.cb_sequence = 0;
1079 guestfs_set_send_callback (g, lvs_send_cb, &ctx);
1080 (void) ml->main_loop_run (ml, g);
1081 guestfs_set_send_callback (g, NULL, NULL);
1082 if (ctx.cb_sequence != 1) {
1083 error (g, "%s send failed, see earlier error messages", "guestfs_lvs");
1087 guestfs__switch_to_receiving (g);
1088 ctx.cb_sequence = 0;
1089 guestfs_set_reply_callback (g, lvs_reply_cb, &ctx);
1090 (void) ml->main_loop_run (ml, g);
1091 guestfs_set_reply_callback (g, NULL, NULL);
1092 if (ctx.cb_sequence != 1001) {
1093 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs");
1097 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS, serial) == -1)
1100 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1101 error (g, "%s", ctx.err.error_message);
1105 /* caller will free this, but we need to add a NULL entry */
1106 ctx.ret.logvols.logvols_val =
1107 safe_realloc (g, ctx.ret.logvols.logvols_val,
1108 sizeof (char *) * (ctx.ret.logvols.logvols_len + 1));
1109 ctx.ret.logvols.logvols_val[ctx.ret.logvols.logvols_len] = NULL;
1110 return ctx.ret.logvols.logvols_val;
1113 struct pvs_full_ctx {
1114 /* This flag is set by the callbacks, so we know we've done
1115 * the callbacks as expected, and in the right sequence.
1116 * 0 = not called, 1 = send called,
1117 * 1001 = reply called.
1120 struct guestfs_message_header hdr;
1121 struct guestfs_message_error err;
1122 struct guestfs_pvs_full_ret ret;
1125 static void pvs_full_send_cb (guestfs_h *g, void *data)
1127 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1128 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
1130 ctx->cb_sequence = 1;
1131 ml->main_loop_quit (ml, g);
1134 static void pvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1136 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1137 struct pvs_full_ctx *ctx = (struct pvs_full_ctx *) data;
1139 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1140 error (g, "%s: failed to parse reply header", "guestfs_pvs_full");
1143 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1144 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1145 error (g, "%s: failed to parse reply error", "guestfs_pvs_full");
1150 if (!xdr_guestfs_pvs_full_ret (xdr, &ctx->ret)) {
1151 error (g, "%s: failed to parse reply", "guestfs_pvs_full");
1155 ctx->cb_sequence = 1001;
1156 ml->main_loop_quit (ml, g);
1159 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
1161 struct pvs_full_ctx ctx;
1162 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1165 if (check_state (g, "guestfs_pvs_full") == -1) return NULL;
1167 memset (&ctx, 0, sizeof ctx);
1169 serial = guestfs__send (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
1173 ctx.cb_sequence = 0;
1174 guestfs_set_send_callback (g, pvs_full_send_cb, &ctx);
1175 (void) ml->main_loop_run (ml, g);
1176 guestfs_set_send_callback (g, NULL, NULL);
1177 if (ctx.cb_sequence != 1) {
1178 error (g, "%s send failed, see earlier error messages", "guestfs_pvs_full");
1182 guestfs__switch_to_receiving (g);
1183 ctx.cb_sequence = 0;
1184 guestfs_set_reply_callback (g, pvs_full_reply_cb, &ctx);
1185 (void) ml->main_loop_run (ml, g);
1186 guestfs_set_reply_callback (g, NULL, NULL);
1187 if (ctx.cb_sequence != 1001) {
1188 error (g, "%s reply failed, see earlier error messages", "guestfs_pvs_full");
1192 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1)
1195 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1196 error (g, "%s", ctx.err.error_message);
1200 /* caller will free this */
1201 return safe_memdup (g, &ctx.ret.physvols, sizeof (ctx.ret.physvols));
1204 struct vgs_full_ctx {
1205 /* This flag is set by the callbacks, so we know we've done
1206 * the callbacks as expected, and in the right sequence.
1207 * 0 = not called, 1 = send called,
1208 * 1001 = reply called.
1211 struct guestfs_message_header hdr;
1212 struct guestfs_message_error err;
1213 struct guestfs_vgs_full_ret ret;
1216 static void vgs_full_send_cb (guestfs_h *g, void *data)
1218 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1219 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1221 ctx->cb_sequence = 1;
1222 ml->main_loop_quit (ml, g);
1225 static void vgs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1227 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1228 struct vgs_full_ctx *ctx = (struct vgs_full_ctx *) data;
1230 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1231 error (g, "%s: failed to parse reply header", "guestfs_vgs_full");
1234 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1235 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1236 error (g, "%s: failed to parse reply error", "guestfs_vgs_full");
1241 if (!xdr_guestfs_vgs_full_ret (xdr, &ctx->ret)) {
1242 error (g, "%s: failed to parse reply", "guestfs_vgs_full");
1246 ctx->cb_sequence = 1001;
1247 ml->main_loop_quit (ml, g);
1250 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
1252 struct vgs_full_ctx ctx;
1253 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1256 if (check_state (g, "guestfs_vgs_full") == -1) return NULL;
1258 memset (&ctx, 0, sizeof ctx);
1260 serial = guestfs__send (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
1264 ctx.cb_sequence = 0;
1265 guestfs_set_send_callback (g, vgs_full_send_cb, &ctx);
1266 (void) ml->main_loop_run (ml, g);
1267 guestfs_set_send_callback (g, NULL, NULL);
1268 if (ctx.cb_sequence != 1) {
1269 error (g, "%s send failed, see earlier error messages", "guestfs_vgs_full");
1273 guestfs__switch_to_receiving (g);
1274 ctx.cb_sequence = 0;
1275 guestfs_set_reply_callback (g, vgs_full_reply_cb, &ctx);
1276 (void) ml->main_loop_run (ml, g);
1277 guestfs_set_reply_callback (g, NULL, NULL);
1278 if (ctx.cb_sequence != 1001) {
1279 error (g, "%s reply failed, see earlier error messages", "guestfs_vgs_full");
1283 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1)
1286 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1287 error (g, "%s", ctx.err.error_message);
1291 /* caller will free this */
1292 return safe_memdup (g, &ctx.ret.volgroups, sizeof (ctx.ret.volgroups));
1295 struct lvs_full_ctx {
1296 /* This flag is set by the callbacks, so we know we've done
1297 * the callbacks as expected, and in the right sequence.
1298 * 0 = not called, 1 = send called,
1299 * 1001 = reply called.
1302 struct guestfs_message_header hdr;
1303 struct guestfs_message_error err;
1304 struct guestfs_lvs_full_ret ret;
1307 static void lvs_full_send_cb (guestfs_h *g, void *data)
1309 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1310 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1312 ctx->cb_sequence = 1;
1313 ml->main_loop_quit (ml, g);
1316 static void lvs_full_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1318 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1319 struct lvs_full_ctx *ctx = (struct lvs_full_ctx *) data;
1321 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1322 error (g, "%s: failed to parse reply header", "guestfs_lvs_full");
1325 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1326 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1327 error (g, "%s: failed to parse reply error", "guestfs_lvs_full");
1332 if (!xdr_guestfs_lvs_full_ret (xdr, &ctx->ret)) {
1333 error (g, "%s: failed to parse reply", "guestfs_lvs_full");
1337 ctx->cb_sequence = 1001;
1338 ml->main_loop_quit (ml, g);
1341 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
1343 struct lvs_full_ctx ctx;
1344 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1347 if (check_state (g, "guestfs_lvs_full") == -1) return NULL;
1349 memset (&ctx, 0, sizeof ctx);
1351 serial = guestfs__send (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
1355 ctx.cb_sequence = 0;
1356 guestfs_set_send_callback (g, lvs_full_send_cb, &ctx);
1357 (void) ml->main_loop_run (ml, g);
1358 guestfs_set_send_callback (g, NULL, NULL);
1359 if (ctx.cb_sequence != 1) {
1360 error (g, "%s send failed, see earlier error messages", "guestfs_lvs_full");
1364 guestfs__switch_to_receiving (g);
1365 ctx.cb_sequence = 0;
1366 guestfs_set_reply_callback (g, lvs_full_reply_cb, &ctx);
1367 (void) ml->main_loop_run (ml, g);
1368 guestfs_set_reply_callback (g, NULL, NULL);
1369 if (ctx.cb_sequence != 1001) {
1370 error (g, "%s reply failed, see earlier error messages", "guestfs_lvs_full");
1374 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1)
1377 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1378 error (g, "%s", ctx.err.error_message);
1382 /* caller will free this */
1383 return safe_memdup (g, &ctx.ret.logvols, sizeof (ctx.ret.logvols));
1386 struct read_lines_ctx {
1387 /* This flag is set by the callbacks, so we know we've done
1388 * the callbacks as expected, and in the right sequence.
1389 * 0 = not called, 1 = send called,
1390 * 1001 = reply called.
1393 struct guestfs_message_header hdr;
1394 struct guestfs_message_error err;
1395 struct guestfs_read_lines_ret ret;
1398 static void read_lines_send_cb (guestfs_h *g, void *data)
1400 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1401 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1403 ctx->cb_sequence = 1;
1404 ml->main_loop_quit (ml, g);
1407 static void read_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1409 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1410 struct read_lines_ctx *ctx = (struct read_lines_ctx *) data;
1412 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1413 error (g, "%s: failed to parse reply header", "guestfs_read_lines");
1416 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1417 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1418 error (g, "%s: failed to parse reply error", "guestfs_read_lines");
1423 if (!xdr_guestfs_read_lines_ret (xdr, &ctx->ret)) {
1424 error (g, "%s: failed to parse reply", "guestfs_read_lines");
1428 ctx->cb_sequence = 1001;
1429 ml->main_loop_quit (ml, g);
1432 char **guestfs_read_lines (guestfs_h *g,
1435 struct guestfs_read_lines_args args;
1436 struct read_lines_ctx ctx;
1437 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1440 if (check_state (g, "guestfs_read_lines") == -1) return NULL;
1442 memset (&ctx, 0, sizeof ctx);
1444 args.path = (char *) path;
1445 serial = guestfs__send (g, GUESTFS_PROC_READ_LINES,
1446 (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
1450 ctx.cb_sequence = 0;
1451 guestfs_set_send_callback (g, read_lines_send_cb, &ctx);
1452 (void) ml->main_loop_run (ml, g);
1453 guestfs_set_send_callback (g, NULL, NULL);
1454 if (ctx.cb_sequence != 1) {
1455 error (g, "%s send failed, see earlier error messages", "guestfs_read_lines");
1459 guestfs__switch_to_receiving (g);
1460 ctx.cb_sequence = 0;
1461 guestfs_set_reply_callback (g, read_lines_reply_cb, &ctx);
1462 (void) ml->main_loop_run (ml, g);
1463 guestfs_set_reply_callback (g, NULL, NULL);
1464 if (ctx.cb_sequence != 1001) {
1465 error (g, "%s reply failed, see earlier error messages", "guestfs_read_lines");
1469 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_READ_LINES, serial) == -1)
1472 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1473 error (g, "%s", ctx.err.error_message);
1477 /* caller will free this, but we need to add a NULL entry */
1478 ctx.ret.lines.lines_val =
1479 safe_realloc (g, ctx.ret.lines.lines_val,
1480 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
1481 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
1482 return ctx.ret.lines.lines_val;
1485 struct aug_init_ctx {
1486 /* This flag is set by the callbacks, so we know we've done
1487 * the callbacks as expected, and in the right sequence.
1488 * 0 = not called, 1 = send called,
1489 * 1001 = reply called.
1492 struct guestfs_message_header hdr;
1493 struct guestfs_message_error err;
1496 static void aug_init_send_cb (guestfs_h *g, void *data)
1498 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1499 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1501 ctx->cb_sequence = 1;
1502 ml->main_loop_quit (ml, g);
1505 static void aug_init_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1507 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1508 struct aug_init_ctx *ctx = (struct aug_init_ctx *) data;
1510 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1511 error (g, "%s: failed to parse reply header", "guestfs_aug_init");
1514 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1515 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1516 error (g, "%s: failed to parse reply error", "guestfs_aug_init");
1522 ctx->cb_sequence = 1001;
1523 ml->main_loop_quit (ml, g);
1526 int guestfs_aug_init (guestfs_h *g,
1530 struct guestfs_aug_init_args args;
1531 struct aug_init_ctx ctx;
1532 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1535 if (check_state (g, "guestfs_aug_init") == -1) return -1;
1537 memset (&ctx, 0, sizeof ctx);
1539 args.root = (char *) root;
1541 serial = guestfs__send (g, GUESTFS_PROC_AUG_INIT,
1542 (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
1546 ctx.cb_sequence = 0;
1547 guestfs_set_send_callback (g, aug_init_send_cb, &ctx);
1548 (void) ml->main_loop_run (ml, g);
1549 guestfs_set_send_callback (g, NULL, NULL);
1550 if (ctx.cb_sequence != 1) {
1551 error (g, "%s send failed, see earlier error messages", "guestfs_aug_init");
1555 guestfs__switch_to_receiving (g);
1556 ctx.cb_sequence = 0;
1557 guestfs_set_reply_callback (g, aug_init_reply_cb, &ctx);
1558 (void) ml->main_loop_run (ml, g);
1559 guestfs_set_reply_callback (g, NULL, NULL);
1560 if (ctx.cb_sequence != 1001) {
1561 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_init");
1565 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1)
1568 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1569 error (g, "%s", ctx.err.error_message);
1576 struct aug_close_ctx {
1577 /* This flag is set by the callbacks, so we know we've done
1578 * the callbacks as expected, and in the right sequence.
1579 * 0 = not called, 1 = send called,
1580 * 1001 = reply called.
1583 struct guestfs_message_header hdr;
1584 struct guestfs_message_error err;
1587 static void aug_close_send_cb (guestfs_h *g, void *data)
1589 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1590 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1592 ctx->cb_sequence = 1;
1593 ml->main_loop_quit (ml, g);
1596 static void aug_close_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1598 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1599 struct aug_close_ctx *ctx = (struct aug_close_ctx *) data;
1601 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1602 error (g, "%s: failed to parse reply header", "guestfs_aug_close");
1605 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1606 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1607 error (g, "%s: failed to parse reply error", "guestfs_aug_close");
1613 ctx->cb_sequence = 1001;
1614 ml->main_loop_quit (ml, g);
1617 int guestfs_aug_close (guestfs_h *g)
1619 struct aug_close_ctx ctx;
1620 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1623 if (check_state (g, "guestfs_aug_close") == -1) return -1;
1625 memset (&ctx, 0, sizeof ctx);
1627 serial = guestfs__send (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
1631 ctx.cb_sequence = 0;
1632 guestfs_set_send_callback (g, aug_close_send_cb, &ctx);
1633 (void) ml->main_loop_run (ml, g);
1634 guestfs_set_send_callback (g, NULL, NULL);
1635 if (ctx.cb_sequence != 1) {
1636 error (g, "%s send failed, see earlier error messages", "guestfs_aug_close");
1640 guestfs__switch_to_receiving (g);
1641 ctx.cb_sequence = 0;
1642 guestfs_set_reply_callback (g, aug_close_reply_cb, &ctx);
1643 (void) ml->main_loop_run (ml, g);
1644 guestfs_set_reply_callback (g, NULL, NULL);
1645 if (ctx.cb_sequence != 1001) {
1646 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_close");
1650 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1)
1653 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1654 error (g, "%s", ctx.err.error_message);
1661 struct aug_defvar_ctx {
1662 /* This flag is set by the callbacks, so we know we've done
1663 * the callbacks as expected, and in the right sequence.
1664 * 0 = not called, 1 = send called,
1665 * 1001 = reply called.
1668 struct guestfs_message_header hdr;
1669 struct guestfs_message_error err;
1670 struct guestfs_aug_defvar_ret ret;
1673 static void aug_defvar_send_cb (guestfs_h *g, void *data)
1675 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1676 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1678 ctx->cb_sequence = 1;
1679 ml->main_loop_quit (ml, g);
1682 static void aug_defvar_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1684 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1685 struct aug_defvar_ctx *ctx = (struct aug_defvar_ctx *) data;
1687 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1688 error (g, "%s: failed to parse reply header", "guestfs_aug_defvar");
1691 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1692 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1693 error (g, "%s: failed to parse reply error", "guestfs_aug_defvar");
1698 if (!xdr_guestfs_aug_defvar_ret (xdr, &ctx->ret)) {
1699 error (g, "%s: failed to parse reply", "guestfs_aug_defvar");
1703 ctx->cb_sequence = 1001;
1704 ml->main_loop_quit (ml, g);
1707 int guestfs_aug_defvar (guestfs_h *g,
1711 struct guestfs_aug_defvar_args args;
1712 struct aug_defvar_ctx ctx;
1713 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1716 if (check_state (g, "guestfs_aug_defvar") == -1) return -1;
1718 memset (&ctx, 0, sizeof ctx);
1720 args.name = (char *) name;
1721 args.expr = expr ? (char **) &expr : NULL;
1722 serial = guestfs__send (g, GUESTFS_PROC_AUG_DEFVAR,
1723 (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
1727 ctx.cb_sequence = 0;
1728 guestfs_set_send_callback (g, aug_defvar_send_cb, &ctx);
1729 (void) ml->main_loop_run (ml, g);
1730 guestfs_set_send_callback (g, NULL, NULL);
1731 if (ctx.cb_sequence != 1) {
1732 error (g, "%s send failed, see earlier error messages", "guestfs_aug_defvar");
1736 guestfs__switch_to_receiving (g);
1737 ctx.cb_sequence = 0;
1738 guestfs_set_reply_callback (g, aug_defvar_reply_cb, &ctx);
1739 (void) ml->main_loop_run (ml, g);
1740 guestfs_set_reply_callback (g, NULL, NULL);
1741 if (ctx.cb_sequence != 1001) {
1742 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defvar");
1746 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1)
1749 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1750 error (g, "%s", ctx.err.error_message);
1754 return ctx.ret.nrnodes;
1757 struct aug_defnode_ctx {
1758 /* This flag is set by the callbacks, so we know we've done
1759 * the callbacks as expected, and in the right sequence.
1760 * 0 = not called, 1 = send called,
1761 * 1001 = reply called.
1764 struct guestfs_message_header hdr;
1765 struct guestfs_message_error err;
1766 struct guestfs_aug_defnode_ret ret;
1769 static void aug_defnode_send_cb (guestfs_h *g, void *data)
1771 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1772 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1774 ctx->cb_sequence = 1;
1775 ml->main_loop_quit (ml, g);
1778 static void aug_defnode_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1780 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1781 struct aug_defnode_ctx *ctx = (struct aug_defnode_ctx *) data;
1783 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1784 error (g, "%s: failed to parse reply header", "guestfs_aug_defnode");
1787 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1788 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1789 error (g, "%s: failed to parse reply error", "guestfs_aug_defnode");
1794 if (!xdr_guestfs_aug_defnode_ret (xdr, &ctx->ret)) {
1795 error (g, "%s: failed to parse reply", "guestfs_aug_defnode");
1799 ctx->cb_sequence = 1001;
1800 ml->main_loop_quit (ml, g);
1803 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
1808 struct guestfs_aug_defnode_args args;
1809 struct aug_defnode_ctx ctx;
1810 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1813 if (check_state (g, "guestfs_aug_defnode") == -1) return NULL;
1815 memset (&ctx, 0, sizeof ctx);
1817 args.name = (char *) name;
1818 args.expr = (char *) expr;
1819 args.val = (char *) val;
1820 serial = guestfs__send (g, GUESTFS_PROC_AUG_DEFNODE,
1821 (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
1825 ctx.cb_sequence = 0;
1826 guestfs_set_send_callback (g, aug_defnode_send_cb, &ctx);
1827 (void) ml->main_loop_run (ml, g);
1828 guestfs_set_send_callback (g, NULL, NULL);
1829 if (ctx.cb_sequence != 1) {
1830 error (g, "%s send failed, see earlier error messages", "guestfs_aug_defnode");
1834 guestfs__switch_to_receiving (g);
1835 ctx.cb_sequence = 0;
1836 guestfs_set_reply_callback (g, aug_defnode_reply_cb, &ctx);
1837 (void) ml->main_loop_run (ml, g);
1838 guestfs_set_reply_callback (g, NULL, NULL);
1839 if (ctx.cb_sequence != 1001) {
1840 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_defnode");
1844 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1)
1847 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1848 error (g, "%s", ctx.err.error_message);
1852 /* caller with free this */
1853 return safe_memdup (g, &ctx.ret, sizeof (ctx.ret));
1856 struct aug_get_ctx {
1857 /* This flag is set by the callbacks, so we know we've done
1858 * the callbacks as expected, and in the right sequence.
1859 * 0 = not called, 1 = send called,
1860 * 1001 = reply called.
1863 struct guestfs_message_header hdr;
1864 struct guestfs_message_error err;
1865 struct guestfs_aug_get_ret ret;
1868 static void aug_get_send_cb (guestfs_h *g, void *data)
1870 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1871 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1873 ctx->cb_sequence = 1;
1874 ml->main_loop_quit (ml, g);
1877 static void aug_get_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1879 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1880 struct aug_get_ctx *ctx = (struct aug_get_ctx *) data;
1882 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1883 error (g, "%s: failed to parse reply header", "guestfs_aug_get");
1886 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1887 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1888 error (g, "%s: failed to parse reply error", "guestfs_aug_get");
1893 if (!xdr_guestfs_aug_get_ret (xdr, &ctx->ret)) {
1894 error (g, "%s: failed to parse reply", "guestfs_aug_get");
1898 ctx->cb_sequence = 1001;
1899 ml->main_loop_quit (ml, g);
1902 char *guestfs_aug_get (guestfs_h *g,
1905 struct guestfs_aug_get_args args;
1906 struct aug_get_ctx ctx;
1907 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1910 if (check_state (g, "guestfs_aug_get") == -1) return NULL;
1912 memset (&ctx, 0, sizeof ctx);
1914 args.path = (char *) path;
1915 serial = guestfs__send (g, GUESTFS_PROC_AUG_GET,
1916 (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
1920 ctx.cb_sequence = 0;
1921 guestfs_set_send_callback (g, aug_get_send_cb, &ctx);
1922 (void) ml->main_loop_run (ml, g);
1923 guestfs_set_send_callback (g, NULL, NULL);
1924 if (ctx.cb_sequence != 1) {
1925 error (g, "%s send failed, see earlier error messages", "guestfs_aug_get");
1929 guestfs__switch_to_receiving (g);
1930 ctx.cb_sequence = 0;
1931 guestfs_set_reply_callback (g, aug_get_reply_cb, &ctx);
1932 (void) ml->main_loop_run (ml, g);
1933 guestfs_set_reply_callback (g, NULL, NULL);
1934 if (ctx.cb_sequence != 1001) {
1935 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_get");
1939 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_GET, serial) == -1)
1942 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
1943 error (g, "%s", ctx.err.error_message);
1947 return ctx.ret.val; /* caller will free */
1950 struct aug_set_ctx {
1951 /* This flag is set by the callbacks, so we know we've done
1952 * the callbacks as expected, and in the right sequence.
1953 * 0 = not called, 1 = send called,
1954 * 1001 = reply called.
1957 struct guestfs_message_header hdr;
1958 struct guestfs_message_error err;
1961 static void aug_set_send_cb (guestfs_h *g, void *data)
1963 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1964 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1966 ctx->cb_sequence = 1;
1967 ml->main_loop_quit (ml, g);
1970 static void aug_set_reply_cb (guestfs_h *g, void *data, XDR *xdr)
1972 guestfs_main_loop *ml = guestfs_get_main_loop (g);
1973 struct aug_set_ctx *ctx = (struct aug_set_ctx *) data;
1975 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
1976 error (g, "%s: failed to parse reply header", "guestfs_aug_set");
1979 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
1980 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
1981 error (g, "%s: failed to parse reply error", "guestfs_aug_set");
1987 ctx->cb_sequence = 1001;
1988 ml->main_loop_quit (ml, g);
1991 int guestfs_aug_set (guestfs_h *g,
1995 struct guestfs_aug_set_args args;
1996 struct aug_set_ctx ctx;
1997 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2000 if (check_state (g, "guestfs_aug_set") == -1) return -1;
2002 memset (&ctx, 0, sizeof ctx);
2004 args.path = (char *) path;
2005 args.val = (char *) val;
2006 serial = guestfs__send (g, GUESTFS_PROC_AUG_SET,
2007 (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
2011 ctx.cb_sequence = 0;
2012 guestfs_set_send_callback (g, aug_set_send_cb, &ctx);
2013 (void) ml->main_loop_run (ml, g);
2014 guestfs_set_send_callback (g, NULL, NULL);
2015 if (ctx.cb_sequence != 1) {
2016 error (g, "%s send failed, see earlier error messages", "guestfs_aug_set");
2020 guestfs__switch_to_receiving (g);
2021 ctx.cb_sequence = 0;
2022 guestfs_set_reply_callback (g, aug_set_reply_cb, &ctx);
2023 (void) ml->main_loop_run (ml, g);
2024 guestfs_set_reply_callback (g, NULL, NULL);
2025 if (ctx.cb_sequence != 1001) {
2026 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_set");
2030 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SET, serial) == -1)
2033 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2034 error (g, "%s", ctx.err.error_message);
2041 struct aug_insert_ctx {
2042 /* This flag is set by the callbacks, so we know we've done
2043 * the callbacks as expected, and in the right sequence.
2044 * 0 = not called, 1 = send called,
2045 * 1001 = reply called.
2048 struct guestfs_message_header hdr;
2049 struct guestfs_message_error err;
2052 static void aug_insert_send_cb (guestfs_h *g, void *data)
2054 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2055 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
2057 ctx->cb_sequence = 1;
2058 ml->main_loop_quit (ml, g);
2061 static void aug_insert_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2063 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2064 struct aug_insert_ctx *ctx = (struct aug_insert_ctx *) data;
2066 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2067 error (g, "%s: failed to parse reply header", "guestfs_aug_insert");
2070 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2071 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2072 error (g, "%s: failed to parse reply error", "guestfs_aug_insert");
2078 ctx->cb_sequence = 1001;
2079 ml->main_loop_quit (ml, g);
2082 int guestfs_aug_insert (guestfs_h *g,
2087 struct guestfs_aug_insert_args args;
2088 struct aug_insert_ctx ctx;
2089 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2092 if (check_state (g, "guestfs_aug_insert") == -1) return -1;
2094 memset (&ctx, 0, sizeof ctx);
2096 args.path = (char *) path;
2097 args.label = (char *) label;
2098 args.before = before;
2099 serial = guestfs__send (g, GUESTFS_PROC_AUG_INSERT,
2100 (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
2104 ctx.cb_sequence = 0;
2105 guestfs_set_send_callback (g, aug_insert_send_cb, &ctx);
2106 (void) ml->main_loop_run (ml, g);
2107 guestfs_set_send_callback (g, NULL, NULL);
2108 if (ctx.cb_sequence != 1) {
2109 error (g, "%s send failed, see earlier error messages", "guestfs_aug_insert");
2113 guestfs__switch_to_receiving (g);
2114 ctx.cb_sequence = 0;
2115 guestfs_set_reply_callback (g, aug_insert_reply_cb, &ctx);
2116 (void) ml->main_loop_run (ml, g);
2117 guestfs_set_reply_callback (g, NULL, NULL);
2118 if (ctx.cb_sequence != 1001) {
2119 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_insert");
2123 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1)
2126 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2127 error (g, "%s", ctx.err.error_message);
2135 /* This flag is set by the callbacks, so we know we've done
2136 * the callbacks as expected, and in the right sequence.
2137 * 0 = not called, 1 = send called,
2138 * 1001 = reply called.
2141 struct guestfs_message_header hdr;
2142 struct guestfs_message_error err;
2143 struct guestfs_aug_rm_ret ret;
2146 static void aug_rm_send_cb (guestfs_h *g, void *data)
2148 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2149 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
2151 ctx->cb_sequence = 1;
2152 ml->main_loop_quit (ml, g);
2155 static void aug_rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2157 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2158 struct aug_rm_ctx *ctx = (struct aug_rm_ctx *) data;
2160 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2161 error (g, "%s: failed to parse reply header", "guestfs_aug_rm");
2164 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2165 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2166 error (g, "%s: failed to parse reply error", "guestfs_aug_rm");
2171 if (!xdr_guestfs_aug_rm_ret (xdr, &ctx->ret)) {
2172 error (g, "%s: failed to parse reply", "guestfs_aug_rm");
2176 ctx->cb_sequence = 1001;
2177 ml->main_loop_quit (ml, g);
2180 int guestfs_aug_rm (guestfs_h *g,
2183 struct guestfs_aug_rm_args args;
2184 struct aug_rm_ctx ctx;
2185 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2188 if (check_state (g, "guestfs_aug_rm") == -1) return -1;
2190 memset (&ctx, 0, sizeof ctx);
2192 args.path = (char *) path;
2193 serial = guestfs__send (g, GUESTFS_PROC_AUG_RM,
2194 (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
2198 ctx.cb_sequence = 0;
2199 guestfs_set_send_callback (g, aug_rm_send_cb, &ctx);
2200 (void) ml->main_loop_run (ml, g);
2201 guestfs_set_send_callback (g, NULL, NULL);
2202 if (ctx.cb_sequence != 1) {
2203 error (g, "%s send failed, see earlier error messages", "guestfs_aug_rm");
2207 guestfs__switch_to_receiving (g);
2208 ctx.cb_sequence = 0;
2209 guestfs_set_reply_callback (g, aug_rm_reply_cb, &ctx);
2210 (void) ml->main_loop_run (ml, g);
2211 guestfs_set_reply_callback (g, NULL, NULL);
2212 if (ctx.cb_sequence != 1001) {
2213 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_rm");
2217 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_RM, serial) == -1)
2220 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2221 error (g, "%s", ctx.err.error_message);
2225 return ctx.ret.nrnodes;
2229 /* This flag is set by the callbacks, so we know we've done
2230 * the callbacks as expected, and in the right sequence.
2231 * 0 = not called, 1 = send called,
2232 * 1001 = reply called.
2235 struct guestfs_message_header hdr;
2236 struct guestfs_message_error err;
2239 static void aug_mv_send_cb (guestfs_h *g, void *data)
2241 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2242 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
2244 ctx->cb_sequence = 1;
2245 ml->main_loop_quit (ml, g);
2248 static void aug_mv_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2250 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2251 struct aug_mv_ctx *ctx = (struct aug_mv_ctx *) data;
2253 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2254 error (g, "%s: failed to parse reply header", "guestfs_aug_mv");
2257 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2258 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2259 error (g, "%s: failed to parse reply error", "guestfs_aug_mv");
2265 ctx->cb_sequence = 1001;
2266 ml->main_loop_quit (ml, g);
2269 int guestfs_aug_mv (guestfs_h *g,
2273 struct guestfs_aug_mv_args args;
2274 struct aug_mv_ctx ctx;
2275 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2278 if (check_state (g, "guestfs_aug_mv") == -1) return -1;
2280 memset (&ctx, 0, sizeof ctx);
2282 args.src = (char *) src;
2283 args.dest = (char *) dest;
2284 serial = guestfs__send (g, GUESTFS_PROC_AUG_MV,
2285 (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
2289 ctx.cb_sequence = 0;
2290 guestfs_set_send_callback (g, aug_mv_send_cb, &ctx);
2291 (void) ml->main_loop_run (ml, g);
2292 guestfs_set_send_callback (g, NULL, NULL);
2293 if (ctx.cb_sequence != 1) {
2294 error (g, "%s send failed, see earlier error messages", "guestfs_aug_mv");
2298 guestfs__switch_to_receiving (g);
2299 ctx.cb_sequence = 0;
2300 guestfs_set_reply_callback (g, aug_mv_reply_cb, &ctx);
2301 (void) ml->main_loop_run (ml, g);
2302 guestfs_set_reply_callback (g, NULL, NULL);
2303 if (ctx.cb_sequence != 1001) {
2304 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_mv");
2308 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MV, serial) == -1)
2311 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2312 error (g, "%s", ctx.err.error_message);
2319 struct aug_match_ctx {
2320 /* This flag is set by the callbacks, so we know we've done
2321 * the callbacks as expected, and in the right sequence.
2322 * 0 = not called, 1 = send called,
2323 * 1001 = reply called.
2326 struct guestfs_message_header hdr;
2327 struct guestfs_message_error err;
2328 struct guestfs_aug_match_ret ret;
2331 static void aug_match_send_cb (guestfs_h *g, void *data)
2333 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2334 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
2336 ctx->cb_sequence = 1;
2337 ml->main_loop_quit (ml, g);
2340 static void aug_match_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2342 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2343 struct aug_match_ctx *ctx = (struct aug_match_ctx *) data;
2345 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2346 error (g, "%s: failed to parse reply header", "guestfs_aug_match");
2349 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2350 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2351 error (g, "%s: failed to parse reply error", "guestfs_aug_match");
2356 if (!xdr_guestfs_aug_match_ret (xdr, &ctx->ret)) {
2357 error (g, "%s: failed to parse reply", "guestfs_aug_match");
2361 ctx->cb_sequence = 1001;
2362 ml->main_loop_quit (ml, g);
2365 char **guestfs_aug_match (guestfs_h *g,
2368 struct guestfs_aug_match_args args;
2369 struct aug_match_ctx ctx;
2370 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2373 if (check_state (g, "guestfs_aug_match") == -1) return NULL;
2375 memset (&ctx, 0, sizeof ctx);
2377 args.path = (char *) path;
2378 serial = guestfs__send (g, GUESTFS_PROC_AUG_MATCH,
2379 (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
2383 ctx.cb_sequence = 0;
2384 guestfs_set_send_callback (g, aug_match_send_cb, &ctx);
2385 (void) ml->main_loop_run (ml, g);
2386 guestfs_set_send_callback (g, NULL, NULL);
2387 if (ctx.cb_sequence != 1) {
2388 error (g, "%s send failed, see earlier error messages", "guestfs_aug_match");
2392 guestfs__switch_to_receiving (g);
2393 ctx.cb_sequence = 0;
2394 guestfs_set_reply_callback (g, aug_match_reply_cb, &ctx);
2395 (void) ml->main_loop_run (ml, g);
2396 guestfs_set_reply_callback (g, NULL, NULL);
2397 if (ctx.cb_sequence != 1001) {
2398 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_match");
2402 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1)
2405 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2406 error (g, "%s", ctx.err.error_message);
2410 /* caller will free this, but we need to add a NULL entry */
2411 ctx.ret.matches.matches_val =
2412 safe_realloc (g, ctx.ret.matches.matches_val,
2413 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2414 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2415 return ctx.ret.matches.matches_val;
2418 struct aug_save_ctx {
2419 /* This flag is set by the callbacks, so we know we've done
2420 * the callbacks as expected, and in the right sequence.
2421 * 0 = not called, 1 = send called,
2422 * 1001 = reply called.
2425 struct guestfs_message_header hdr;
2426 struct guestfs_message_error err;
2429 static void aug_save_send_cb (guestfs_h *g, void *data)
2431 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2432 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2434 ctx->cb_sequence = 1;
2435 ml->main_loop_quit (ml, g);
2438 static void aug_save_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2440 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2441 struct aug_save_ctx *ctx = (struct aug_save_ctx *) data;
2443 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2444 error (g, "%s: failed to parse reply header", "guestfs_aug_save");
2447 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2448 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2449 error (g, "%s: failed to parse reply error", "guestfs_aug_save");
2455 ctx->cb_sequence = 1001;
2456 ml->main_loop_quit (ml, g);
2459 int guestfs_aug_save (guestfs_h *g)
2461 struct aug_save_ctx ctx;
2462 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2465 if (check_state (g, "guestfs_aug_save") == -1) return -1;
2467 memset (&ctx, 0, sizeof ctx);
2469 serial = guestfs__send (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
2473 ctx.cb_sequence = 0;
2474 guestfs_set_send_callback (g, aug_save_send_cb, &ctx);
2475 (void) ml->main_loop_run (ml, g);
2476 guestfs_set_send_callback (g, NULL, NULL);
2477 if (ctx.cb_sequence != 1) {
2478 error (g, "%s send failed, see earlier error messages", "guestfs_aug_save");
2482 guestfs__switch_to_receiving (g);
2483 ctx.cb_sequence = 0;
2484 guestfs_set_reply_callback (g, aug_save_reply_cb, &ctx);
2485 (void) ml->main_loop_run (ml, g);
2486 guestfs_set_reply_callback (g, NULL, NULL);
2487 if (ctx.cb_sequence != 1001) {
2488 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_save");
2492 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1)
2495 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2496 error (g, "%s", ctx.err.error_message);
2503 struct aug_load_ctx {
2504 /* This flag is set by the callbacks, so we know we've done
2505 * the callbacks as expected, and in the right sequence.
2506 * 0 = not called, 1 = send called,
2507 * 1001 = reply called.
2510 struct guestfs_message_header hdr;
2511 struct guestfs_message_error err;
2514 static void aug_load_send_cb (guestfs_h *g, void *data)
2516 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2517 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2519 ctx->cb_sequence = 1;
2520 ml->main_loop_quit (ml, g);
2523 static void aug_load_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2525 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2526 struct aug_load_ctx *ctx = (struct aug_load_ctx *) data;
2528 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2529 error (g, "%s: failed to parse reply header", "guestfs_aug_load");
2532 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2533 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2534 error (g, "%s: failed to parse reply error", "guestfs_aug_load");
2540 ctx->cb_sequence = 1001;
2541 ml->main_loop_quit (ml, g);
2544 int guestfs_aug_load (guestfs_h *g)
2546 struct aug_load_ctx ctx;
2547 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2550 if (check_state (g, "guestfs_aug_load") == -1) return -1;
2552 memset (&ctx, 0, sizeof ctx);
2554 serial = guestfs__send (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
2558 ctx.cb_sequence = 0;
2559 guestfs_set_send_callback (g, aug_load_send_cb, &ctx);
2560 (void) ml->main_loop_run (ml, g);
2561 guestfs_set_send_callback (g, NULL, NULL);
2562 if (ctx.cb_sequence != 1) {
2563 error (g, "%s send failed, see earlier error messages", "guestfs_aug_load");
2567 guestfs__switch_to_receiving (g);
2568 ctx.cb_sequence = 0;
2569 guestfs_set_reply_callback (g, aug_load_reply_cb, &ctx);
2570 (void) ml->main_loop_run (ml, g);
2571 guestfs_set_reply_callback (g, NULL, NULL);
2572 if (ctx.cb_sequence != 1001) {
2573 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_load");
2577 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1)
2580 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2581 error (g, "%s", ctx.err.error_message);
2589 /* This flag is set by the callbacks, so we know we've done
2590 * the callbacks as expected, and in the right sequence.
2591 * 0 = not called, 1 = send called,
2592 * 1001 = reply called.
2595 struct guestfs_message_header hdr;
2596 struct guestfs_message_error err;
2597 struct guestfs_aug_ls_ret ret;
2600 static void aug_ls_send_cb (guestfs_h *g, void *data)
2602 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2603 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2605 ctx->cb_sequence = 1;
2606 ml->main_loop_quit (ml, g);
2609 static void aug_ls_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2611 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2612 struct aug_ls_ctx *ctx = (struct aug_ls_ctx *) data;
2614 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2615 error (g, "%s: failed to parse reply header", "guestfs_aug_ls");
2618 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2619 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2620 error (g, "%s: failed to parse reply error", "guestfs_aug_ls");
2625 if (!xdr_guestfs_aug_ls_ret (xdr, &ctx->ret)) {
2626 error (g, "%s: failed to parse reply", "guestfs_aug_ls");
2630 ctx->cb_sequence = 1001;
2631 ml->main_loop_quit (ml, g);
2634 char **guestfs_aug_ls (guestfs_h *g,
2637 struct guestfs_aug_ls_args args;
2638 struct aug_ls_ctx ctx;
2639 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2642 if (check_state (g, "guestfs_aug_ls") == -1) return NULL;
2644 memset (&ctx, 0, sizeof ctx);
2646 args.path = (char *) path;
2647 serial = guestfs__send (g, GUESTFS_PROC_AUG_LS,
2648 (xdrproc_t) xdr_guestfs_aug_ls_args, (char *) &args);
2652 ctx.cb_sequence = 0;
2653 guestfs_set_send_callback (g, aug_ls_send_cb, &ctx);
2654 (void) ml->main_loop_run (ml, g);
2655 guestfs_set_send_callback (g, NULL, NULL);
2656 if (ctx.cb_sequence != 1) {
2657 error (g, "%s send failed, see earlier error messages", "guestfs_aug_ls");
2661 guestfs__switch_to_receiving (g);
2662 ctx.cb_sequence = 0;
2663 guestfs_set_reply_callback (g, aug_ls_reply_cb, &ctx);
2664 (void) ml->main_loop_run (ml, g);
2665 guestfs_set_reply_callback (g, NULL, NULL);
2666 if (ctx.cb_sequence != 1001) {
2667 error (g, "%s reply failed, see earlier error messages", "guestfs_aug_ls");
2671 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_AUG_LS, serial) == -1)
2674 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2675 error (g, "%s", ctx.err.error_message);
2679 /* caller will free this, but we need to add a NULL entry */
2680 ctx.ret.matches.matches_val =
2681 safe_realloc (g, ctx.ret.matches.matches_val,
2682 sizeof (char *) * (ctx.ret.matches.matches_len + 1));
2683 ctx.ret.matches.matches_val[ctx.ret.matches.matches_len] = NULL;
2684 return ctx.ret.matches.matches_val;
2688 /* This flag is set by the callbacks, so we know we've done
2689 * the callbacks as expected, and in the right sequence.
2690 * 0 = not called, 1 = send called,
2691 * 1001 = reply called.
2694 struct guestfs_message_header hdr;
2695 struct guestfs_message_error err;
2698 static void rm_send_cb (guestfs_h *g, void *data)
2700 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2701 struct rm_ctx *ctx = (struct rm_ctx *) data;
2703 ctx->cb_sequence = 1;
2704 ml->main_loop_quit (ml, g);
2707 static void rm_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2709 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2710 struct rm_ctx *ctx = (struct rm_ctx *) data;
2712 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2713 error (g, "%s: failed to parse reply header", "guestfs_rm");
2716 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2717 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2718 error (g, "%s: failed to parse reply error", "guestfs_rm");
2724 ctx->cb_sequence = 1001;
2725 ml->main_loop_quit (ml, g);
2728 int guestfs_rm (guestfs_h *g,
2731 struct guestfs_rm_args args;
2733 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2736 if (check_state (g, "guestfs_rm") == -1) return -1;
2738 memset (&ctx, 0, sizeof ctx);
2740 args.path = (char *) path;
2741 serial = guestfs__send (g, GUESTFS_PROC_RM,
2742 (xdrproc_t) xdr_guestfs_rm_args, (char *) &args);
2746 ctx.cb_sequence = 0;
2747 guestfs_set_send_callback (g, rm_send_cb, &ctx);
2748 (void) ml->main_loop_run (ml, g);
2749 guestfs_set_send_callback (g, NULL, NULL);
2750 if (ctx.cb_sequence != 1) {
2751 error (g, "%s send failed, see earlier error messages", "guestfs_rm");
2755 guestfs__switch_to_receiving (g);
2756 ctx.cb_sequence = 0;
2757 guestfs_set_reply_callback (g, rm_reply_cb, &ctx);
2758 (void) ml->main_loop_run (ml, g);
2759 guestfs_set_reply_callback (g, NULL, NULL);
2760 if (ctx.cb_sequence != 1001) {
2761 error (g, "%s reply failed, see earlier error messages", "guestfs_rm");
2765 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM, serial) == -1)
2768 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2769 error (g, "%s", ctx.err.error_message);
2777 /* This flag is set by the callbacks, so we know we've done
2778 * the callbacks as expected, and in the right sequence.
2779 * 0 = not called, 1 = send called,
2780 * 1001 = reply called.
2783 struct guestfs_message_header hdr;
2784 struct guestfs_message_error err;
2787 static void rmdir_send_cb (guestfs_h *g, void *data)
2789 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2790 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2792 ctx->cb_sequence = 1;
2793 ml->main_loop_quit (ml, g);
2796 static void rmdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2798 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2799 struct rmdir_ctx *ctx = (struct rmdir_ctx *) data;
2801 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2802 error (g, "%s: failed to parse reply header", "guestfs_rmdir");
2805 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2806 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2807 error (g, "%s: failed to parse reply error", "guestfs_rmdir");
2813 ctx->cb_sequence = 1001;
2814 ml->main_loop_quit (ml, g);
2817 int guestfs_rmdir (guestfs_h *g,
2820 struct guestfs_rmdir_args args;
2821 struct rmdir_ctx ctx;
2822 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2825 if (check_state (g, "guestfs_rmdir") == -1) return -1;
2827 memset (&ctx, 0, sizeof ctx);
2829 args.path = (char *) path;
2830 serial = guestfs__send (g, GUESTFS_PROC_RMDIR,
2831 (xdrproc_t) xdr_guestfs_rmdir_args, (char *) &args);
2835 ctx.cb_sequence = 0;
2836 guestfs_set_send_callback (g, rmdir_send_cb, &ctx);
2837 (void) ml->main_loop_run (ml, g);
2838 guestfs_set_send_callback (g, NULL, NULL);
2839 if (ctx.cb_sequence != 1) {
2840 error (g, "%s send failed, see earlier error messages", "guestfs_rmdir");
2844 guestfs__switch_to_receiving (g);
2845 ctx.cb_sequence = 0;
2846 guestfs_set_reply_callback (g, rmdir_reply_cb, &ctx);
2847 (void) ml->main_loop_run (ml, g);
2848 guestfs_set_reply_callback (g, NULL, NULL);
2849 if (ctx.cb_sequence != 1001) {
2850 error (g, "%s reply failed, see earlier error messages", "guestfs_rmdir");
2854 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RMDIR, serial) == -1)
2857 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2858 error (g, "%s", ctx.err.error_message);
2866 /* This flag is set by the callbacks, so we know we've done
2867 * the callbacks as expected, and in the right sequence.
2868 * 0 = not called, 1 = send called,
2869 * 1001 = reply called.
2872 struct guestfs_message_header hdr;
2873 struct guestfs_message_error err;
2876 static void rm_rf_send_cb (guestfs_h *g, void *data)
2878 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2879 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2881 ctx->cb_sequence = 1;
2882 ml->main_loop_quit (ml, g);
2885 static void rm_rf_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2887 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2888 struct rm_rf_ctx *ctx = (struct rm_rf_ctx *) data;
2890 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2891 error (g, "%s: failed to parse reply header", "guestfs_rm_rf");
2894 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2895 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2896 error (g, "%s: failed to parse reply error", "guestfs_rm_rf");
2902 ctx->cb_sequence = 1001;
2903 ml->main_loop_quit (ml, g);
2906 int guestfs_rm_rf (guestfs_h *g,
2909 struct guestfs_rm_rf_args args;
2910 struct rm_rf_ctx ctx;
2911 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2914 if (check_state (g, "guestfs_rm_rf") == -1) return -1;
2916 memset (&ctx, 0, sizeof ctx);
2918 args.path = (char *) path;
2919 serial = guestfs__send (g, GUESTFS_PROC_RM_RF,
2920 (xdrproc_t) xdr_guestfs_rm_rf_args, (char *) &args);
2924 ctx.cb_sequence = 0;
2925 guestfs_set_send_callback (g, rm_rf_send_cb, &ctx);
2926 (void) ml->main_loop_run (ml, g);
2927 guestfs_set_send_callback (g, NULL, NULL);
2928 if (ctx.cb_sequence != 1) {
2929 error (g, "%s send failed, see earlier error messages", "guestfs_rm_rf");
2933 guestfs__switch_to_receiving (g);
2934 ctx.cb_sequence = 0;
2935 guestfs_set_reply_callback (g, rm_rf_reply_cb, &ctx);
2936 (void) ml->main_loop_run (ml, g);
2937 guestfs_set_reply_callback (g, NULL, NULL);
2938 if (ctx.cb_sequence != 1001) {
2939 error (g, "%s reply failed, see earlier error messages", "guestfs_rm_rf");
2943 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_RM_RF, serial) == -1)
2946 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
2947 error (g, "%s", ctx.err.error_message);
2955 /* This flag is set by the callbacks, so we know we've done
2956 * the callbacks as expected, and in the right sequence.
2957 * 0 = not called, 1 = send called,
2958 * 1001 = reply called.
2961 struct guestfs_message_header hdr;
2962 struct guestfs_message_error err;
2965 static void mkdir_send_cb (guestfs_h *g, void *data)
2967 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2968 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
2970 ctx->cb_sequence = 1;
2971 ml->main_loop_quit (ml, g);
2974 static void mkdir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
2976 guestfs_main_loop *ml = guestfs_get_main_loop (g);
2977 struct mkdir_ctx *ctx = (struct mkdir_ctx *) data;
2979 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
2980 error (g, "%s: failed to parse reply header", "guestfs_mkdir");
2983 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
2984 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
2985 error (g, "%s: failed to parse reply error", "guestfs_mkdir");
2991 ctx->cb_sequence = 1001;
2992 ml->main_loop_quit (ml, g);
2995 int guestfs_mkdir (guestfs_h *g,
2998 struct guestfs_mkdir_args args;
2999 struct mkdir_ctx ctx;
3000 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3003 if (check_state (g, "guestfs_mkdir") == -1) return -1;
3005 memset (&ctx, 0, sizeof ctx);
3007 args.path = (char *) path;
3008 serial = guestfs__send (g, GUESTFS_PROC_MKDIR,
3009 (xdrproc_t) xdr_guestfs_mkdir_args, (char *) &args);
3013 ctx.cb_sequence = 0;
3014 guestfs_set_send_callback (g, mkdir_send_cb, &ctx);
3015 (void) ml->main_loop_run (ml, g);
3016 guestfs_set_send_callback (g, NULL, NULL);
3017 if (ctx.cb_sequence != 1) {
3018 error (g, "%s send failed, see earlier error messages", "guestfs_mkdir");
3022 guestfs__switch_to_receiving (g);
3023 ctx.cb_sequence = 0;
3024 guestfs_set_reply_callback (g, mkdir_reply_cb, &ctx);
3025 (void) ml->main_loop_run (ml, g);
3026 guestfs_set_reply_callback (g, NULL, NULL);
3027 if (ctx.cb_sequence != 1001) {
3028 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir");
3032 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR, serial) == -1)
3035 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3036 error (g, "%s", ctx.err.error_message);
3043 struct mkdir_p_ctx {
3044 /* This flag is set by the callbacks, so we know we've done
3045 * the callbacks as expected, and in the right sequence.
3046 * 0 = not called, 1 = send called,
3047 * 1001 = reply called.
3050 struct guestfs_message_header hdr;
3051 struct guestfs_message_error err;
3054 static void mkdir_p_send_cb (guestfs_h *g, void *data)
3056 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3057 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
3059 ctx->cb_sequence = 1;
3060 ml->main_loop_quit (ml, g);
3063 static void mkdir_p_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3065 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3066 struct mkdir_p_ctx *ctx = (struct mkdir_p_ctx *) data;
3068 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3069 error (g, "%s: failed to parse reply header", "guestfs_mkdir_p");
3072 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3073 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3074 error (g, "%s: failed to parse reply error", "guestfs_mkdir_p");
3080 ctx->cb_sequence = 1001;
3081 ml->main_loop_quit (ml, g);
3084 int guestfs_mkdir_p (guestfs_h *g,
3087 struct guestfs_mkdir_p_args args;
3088 struct mkdir_p_ctx ctx;
3089 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3092 if (check_state (g, "guestfs_mkdir_p") == -1) return -1;
3094 memset (&ctx, 0, sizeof ctx);
3096 args.path = (char *) path;
3097 serial = guestfs__send (g, GUESTFS_PROC_MKDIR_P,
3098 (xdrproc_t) xdr_guestfs_mkdir_p_args, (char *) &args);
3102 ctx.cb_sequence = 0;
3103 guestfs_set_send_callback (g, mkdir_p_send_cb, &ctx);
3104 (void) ml->main_loop_run (ml, g);
3105 guestfs_set_send_callback (g, NULL, NULL);
3106 if (ctx.cb_sequence != 1) {
3107 error (g, "%s send failed, see earlier error messages", "guestfs_mkdir_p");
3111 guestfs__switch_to_receiving (g);
3112 ctx.cb_sequence = 0;
3113 guestfs_set_reply_callback (g, mkdir_p_reply_cb, &ctx);
3114 (void) ml->main_loop_run (ml, g);
3115 guestfs_set_reply_callback (g, NULL, NULL);
3116 if (ctx.cb_sequence != 1001) {
3117 error (g, "%s reply failed, see earlier error messages", "guestfs_mkdir_p");
3121 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKDIR_P, serial) == -1)
3124 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3125 error (g, "%s", ctx.err.error_message);
3133 /* This flag is set by the callbacks, so we know we've done
3134 * the callbacks as expected, and in the right sequence.
3135 * 0 = not called, 1 = send called,
3136 * 1001 = reply called.
3139 struct guestfs_message_header hdr;
3140 struct guestfs_message_error err;
3143 static void chmod_send_cb (guestfs_h *g, void *data)
3145 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3146 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
3148 ctx->cb_sequence = 1;
3149 ml->main_loop_quit (ml, g);
3152 static void chmod_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3154 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3155 struct chmod_ctx *ctx = (struct chmod_ctx *) data;
3157 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3158 error (g, "%s: failed to parse reply header", "guestfs_chmod");
3161 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3162 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3163 error (g, "%s: failed to parse reply error", "guestfs_chmod");
3169 ctx->cb_sequence = 1001;
3170 ml->main_loop_quit (ml, g);
3173 int guestfs_chmod (guestfs_h *g,
3177 struct guestfs_chmod_args args;
3178 struct chmod_ctx ctx;
3179 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3182 if (check_state (g, "guestfs_chmod") == -1) return -1;
3184 memset (&ctx, 0, sizeof ctx);
3187 args.path = (char *) path;
3188 serial = guestfs__send (g, GUESTFS_PROC_CHMOD,
3189 (xdrproc_t) xdr_guestfs_chmod_args, (char *) &args);
3193 ctx.cb_sequence = 0;
3194 guestfs_set_send_callback (g, chmod_send_cb, &ctx);
3195 (void) ml->main_loop_run (ml, g);
3196 guestfs_set_send_callback (g, NULL, NULL);
3197 if (ctx.cb_sequence != 1) {
3198 error (g, "%s send failed, see earlier error messages", "guestfs_chmod");
3202 guestfs__switch_to_receiving (g);
3203 ctx.cb_sequence = 0;
3204 guestfs_set_reply_callback (g, chmod_reply_cb, &ctx);
3205 (void) ml->main_loop_run (ml, g);
3206 guestfs_set_reply_callback (g, NULL, NULL);
3207 if (ctx.cb_sequence != 1001) {
3208 error (g, "%s reply failed, see earlier error messages", "guestfs_chmod");
3212 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHMOD, serial) == -1)
3215 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3216 error (g, "%s", ctx.err.error_message);
3224 /* This flag is set by the callbacks, so we know we've done
3225 * the callbacks as expected, and in the right sequence.
3226 * 0 = not called, 1 = send called,
3227 * 1001 = reply called.
3230 struct guestfs_message_header hdr;
3231 struct guestfs_message_error err;
3234 static void chown_send_cb (guestfs_h *g, void *data)
3236 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3237 struct chown_ctx *ctx = (struct chown_ctx *) data;
3239 ctx->cb_sequence = 1;
3240 ml->main_loop_quit (ml, g);
3243 static void chown_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3245 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3246 struct chown_ctx *ctx = (struct chown_ctx *) data;
3248 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3249 error (g, "%s: failed to parse reply header", "guestfs_chown");
3252 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3253 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3254 error (g, "%s: failed to parse reply error", "guestfs_chown");
3260 ctx->cb_sequence = 1001;
3261 ml->main_loop_quit (ml, g);
3264 int guestfs_chown (guestfs_h *g,
3269 struct guestfs_chown_args args;
3270 struct chown_ctx ctx;
3271 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3274 if (check_state (g, "guestfs_chown") == -1) return -1;
3276 memset (&ctx, 0, sizeof ctx);
3280 args.path = (char *) path;
3281 serial = guestfs__send (g, GUESTFS_PROC_CHOWN,
3282 (xdrproc_t) xdr_guestfs_chown_args, (char *) &args);
3286 ctx.cb_sequence = 0;
3287 guestfs_set_send_callback (g, chown_send_cb, &ctx);
3288 (void) ml->main_loop_run (ml, g);
3289 guestfs_set_send_callback (g, NULL, NULL);
3290 if (ctx.cb_sequence != 1) {
3291 error (g, "%s send failed, see earlier error messages", "guestfs_chown");
3295 guestfs__switch_to_receiving (g);
3296 ctx.cb_sequence = 0;
3297 guestfs_set_reply_callback (g, chown_reply_cb, &ctx);
3298 (void) ml->main_loop_run (ml, g);
3299 guestfs_set_reply_callback (g, NULL, NULL);
3300 if (ctx.cb_sequence != 1001) {
3301 error (g, "%s reply failed, see earlier error messages", "guestfs_chown");
3305 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_CHOWN, serial) == -1)
3308 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3309 error (g, "%s", ctx.err.error_message);
3317 /* This flag is set by the callbacks, so we know we've done
3318 * the callbacks as expected, and in the right sequence.
3319 * 0 = not called, 1 = send called,
3320 * 1001 = reply called.
3323 struct guestfs_message_header hdr;
3324 struct guestfs_message_error err;
3325 struct guestfs_exists_ret ret;
3328 static void exists_send_cb (guestfs_h *g, void *data)
3330 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3331 struct exists_ctx *ctx = (struct exists_ctx *) data;
3333 ctx->cb_sequence = 1;
3334 ml->main_loop_quit (ml, g);
3337 static void exists_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3339 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3340 struct exists_ctx *ctx = (struct exists_ctx *) data;
3342 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3343 error (g, "%s: failed to parse reply header", "guestfs_exists");
3346 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3347 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3348 error (g, "%s: failed to parse reply error", "guestfs_exists");
3353 if (!xdr_guestfs_exists_ret (xdr, &ctx->ret)) {
3354 error (g, "%s: failed to parse reply", "guestfs_exists");
3358 ctx->cb_sequence = 1001;
3359 ml->main_loop_quit (ml, g);
3362 int guestfs_exists (guestfs_h *g,
3365 struct guestfs_exists_args args;
3366 struct exists_ctx ctx;
3367 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3370 if (check_state (g, "guestfs_exists") == -1) return -1;
3372 memset (&ctx, 0, sizeof ctx);
3374 args.path = (char *) path;
3375 serial = guestfs__send (g, GUESTFS_PROC_EXISTS,
3376 (xdrproc_t) xdr_guestfs_exists_args, (char *) &args);
3380 ctx.cb_sequence = 0;
3381 guestfs_set_send_callback (g, exists_send_cb, &ctx);
3382 (void) ml->main_loop_run (ml, g);
3383 guestfs_set_send_callback (g, NULL, NULL);
3384 if (ctx.cb_sequence != 1) {
3385 error (g, "%s send failed, see earlier error messages", "guestfs_exists");
3389 guestfs__switch_to_receiving (g);
3390 ctx.cb_sequence = 0;
3391 guestfs_set_reply_callback (g, exists_reply_cb, &ctx);
3392 (void) ml->main_loop_run (ml, g);
3393 guestfs_set_reply_callback (g, NULL, NULL);
3394 if (ctx.cb_sequence != 1001) {
3395 error (g, "%s reply failed, see earlier error messages", "guestfs_exists");
3399 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_EXISTS, serial) == -1)
3402 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3403 error (g, "%s", ctx.err.error_message);
3407 return ctx.ret.existsflag;
3410 struct is_file_ctx {
3411 /* This flag is set by the callbacks, so we know we've done
3412 * the callbacks as expected, and in the right sequence.
3413 * 0 = not called, 1 = send called,
3414 * 1001 = reply called.
3417 struct guestfs_message_header hdr;
3418 struct guestfs_message_error err;
3419 struct guestfs_is_file_ret ret;
3422 static void is_file_send_cb (guestfs_h *g, void *data)
3424 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3425 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
3427 ctx->cb_sequence = 1;
3428 ml->main_loop_quit (ml, g);
3431 static void is_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3433 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3434 struct is_file_ctx *ctx = (struct is_file_ctx *) data;
3436 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3437 error (g, "%s: failed to parse reply header", "guestfs_is_file");
3440 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3441 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3442 error (g, "%s: failed to parse reply error", "guestfs_is_file");
3447 if (!xdr_guestfs_is_file_ret (xdr, &ctx->ret)) {
3448 error (g, "%s: failed to parse reply", "guestfs_is_file");
3452 ctx->cb_sequence = 1001;
3453 ml->main_loop_quit (ml, g);
3456 int guestfs_is_file (guestfs_h *g,
3459 struct guestfs_is_file_args args;
3460 struct is_file_ctx ctx;
3461 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3464 if (check_state (g, "guestfs_is_file") == -1) return -1;
3466 memset (&ctx, 0, sizeof ctx);
3468 args.path = (char *) path;
3469 serial = guestfs__send (g, GUESTFS_PROC_IS_FILE,
3470 (xdrproc_t) xdr_guestfs_is_file_args, (char *) &args);
3474 ctx.cb_sequence = 0;
3475 guestfs_set_send_callback (g, is_file_send_cb, &ctx);
3476 (void) ml->main_loop_run (ml, g);
3477 guestfs_set_send_callback (g, NULL, NULL);
3478 if (ctx.cb_sequence != 1) {
3479 error (g, "%s send failed, see earlier error messages", "guestfs_is_file");
3483 guestfs__switch_to_receiving (g);
3484 ctx.cb_sequence = 0;
3485 guestfs_set_reply_callback (g, is_file_reply_cb, &ctx);
3486 (void) ml->main_loop_run (ml, g);
3487 guestfs_set_reply_callback (g, NULL, NULL);
3488 if (ctx.cb_sequence != 1001) {
3489 error (g, "%s reply failed, see earlier error messages", "guestfs_is_file");
3493 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_FILE, serial) == -1)
3496 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3497 error (g, "%s", ctx.err.error_message);
3501 return ctx.ret.fileflag;
3505 /* This flag is set by the callbacks, so we know we've done
3506 * the callbacks as expected, and in the right sequence.
3507 * 0 = not called, 1 = send called,
3508 * 1001 = reply called.
3511 struct guestfs_message_header hdr;
3512 struct guestfs_message_error err;
3513 struct guestfs_is_dir_ret ret;
3516 static void is_dir_send_cb (guestfs_h *g, void *data)
3518 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3519 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
3521 ctx->cb_sequence = 1;
3522 ml->main_loop_quit (ml, g);
3525 static void is_dir_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3527 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3528 struct is_dir_ctx *ctx = (struct is_dir_ctx *) data;
3530 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3531 error (g, "%s: failed to parse reply header", "guestfs_is_dir");
3534 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3535 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3536 error (g, "%s: failed to parse reply error", "guestfs_is_dir");
3541 if (!xdr_guestfs_is_dir_ret (xdr, &ctx->ret)) {
3542 error (g, "%s: failed to parse reply", "guestfs_is_dir");
3546 ctx->cb_sequence = 1001;
3547 ml->main_loop_quit (ml, g);
3550 int guestfs_is_dir (guestfs_h *g,
3553 struct guestfs_is_dir_args args;
3554 struct is_dir_ctx ctx;
3555 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3558 if (check_state (g, "guestfs_is_dir") == -1) return -1;
3560 memset (&ctx, 0, sizeof ctx);
3562 args.path = (char *) path;
3563 serial = guestfs__send (g, GUESTFS_PROC_IS_DIR,
3564 (xdrproc_t) xdr_guestfs_is_dir_args, (char *) &args);
3568 ctx.cb_sequence = 0;
3569 guestfs_set_send_callback (g, is_dir_send_cb, &ctx);
3570 (void) ml->main_loop_run (ml, g);
3571 guestfs_set_send_callback (g, NULL, NULL);
3572 if (ctx.cb_sequence != 1) {
3573 error (g, "%s send failed, see earlier error messages", "guestfs_is_dir");
3577 guestfs__switch_to_receiving (g);
3578 ctx.cb_sequence = 0;
3579 guestfs_set_reply_callback (g, is_dir_reply_cb, &ctx);
3580 (void) ml->main_loop_run (ml, g);
3581 guestfs_set_reply_callback (g, NULL, NULL);
3582 if (ctx.cb_sequence != 1001) {
3583 error (g, "%s reply failed, see earlier error messages", "guestfs_is_dir");
3587 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_IS_DIR, serial) == -1)
3590 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3591 error (g, "%s", ctx.err.error_message);
3595 return ctx.ret.dirflag;
3598 struct pvcreate_ctx {
3599 /* This flag is set by the callbacks, so we know we've done
3600 * the callbacks as expected, and in the right sequence.
3601 * 0 = not called, 1 = send called,
3602 * 1001 = reply called.
3605 struct guestfs_message_header hdr;
3606 struct guestfs_message_error err;
3609 static void pvcreate_send_cb (guestfs_h *g, void *data)
3611 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3612 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
3614 ctx->cb_sequence = 1;
3615 ml->main_loop_quit (ml, g);
3618 static void pvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3620 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3621 struct pvcreate_ctx *ctx = (struct pvcreate_ctx *) data;
3623 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3624 error (g, "%s: failed to parse reply header", "guestfs_pvcreate");
3627 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3628 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3629 error (g, "%s: failed to parse reply error", "guestfs_pvcreate");
3635 ctx->cb_sequence = 1001;
3636 ml->main_loop_quit (ml, g);
3639 int guestfs_pvcreate (guestfs_h *g,
3642 struct guestfs_pvcreate_args args;
3643 struct pvcreate_ctx ctx;
3644 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3647 if (check_state (g, "guestfs_pvcreate") == -1) return -1;
3649 memset (&ctx, 0, sizeof ctx);
3651 args.device = (char *) device;
3652 serial = guestfs__send (g, GUESTFS_PROC_PVCREATE,
3653 (xdrproc_t) xdr_guestfs_pvcreate_args, (char *) &args);
3657 ctx.cb_sequence = 0;
3658 guestfs_set_send_callback (g, pvcreate_send_cb, &ctx);
3659 (void) ml->main_loop_run (ml, g);
3660 guestfs_set_send_callback (g, NULL, NULL);
3661 if (ctx.cb_sequence != 1) {
3662 error (g, "%s send failed, see earlier error messages", "guestfs_pvcreate");
3666 guestfs__switch_to_receiving (g);
3667 ctx.cb_sequence = 0;
3668 guestfs_set_reply_callback (g, pvcreate_reply_cb, &ctx);
3669 (void) ml->main_loop_run (ml, g);
3670 guestfs_set_reply_callback (g, NULL, NULL);
3671 if (ctx.cb_sequence != 1001) {
3672 error (g, "%s reply failed, see earlier error messages", "guestfs_pvcreate");
3676 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_PVCREATE, serial) == -1)
3679 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3680 error (g, "%s", ctx.err.error_message);
3687 struct vgcreate_ctx {
3688 /* This flag is set by the callbacks, so we know we've done
3689 * the callbacks as expected, and in the right sequence.
3690 * 0 = not called, 1 = send called,
3691 * 1001 = reply called.
3694 struct guestfs_message_header hdr;
3695 struct guestfs_message_error err;
3698 static void vgcreate_send_cb (guestfs_h *g, void *data)
3700 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3701 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3703 ctx->cb_sequence = 1;
3704 ml->main_loop_quit (ml, g);
3707 static void vgcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3709 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3710 struct vgcreate_ctx *ctx = (struct vgcreate_ctx *) data;
3712 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3713 error (g, "%s: failed to parse reply header", "guestfs_vgcreate");
3716 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3717 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3718 error (g, "%s: failed to parse reply error", "guestfs_vgcreate");
3724 ctx->cb_sequence = 1001;
3725 ml->main_loop_quit (ml, g);
3728 int guestfs_vgcreate (guestfs_h *g,
3729 const char *volgroup,
3730 char * const* const physvols)
3732 struct guestfs_vgcreate_args args;
3733 struct vgcreate_ctx ctx;
3734 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3737 if (check_state (g, "guestfs_vgcreate") == -1) return -1;
3739 memset (&ctx, 0, sizeof ctx);
3741 args.volgroup = (char *) volgroup;
3742 args.physvols.physvols_val = (char **) physvols;
3743 for (args.physvols.physvols_len = 0; physvols[args.physvols.physvols_len]; args.physvols.physvols_len++) ;
3744 serial = guestfs__send (g, GUESTFS_PROC_VGCREATE,
3745 (xdrproc_t) xdr_guestfs_vgcreate_args, (char *) &args);
3749 ctx.cb_sequence = 0;
3750 guestfs_set_send_callback (g, vgcreate_send_cb, &ctx);
3751 (void) ml->main_loop_run (ml, g);
3752 guestfs_set_send_callback (g, NULL, NULL);
3753 if (ctx.cb_sequence != 1) {
3754 error (g, "%s send failed, see earlier error messages", "guestfs_vgcreate");
3758 guestfs__switch_to_receiving (g);
3759 ctx.cb_sequence = 0;
3760 guestfs_set_reply_callback (g, vgcreate_reply_cb, &ctx);
3761 (void) ml->main_loop_run (ml, g);
3762 guestfs_set_reply_callback (g, NULL, NULL);
3763 if (ctx.cb_sequence != 1001) {
3764 error (g, "%s reply failed, see earlier error messages", "guestfs_vgcreate");
3768 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_VGCREATE, serial) == -1)
3771 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3772 error (g, "%s", ctx.err.error_message);
3779 struct lvcreate_ctx {
3780 /* This flag is set by the callbacks, so we know we've done
3781 * the callbacks as expected, and in the right sequence.
3782 * 0 = not called, 1 = send called,
3783 * 1001 = reply called.
3786 struct guestfs_message_header hdr;
3787 struct guestfs_message_error err;
3790 static void lvcreate_send_cb (guestfs_h *g, void *data)
3792 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3793 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3795 ctx->cb_sequence = 1;
3796 ml->main_loop_quit (ml, g);
3799 static void lvcreate_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3801 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3802 struct lvcreate_ctx *ctx = (struct lvcreate_ctx *) data;
3804 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3805 error (g, "%s: failed to parse reply header", "guestfs_lvcreate");
3808 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3809 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3810 error (g, "%s: failed to parse reply error", "guestfs_lvcreate");
3816 ctx->cb_sequence = 1001;
3817 ml->main_loop_quit (ml, g);
3820 int guestfs_lvcreate (guestfs_h *g,
3822 const char *volgroup,
3825 struct guestfs_lvcreate_args args;
3826 struct lvcreate_ctx ctx;
3827 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3830 if (check_state (g, "guestfs_lvcreate") == -1) return -1;
3832 memset (&ctx, 0, sizeof ctx);
3834 args.logvol = (char *) logvol;
3835 args.volgroup = (char *) volgroup;
3836 args.mbytes = mbytes;
3837 serial = guestfs__send (g, GUESTFS_PROC_LVCREATE,
3838 (xdrproc_t) xdr_guestfs_lvcreate_args, (char *) &args);
3842 ctx.cb_sequence = 0;
3843 guestfs_set_send_callback (g, lvcreate_send_cb, &ctx);
3844 (void) ml->main_loop_run (ml, g);
3845 guestfs_set_send_callback (g, NULL, NULL);
3846 if (ctx.cb_sequence != 1) {
3847 error (g, "%s send failed, see earlier error messages", "guestfs_lvcreate");
3851 guestfs__switch_to_receiving (g);
3852 ctx.cb_sequence = 0;
3853 guestfs_set_reply_callback (g, lvcreate_reply_cb, &ctx);
3854 (void) ml->main_loop_run (ml, g);
3855 guestfs_set_reply_callback (g, NULL, NULL);
3856 if (ctx.cb_sequence != 1001) {
3857 error (g, "%s reply failed, see earlier error messages", "guestfs_lvcreate");
3861 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVCREATE, serial) == -1)
3864 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3865 error (g, "%s", ctx.err.error_message);
3873 /* This flag is set by the callbacks, so we know we've done
3874 * the callbacks as expected, and in the right sequence.
3875 * 0 = not called, 1 = send called,
3876 * 1001 = reply called.
3879 struct guestfs_message_header hdr;
3880 struct guestfs_message_error err;
3883 static void mkfs_send_cb (guestfs_h *g, void *data)
3885 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3886 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3888 ctx->cb_sequence = 1;
3889 ml->main_loop_quit (ml, g);
3892 static void mkfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3894 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3895 struct mkfs_ctx *ctx = (struct mkfs_ctx *) data;
3897 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3898 error (g, "%s: failed to parse reply header", "guestfs_mkfs");
3901 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3902 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3903 error (g, "%s: failed to parse reply error", "guestfs_mkfs");
3909 ctx->cb_sequence = 1001;
3910 ml->main_loop_quit (ml, g);
3913 int guestfs_mkfs (guestfs_h *g,
3917 struct guestfs_mkfs_args args;
3918 struct mkfs_ctx ctx;
3919 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3922 if (check_state (g, "guestfs_mkfs") == -1) return -1;
3924 memset (&ctx, 0, sizeof ctx);
3926 args.fstype = (char *) fstype;
3927 args.device = (char *) device;
3928 serial = guestfs__send (g, GUESTFS_PROC_MKFS,
3929 (xdrproc_t) xdr_guestfs_mkfs_args, (char *) &args);
3933 ctx.cb_sequence = 0;
3934 guestfs_set_send_callback (g, mkfs_send_cb, &ctx);
3935 (void) ml->main_loop_run (ml, g);
3936 guestfs_set_send_callback (g, NULL, NULL);
3937 if (ctx.cb_sequence != 1) {
3938 error (g, "%s send failed, see earlier error messages", "guestfs_mkfs");
3942 guestfs__switch_to_receiving (g);
3943 ctx.cb_sequence = 0;
3944 guestfs_set_reply_callback (g, mkfs_reply_cb, &ctx);
3945 (void) ml->main_loop_run (ml, g);
3946 guestfs_set_reply_callback (g, NULL, NULL);
3947 if (ctx.cb_sequence != 1001) {
3948 error (g, "%s reply failed, see earlier error messages", "guestfs_mkfs");
3952 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MKFS, serial) == -1)
3955 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
3956 error (g, "%s", ctx.err.error_message);
3964 /* This flag is set by the callbacks, so we know we've done
3965 * the callbacks as expected, and in the right sequence.
3966 * 0 = not called, 1 = send called,
3967 * 1001 = reply called.
3970 struct guestfs_message_header hdr;
3971 struct guestfs_message_error err;
3974 static void sfdisk_send_cb (guestfs_h *g, void *data)
3976 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3977 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
3979 ctx->cb_sequence = 1;
3980 ml->main_loop_quit (ml, g);
3983 static void sfdisk_reply_cb (guestfs_h *g, void *data, XDR *xdr)
3985 guestfs_main_loop *ml = guestfs_get_main_loop (g);
3986 struct sfdisk_ctx *ctx = (struct sfdisk_ctx *) data;
3988 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
3989 error (g, "%s: failed to parse reply header", "guestfs_sfdisk");
3992 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
3993 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
3994 error (g, "%s: failed to parse reply error", "guestfs_sfdisk");
4000 ctx->cb_sequence = 1001;
4001 ml->main_loop_quit (ml, g);
4004 int guestfs_sfdisk (guestfs_h *g,
4009 char * const* const lines)
4011 struct guestfs_sfdisk_args args;
4012 struct sfdisk_ctx ctx;
4013 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4016 if (check_state (g, "guestfs_sfdisk") == -1) return -1;
4018 memset (&ctx, 0, sizeof ctx);
4020 args.device = (char *) device;
4023 args.sectors = sectors;
4024 args.lines.lines_val = (char **) lines;
4025 for (args.lines.lines_len = 0; lines[args.lines.lines_len]; args.lines.lines_len++) ;
4026 serial = guestfs__send (g, GUESTFS_PROC_SFDISK,
4027 (xdrproc_t) xdr_guestfs_sfdisk_args, (char *) &args);
4031 ctx.cb_sequence = 0;
4032 guestfs_set_send_callback (g, sfdisk_send_cb, &ctx);
4033 (void) ml->main_loop_run (ml, g);
4034 guestfs_set_send_callback (g, NULL, NULL);
4035 if (ctx.cb_sequence != 1) {
4036 error (g, "%s send failed, see earlier error messages", "guestfs_sfdisk");
4040 guestfs__switch_to_receiving (g);
4041 ctx.cb_sequence = 0;
4042 guestfs_set_reply_callback (g, sfdisk_reply_cb, &ctx);
4043 (void) ml->main_loop_run (ml, g);
4044 guestfs_set_reply_callback (g, NULL, NULL);
4045 if (ctx.cb_sequence != 1001) {
4046 error (g, "%s reply failed, see earlier error messages", "guestfs_sfdisk");
4050 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_SFDISK, serial) == -1)
4053 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4054 error (g, "%s", ctx.err.error_message);
4061 struct write_file_ctx {
4062 /* This flag is set by the callbacks, so we know we've done
4063 * the callbacks as expected, and in the right sequence.
4064 * 0 = not called, 1 = send called,
4065 * 1001 = reply called.
4068 struct guestfs_message_header hdr;
4069 struct guestfs_message_error err;
4072 static void write_file_send_cb (guestfs_h *g, void *data)
4074 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4075 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
4077 ctx->cb_sequence = 1;
4078 ml->main_loop_quit (ml, g);
4081 static void write_file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4083 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4084 struct write_file_ctx *ctx = (struct write_file_ctx *) data;
4086 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4087 error (g, "%s: failed to parse reply header", "guestfs_write_file");
4090 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4091 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4092 error (g, "%s: failed to parse reply error", "guestfs_write_file");
4098 ctx->cb_sequence = 1001;
4099 ml->main_loop_quit (ml, g);
4102 int guestfs_write_file (guestfs_h *g,
4104 const char *content,
4107 struct guestfs_write_file_args args;
4108 struct write_file_ctx ctx;
4109 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4112 if (check_state (g, "guestfs_write_file") == -1) return -1;
4114 memset (&ctx, 0, sizeof ctx);
4116 args.path = (char *) path;
4117 args.content = (char *) content;
4119 serial = guestfs__send (g, GUESTFS_PROC_WRITE_FILE,
4120 (xdrproc_t) xdr_guestfs_write_file_args, (char *) &args);
4124 ctx.cb_sequence = 0;
4125 guestfs_set_send_callback (g, write_file_send_cb, &ctx);
4126 (void) ml->main_loop_run (ml, g);
4127 guestfs_set_send_callback (g, NULL, NULL);
4128 if (ctx.cb_sequence != 1) {
4129 error (g, "%s send failed, see earlier error messages", "guestfs_write_file");
4133 guestfs__switch_to_receiving (g);
4134 ctx.cb_sequence = 0;
4135 guestfs_set_reply_callback (g, write_file_reply_cb, &ctx);
4136 (void) ml->main_loop_run (ml, g);
4137 guestfs_set_reply_callback (g, NULL, NULL);
4138 if (ctx.cb_sequence != 1001) {
4139 error (g, "%s reply failed, see earlier error messages", "guestfs_write_file");
4143 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_WRITE_FILE, serial) == -1)
4146 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4147 error (g, "%s", ctx.err.error_message);
4155 /* This flag is set by the callbacks, so we know we've done
4156 * the callbacks as expected, and in the right sequence.
4157 * 0 = not called, 1 = send called,
4158 * 1001 = reply called.
4161 struct guestfs_message_header hdr;
4162 struct guestfs_message_error err;
4165 static void umount_send_cb (guestfs_h *g, void *data)
4167 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4168 struct umount_ctx *ctx = (struct umount_ctx *) data;
4170 ctx->cb_sequence = 1;
4171 ml->main_loop_quit (ml, g);
4174 static void umount_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4176 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4177 struct umount_ctx *ctx = (struct umount_ctx *) data;
4179 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4180 error (g, "%s: failed to parse reply header", "guestfs_umount");
4183 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4184 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4185 error (g, "%s: failed to parse reply error", "guestfs_umount");
4191 ctx->cb_sequence = 1001;
4192 ml->main_loop_quit (ml, g);
4195 int guestfs_umount (guestfs_h *g,
4196 const char *pathordevice)
4198 struct guestfs_umount_args args;
4199 struct umount_ctx ctx;
4200 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4203 if (check_state (g, "guestfs_umount") == -1) return -1;
4205 memset (&ctx, 0, sizeof ctx);
4207 args.pathordevice = (char *) pathordevice;
4208 serial = guestfs__send (g, GUESTFS_PROC_UMOUNT,
4209 (xdrproc_t) xdr_guestfs_umount_args, (char *) &args);
4213 ctx.cb_sequence = 0;
4214 guestfs_set_send_callback (g, umount_send_cb, &ctx);
4215 (void) ml->main_loop_run (ml, g);
4216 guestfs_set_send_callback (g, NULL, NULL);
4217 if (ctx.cb_sequence != 1) {
4218 error (g, "%s send failed, see earlier error messages", "guestfs_umount");
4222 guestfs__switch_to_receiving (g);
4223 ctx.cb_sequence = 0;
4224 guestfs_set_reply_callback (g, umount_reply_cb, &ctx);
4225 (void) ml->main_loop_run (ml, g);
4226 guestfs_set_reply_callback (g, NULL, NULL);
4227 if (ctx.cb_sequence != 1001) {
4228 error (g, "%s reply failed, see earlier error messages", "guestfs_umount");
4232 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT, serial) == -1)
4235 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4236 error (g, "%s", ctx.err.error_message);
4244 /* This flag is set by the callbacks, so we know we've done
4245 * the callbacks as expected, and in the right sequence.
4246 * 0 = not called, 1 = send called,
4247 * 1001 = reply called.
4250 struct guestfs_message_header hdr;
4251 struct guestfs_message_error err;
4252 struct guestfs_mounts_ret ret;
4255 static void mounts_send_cb (guestfs_h *g, void *data)
4257 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4258 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
4260 ctx->cb_sequence = 1;
4261 ml->main_loop_quit (ml, g);
4264 static void mounts_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4266 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4267 struct mounts_ctx *ctx = (struct mounts_ctx *) data;
4269 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4270 error (g, "%s: failed to parse reply header", "guestfs_mounts");
4273 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4274 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4275 error (g, "%s: failed to parse reply error", "guestfs_mounts");
4280 if (!xdr_guestfs_mounts_ret (xdr, &ctx->ret)) {
4281 error (g, "%s: failed to parse reply", "guestfs_mounts");
4285 ctx->cb_sequence = 1001;
4286 ml->main_loop_quit (ml, g);
4289 char **guestfs_mounts (guestfs_h *g)
4291 struct mounts_ctx ctx;
4292 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4295 if (check_state (g, "guestfs_mounts") == -1) return NULL;
4297 memset (&ctx, 0, sizeof ctx);
4299 serial = guestfs__send (g, GUESTFS_PROC_MOUNTS, NULL, NULL);
4303 ctx.cb_sequence = 0;
4304 guestfs_set_send_callback (g, mounts_send_cb, &ctx);
4305 (void) ml->main_loop_run (ml, g);
4306 guestfs_set_send_callback (g, NULL, NULL);
4307 if (ctx.cb_sequence != 1) {
4308 error (g, "%s send failed, see earlier error messages", "guestfs_mounts");
4312 guestfs__switch_to_receiving (g);
4313 ctx.cb_sequence = 0;
4314 guestfs_set_reply_callback (g, mounts_reply_cb, &ctx);
4315 (void) ml->main_loop_run (ml, g);
4316 guestfs_set_reply_callback (g, NULL, NULL);
4317 if (ctx.cb_sequence != 1001) {
4318 error (g, "%s reply failed, see earlier error messages", "guestfs_mounts");
4322 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_MOUNTS, serial) == -1)
4325 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4326 error (g, "%s", ctx.err.error_message);
4330 /* caller will free this, but we need to add a NULL entry */
4331 ctx.ret.devices.devices_val =
4332 safe_realloc (g, ctx.ret.devices.devices_val,
4333 sizeof (char *) * (ctx.ret.devices.devices_len + 1));
4334 ctx.ret.devices.devices_val[ctx.ret.devices.devices_len] = NULL;
4335 return ctx.ret.devices.devices_val;
4338 struct umount_all_ctx {
4339 /* This flag is set by the callbacks, so we know we've done
4340 * the callbacks as expected, and in the right sequence.
4341 * 0 = not called, 1 = send called,
4342 * 1001 = reply called.
4345 struct guestfs_message_header hdr;
4346 struct guestfs_message_error err;
4349 static void umount_all_send_cb (guestfs_h *g, void *data)
4351 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4352 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
4354 ctx->cb_sequence = 1;
4355 ml->main_loop_quit (ml, g);
4358 static void umount_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4360 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4361 struct umount_all_ctx *ctx = (struct umount_all_ctx *) data;
4363 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4364 error (g, "%s: failed to parse reply header", "guestfs_umount_all");
4367 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4368 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4369 error (g, "%s: failed to parse reply error", "guestfs_umount_all");
4375 ctx->cb_sequence = 1001;
4376 ml->main_loop_quit (ml, g);
4379 int guestfs_umount_all (guestfs_h *g)
4381 struct umount_all_ctx ctx;
4382 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4385 if (check_state (g, "guestfs_umount_all") == -1) return -1;
4387 memset (&ctx, 0, sizeof ctx);
4389 serial = guestfs__send (g, GUESTFS_PROC_UMOUNT_ALL, NULL, NULL);
4393 ctx.cb_sequence = 0;
4394 guestfs_set_send_callback (g, umount_all_send_cb, &ctx);
4395 (void) ml->main_loop_run (ml, g);
4396 guestfs_set_send_callback (g, NULL, NULL);
4397 if (ctx.cb_sequence != 1) {
4398 error (g, "%s send failed, see earlier error messages", "guestfs_umount_all");
4402 guestfs__switch_to_receiving (g);
4403 ctx.cb_sequence = 0;
4404 guestfs_set_reply_callback (g, umount_all_reply_cb, &ctx);
4405 (void) ml->main_loop_run (ml, g);
4406 guestfs_set_reply_callback (g, NULL, NULL);
4407 if (ctx.cb_sequence != 1001) {
4408 error (g, "%s reply failed, see earlier error messages", "guestfs_umount_all");
4412 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UMOUNT_ALL, serial) == -1)
4415 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4416 error (g, "%s", ctx.err.error_message);
4423 struct lvm_remove_all_ctx {
4424 /* This flag is set by the callbacks, so we know we've done
4425 * the callbacks as expected, and in the right sequence.
4426 * 0 = not called, 1 = send called,
4427 * 1001 = reply called.
4430 struct guestfs_message_header hdr;
4431 struct guestfs_message_error err;
4434 static void lvm_remove_all_send_cb (guestfs_h *g, void *data)
4436 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4437 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
4439 ctx->cb_sequence = 1;
4440 ml->main_loop_quit (ml, g);
4443 static void lvm_remove_all_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4445 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4446 struct lvm_remove_all_ctx *ctx = (struct lvm_remove_all_ctx *) data;
4448 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4449 error (g, "%s: failed to parse reply header", "guestfs_lvm_remove_all");
4452 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4453 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4454 error (g, "%s: failed to parse reply error", "guestfs_lvm_remove_all");
4460 ctx->cb_sequence = 1001;
4461 ml->main_loop_quit (ml, g);
4464 int guestfs_lvm_remove_all (guestfs_h *g)
4466 struct lvm_remove_all_ctx ctx;
4467 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4470 if (check_state (g, "guestfs_lvm_remove_all") == -1) return -1;
4472 memset (&ctx, 0, sizeof ctx);
4474 serial = guestfs__send (g, GUESTFS_PROC_LVM_REMOVE_ALL, NULL, NULL);
4478 ctx.cb_sequence = 0;
4479 guestfs_set_send_callback (g, lvm_remove_all_send_cb, &ctx);
4480 (void) ml->main_loop_run (ml, g);
4481 guestfs_set_send_callback (g, NULL, NULL);
4482 if (ctx.cb_sequence != 1) {
4483 error (g, "%s send failed, see earlier error messages", "guestfs_lvm_remove_all");
4487 guestfs__switch_to_receiving (g);
4488 ctx.cb_sequence = 0;
4489 guestfs_set_reply_callback (g, lvm_remove_all_reply_cb, &ctx);
4490 (void) ml->main_loop_run (ml, g);
4491 guestfs_set_reply_callback (g, NULL, NULL);
4492 if (ctx.cb_sequence != 1001) {
4493 error (g, "%s reply failed, see earlier error messages", "guestfs_lvm_remove_all");
4497 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LVM_REMOVE_ALL, serial) == -1)
4500 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4501 error (g, "%s", ctx.err.error_message);
4509 /* This flag is set by the callbacks, so we know we've done
4510 * the callbacks as expected, and in the right sequence.
4511 * 0 = not called, 1 = send called,
4512 * 1001 = reply called.
4515 struct guestfs_message_header hdr;
4516 struct guestfs_message_error err;
4517 struct guestfs_file_ret ret;
4520 static void file_send_cb (guestfs_h *g, void *data)
4522 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4523 struct file_ctx *ctx = (struct file_ctx *) data;
4525 ctx->cb_sequence = 1;
4526 ml->main_loop_quit (ml, g);
4529 static void file_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4531 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4532 struct file_ctx *ctx = (struct file_ctx *) data;
4534 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4535 error (g, "%s: failed to parse reply header", "guestfs_file");
4538 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4539 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4540 error (g, "%s: failed to parse reply error", "guestfs_file");
4545 if (!xdr_guestfs_file_ret (xdr, &ctx->ret)) {
4546 error (g, "%s: failed to parse reply", "guestfs_file");
4550 ctx->cb_sequence = 1001;
4551 ml->main_loop_quit (ml, g);
4554 char *guestfs_file (guestfs_h *g,
4557 struct guestfs_file_args args;
4558 struct file_ctx ctx;
4559 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4562 if (check_state (g, "guestfs_file") == -1) return NULL;
4564 memset (&ctx, 0, sizeof ctx);
4566 args.path = (char *) path;
4567 serial = guestfs__send (g, GUESTFS_PROC_FILE,
4568 (xdrproc_t) xdr_guestfs_file_args, (char *) &args);
4572 ctx.cb_sequence = 0;
4573 guestfs_set_send_callback (g, file_send_cb, &ctx);
4574 (void) ml->main_loop_run (ml, g);
4575 guestfs_set_send_callback (g, NULL, NULL);
4576 if (ctx.cb_sequence != 1) {
4577 error (g, "%s send failed, see earlier error messages", "guestfs_file");
4581 guestfs__switch_to_receiving (g);
4582 ctx.cb_sequence = 0;
4583 guestfs_set_reply_callback (g, file_reply_cb, &ctx);
4584 (void) ml->main_loop_run (ml, g);
4585 guestfs_set_reply_callback (g, NULL, NULL);
4586 if (ctx.cb_sequence != 1001) {
4587 error (g, "%s reply failed, see earlier error messages", "guestfs_file");
4591 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_FILE, serial) == -1)
4594 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4595 error (g, "%s", ctx.err.error_message);
4599 return ctx.ret.description; /* caller will free */
4602 struct command_ctx {
4603 /* This flag is set by the callbacks, so we know we've done
4604 * the callbacks as expected, and in the right sequence.
4605 * 0 = not called, 1 = send called,
4606 * 1001 = reply called.
4609 struct guestfs_message_header hdr;
4610 struct guestfs_message_error err;
4611 struct guestfs_command_ret ret;
4614 static void command_send_cb (guestfs_h *g, void *data)
4616 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4617 struct command_ctx *ctx = (struct command_ctx *) data;
4619 ctx->cb_sequence = 1;
4620 ml->main_loop_quit (ml, g);
4623 static void command_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4625 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4626 struct command_ctx *ctx = (struct command_ctx *) data;
4628 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4629 error (g, "%s: failed to parse reply header", "guestfs_command");
4632 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4633 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4634 error (g, "%s: failed to parse reply error", "guestfs_command");
4639 if (!xdr_guestfs_command_ret (xdr, &ctx->ret)) {
4640 error (g, "%s: failed to parse reply", "guestfs_command");
4644 ctx->cb_sequence = 1001;
4645 ml->main_loop_quit (ml, g);
4648 char *guestfs_command (guestfs_h *g,
4649 char * const* const arguments)
4651 struct guestfs_command_args args;
4652 struct command_ctx ctx;
4653 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4656 if (check_state (g, "guestfs_command") == -1) return NULL;
4658 memset (&ctx, 0, sizeof ctx);
4660 args.arguments.arguments_val = (char **) arguments;
4661 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4662 serial = guestfs__send (g, GUESTFS_PROC_COMMAND,
4663 (xdrproc_t) xdr_guestfs_command_args, (char *) &args);
4667 ctx.cb_sequence = 0;
4668 guestfs_set_send_callback (g, command_send_cb, &ctx);
4669 (void) ml->main_loop_run (ml, g);
4670 guestfs_set_send_callback (g, NULL, NULL);
4671 if (ctx.cb_sequence != 1) {
4672 error (g, "%s send failed, see earlier error messages", "guestfs_command");
4676 guestfs__switch_to_receiving (g);
4677 ctx.cb_sequence = 0;
4678 guestfs_set_reply_callback (g, command_reply_cb, &ctx);
4679 (void) ml->main_loop_run (ml, g);
4680 guestfs_set_reply_callback (g, NULL, NULL);
4681 if (ctx.cb_sequence != 1001) {
4682 error (g, "%s reply failed, see earlier error messages", "guestfs_command");
4686 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND, serial) == -1)
4689 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4690 error (g, "%s", ctx.err.error_message);
4694 return ctx.ret.output; /* caller will free */
4697 struct command_lines_ctx {
4698 /* This flag is set by the callbacks, so we know we've done
4699 * the callbacks as expected, and in the right sequence.
4700 * 0 = not called, 1 = send called,
4701 * 1001 = reply called.
4704 struct guestfs_message_header hdr;
4705 struct guestfs_message_error err;
4706 struct guestfs_command_lines_ret ret;
4709 static void command_lines_send_cb (guestfs_h *g, void *data)
4711 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4712 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
4714 ctx->cb_sequence = 1;
4715 ml->main_loop_quit (ml, g);
4718 static void command_lines_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4720 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4721 struct command_lines_ctx *ctx = (struct command_lines_ctx *) data;
4723 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4724 error (g, "%s: failed to parse reply header", "guestfs_command_lines");
4727 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4728 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4729 error (g, "%s: failed to parse reply error", "guestfs_command_lines");
4734 if (!xdr_guestfs_command_lines_ret (xdr, &ctx->ret)) {
4735 error (g, "%s: failed to parse reply", "guestfs_command_lines");
4739 ctx->cb_sequence = 1001;
4740 ml->main_loop_quit (ml, g);
4743 char **guestfs_command_lines (guestfs_h *g,
4744 char * const* const arguments)
4746 struct guestfs_command_lines_args args;
4747 struct command_lines_ctx ctx;
4748 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4751 if (check_state (g, "guestfs_command_lines") == -1) return NULL;
4753 memset (&ctx, 0, sizeof ctx);
4755 args.arguments.arguments_val = (char **) arguments;
4756 for (args.arguments.arguments_len = 0; arguments[args.arguments.arguments_len]; args.arguments.arguments_len++) ;
4757 serial = guestfs__send (g, GUESTFS_PROC_COMMAND_LINES,
4758 (xdrproc_t) xdr_guestfs_command_lines_args, (char *) &args);
4762 ctx.cb_sequence = 0;
4763 guestfs_set_send_callback (g, command_lines_send_cb, &ctx);
4764 (void) ml->main_loop_run (ml, g);
4765 guestfs_set_send_callback (g, NULL, NULL);
4766 if (ctx.cb_sequence != 1) {
4767 error (g, "%s send failed, see earlier error messages", "guestfs_command_lines");
4771 guestfs__switch_to_receiving (g);
4772 ctx.cb_sequence = 0;
4773 guestfs_set_reply_callback (g, command_lines_reply_cb, &ctx);
4774 (void) ml->main_loop_run (ml, g);
4775 guestfs_set_reply_callback (g, NULL, NULL);
4776 if (ctx.cb_sequence != 1001) {
4777 error (g, "%s reply failed, see earlier error messages", "guestfs_command_lines");
4781 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_COMMAND_LINES, serial) == -1)
4784 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4785 error (g, "%s", ctx.err.error_message);
4789 /* caller will free this, but we need to add a NULL entry */
4790 ctx.ret.lines.lines_val =
4791 safe_realloc (g, ctx.ret.lines.lines_val,
4792 sizeof (char *) * (ctx.ret.lines.lines_len + 1));
4793 ctx.ret.lines.lines_val[ctx.ret.lines.lines_len] = NULL;
4794 return ctx.ret.lines.lines_val;
4798 /* This flag is set by the callbacks, so we know we've done
4799 * the callbacks as expected, and in the right sequence.
4800 * 0 = not called, 1 = send called,
4801 * 1001 = reply called.
4804 struct guestfs_message_header hdr;
4805 struct guestfs_message_error err;
4806 struct guestfs_stat_ret ret;
4809 static void stat_send_cb (guestfs_h *g, void *data)
4811 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4812 struct stat_ctx *ctx = (struct stat_ctx *) data;
4814 ctx->cb_sequence = 1;
4815 ml->main_loop_quit (ml, g);
4818 static void stat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4820 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4821 struct stat_ctx *ctx = (struct stat_ctx *) data;
4823 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4824 error (g, "%s: failed to parse reply header", "guestfs_stat");
4827 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4828 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4829 error (g, "%s: failed to parse reply error", "guestfs_stat");
4834 if (!xdr_guestfs_stat_ret (xdr, &ctx->ret)) {
4835 error (g, "%s: failed to parse reply", "guestfs_stat");
4839 ctx->cb_sequence = 1001;
4840 ml->main_loop_quit (ml, g);
4843 struct guestfs_stat *guestfs_stat (guestfs_h *g,
4846 struct guestfs_stat_args args;
4847 struct stat_ctx ctx;
4848 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4851 if (check_state (g, "guestfs_stat") == -1) return NULL;
4853 memset (&ctx, 0, sizeof ctx);
4855 args.path = (char *) path;
4856 serial = guestfs__send (g, GUESTFS_PROC_STAT,
4857 (xdrproc_t) xdr_guestfs_stat_args, (char *) &args);
4861 ctx.cb_sequence = 0;
4862 guestfs_set_send_callback (g, stat_send_cb, &ctx);
4863 (void) ml->main_loop_run (ml, g);
4864 guestfs_set_send_callback (g, NULL, NULL);
4865 if (ctx.cb_sequence != 1) {
4866 error (g, "%s send failed, see earlier error messages", "guestfs_stat");
4870 guestfs__switch_to_receiving (g);
4871 ctx.cb_sequence = 0;
4872 guestfs_set_reply_callback (g, stat_reply_cb, &ctx);
4873 (void) ml->main_loop_run (ml, g);
4874 guestfs_set_reply_callback (g, NULL, NULL);
4875 if (ctx.cb_sequence != 1001) {
4876 error (g, "%s reply failed, see earlier error messages", "guestfs_stat");
4880 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STAT, serial) == -1)
4883 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4884 error (g, "%s", ctx.err.error_message);
4888 /* caller will free this */
4889 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4893 /* This flag is set by the callbacks, so we know we've done
4894 * the callbacks as expected, and in the right sequence.
4895 * 0 = not called, 1 = send called,
4896 * 1001 = reply called.
4899 struct guestfs_message_header hdr;
4900 struct guestfs_message_error err;
4901 struct guestfs_lstat_ret ret;
4904 static void lstat_send_cb (guestfs_h *g, void *data)
4906 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4907 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4909 ctx->cb_sequence = 1;
4910 ml->main_loop_quit (ml, g);
4913 static void lstat_reply_cb (guestfs_h *g, void *data, XDR *xdr)
4915 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4916 struct lstat_ctx *ctx = (struct lstat_ctx *) data;
4918 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
4919 error (g, "%s: failed to parse reply header", "guestfs_lstat");
4922 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
4923 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
4924 error (g, "%s: failed to parse reply error", "guestfs_lstat");
4929 if (!xdr_guestfs_lstat_ret (xdr, &ctx->ret)) {
4930 error (g, "%s: failed to parse reply", "guestfs_lstat");
4934 ctx->cb_sequence = 1001;
4935 ml->main_loop_quit (ml, g);
4938 struct guestfs_stat *guestfs_lstat (guestfs_h *g,
4941 struct guestfs_lstat_args args;
4942 struct lstat_ctx ctx;
4943 guestfs_main_loop *ml = guestfs_get_main_loop (g);
4946 if (check_state (g, "guestfs_lstat") == -1) return NULL;
4948 memset (&ctx, 0, sizeof ctx);
4950 args.path = (char *) path;
4951 serial = guestfs__send (g, GUESTFS_PROC_LSTAT,
4952 (xdrproc_t) xdr_guestfs_lstat_args, (char *) &args);
4956 ctx.cb_sequence = 0;
4957 guestfs_set_send_callback (g, lstat_send_cb, &ctx);
4958 (void) ml->main_loop_run (ml, g);
4959 guestfs_set_send_callback (g, NULL, NULL);
4960 if (ctx.cb_sequence != 1) {
4961 error (g, "%s send failed, see earlier error messages", "guestfs_lstat");
4965 guestfs__switch_to_receiving (g);
4966 ctx.cb_sequence = 0;
4967 guestfs_set_reply_callback (g, lstat_reply_cb, &ctx);
4968 (void) ml->main_loop_run (ml, g);
4969 guestfs_set_reply_callback (g, NULL, NULL);
4970 if (ctx.cb_sequence != 1001) {
4971 error (g, "%s reply failed, see earlier error messages", "guestfs_lstat");
4975 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_LSTAT, serial) == -1)
4978 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
4979 error (g, "%s", ctx.err.error_message);
4983 /* caller will free this */
4984 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
4987 struct statvfs_ctx {
4988 /* This flag is set by the callbacks, so we know we've done
4989 * the callbacks as expected, and in the right sequence.
4990 * 0 = not called, 1 = send called,
4991 * 1001 = reply called.
4994 struct guestfs_message_header hdr;
4995 struct guestfs_message_error err;
4996 struct guestfs_statvfs_ret ret;
4999 static void statvfs_send_cb (guestfs_h *g, void *data)
5001 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5002 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
5004 ctx->cb_sequence = 1;
5005 ml->main_loop_quit (ml, g);
5008 static void statvfs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5010 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5011 struct statvfs_ctx *ctx = (struct statvfs_ctx *) data;
5013 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5014 error (g, "%s: failed to parse reply header", "guestfs_statvfs");
5017 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5018 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5019 error (g, "%s: failed to parse reply error", "guestfs_statvfs");
5024 if (!xdr_guestfs_statvfs_ret (xdr, &ctx->ret)) {
5025 error (g, "%s: failed to parse reply", "guestfs_statvfs");
5029 ctx->cb_sequence = 1001;
5030 ml->main_loop_quit (ml, g);
5033 struct guestfs_statvfs *guestfs_statvfs (guestfs_h *g,
5036 struct guestfs_statvfs_args args;
5037 struct statvfs_ctx ctx;
5038 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5041 if (check_state (g, "guestfs_statvfs") == -1) return NULL;
5043 memset (&ctx, 0, sizeof ctx);
5045 args.path = (char *) path;
5046 serial = guestfs__send (g, GUESTFS_PROC_STATVFS,
5047 (xdrproc_t) xdr_guestfs_statvfs_args, (char *) &args);
5051 ctx.cb_sequence = 0;
5052 guestfs_set_send_callback (g, statvfs_send_cb, &ctx);
5053 (void) ml->main_loop_run (ml, g);
5054 guestfs_set_send_callback (g, NULL, NULL);
5055 if (ctx.cb_sequence != 1) {
5056 error (g, "%s send failed, see earlier error messages", "guestfs_statvfs");
5060 guestfs__switch_to_receiving (g);
5061 ctx.cb_sequence = 0;
5062 guestfs_set_reply_callback (g, statvfs_reply_cb, &ctx);
5063 (void) ml->main_loop_run (ml, g);
5064 guestfs_set_reply_callback (g, NULL, NULL);
5065 if (ctx.cb_sequence != 1001) {
5066 error (g, "%s reply failed, see earlier error messages", "guestfs_statvfs");
5070 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_STATVFS, serial) == -1)
5073 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5074 error (g, "%s", ctx.err.error_message);
5078 /* caller will free this */
5079 return safe_memdup (g, &ctx.ret.statbuf, sizeof (ctx.ret.statbuf));
5082 struct tune2fs_l_ctx {
5083 /* This flag is set by the callbacks, so we know we've done
5084 * the callbacks as expected, and in the right sequence.
5085 * 0 = not called, 1 = send called,
5086 * 1001 = reply called.
5089 struct guestfs_message_header hdr;
5090 struct guestfs_message_error err;
5091 struct guestfs_tune2fs_l_ret ret;
5094 static void tune2fs_l_send_cb (guestfs_h *g, void *data)
5096 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5097 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
5099 ctx->cb_sequence = 1;
5100 ml->main_loop_quit (ml, g);
5103 static void tune2fs_l_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5105 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5106 struct tune2fs_l_ctx *ctx = (struct tune2fs_l_ctx *) data;
5108 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5109 error (g, "%s: failed to parse reply header", "guestfs_tune2fs_l");
5112 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5113 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5114 error (g, "%s: failed to parse reply error", "guestfs_tune2fs_l");
5119 if (!xdr_guestfs_tune2fs_l_ret (xdr, &ctx->ret)) {
5120 error (g, "%s: failed to parse reply", "guestfs_tune2fs_l");
5124 ctx->cb_sequence = 1001;
5125 ml->main_loop_quit (ml, g);
5128 char **guestfs_tune2fs_l (guestfs_h *g,
5131 struct guestfs_tune2fs_l_args args;
5132 struct tune2fs_l_ctx ctx;
5133 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5136 if (check_state (g, "guestfs_tune2fs_l") == -1) return NULL;
5138 memset (&ctx, 0, sizeof ctx);
5140 args.device = (char *) device;
5141 serial = guestfs__send (g, GUESTFS_PROC_TUNE2FS_L,
5142 (xdrproc_t) xdr_guestfs_tune2fs_l_args, (char *) &args);
5146 ctx.cb_sequence = 0;
5147 guestfs_set_send_callback (g, tune2fs_l_send_cb, &ctx);
5148 (void) ml->main_loop_run (ml, g);
5149 guestfs_set_send_callback (g, NULL, NULL);
5150 if (ctx.cb_sequence != 1) {
5151 error (g, "%s send failed, see earlier error messages", "guestfs_tune2fs_l");
5155 guestfs__switch_to_receiving (g);
5156 ctx.cb_sequence = 0;
5157 guestfs_set_reply_callback (g, tune2fs_l_reply_cb, &ctx);
5158 (void) ml->main_loop_run (ml, g);
5159 guestfs_set_reply_callback (g, NULL, NULL);
5160 if (ctx.cb_sequence != 1001) {
5161 error (g, "%s reply failed, see earlier error messages", "guestfs_tune2fs_l");
5165 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_TUNE2FS_L, serial) == -1)
5168 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5169 error (g, "%s", ctx.err.error_message);
5173 /* caller will free this, but we need to add a NULL entry */
5174 ctx.ret.superblock.superblock_val =
5175 safe_realloc (g, ctx.ret.superblock.superblock_val,
5176 sizeof (char *) * (ctx.ret.superblock.superblock_len + 1));
5177 ctx.ret.superblock.superblock_val[ctx.ret.superblock.superblock_len] = NULL;
5178 return ctx.ret.superblock.superblock_val;
5181 struct blockdev_setro_ctx {
5182 /* This flag is set by the callbacks, so we know we've done
5183 * the callbacks as expected, and in the right sequence.
5184 * 0 = not called, 1 = send called,
5185 * 1001 = reply called.
5188 struct guestfs_message_header hdr;
5189 struct guestfs_message_error err;
5192 static void blockdev_setro_send_cb (guestfs_h *g, void *data)
5194 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5195 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
5197 ctx->cb_sequence = 1;
5198 ml->main_loop_quit (ml, g);
5201 static void blockdev_setro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5203 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5204 struct blockdev_setro_ctx *ctx = (struct blockdev_setro_ctx *) data;
5206 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5207 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setro");
5210 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5211 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5212 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setro");
5218 ctx->cb_sequence = 1001;
5219 ml->main_loop_quit (ml, g);
5222 int guestfs_blockdev_setro (guestfs_h *g,
5225 struct guestfs_blockdev_setro_args args;
5226 struct blockdev_setro_ctx ctx;
5227 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5230 if (check_state (g, "guestfs_blockdev_setro") == -1) return -1;
5232 memset (&ctx, 0, sizeof ctx);
5234 args.device = (char *) device;
5235 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETRO,
5236 (xdrproc_t) xdr_guestfs_blockdev_setro_args, (char *) &args);
5240 ctx.cb_sequence = 0;
5241 guestfs_set_send_callback (g, blockdev_setro_send_cb, &ctx);
5242 (void) ml->main_loop_run (ml, g);
5243 guestfs_set_send_callback (g, NULL, NULL);
5244 if (ctx.cb_sequence != 1) {
5245 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setro");
5249 guestfs__switch_to_receiving (g);
5250 ctx.cb_sequence = 0;
5251 guestfs_set_reply_callback (g, blockdev_setro_reply_cb, &ctx);
5252 (void) ml->main_loop_run (ml, g);
5253 guestfs_set_reply_callback (g, NULL, NULL);
5254 if (ctx.cb_sequence != 1001) {
5255 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setro");
5259 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRO, serial) == -1)
5262 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5263 error (g, "%s", ctx.err.error_message);
5270 struct blockdev_setrw_ctx {
5271 /* This flag is set by the callbacks, so we know we've done
5272 * the callbacks as expected, and in the right sequence.
5273 * 0 = not called, 1 = send called,
5274 * 1001 = reply called.
5277 struct guestfs_message_header hdr;
5278 struct guestfs_message_error err;
5281 static void blockdev_setrw_send_cb (guestfs_h *g, void *data)
5283 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5284 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
5286 ctx->cb_sequence = 1;
5287 ml->main_loop_quit (ml, g);
5290 static void blockdev_setrw_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5292 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5293 struct blockdev_setrw_ctx *ctx = (struct blockdev_setrw_ctx *) data;
5295 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5296 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setrw");
5299 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5300 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5301 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setrw");
5307 ctx->cb_sequence = 1001;
5308 ml->main_loop_quit (ml, g);
5311 int guestfs_blockdev_setrw (guestfs_h *g,
5314 struct guestfs_blockdev_setrw_args args;
5315 struct blockdev_setrw_ctx ctx;
5316 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5319 if (check_state (g, "guestfs_blockdev_setrw") == -1) return -1;
5321 memset (&ctx, 0, sizeof ctx);
5323 args.device = (char *) device;
5324 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETRW,
5325 (xdrproc_t) xdr_guestfs_blockdev_setrw_args, (char *) &args);
5329 ctx.cb_sequence = 0;
5330 guestfs_set_send_callback (g, blockdev_setrw_send_cb, &ctx);
5331 (void) ml->main_loop_run (ml, g);
5332 guestfs_set_send_callback (g, NULL, NULL);
5333 if (ctx.cb_sequence != 1) {
5334 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setrw");
5338 guestfs__switch_to_receiving (g);
5339 ctx.cb_sequence = 0;
5340 guestfs_set_reply_callback (g, blockdev_setrw_reply_cb, &ctx);
5341 (void) ml->main_loop_run (ml, g);
5342 guestfs_set_reply_callback (g, NULL, NULL);
5343 if (ctx.cb_sequence != 1001) {
5344 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setrw");
5348 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETRW, serial) == -1)
5351 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5352 error (g, "%s", ctx.err.error_message);
5359 struct blockdev_getro_ctx {
5360 /* This flag is set by the callbacks, so we know we've done
5361 * the callbacks as expected, and in the right sequence.
5362 * 0 = not called, 1 = send called,
5363 * 1001 = reply called.
5366 struct guestfs_message_header hdr;
5367 struct guestfs_message_error err;
5368 struct guestfs_blockdev_getro_ret ret;
5371 static void blockdev_getro_send_cb (guestfs_h *g, void *data)
5373 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5374 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
5376 ctx->cb_sequence = 1;
5377 ml->main_loop_quit (ml, g);
5380 static void blockdev_getro_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5382 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5383 struct blockdev_getro_ctx *ctx = (struct blockdev_getro_ctx *) data;
5385 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5386 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getro");
5389 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5390 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5391 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getro");
5396 if (!xdr_guestfs_blockdev_getro_ret (xdr, &ctx->ret)) {
5397 error (g, "%s: failed to parse reply", "guestfs_blockdev_getro");
5401 ctx->cb_sequence = 1001;
5402 ml->main_loop_quit (ml, g);
5405 int guestfs_blockdev_getro (guestfs_h *g,
5408 struct guestfs_blockdev_getro_args args;
5409 struct blockdev_getro_ctx ctx;
5410 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5413 if (check_state (g, "guestfs_blockdev_getro") == -1) return -1;
5415 memset (&ctx, 0, sizeof ctx);
5417 args.device = (char *) device;
5418 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETRO,
5419 (xdrproc_t) xdr_guestfs_blockdev_getro_args, (char *) &args);
5423 ctx.cb_sequence = 0;
5424 guestfs_set_send_callback (g, blockdev_getro_send_cb, &ctx);
5425 (void) ml->main_loop_run (ml, g);
5426 guestfs_set_send_callback (g, NULL, NULL);
5427 if (ctx.cb_sequence != 1) {
5428 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getro");
5432 guestfs__switch_to_receiving (g);
5433 ctx.cb_sequence = 0;
5434 guestfs_set_reply_callback (g, blockdev_getro_reply_cb, &ctx);
5435 (void) ml->main_loop_run (ml, g);
5436 guestfs_set_reply_callback (g, NULL, NULL);
5437 if (ctx.cb_sequence != 1001) {
5438 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getro");
5442 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETRO, serial) == -1)
5445 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5446 error (g, "%s", ctx.err.error_message);
5453 struct blockdev_getss_ctx {
5454 /* This flag is set by the callbacks, so we know we've done
5455 * the callbacks as expected, and in the right sequence.
5456 * 0 = not called, 1 = send called,
5457 * 1001 = reply called.
5460 struct guestfs_message_header hdr;
5461 struct guestfs_message_error err;
5462 struct guestfs_blockdev_getss_ret ret;
5465 static void blockdev_getss_send_cb (guestfs_h *g, void *data)
5467 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5468 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
5470 ctx->cb_sequence = 1;
5471 ml->main_loop_quit (ml, g);
5474 static void blockdev_getss_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5476 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5477 struct blockdev_getss_ctx *ctx = (struct blockdev_getss_ctx *) data;
5479 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5480 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getss");
5483 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5484 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5485 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getss");
5490 if (!xdr_guestfs_blockdev_getss_ret (xdr, &ctx->ret)) {
5491 error (g, "%s: failed to parse reply", "guestfs_blockdev_getss");
5495 ctx->cb_sequence = 1001;
5496 ml->main_loop_quit (ml, g);
5499 int guestfs_blockdev_getss (guestfs_h *g,
5502 struct guestfs_blockdev_getss_args args;
5503 struct blockdev_getss_ctx ctx;
5504 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5507 if (check_state (g, "guestfs_blockdev_getss") == -1) return -1;
5509 memset (&ctx, 0, sizeof ctx);
5511 args.device = (char *) device;
5512 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSS,
5513 (xdrproc_t) xdr_guestfs_blockdev_getss_args, (char *) &args);
5517 ctx.cb_sequence = 0;
5518 guestfs_set_send_callback (g, blockdev_getss_send_cb, &ctx);
5519 (void) ml->main_loop_run (ml, g);
5520 guestfs_set_send_callback (g, NULL, NULL);
5521 if (ctx.cb_sequence != 1) {
5522 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getss");
5526 guestfs__switch_to_receiving (g);
5527 ctx.cb_sequence = 0;
5528 guestfs_set_reply_callback (g, blockdev_getss_reply_cb, &ctx);
5529 (void) ml->main_loop_run (ml, g);
5530 guestfs_set_reply_callback (g, NULL, NULL);
5531 if (ctx.cb_sequence != 1001) {
5532 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getss");
5536 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSS, serial) == -1)
5539 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5540 error (g, "%s", ctx.err.error_message);
5544 return ctx.ret.sectorsize;
5547 struct blockdev_getbsz_ctx {
5548 /* This flag is set by the callbacks, so we know we've done
5549 * the callbacks as expected, and in the right sequence.
5550 * 0 = not called, 1 = send called,
5551 * 1001 = reply called.
5554 struct guestfs_message_header hdr;
5555 struct guestfs_message_error err;
5556 struct guestfs_blockdev_getbsz_ret ret;
5559 static void blockdev_getbsz_send_cb (guestfs_h *g, void *data)
5561 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5562 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
5564 ctx->cb_sequence = 1;
5565 ml->main_loop_quit (ml, g);
5568 static void blockdev_getbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5570 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5571 struct blockdev_getbsz_ctx *ctx = (struct blockdev_getbsz_ctx *) data;
5573 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5574 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getbsz");
5577 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5578 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5579 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getbsz");
5584 if (!xdr_guestfs_blockdev_getbsz_ret (xdr, &ctx->ret)) {
5585 error (g, "%s: failed to parse reply", "guestfs_blockdev_getbsz");
5589 ctx->cb_sequence = 1001;
5590 ml->main_loop_quit (ml, g);
5593 int guestfs_blockdev_getbsz (guestfs_h *g,
5596 struct guestfs_blockdev_getbsz_args args;
5597 struct blockdev_getbsz_ctx ctx;
5598 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5601 if (check_state (g, "guestfs_blockdev_getbsz") == -1) return -1;
5603 memset (&ctx, 0, sizeof ctx);
5605 args.device = (char *) device;
5606 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETBSZ,
5607 (xdrproc_t) xdr_guestfs_blockdev_getbsz_args, (char *) &args);
5611 ctx.cb_sequence = 0;
5612 guestfs_set_send_callback (g, blockdev_getbsz_send_cb, &ctx);
5613 (void) ml->main_loop_run (ml, g);
5614 guestfs_set_send_callback (g, NULL, NULL);
5615 if (ctx.cb_sequence != 1) {
5616 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getbsz");
5620 guestfs__switch_to_receiving (g);
5621 ctx.cb_sequence = 0;
5622 guestfs_set_reply_callback (g, blockdev_getbsz_reply_cb, &ctx);
5623 (void) ml->main_loop_run (ml, g);
5624 guestfs_set_reply_callback (g, NULL, NULL);
5625 if (ctx.cb_sequence != 1001) {
5626 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getbsz");
5630 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETBSZ, serial) == -1)
5633 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5634 error (g, "%s", ctx.err.error_message);
5638 return ctx.ret.blocksize;
5641 struct blockdev_setbsz_ctx {
5642 /* This flag is set by the callbacks, so we know we've done
5643 * the callbacks as expected, and in the right sequence.
5644 * 0 = not called, 1 = send called,
5645 * 1001 = reply called.
5648 struct guestfs_message_header hdr;
5649 struct guestfs_message_error err;
5652 static void blockdev_setbsz_send_cb (guestfs_h *g, void *data)
5654 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5655 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
5657 ctx->cb_sequence = 1;
5658 ml->main_loop_quit (ml, g);
5661 static void blockdev_setbsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5663 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5664 struct blockdev_setbsz_ctx *ctx = (struct blockdev_setbsz_ctx *) data;
5666 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5667 error (g, "%s: failed to parse reply header", "guestfs_blockdev_setbsz");
5670 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5671 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5672 error (g, "%s: failed to parse reply error", "guestfs_blockdev_setbsz");
5678 ctx->cb_sequence = 1001;
5679 ml->main_loop_quit (ml, g);
5682 int guestfs_blockdev_setbsz (guestfs_h *g,
5686 struct guestfs_blockdev_setbsz_args args;
5687 struct blockdev_setbsz_ctx ctx;
5688 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5691 if (check_state (g, "guestfs_blockdev_setbsz") == -1) return -1;
5693 memset (&ctx, 0, sizeof ctx);
5695 args.device = (char *) device;
5696 args.blocksize = blocksize;
5697 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_SETBSZ,
5698 (xdrproc_t) xdr_guestfs_blockdev_setbsz_args, (char *) &args);
5702 ctx.cb_sequence = 0;
5703 guestfs_set_send_callback (g, blockdev_setbsz_send_cb, &ctx);
5704 (void) ml->main_loop_run (ml, g);
5705 guestfs_set_send_callback (g, NULL, NULL);
5706 if (ctx.cb_sequence != 1) {
5707 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_setbsz");
5711 guestfs__switch_to_receiving (g);
5712 ctx.cb_sequence = 0;
5713 guestfs_set_reply_callback (g, blockdev_setbsz_reply_cb, &ctx);
5714 (void) ml->main_loop_run (ml, g);
5715 guestfs_set_reply_callback (g, NULL, NULL);
5716 if (ctx.cb_sequence != 1001) {
5717 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_setbsz");
5721 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_SETBSZ, serial) == -1)
5724 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5725 error (g, "%s", ctx.err.error_message);
5732 struct blockdev_getsz_ctx {
5733 /* This flag is set by the callbacks, so we know we've done
5734 * the callbacks as expected, and in the right sequence.
5735 * 0 = not called, 1 = send called,
5736 * 1001 = reply called.
5739 struct guestfs_message_header hdr;
5740 struct guestfs_message_error err;
5741 struct guestfs_blockdev_getsz_ret ret;
5744 static void blockdev_getsz_send_cb (guestfs_h *g, void *data)
5746 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5747 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
5749 ctx->cb_sequence = 1;
5750 ml->main_loop_quit (ml, g);
5753 static void blockdev_getsz_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5755 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5756 struct blockdev_getsz_ctx *ctx = (struct blockdev_getsz_ctx *) data;
5758 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5759 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsz");
5762 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5763 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5764 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsz");
5769 if (!xdr_guestfs_blockdev_getsz_ret (xdr, &ctx->ret)) {
5770 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsz");
5774 ctx->cb_sequence = 1001;
5775 ml->main_loop_quit (ml, g);
5778 int64_t guestfs_blockdev_getsz (guestfs_h *g,
5781 struct guestfs_blockdev_getsz_args args;
5782 struct blockdev_getsz_ctx ctx;
5783 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5786 if (check_state (g, "guestfs_blockdev_getsz") == -1) return -1;
5788 memset (&ctx, 0, sizeof ctx);
5790 args.device = (char *) device;
5791 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSZ,
5792 (xdrproc_t) xdr_guestfs_blockdev_getsz_args, (char *) &args);
5796 ctx.cb_sequence = 0;
5797 guestfs_set_send_callback (g, blockdev_getsz_send_cb, &ctx);
5798 (void) ml->main_loop_run (ml, g);
5799 guestfs_set_send_callback (g, NULL, NULL);
5800 if (ctx.cb_sequence != 1) {
5801 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getsz");
5805 guestfs__switch_to_receiving (g);
5806 ctx.cb_sequence = 0;
5807 guestfs_set_reply_callback (g, blockdev_getsz_reply_cb, &ctx);
5808 (void) ml->main_loop_run (ml, g);
5809 guestfs_set_reply_callback (g, NULL, NULL);
5810 if (ctx.cb_sequence != 1001) {
5811 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsz");
5815 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSZ, serial) == -1)
5818 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5819 error (g, "%s", ctx.err.error_message);
5823 return ctx.ret.sizeinsectors;
5826 struct blockdev_getsize64_ctx {
5827 /* This flag is set by the callbacks, so we know we've done
5828 * the callbacks as expected, and in the right sequence.
5829 * 0 = not called, 1 = send called,
5830 * 1001 = reply called.
5833 struct guestfs_message_header hdr;
5834 struct guestfs_message_error err;
5835 struct guestfs_blockdev_getsize64_ret ret;
5838 static void blockdev_getsize64_send_cb (guestfs_h *g, void *data)
5840 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5841 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
5843 ctx->cb_sequence = 1;
5844 ml->main_loop_quit (ml, g);
5847 static void blockdev_getsize64_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5849 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5850 struct blockdev_getsize64_ctx *ctx = (struct blockdev_getsize64_ctx *) data;
5852 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5853 error (g, "%s: failed to parse reply header", "guestfs_blockdev_getsize64");
5856 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5857 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5858 error (g, "%s: failed to parse reply error", "guestfs_blockdev_getsize64");
5863 if (!xdr_guestfs_blockdev_getsize64_ret (xdr, &ctx->ret)) {
5864 error (g, "%s: failed to parse reply", "guestfs_blockdev_getsize64");
5868 ctx->cb_sequence = 1001;
5869 ml->main_loop_quit (ml, g);
5872 int64_t guestfs_blockdev_getsize64 (guestfs_h *g,
5875 struct guestfs_blockdev_getsize64_args args;
5876 struct blockdev_getsize64_ctx ctx;
5877 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5880 if (check_state (g, "guestfs_blockdev_getsize64") == -1) return -1;
5882 memset (&ctx, 0, sizeof ctx);
5884 args.device = (char *) device;
5885 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_GETSIZE64,
5886 (xdrproc_t) xdr_guestfs_blockdev_getsize64_args, (char *) &args);
5890 ctx.cb_sequence = 0;
5891 guestfs_set_send_callback (g, blockdev_getsize64_send_cb, &ctx);
5892 (void) ml->main_loop_run (ml, g);
5893 guestfs_set_send_callback (g, NULL, NULL);
5894 if (ctx.cb_sequence != 1) {
5895 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_getsize64");
5899 guestfs__switch_to_receiving (g);
5900 ctx.cb_sequence = 0;
5901 guestfs_set_reply_callback (g, blockdev_getsize64_reply_cb, &ctx);
5902 (void) ml->main_loop_run (ml, g);
5903 guestfs_set_reply_callback (g, NULL, NULL);
5904 if (ctx.cb_sequence != 1001) {
5905 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_getsize64");
5909 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_GETSIZE64, serial) == -1)
5912 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
5913 error (g, "%s", ctx.err.error_message);
5917 return ctx.ret.sizeinbytes;
5920 struct blockdev_flushbufs_ctx {
5921 /* This flag is set by the callbacks, so we know we've done
5922 * the callbacks as expected, and in the right sequence.
5923 * 0 = not called, 1 = send called,
5924 * 1001 = reply called.
5927 struct guestfs_message_header hdr;
5928 struct guestfs_message_error err;
5931 static void blockdev_flushbufs_send_cb (guestfs_h *g, void *data)
5933 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5934 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
5936 ctx->cb_sequence = 1;
5937 ml->main_loop_quit (ml, g);
5940 static void blockdev_flushbufs_reply_cb (guestfs_h *g, void *data, XDR *xdr)
5942 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5943 struct blockdev_flushbufs_ctx *ctx = (struct blockdev_flushbufs_ctx *) data;
5945 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
5946 error (g, "%s: failed to parse reply header", "guestfs_blockdev_flushbufs");
5949 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
5950 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
5951 error (g, "%s: failed to parse reply error", "guestfs_blockdev_flushbufs");
5957 ctx->cb_sequence = 1001;
5958 ml->main_loop_quit (ml, g);
5961 int guestfs_blockdev_flushbufs (guestfs_h *g,
5964 struct guestfs_blockdev_flushbufs_args args;
5965 struct blockdev_flushbufs_ctx ctx;
5966 guestfs_main_loop *ml = guestfs_get_main_loop (g);
5969 if (check_state (g, "guestfs_blockdev_flushbufs") == -1) return -1;
5971 memset (&ctx, 0, sizeof ctx);
5973 args.device = (char *) device;
5974 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS,
5975 (xdrproc_t) xdr_guestfs_blockdev_flushbufs_args, (char *) &args);
5979 ctx.cb_sequence = 0;
5980 guestfs_set_send_callback (g, blockdev_flushbufs_send_cb, &ctx);
5981 (void) ml->main_loop_run (ml, g);
5982 guestfs_set_send_callback (g, NULL, NULL);
5983 if (ctx.cb_sequence != 1) {
5984 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_flushbufs");
5988 guestfs__switch_to_receiving (g);
5989 ctx.cb_sequence = 0;
5990 guestfs_set_reply_callback (g, blockdev_flushbufs_reply_cb, &ctx);
5991 (void) ml->main_loop_run (ml, g);
5992 guestfs_set_reply_callback (g, NULL, NULL);
5993 if (ctx.cb_sequence != 1001) {
5994 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_flushbufs");
5998 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_FLUSHBUFS, serial) == -1)
6001 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6002 error (g, "%s", ctx.err.error_message);
6009 struct blockdev_rereadpt_ctx {
6010 /* This flag is set by the callbacks, so we know we've done
6011 * the callbacks as expected, and in the right sequence.
6012 * 0 = not called, 1 = send called,
6013 * 1001 = reply called.
6016 struct guestfs_message_header hdr;
6017 struct guestfs_message_error err;
6020 static void blockdev_rereadpt_send_cb (guestfs_h *g, void *data)
6022 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6023 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
6025 ctx->cb_sequence = 1;
6026 ml->main_loop_quit (ml, g);
6029 static void blockdev_rereadpt_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6031 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6032 struct blockdev_rereadpt_ctx *ctx = (struct blockdev_rereadpt_ctx *) data;
6034 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6035 error (g, "%s: failed to parse reply header", "guestfs_blockdev_rereadpt");
6038 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6039 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6040 error (g, "%s: failed to parse reply error", "guestfs_blockdev_rereadpt");
6046 ctx->cb_sequence = 1001;
6047 ml->main_loop_quit (ml, g);
6050 int guestfs_blockdev_rereadpt (guestfs_h *g,
6053 struct guestfs_blockdev_rereadpt_args args;
6054 struct blockdev_rereadpt_ctx ctx;
6055 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6058 if (check_state (g, "guestfs_blockdev_rereadpt") == -1) return -1;
6060 memset (&ctx, 0, sizeof ctx);
6062 args.device = (char *) device;
6063 serial = guestfs__send (g, GUESTFS_PROC_BLOCKDEV_REREADPT,
6064 (xdrproc_t) xdr_guestfs_blockdev_rereadpt_args, (char *) &args);
6068 ctx.cb_sequence = 0;
6069 guestfs_set_send_callback (g, blockdev_rereadpt_send_cb, &ctx);
6070 (void) ml->main_loop_run (ml, g);
6071 guestfs_set_send_callback (g, NULL, NULL);
6072 if (ctx.cb_sequence != 1) {
6073 error (g, "%s send failed, see earlier error messages", "guestfs_blockdev_rereadpt");
6077 guestfs__switch_to_receiving (g);
6078 ctx.cb_sequence = 0;
6079 guestfs_set_reply_callback (g, blockdev_rereadpt_reply_cb, &ctx);
6080 (void) ml->main_loop_run (ml, g);
6081 guestfs_set_reply_callback (g, NULL, NULL);
6082 if (ctx.cb_sequence != 1001) {
6083 error (g, "%s reply failed, see earlier error messages", "guestfs_blockdev_rereadpt");
6087 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_BLOCKDEV_REREADPT, serial) == -1)
6090 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6091 error (g, "%s", ctx.err.error_message);
6099 /* This flag is set by the callbacks, so we know we've done
6100 * the callbacks as expected, and in the right sequence.
6101 * 0 = not called, 1 = send called,
6102 * 1001 = reply called.
6105 struct guestfs_message_header hdr;
6106 struct guestfs_message_error err;
6109 static void upload_send_cb (guestfs_h *g, void *data)
6111 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6112 struct upload_ctx *ctx = (struct upload_ctx *) data;
6114 ctx->cb_sequence = 1;
6115 ml->main_loop_quit (ml, g);
6118 static void upload_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6120 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6121 struct upload_ctx *ctx = (struct upload_ctx *) data;
6123 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6124 error (g, "%s: failed to parse reply header", "guestfs_upload");
6127 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6128 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6129 error (g, "%s: failed to parse reply error", "guestfs_upload");
6135 ctx->cb_sequence = 1001;
6136 ml->main_loop_quit (ml, g);
6139 int guestfs_upload (guestfs_h *g,
6140 const char *filename,
6141 const char *remotefilename)
6143 struct guestfs_upload_args args;
6144 struct upload_ctx ctx;
6145 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6148 if (check_state (g, "guestfs_upload") == -1) return -1;
6150 memset (&ctx, 0, sizeof ctx);
6152 args.remotefilename = (char *) remotefilename;
6153 serial = guestfs__send (g, GUESTFS_PROC_UPLOAD,
6154 (xdrproc_t) xdr_guestfs_upload_args, (char *) &args);
6158 ctx.cb_sequence = 0;
6159 guestfs_set_send_callback (g, upload_send_cb, &ctx);
6160 (void) ml->main_loop_run (ml, g);
6161 guestfs_set_send_callback (g, NULL, NULL);
6162 if (ctx.cb_sequence != 1) {
6163 error (g, "%s send failed, see earlier error messages", "guestfs_upload");
6167 if (guestfs__send_file_sync (ml, g, filename) == -1)
6170 guestfs__switch_to_receiving (g);
6171 ctx.cb_sequence = 0;
6172 guestfs_set_reply_callback (g, upload_reply_cb, &ctx);
6173 (void) ml->main_loop_run (ml, g);
6174 guestfs_set_reply_callback (g, NULL, NULL);
6175 if (ctx.cb_sequence != 1001) {
6176 error (g, "%s reply failed, see earlier error messages", "guestfs_upload");
6180 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_UPLOAD, serial) == -1)
6183 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6184 error (g, "%s", ctx.err.error_message);
6191 struct download_ctx {
6192 /* This flag is set by the callbacks, so we know we've done
6193 * the callbacks as expected, and in the right sequence.
6194 * 0 = not called, 1 = send called,
6195 * 1001 = reply called.
6198 struct guestfs_message_header hdr;
6199 struct guestfs_message_error err;
6202 static void download_send_cb (guestfs_h *g, void *data)
6204 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6205 struct download_ctx *ctx = (struct download_ctx *) data;
6207 ctx->cb_sequence = 1;
6208 ml->main_loop_quit (ml, g);
6211 static void download_reply_cb (guestfs_h *g, void *data, XDR *xdr)
6213 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6214 struct download_ctx *ctx = (struct download_ctx *) data;
6216 if (!xdr_guestfs_message_header (xdr, &ctx->hdr)) {
6217 error (g, "%s: failed to parse reply header", "guestfs_download");
6220 if (ctx->hdr.status == GUESTFS_STATUS_ERROR) {
6221 if (!xdr_guestfs_message_error (xdr, &ctx->err)) {
6222 error (g, "%s: failed to parse reply error", "guestfs_download");
6228 ctx->cb_sequence = 1001;
6229 ml->main_loop_quit (ml, g);
6232 int guestfs_download (guestfs_h *g,
6233 const char *remotefilename,
6234 const char *filename)
6236 struct guestfs_download_args args;
6237 struct download_ctx ctx;
6238 guestfs_main_loop *ml = guestfs_get_main_loop (g);
6241 if (check_state (g, "guestfs_download") == -1) return -1;
6243 memset (&ctx, 0, sizeof ctx);
6245 args.remotefilename = (char *) remotefilename;
6246 serial = guestfs__send (g, GUESTFS_PROC_DOWNLOAD,
6247 (xdrproc_t) xdr_guestfs_download_args, (char *) &args);
6251 ctx.cb_sequence = 0;
6252 guestfs_set_send_callback (g, download_send_cb, &ctx);
6253 (void) ml->main_loop_run (ml, g);
6254 guestfs_set_send_callback (g, NULL, NULL);
6255 if (ctx.cb_sequence != 1) {
6256 error (g, "%s send failed, see earlier error messages", "guestfs_download");
6260 guestfs__switch_to_receiving (g);
6261 ctx.cb_sequence = 0;
6262 guestfs_set_reply_callback (g, download_reply_cb, &ctx);
6263 (void) ml->main_loop_run (ml, g);
6264 guestfs_set_reply_callback (g, NULL, NULL);
6265 if (ctx.cb_sequence != 1001) {
6266 error (g, "%s reply failed, see earlier error messages", "guestfs_download");
6270 if (check_reply_header (g, &ctx.hdr, GUESTFS_PROC_DOWNLOAD, serial) == -1)
6273 if (ctx.hdr.status == GUESTFS_STATUS_ERROR) {
6274 error (g, "%s", ctx.err.error_message);
6278 if (guestfs__receive_file_sync (ml, g, filename) == -1)