Added Augeas support.
[libguestfs.git] / src / guestfs-actions.c
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.
4  *
5  * Copyright (C) 2009 Red Hat Inc.
6  *
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.
11  *
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.
16  *
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
20  */
21
22 struct mount_rv {
23   int cb_done;  /* flag to indicate callback was called */
24   struct guestfs_message_header hdr;
25   struct guestfs_message_error err;
26 };
27
28 static void mount_cb (guestfs_h *g, void *data, XDR *xdr)
29 {
30   struct mount_rv *rv = (struct mount_rv *) data;
31
32   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
33     error (g, "guestfs_mount: failed to parse reply header");
34     return;
35   }
36   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
37     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
38       error (g, "guestfs_mount: failed to parse reply error");
39       return;
40     }
41     goto done;
42   }
43  done:
44   rv->cb_done = 1;
45   main_loop.main_loop_quit (g);
46 }
47
48 int guestfs_mount (guestfs_h *g,
49                 const char *device,
50                 const char *mountpoint)
51 {
52   struct guestfs_mount_args args;
53   struct mount_rv rv;
54   int serial;
55
56   if (g->state != READY) {
57     error (g, "guestfs_mount called from the wrong state, %d != READY",
58       g->state);
59     return -1;
60   }
61
62   memset (&rv, 0, sizeof rv);
63
64   args.device = (char *) device;
65   args.mountpoint = (char *) mountpoint;
66   serial = dispatch (g, GUESTFS_PROC_MOUNT,
67                      (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
68   if (serial == -1)
69     return -1;
70
71   rv.cb_done = 0;
72   g->reply_cb_internal = mount_cb;
73   g->reply_cb_internal_data = &rv;
74   main_loop.main_loop_run (g);
75   g->reply_cb_internal = NULL;
76   g->reply_cb_internal_data = NULL;
77   if (!rv.cb_done) {
78     error (g, "guestfs_mount failed, see earlier error messages");
79     return -1;
80   }
81
82   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
83     return -1;
84
85   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
86     error (g, "%s", rv.err.error);
87     return -1;
88   }
89
90   return 0;
91 }
92
93 struct sync_rv {
94   int cb_done;  /* flag to indicate callback was called */
95   struct guestfs_message_header hdr;
96   struct guestfs_message_error err;
97 };
98
99 static void sync_cb (guestfs_h *g, void *data, XDR *xdr)
100 {
101   struct sync_rv *rv = (struct sync_rv *) data;
102
103   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
104     error (g, "guestfs_sync: failed to parse reply header");
105     return;
106   }
107   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
108     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
109       error (g, "guestfs_sync: failed to parse reply error");
110       return;
111     }
112     goto done;
113   }
114  done:
115   rv->cb_done = 1;
116   main_loop.main_loop_quit (g);
117 }
118
119 int guestfs_sync (guestfs_h *g)
120 {
121   struct sync_rv rv;
122   int serial;
123
124   if (g->state != READY) {
125     error (g, "guestfs_sync called from the wrong state, %d != READY",
126       g->state);
127     return -1;
128   }
129
130   memset (&rv, 0, sizeof rv);
131
132   serial = dispatch (g, GUESTFS_PROC_SYNC, NULL, NULL);
133   if (serial == -1)
134     return -1;
135
136   rv.cb_done = 0;
137   g->reply_cb_internal = sync_cb;
138   g->reply_cb_internal_data = &rv;
139   main_loop.main_loop_run (g);
140   g->reply_cb_internal = NULL;
141   g->reply_cb_internal_data = NULL;
142   if (!rv.cb_done) {
143     error (g, "guestfs_sync failed, see earlier error messages");
144     return -1;
145   }
146
147   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_SYNC, serial) == -1)
148     return -1;
149
150   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
151     error (g, "%s", rv.err.error);
152     return -1;
153   }
154
155   return 0;
156 }
157
158 struct touch_rv {
159   int cb_done;  /* flag to indicate callback was called */
160   struct guestfs_message_header hdr;
161   struct guestfs_message_error err;
162 };
163
164 static void touch_cb (guestfs_h *g, void *data, XDR *xdr)
165 {
166   struct touch_rv *rv = (struct touch_rv *) data;
167
168   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
169     error (g, "guestfs_touch: failed to parse reply header");
170     return;
171   }
172   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
173     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
174       error (g, "guestfs_touch: failed to parse reply error");
175       return;
176     }
177     goto done;
178   }
179  done:
180   rv->cb_done = 1;
181   main_loop.main_loop_quit (g);
182 }
183
184 int guestfs_touch (guestfs_h *g,
185                 const char *path)
186 {
187   struct guestfs_touch_args args;
188   struct touch_rv rv;
189   int serial;
190
191   if (g->state != READY) {
192     error (g, "guestfs_touch called from the wrong state, %d != READY",
193       g->state);
194     return -1;
195   }
196
197   memset (&rv, 0, sizeof rv);
198
199   args.path = (char *) path;
200   serial = dispatch (g, GUESTFS_PROC_TOUCH,
201                      (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
202   if (serial == -1)
203     return -1;
204
205   rv.cb_done = 0;
206   g->reply_cb_internal = touch_cb;
207   g->reply_cb_internal_data = &rv;
208   main_loop.main_loop_run (g);
209   g->reply_cb_internal = NULL;
210   g->reply_cb_internal_data = NULL;
211   if (!rv.cb_done) {
212     error (g, "guestfs_touch failed, see earlier error messages");
213     return -1;
214   }
215
216   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
217     return -1;
218
219   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
220     error (g, "%s", rv.err.error);
221     return -1;
222   }
223
224   return 0;
225 }
226
227 struct cat_rv {
228   int cb_done;  /* flag to indicate callback was called */
229   struct guestfs_message_header hdr;
230   struct guestfs_message_error err;
231   struct guestfs_cat_ret ret;
232 };
233
234 static void cat_cb (guestfs_h *g, void *data, XDR *xdr)
235 {
236   struct cat_rv *rv = (struct cat_rv *) data;
237
238   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
239     error (g, "guestfs_cat: failed to parse reply header");
240     return;
241   }
242   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
243     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
244       error (g, "guestfs_cat: failed to parse reply error");
245       return;
246     }
247     goto done;
248   }
249   if (!xdr_guestfs_cat_ret (xdr, &rv->ret)) {
250     error (g, "guestfs_cat: failed to parse reply");
251     return;
252   }
253  done:
254   rv->cb_done = 1;
255   main_loop.main_loop_quit (g);
256 }
257
258 char *guestfs_cat (guestfs_h *g,
259                 const char *path)
260 {
261   struct guestfs_cat_args args;
262   struct cat_rv rv;
263   int serial;
264
265   if (g->state != READY) {
266     error (g, "guestfs_cat called from the wrong state, %d != READY",
267       g->state);
268     return NULL;
269   }
270
271   memset (&rv, 0, sizeof rv);
272
273   args.path = (char *) path;
274   serial = dispatch (g, GUESTFS_PROC_CAT,
275                      (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
276   if (serial == -1)
277     return NULL;
278
279   rv.cb_done = 0;
280   g->reply_cb_internal = cat_cb;
281   g->reply_cb_internal_data = &rv;
282   main_loop.main_loop_run (g);
283   g->reply_cb_internal = NULL;
284   g->reply_cb_internal_data = NULL;
285   if (!rv.cb_done) {
286     error (g, "guestfs_cat failed, see earlier error messages");
287     return NULL;
288   }
289
290   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_CAT, serial) == -1)
291     return NULL;
292
293   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
294     error (g, "%s", rv.err.error);
295     return NULL;
296   }
297
298   return rv.ret.content; /* caller will free */
299 }
300
301 struct ll_rv {
302   int cb_done;  /* flag to indicate callback was called */
303   struct guestfs_message_header hdr;
304   struct guestfs_message_error err;
305   struct guestfs_ll_ret ret;
306 };
307
308 static void ll_cb (guestfs_h *g, void *data, XDR *xdr)
309 {
310   struct ll_rv *rv = (struct ll_rv *) data;
311
312   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
313     error (g, "guestfs_ll: failed to parse reply header");
314     return;
315   }
316   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
317     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
318       error (g, "guestfs_ll: failed to parse reply error");
319       return;
320     }
321     goto done;
322   }
323   if (!xdr_guestfs_ll_ret (xdr, &rv->ret)) {
324     error (g, "guestfs_ll: failed to parse reply");
325     return;
326   }
327  done:
328   rv->cb_done = 1;
329   main_loop.main_loop_quit (g);
330 }
331
332 char *guestfs_ll (guestfs_h *g,
333                 const char *directory)
334 {
335   struct guestfs_ll_args args;
336   struct ll_rv rv;
337   int serial;
338
339   if (g->state != READY) {
340     error (g, "guestfs_ll called from the wrong state, %d != READY",
341       g->state);
342     return NULL;
343   }
344
345   memset (&rv, 0, sizeof rv);
346
347   args.directory = (char *) directory;
348   serial = dispatch (g, GUESTFS_PROC_LL,
349                      (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
350   if (serial == -1)
351     return NULL;
352
353   rv.cb_done = 0;
354   g->reply_cb_internal = ll_cb;
355   g->reply_cb_internal_data = &rv;
356   main_loop.main_loop_run (g);
357   g->reply_cb_internal = NULL;
358   g->reply_cb_internal_data = NULL;
359   if (!rv.cb_done) {
360     error (g, "guestfs_ll failed, see earlier error messages");
361     return NULL;
362   }
363
364   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LL, serial) == -1)
365     return NULL;
366
367   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
368     error (g, "%s", rv.err.error);
369     return NULL;
370   }
371
372   return rv.ret.listing; /* caller will free */
373 }
374
375 struct ls_rv {
376   int cb_done;  /* flag to indicate callback was called */
377   struct guestfs_message_header hdr;
378   struct guestfs_message_error err;
379   struct guestfs_ls_ret ret;
380 };
381
382 static void ls_cb (guestfs_h *g, void *data, XDR *xdr)
383 {
384   struct ls_rv *rv = (struct ls_rv *) data;
385
386   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
387     error (g, "guestfs_ls: failed to parse reply header");
388     return;
389   }
390   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
391     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
392       error (g, "guestfs_ls: failed to parse reply error");
393       return;
394     }
395     goto done;
396   }
397   if (!xdr_guestfs_ls_ret (xdr, &rv->ret)) {
398     error (g, "guestfs_ls: failed to parse reply");
399     return;
400   }
401  done:
402   rv->cb_done = 1;
403   main_loop.main_loop_quit (g);
404 }
405
406 char **guestfs_ls (guestfs_h *g,
407                 const char *directory)
408 {
409   struct guestfs_ls_args args;
410   struct ls_rv rv;
411   int serial;
412
413   if (g->state != READY) {
414     error (g, "guestfs_ls called from the wrong state, %d != READY",
415       g->state);
416     return NULL;
417   }
418
419   memset (&rv, 0, sizeof rv);
420
421   args.directory = (char *) directory;
422   serial = dispatch (g, GUESTFS_PROC_LS,
423                      (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
424   if (serial == -1)
425     return NULL;
426
427   rv.cb_done = 0;
428   g->reply_cb_internal = ls_cb;
429   g->reply_cb_internal_data = &rv;
430   main_loop.main_loop_run (g);
431   g->reply_cb_internal = NULL;
432   g->reply_cb_internal_data = NULL;
433   if (!rv.cb_done) {
434     error (g, "guestfs_ls failed, see earlier error messages");
435     return NULL;
436   }
437
438   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LS, serial) == -1)
439     return NULL;
440
441   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
442     error (g, "%s", rv.err.error);
443     return NULL;
444   }
445
446   /* caller will free this, but we need to add a NULL entry */
447   rv.ret.listing.listing_val =    safe_realloc (g, rv.ret.listing.listing_val,
448                   sizeof (char *) * (rv.ret.listing.listing_len + 1));
449   rv.ret.listing.listing_val[rv.ret.listing.listing_len] = NULL;
450   return rv.ret.listing.listing_val;
451 }
452
453 struct list_devices_rv {
454   int cb_done;  /* flag to indicate callback was called */
455   struct guestfs_message_header hdr;
456   struct guestfs_message_error err;
457   struct guestfs_list_devices_ret ret;
458 };
459
460 static void list_devices_cb (guestfs_h *g, void *data, XDR *xdr)
461 {
462   struct list_devices_rv *rv = (struct list_devices_rv *) data;
463
464   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
465     error (g, "guestfs_list_devices: failed to parse reply header");
466     return;
467   }
468   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
469     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
470       error (g, "guestfs_list_devices: failed to parse reply error");
471       return;
472     }
473     goto done;
474   }
475   if (!xdr_guestfs_list_devices_ret (xdr, &rv->ret)) {
476     error (g, "guestfs_list_devices: failed to parse reply");
477     return;
478   }
479  done:
480   rv->cb_done = 1;
481   main_loop.main_loop_quit (g);
482 }
483
484 char **guestfs_list_devices (guestfs_h *g)
485 {
486   struct list_devices_rv rv;
487   int serial;
488
489   if (g->state != READY) {
490     error (g, "guestfs_list_devices called from the wrong state, %d != READY",
491       g->state);
492     return NULL;
493   }
494
495   memset (&rv, 0, sizeof rv);
496
497   serial = dispatch (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
498   if (serial == -1)
499     return NULL;
500
501   rv.cb_done = 0;
502   g->reply_cb_internal = list_devices_cb;
503   g->reply_cb_internal_data = &rv;
504   main_loop.main_loop_run (g);
505   g->reply_cb_internal = NULL;
506   g->reply_cb_internal_data = NULL;
507   if (!rv.cb_done) {
508     error (g, "guestfs_list_devices failed, see earlier error messages");
509     return NULL;
510   }
511
512   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1)
513     return NULL;
514
515   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
516     error (g, "%s", rv.err.error);
517     return NULL;
518   }
519
520   /* caller will free this, but we need to add a NULL entry */
521   rv.ret.devices.devices_val =    safe_realloc (g, rv.ret.devices.devices_val,
522                   sizeof (char *) * (rv.ret.devices.devices_len + 1));
523   rv.ret.devices.devices_val[rv.ret.devices.devices_len] = NULL;
524   return rv.ret.devices.devices_val;
525 }
526
527 struct list_partitions_rv {
528   int cb_done;  /* flag to indicate callback was called */
529   struct guestfs_message_header hdr;
530   struct guestfs_message_error err;
531   struct guestfs_list_partitions_ret ret;
532 };
533
534 static void list_partitions_cb (guestfs_h *g, void *data, XDR *xdr)
535 {
536   struct list_partitions_rv *rv = (struct list_partitions_rv *) data;
537
538   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
539     error (g, "guestfs_list_partitions: failed to parse reply header");
540     return;
541   }
542   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
543     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
544       error (g, "guestfs_list_partitions: failed to parse reply error");
545       return;
546     }
547     goto done;
548   }
549   if (!xdr_guestfs_list_partitions_ret (xdr, &rv->ret)) {
550     error (g, "guestfs_list_partitions: failed to parse reply");
551     return;
552   }
553  done:
554   rv->cb_done = 1;
555   main_loop.main_loop_quit (g);
556 }
557
558 char **guestfs_list_partitions (guestfs_h *g)
559 {
560   struct list_partitions_rv rv;
561   int serial;
562
563   if (g->state != READY) {
564     error (g, "guestfs_list_partitions called from the wrong state, %d != READY",
565       g->state);
566     return NULL;
567   }
568
569   memset (&rv, 0, sizeof rv);
570
571   serial = dispatch (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
572   if (serial == -1)
573     return NULL;
574
575   rv.cb_done = 0;
576   g->reply_cb_internal = list_partitions_cb;
577   g->reply_cb_internal_data = &rv;
578   main_loop.main_loop_run (g);
579   g->reply_cb_internal = NULL;
580   g->reply_cb_internal_data = NULL;
581   if (!rv.cb_done) {
582     error (g, "guestfs_list_partitions failed, see earlier error messages");
583     return NULL;
584   }
585
586   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1)
587     return NULL;
588
589   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
590     error (g, "%s", rv.err.error);
591     return NULL;
592   }
593
594   /* caller will free this, but we need to add a NULL entry */
595   rv.ret.partitions.partitions_val =    safe_realloc (g, rv.ret.partitions.partitions_val,
596                   sizeof (char *) * (rv.ret.partitions.partitions_len + 1));
597   rv.ret.partitions.partitions_val[rv.ret.partitions.partitions_len] = NULL;
598   return rv.ret.partitions.partitions_val;
599 }
600
601 struct pvs_rv {
602   int cb_done;  /* flag to indicate callback was called */
603   struct guestfs_message_header hdr;
604   struct guestfs_message_error err;
605   struct guestfs_pvs_ret ret;
606 };
607
608 static void pvs_cb (guestfs_h *g, void *data, XDR *xdr)
609 {
610   struct pvs_rv *rv = (struct pvs_rv *) data;
611
612   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
613     error (g, "guestfs_pvs: failed to parse reply header");
614     return;
615   }
616   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
617     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
618       error (g, "guestfs_pvs: failed to parse reply error");
619       return;
620     }
621     goto done;
622   }
623   if (!xdr_guestfs_pvs_ret (xdr, &rv->ret)) {
624     error (g, "guestfs_pvs: failed to parse reply");
625     return;
626   }
627  done:
628   rv->cb_done = 1;
629   main_loop.main_loop_quit (g);
630 }
631
632 char **guestfs_pvs (guestfs_h *g)
633 {
634   struct pvs_rv rv;
635   int serial;
636
637   if (g->state != READY) {
638     error (g, "guestfs_pvs called from the wrong state, %d != READY",
639       g->state);
640     return NULL;
641   }
642
643   memset (&rv, 0, sizeof rv);
644
645   serial = dispatch (g, GUESTFS_PROC_PVS, NULL, NULL);
646   if (serial == -1)
647     return NULL;
648
649   rv.cb_done = 0;
650   g->reply_cb_internal = pvs_cb;
651   g->reply_cb_internal_data = &rv;
652   main_loop.main_loop_run (g);
653   g->reply_cb_internal = NULL;
654   g->reply_cb_internal_data = NULL;
655   if (!rv.cb_done) {
656     error (g, "guestfs_pvs failed, see earlier error messages");
657     return NULL;
658   }
659
660   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_PVS, serial) == -1)
661     return NULL;
662
663   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
664     error (g, "%s", rv.err.error);
665     return NULL;
666   }
667
668   /* caller will free this, but we need to add a NULL entry */
669   rv.ret.physvols.physvols_val =    safe_realloc (g, rv.ret.physvols.physvols_val,
670                   sizeof (char *) * (rv.ret.physvols.physvols_len + 1));
671   rv.ret.physvols.physvols_val[rv.ret.physvols.physvols_len] = NULL;
672   return rv.ret.physvols.physvols_val;
673 }
674
675 struct vgs_rv {
676   int cb_done;  /* flag to indicate callback was called */
677   struct guestfs_message_header hdr;
678   struct guestfs_message_error err;
679   struct guestfs_vgs_ret ret;
680 };
681
682 static void vgs_cb (guestfs_h *g, void *data, XDR *xdr)
683 {
684   struct vgs_rv *rv = (struct vgs_rv *) data;
685
686   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
687     error (g, "guestfs_vgs: failed to parse reply header");
688     return;
689   }
690   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
691     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
692       error (g, "guestfs_vgs: failed to parse reply error");
693       return;
694     }
695     goto done;
696   }
697   if (!xdr_guestfs_vgs_ret (xdr, &rv->ret)) {
698     error (g, "guestfs_vgs: failed to parse reply");
699     return;
700   }
701  done:
702   rv->cb_done = 1;
703   main_loop.main_loop_quit (g);
704 }
705
706 char **guestfs_vgs (guestfs_h *g)
707 {
708   struct vgs_rv rv;
709   int serial;
710
711   if (g->state != READY) {
712     error (g, "guestfs_vgs called from the wrong state, %d != READY",
713       g->state);
714     return NULL;
715   }
716
717   memset (&rv, 0, sizeof rv);
718
719   serial = dispatch (g, GUESTFS_PROC_VGS, NULL, NULL);
720   if (serial == -1)
721     return NULL;
722
723   rv.cb_done = 0;
724   g->reply_cb_internal = vgs_cb;
725   g->reply_cb_internal_data = &rv;
726   main_loop.main_loop_run (g);
727   g->reply_cb_internal = NULL;
728   g->reply_cb_internal_data = NULL;
729   if (!rv.cb_done) {
730     error (g, "guestfs_vgs failed, see earlier error messages");
731     return NULL;
732   }
733
734   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_VGS, serial) == -1)
735     return NULL;
736
737   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
738     error (g, "%s", rv.err.error);
739     return NULL;
740   }
741
742   /* caller will free this, but we need to add a NULL entry */
743   rv.ret.volgroups.volgroups_val =    safe_realloc (g, rv.ret.volgroups.volgroups_val,
744                   sizeof (char *) * (rv.ret.volgroups.volgroups_len + 1));
745   rv.ret.volgroups.volgroups_val[rv.ret.volgroups.volgroups_len] = NULL;
746   return rv.ret.volgroups.volgroups_val;
747 }
748
749 struct lvs_rv {
750   int cb_done;  /* flag to indicate callback was called */
751   struct guestfs_message_header hdr;
752   struct guestfs_message_error err;
753   struct guestfs_lvs_ret ret;
754 };
755
756 static void lvs_cb (guestfs_h *g, void *data, XDR *xdr)
757 {
758   struct lvs_rv *rv = (struct lvs_rv *) data;
759
760   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
761     error (g, "guestfs_lvs: failed to parse reply header");
762     return;
763   }
764   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
765     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
766       error (g, "guestfs_lvs: failed to parse reply error");
767       return;
768     }
769     goto done;
770   }
771   if (!xdr_guestfs_lvs_ret (xdr, &rv->ret)) {
772     error (g, "guestfs_lvs: failed to parse reply");
773     return;
774   }
775  done:
776   rv->cb_done = 1;
777   main_loop.main_loop_quit (g);
778 }
779
780 char **guestfs_lvs (guestfs_h *g)
781 {
782   struct lvs_rv rv;
783   int serial;
784
785   if (g->state != READY) {
786     error (g, "guestfs_lvs called from the wrong state, %d != READY",
787       g->state);
788     return NULL;
789   }
790
791   memset (&rv, 0, sizeof rv);
792
793   serial = dispatch (g, GUESTFS_PROC_LVS, NULL, NULL);
794   if (serial == -1)
795     return NULL;
796
797   rv.cb_done = 0;
798   g->reply_cb_internal = lvs_cb;
799   g->reply_cb_internal_data = &rv;
800   main_loop.main_loop_run (g);
801   g->reply_cb_internal = NULL;
802   g->reply_cb_internal_data = NULL;
803   if (!rv.cb_done) {
804     error (g, "guestfs_lvs failed, see earlier error messages");
805     return NULL;
806   }
807
808   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LVS, serial) == -1)
809     return NULL;
810
811   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
812     error (g, "%s", rv.err.error);
813     return NULL;
814   }
815
816   /* caller will free this, but we need to add a NULL entry */
817   rv.ret.logvols.logvols_val =    safe_realloc (g, rv.ret.logvols.logvols_val,
818                   sizeof (char *) * (rv.ret.logvols.logvols_len + 1));
819   rv.ret.logvols.logvols_val[rv.ret.logvols.logvols_len] = NULL;
820   return rv.ret.logvols.logvols_val;
821 }
822
823 struct pvs_full_rv {
824   int cb_done;  /* flag to indicate callback was called */
825   struct guestfs_message_header hdr;
826   struct guestfs_message_error err;
827   struct guestfs_pvs_full_ret ret;
828 };
829
830 static void pvs_full_cb (guestfs_h *g, void *data, XDR *xdr)
831 {
832   struct pvs_full_rv *rv = (struct pvs_full_rv *) data;
833
834   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
835     error (g, "guestfs_pvs_full: failed to parse reply header");
836     return;
837   }
838   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
839     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
840       error (g, "guestfs_pvs_full: failed to parse reply error");
841       return;
842     }
843     goto done;
844   }
845   if (!xdr_guestfs_pvs_full_ret (xdr, &rv->ret)) {
846     error (g, "guestfs_pvs_full: failed to parse reply");
847     return;
848   }
849  done:
850   rv->cb_done = 1;
851   main_loop.main_loop_quit (g);
852 }
853
854 struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *g)
855 {
856   struct pvs_full_rv rv;
857   int serial;
858
859   if (g->state != READY) {
860     error (g, "guestfs_pvs_full called from the wrong state, %d != READY",
861       g->state);
862     return NULL;
863   }
864
865   memset (&rv, 0, sizeof rv);
866
867   serial = dispatch (g, GUESTFS_PROC_PVS_FULL, NULL, NULL);
868   if (serial == -1)
869     return NULL;
870
871   rv.cb_done = 0;
872   g->reply_cb_internal = pvs_full_cb;
873   g->reply_cb_internal_data = &rv;
874   main_loop.main_loop_run (g);
875   g->reply_cb_internal = NULL;
876   g->reply_cb_internal_data = NULL;
877   if (!rv.cb_done) {
878     error (g, "guestfs_pvs_full failed, see earlier error messages");
879     return NULL;
880   }
881
882   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_PVS_FULL, serial) == -1)
883     return NULL;
884
885   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
886     error (g, "%s", rv.err.error);
887     return NULL;
888   }
889
890   /* caller will free this */
891   return safe_memdup (g, &rv.ret.physvols, sizeof (rv.ret.physvols));
892 }
893
894 struct vgs_full_rv {
895   int cb_done;  /* flag to indicate callback was called */
896   struct guestfs_message_header hdr;
897   struct guestfs_message_error err;
898   struct guestfs_vgs_full_ret ret;
899 };
900
901 static void vgs_full_cb (guestfs_h *g, void *data, XDR *xdr)
902 {
903   struct vgs_full_rv *rv = (struct vgs_full_rv *) data;
904
905   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
906     error (g, "guestfs_vgs_full: failed to parse reply header");
907     return;
908   }
909   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
910     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
911       error (g, "guestfs_vgs_full: failed to parse reply error");
912       return;
913     }
914     goto done;
915   }
916   if (!xdr_guestfs_vgs_full_ret (xdr, &rv->ret)) {
917     error (g, "guestfs_vgs_full: failed to parse reply");
918     return;
919   }
920  done:
921   rv->cb_done = 1;
922   main_loop.main_loop_quit (g);
923 }
924
925 struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *g)
926 {
927   struct vgs_full_rv rv;
928   int serial;
929
930   if (g->state != READY) {
931     error (g, "guestfs_vgs_full called from the wrong state, %d != READY",
932       g->state);
933     return NULL;
934   }
935
936   memset (&rv, 0, sizeof rv);
937
938   serial = dispatch (g, GUESTFS_PROC_VGS_FULL, NULL, NULL);
939   if (serial == -1)
940     return NULL;
941
942   rv.cb_done = 0;
943   g->reply_cb_internal = vgs_full_cb;
944   g->reply_cb_internal_data = &rv;
945   main_loop.main_loop_run (g);
946   g->reply_cb_internal = NULL;
947   g->reply_cb_internal_data = NULL;
948   if (!rv.cb_done) {
949     error (g, "guestfs_vgs_full failed, see earlier error messages");
950     return NULL;
951   }
952
953   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_VGS_FULL, serial) == -1)
954     return NULL;
955
956   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
957     error (g, "%s", rv.err.error);
958     return NULL;
959   }
960
961   /* caller will free this */
962   return safe_memdup (g, &rv.ret.volgroups, sizeof (rv.ret.volgroups));
963 }
964
965 struct lvs_full_rv {
966   int cb_done;  /* flag to indicate callback was called */
967   struct guestfs_message_header hdr;
968   struct guestfs_message_error err;
969   struct guestfs_lvs_full_ret ret;
970 };
971
972 static void lvs_full_cb (guestfs_h *g, void *data, XDR *xdr)
973 {
974   struct lvs_full_rv *rv = (struct lvs_full_rv *) data;
975
976   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
977     error (g, "guestfs_lvs_full: failed to parse reply header");
978     return;
979   }
980   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
981     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
982       error (g, "guestfs_lvs_full: failed to parse reply error");
983       return;
984     }
985     goto done;
986   }
987   if (!xdr_guestfs_lvs_full_ret (xdr, &rv->ret)) {
988     error (g, "guestfs_lvs_full: failed to parse reply");
989     return;
990   }
991  done:
992   rv->cb_done = 1;
993   main_loop.main_loop_quit (g);
994 }
995
996 struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *g)
997 {
998   struct lvs_full_rv rv;
999   int serial;
1000
1001   if (g->state != READY) {
1002     error (g, "guestfs_lvs_full called from the wrong state, %d != READY",
1003       g->state);
1004     return NULL;
1005   }
1006
1007   memset (&rv, 0, sizeof rv);
1008
1009   serial = dispatch (g, GUESTFS_PROC_LVS_FULL, NULL, NULL);
1010   if (serial == -1)
1011     return NULL;
1012
1013   rv.cb_done = 0;
1014   g->reply_cb_internal = lvs_full_cb;
1015   g->reply_cb_internal_data = &rv;
1016   main_loop.main_loop_run (g);
1017   g->reply_cb_internal = NULL;
1018   g->reply_cb_internal_data = NULL;
1019   if (!rv.cb_done) {
1020     error (g, "guestfs_lvs_full failed, see earlier error messages");
1021     return NULL;
1022   }
1023
1024   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LVS_FULL, serial) == -1)
1025     return NULL;
1026
1027   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1028     error (g, "%s", rv.err.error);
1029     return NULL;
1030   }
1031
1032   /* caller will free this */
1033   return safe_memdup (g, &rv.ret.logvols, sizeof (rv.ret.logvols));
1034 }
1035
1036 struct read_lines_rv {
1037   int cb_done;  /* flag to indicate callback was called */
1038   struct guestfs_message_header hdr;
1039   struct guestfs_message_error err;
1040   struct guestfs_read_lines_ret ret;
1041 };
1042
1043 static void read_lines_cb (guestfs_h *g, void *data, XDR *xdr)
1044 {
1045   struct read_lines_rv *rv = (struct read_lines_rv *) data;
1046
1047   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1048     error (g, "guestfs_read_lines: failed to parse reply header");
1049     return;
1050   }
1051   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1052     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1053       error (g, "guestfs_read_lines: failed to parse reply error");
1054       return;
1055     }
1056     goto done;
1057   }
1058   if (!xdr_guestfs_read_lines_ret (xdr, &rv->ret)) {
1059     error (g, "guestfs_read_lines: failed to parse reply");
1060     return;
1061   }
1062  done:
1063   rv->cb_done = 1;
1064   main_loop.main_loop_quit (g);
1065 }
1066
1067 char **guestfs_read_lines (guestfs_h *g,
1068                 const char *path)
1069 {
1070   struct guestfs_read_lines_args args;
1071   struct read_lines_rv rv;
1072   int serial;
1073
1074   if (g->state != READY) {
1075     error (g, "guestfs_read_lines called from the wrong state, %d != READY",
1076       g->state);
1077     return NULL;
1078   }
1079
1080   memset (&rv, 0, sizeof rv);
1081
1082   args.path = (char *) path;
1083   serial = dispatch (g, GUESTFS_PROC_READ_LINES,
1084                      (xdrproc_t) xdr_guestfs_read_lines_args, (char *) &args);
1085   if (serial == -1)
1086     return NULL;
1087
1088   rv.cb_done = 0;
1089   g->reply_cb_internal = read_lines_cb;
1090   g->reply_cb_internal_data = &rv;
1091   main_loop.main_loop_run (g);
1092   g->reply_cb_internal = NULL;
1093   g->reply_cb_internal_data = NULL;
1094   if (!rv.cb_done) {
1095     error (g, "guestfs_read_lines failed, see earlier error messages");
1096     return NULL;
1097   }
1098
1099   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_READ_LINES, serial) == -1)
1100     return NULL;
1101
1102   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1103     error (g, "%s", rv.err.error);
1104     return NULL;
1105   }
1106
1107   /* caller will free this, but we need to add a NULL entry */
1108   rv.ret.lines.lines_val =    safe_realloc (g, rv.ret.lines.lines_val,
1109                   sizeof (char *) * (rv.ret.lines.lines_len + 1));
1110   rv.ret.lines.lines_val[rv.ret.lines.lines_len] = NULL;
1111   return rv.ret.lines.lines_val;
1112 }
1113
1114 struct aug_init_rv {
1115   int cb_done;  /* flag to indicate callback was called */
1116   struct guestfs_message_header hdr;
1117   struct guestfs_message_error err;
1118 };
1119
1120 static void aug_init_cb (guestfs_h *g, void *data, XDR *xdr)
1121 {
1122   struct aug_init_rv *rv = (struct aug_init_rv *) data;
1123
1124   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1125     error (g, "guestfs_aug_init: failed to parse reply header");
1126     return;
1127   }
1128   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1129     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1130       error (g, "guestfs_aug_init: failed to parse reply error");
1131       return;
1132     }
1133     goto done;
1134   }
1135  done:
1136   rv->cb_done = 1;
1137   main_loop.main_loop_quit (g);
1138 }
1139
1140 int guestfs_aug_init (guestfs_h *g,
1141                 const char *root,
1142                 int flags)
1143 {
1144   struct guestfs_aug_init_args args;
1145   struct aug_init_rv rv;
1146   int serial;
1147
1148   if (g->state != READY) {
1149     error (g, "guestfs_aug_init called from the wrong state, %d != READY",
1150       g->state);
1151     return -1;
1152   }
1153
1154   memset (&rv, 0, sizeof rv);
1155
1156   args.root = (char *) root;
1157   args.flags = flags;
1158   serial = dispatch (g, GUESTFS_PROC_AUG_INIT,
1159                      (xdrproc_t) xdr_guestfs_aug_init_args, (char *) &args);
1160   if (serial == -1)
1161     return -1;
1162
1163   rv.cb_done = 0;
1164   g->reply_cb_internal = aug_init_cb;
1165   g->reply_cb_internal_data = &rv;
1166   main_loop.main_loop_run (g);
1167   g->reply_cb_internal = NULL;
1168   g->reply_cb_internal_data = NULL;
1169   if (!rv.cb_done) {
1170     error (g, "guestfs_aug_init failed, see earlier error messages");
1171     return -1;
1172   }
1173
1174   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_INIT, serial) == -1)
1175     return -1;
1176
1177   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1178     error (g, "%s", rv.err.error);
1179     return -1;
1180   }
1181
1182   return 0;
1183 }
1184
1185 struct aug_close_rv {
1186   int cb_done;  /* flag to indicate callback was called */
1187   struct guestfs_message_header hdr;
1188   struct guestfs_message_error err;
1189 };
1190
1191 static void aug_close_cb (guestfs_h *g, void *data, XDR *xdr)
1192 {
1193   struct aug_close_rv *rv = (struct aug_close_rv *) data;
1194
1195   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1196     error (g, "guestfs_aug_close: failed to parse reply header");
1197     return;
1198   }
1199   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1200     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1201       error (g, "guestfs_aug_close: failed to parse reply error");
1202       return;
1203     }
1204     goto done;
1205   }
1206  done:
1207   rv->cb_done = 1;
1208   main_loop.main_loop_quit (g);
1209 }
1210
1211 int guestfs_aug_close (guestfs_h *g)
1212 {
1213   struct aug_close_rv rv;
1214   int serial;
1215
1216   if (g->state != READY) {
1217     error (g, "guestfs_aug_close called from the wrong state, %d != READY",
1218       g->state);
1219     return -1;
1220   }
1221
1222   memset (&rv, 0, sizeof rv);
1223
1224   serial = dispatch (g, GUESTFS_PROC_AUG_CLOSE, NULL, NULL);
1225   if (serial == -1)
1226     return -1;
1227
1228   rv.cb_done = 0;
1229   g->reply_cb_internal = aug_close_cb;
1230   g->reply_cb_internal_data = &rv;
1231   main_loop.main_loop_run (g);
1232   g->reply_cb_internal = NULL;
1233   g->reply_cb_internal_data = NULL;
1234   if (!rv.cb_done) {
1235     error (g, "guestfs_aug_close failed, see earlier error messages");
1236     return -1;
1237   }
1238
1239   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_CLOSE, serial) == -1)
1240     return -1;
1241
1242   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1243     error (g, "%s", rv.err.error);
1244     return -1;
1245   }
1246
1247   return 0;
1248 }
1249
1250 struct aug_defvar_rv {
1251   int cb_done;  /* flag to indicate callback was called */
1252   struct guestfs_message_header hdr;
1253   struct guestfs_message_error err;
1254   struct guestfs_aug_defvar_ret ret;
1255 };
1256
1257 static void aug_defvar_cb (guestfs_h *g, void *data, XDR *xdr)
1258 {
1259   struct aug_defvar_rv *rv = (struct aug_defvar_rv *) data;
1260
1261   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1262     error (g, "guestfs_aug_defvar: failed to parse reply header");
1263     return;
1264   }
1265   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1266     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1267       error (g, "guestfs_aug_defvar: failed to parse reply error");
1268       return;
1269     }
1270     goto done;
1271   }
1272   if (!xdr_guestfs_aug_defvar_ret (xdr, &rv->ret)) {
1273     error (g, "guestfs_aug_defvar: failed to parse reply");
1274     return;
1275   }
1276  done:
1277   rv->cb_done = 1;
1278   main_loop.main_loop_quit (g);
1279 }
1280
1281 int guestfs_aug_defvar (guestfs_h *g,
1282                 const char *name,
1283                 const char *expr)
1284 {
1285   struct guestfs_aug_defvar_args args;
1286   struct aug_defvar_rv rv;
1287   int serial;
1288
1289   if (g->state != READY) {
1290     error (g, "guestfs_aug_defvar called from the wrong state, %d != READY",
1291       g->state);
1292     return -1;
1293   }
1294
1295   memset (&rv, 0, sizeof rv);
1296
1297   args.name = (char *) name;
1298   args.expr = expr ? (char **) &expr : NULL;
1299   serial = dispatch (g, GUESTFS_PROC_AUG_DEFVAR,
1300                      (xdrproc_t) xdr_guestfs_aug_defvar_args, (char *) &args);
1301   if (serial == -1)
1302     return -1;
1303
1304   rv.cb_done = 0;
1305   g->reply_cb_internal = aug_defvar_cb;
1306   g->reply_cb_internal_data = &rv;
1307   main_loop.main_loop_run (g);
1308   g->reply_cb_internal = NULL;
1309   g->reply_cb_internal_data = NULL;
1310   if (!rv.cb_done) {
1311     error (g, "guestfs_aug_defvar failed, see earlier error messages");
1312     return -1;
1313   }
1314
1315   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_DEFVAR, serial) == -1)
1316     return -1;
1317
1318   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1319     error (g, "%s", rv.err.error);
1320     return -1;
1321   }
1322
1323   return rv.ret.nrnodes;
1324 }
1325
1326 struct aug_defnode_rv {
1327   int cb_done;  /* flag to indicate callback was called */
1328   struct guestfs_message_header hdr;
1329   struct guestfs_message_error err;
1330   struct guestfs_aug_defnode_ret ret;
1331 };
1332
1333 static void aug_defnode_cb (guestfs_h *g, void *data, XDR *xdr)
1334 {
1335   struct aug_defnode_rv *rv = (struct aug_defnode_rv *) data;
1336
1337   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1338     error (g, "guestfs_aug_defnode: failed to parse reply header");
1339     return;
1340   }
1341   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1342     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1343       error (g, "guestfs_aug_defnode: failed to parse reply error");
1344       return;
1345     }
1346     goto done;
1347   }
1348   if (!xdr_guestfs_aug_defnode_ret (xdr, &rv->ret)) {
1349     error (g, "guestfs_aug_defnode: failed to parse reply");
1350     return;
1351   }
1352  done:
1353   rv->cb_done = 1;
1354   main_loop.main_loop_quit (g);
1355 }
1356
1357 struct guestfs_int_bool *guestfs_aug_defnode (guestfs_h *g,
1358                 const char *name,
1359                 const char *expr,
1360                 const char *val)
1361 {
1362   struct guestfs_aug_defnode_args args;
1363   struct aug_defnode_rv rv;
1364   int serial;
1365
1366   if (g->state != READY) {
1367     error (g, "guestfs_aug_defnode called from the wrong state, %d != READY",
1368       g->state);
1369     return NULL;
1370   }
1371
1372   memset (&rv, 0, sizeof rv);
1373
1374   args.name = (char *) name;
1375   args.expr = (char *) expr;
1376   args.val = (char *) val;
1377   serial = dispatch (g, GUESTFS_PROC_AUG_DEFNODE,
1378                      (xdrproc_t) xdr_guestfs_aug_defnode_args, (char *) &args);
1379   if (serial == -1)
1380     return NULL;
1381
1382   rv.cb_done = 0;
1383   g->reply_cb_internal = aug_defnode_cb;
1384   g->reply_cb_internal_data = &rv;
1385   main_loop.main_loop_run (g);
1386   g->reply_cb_internal = NULL;
1387   g->reply_cb_internal_data = NULL;
1388   if (!rv.cb_done) {
1389     error (g, "guestfs_aug_defnode failed, see earlier error messages");
1390     return NULL;
1391   }
1392
1393   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_DEFNODE, serial) == -1)
1394     return NULL;
1395
1396   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1397     error (g, "%s", rv.err.error);
1398     return NULL;
1399   }
1400
1401   /* caller with free this */
1402   return safe_memdup (g, &rv.ret, sizeof (rv.ret));
1403 }
1404
1405 struct aug_get_rv {
1406   int cb_done;  /* flag to indicate callback was called */
1407   struct guestfs_message_header hdr;
1408   struct guestfs_message_error err;
1409   struct guestfs_aug_get_ret ret;
1410 };
1411
1412 static void aug_get_cb (guestfs_h *g, void *data, XDR *xdr)
1413 {
1414   struct aug_get_rv *rv = (struct aug_get_rv *) data;
1415
1416   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1417     error (g, "guestfs_aug_get: failed to parse reply header");
1418     return;
1419   }
1420   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1421     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1422       error (g, "guestfs_aug_get: failed to parse reply error");
1423       return;
1424     }
1425     goto done;
1426   }
1427   if (!xdr_guestfs_aug_get_ret (xdr, &rv->ret)) {
1428     error (g, "guestfs_aug_get: failed to parse reply");
1429     return;
1430   }
1431  done:
1432   rv->cb_done = 1;
1433   main_loop.main_loop_quit (g);
1434 }
1435
1436 char *guestfs_aug_get (guestfs_h *g,
1437                 const char *path)
1438 {
1439   struct guestfs_aug_get_args args;
1440   struct aug_get_rv rv;
1441   int serial;
1442
1443   if (g->state != READY) {
1444     error (g, "guestfs_aug_get called from the wrong state, %d != READY",
1445       g->state);
1446     return NULL;
1447   }
1448
1449   memset (&rv, 0, sizeof rv);
1450
1451   args.path = (char *) path;
1452   serial = dispatch (g, GUESTFS_PROC_AUG_GET,
1453                      (xdrproc_t) xdr_guestfs_aug_get_args, (char *) &args);
1454   if (serial == -1)
1455     return NULL;
1456
1457   rv.cb_done = 0;
1458   g->reply_cb_internal = aug_get_cb;
1459   g->reply_cb_internal_data = &rv;
1460   main_loop.main_loop_run (g);
1461   g->reply_cb_internal = NULL;
1462   g->reply_cb_internal_data = NULL;
1463   if (!rv.cb_done) {
1464     error (g, "guestfs_aug_get failed, see earlier error messages");
1465     return NULL;
1466   }
1467
1468   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_GET, serial) == -1)
1469     return NULL;
1470
1471   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1472     error (g, "%s", rv.err.error);
1473     return NULL;
1474   }
1475
1476   return rv.ret.val; /* caller will free */
1477 }
1478
1479 struct aug_set_rv {
1480   int cb_done;  /* flag to indicate callback was called */
1481   struct guestfs_message_header hdr;
1482   struct guestfs_message_error err;
1483 };
1484
1485 static void aug_set_cb (guestfs_h *g, void *data, XDR *xdr)
1486 {
1487   struct aug_set_rv *rv = (struct aug_set_rv *) data;
1488
1489   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1490     error (g, "guestfs_aug_set: failed to parse reply header");
1491     return;
1492   }
1493   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1494     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1495       error (g, "guestfs_aug_set: failed to parse reply error");
1496       return;
1497     }
1498     goto done;
1499   }
1500  done:
1501   rv->cb_done = 1;
1502   main_loop.main_loop_quit (g);
1503 }
1504
1505 int guestfs_aug_set (guestfs_h *g,
1506                 const char *path,
1507                 const char *val)
1508 {
1509   struct guestfs_aug_set_args args;
1510   struct aug_set_rv rv;
1511   int serial;
1512
1513   if (g->state != READY) {
1514     error (g, "guestfs_aug_set called from the wrong state, %d != READY",
1515       g->state);
1516     return -1;
1517   }
1518
1519   memset (&rv, 0, sizeof rv);
1520
1521   args.path = (char *) path;
1522   args.val = (char *) val;
1523   serial = dispatch (g, GUESTFS_PROC_AUG_SET,
1524                      (xdrproc_t) xdr_guestfs_aug_set_args, (char *) &args);
1525   if (serial == -1)
1526     return -1;
1527
1528   rv.cb_done = 0;
1529   g->reply_cb_internal = aug_set_cb;
1530   g->reply_cb_internal_data = &rv;
1531   main_loop.main_loop_run (g);
1532   g->reply_cb_internal = NULL;
1533   g->reply_cb_internal_data = NULL;
1534   if (!rv.cb_done) {
1535     error (g, "guestfs_aug_set failed, see earlier error messages");
1536     return -1;
1537   }
1538
1539   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_SET, serial) == -1)
1540     return -1;
1541
1542   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1543     error (g, "%s", rv.err.error);
1544     return -1;
1545   }
1546
1547   return 0;
1548 }
1549
1550 struct aug_insert_rv {
1551   int cb_done;  /* flag to indicate callback was called */
1552   struct guestfs_message_header hdr;
1553   struct guestfs_message_error err;
1554 };
1555
1556 static void aug_insert_cb (guestfs_h *g, void *data, XDR *xdr)
1557 {
1558   struct aug_insert_rv *rv = (struct aug_insert_rv *) data;
1559
1560   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1561     error (g, "guestfs_aug_insert: failed to parse reply header");
1562     return;
1563   }
1564   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1565     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1566       error (g, "guestfs_aug_insert: failed to parse reply error");
1567       return;
1568     }
1569     goto done;
1570   }
1571  done:
1572   rv->cb_done = 1;
1573   main_loop.main_loop_quit (g);
1574 }
1575
1576 int guestfs_aug_insert (guestfs_h *g,
1577                 const char *path,
1578                 const char *label,
1579                 int before)
1580 {
1581   struct guestfs_aug_insert_args args;
1582   struct aug_insert_rv rv;
1583   int serial;
1584
1585   if (g->state != READY) {
1586     error (g, "guestfs_aug_insert called from the wrong state, %d != READY",
1587       g->state);
1588     return -1;
1589   }
1590
1591   memset (&rv, 0, sizeof rv);
1592
1593   args.path = (char *) path;
1594   args.label = (char *) label;
1595   args.before = before;
1596   serial = dispatch (g, GUESTFS_PROC_AUG_INSERT,
1597                      (xdrproc_t) xdr_guestfs_aug_insert_args, (char *) &args);
1598   if (serial == -1)
1599     return -1;
1600
1601   rv.cb_done = 0;
1602   g->reply_cb_internal = aug_insert_cb;
1603   g->reply_cb_internal_data = &rv;
1604   main_loop.main_loop_run (g);
1605   g->reply_cb_internal = NULL;
1606   g->reply_cb_internal_data = NULL;
1607   if (!rv.cb_done) {
1608     error (g, "guestfs_aug_insert failed, see earlier error messages");
1609     return -1;
1610   }
1611
1612   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_INSERT, serial) == -1)
1613     return -1;
1614
1615   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1616     error (g, "%s", rv.err.error);
1617     return -1;
1618   }
1619
1620   return 0;
1621 }
1622
1623 struct aug_rm_rv {
1624   int cb_done;  /* flag to indicate callback was called */
1625   struct guestfs_message_header hdr;
1626   struct guestfs_message_error err;
1627   struct guestfs_aug_rm_ret ret;
1628 };
1629
1630 static void aug_rm_cb (guestfs_h *g, void *data, XDR *xdr)
1631 {
1632   struct aug_rm_rv *rv = (struct aug_rm_rv *) data;
1633
1634   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1635     error (g, "guestfs_aug_rm: failed to parse reply header");
1636     return;
1637   }
1638   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1639     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1640       error (g, "guestfs_aug_rm: failed to parse reply error");
1641       return;
1642     }
1643     goto done;
1644   }
1645   if (!xdr_guestfs_aug_rm_ret (xdr, &rv->ret)) {
1646     error (g, "guestfs_aug_rm: failed to parse reply");
1647     return;
1648   }
1649  done:
1650   rv->cb_done = 1;
1651   main_loop.main_loop_quit (g);
1652 }
1653
1654 int guestfs_aug_rm (guestfs_h *g,
1655                 const char *path)
1656 {
1657   struct guestfs_aug_rm_args args;
1658   struct aug_rm_rv rv;
1659   int serial;
1660
1661   if (g->state != READY) {
1662     error (g, "guestfs_aug_rm called from the wrong state, %d != READY",
1663       g->state);
1664     return -1;
1665   }
1666
1667   memset (&rv, 0, sizeof rv);
1668
1669   args.path = (char *) path;
1670   serial = dispatch (g, GUESTFS_PROC_AUG_RM,
1671                      (xdrproc_t) xdr_guestfs_aug_rm_args, (char *) &args);
1672   if (serial == -1)
1673     return -1;
1674
1675   rv.cb_done = 0;
1676   g->reply_cb_internal = aug_rm_cb;
1677   g->reply_cb_internal_data = &rv;
1678   main_loop.main_loop_run (g);
1679   g->reply_cb_internal = NULL;
1680   g->reply_cb_internal_data = NULL;
1681   if (!rv.cb_done) {
1682     error (g, "guestfs_aug_rm failed, see earlier error messages");
1683     return -1;
1684   }
1685
1686   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_RM, serial) == -1)
1687     return -1;
1688
1689   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1690     error (g, "%s", rv.err.error);
1691     return -1;
1692   }
1693
1694   return rv.ret.nrnodes;
1695 }
1696
1697 struct aug_mv_rv {
1698   int cb_done;  /* flag to indicate callback was called */
1699   struct guestfs_message_header hdr;
1700   struct guestfs_message_error err;
1701 };
1702
1703 static void aug_mv_cb (guestfs_h *g, void *data, XDR *xdr)
1704 {
1705   struct aug_mv_rv *rv = (struct aug_mv_rv *) data;
1706
1707   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1708     error (g, "guestfs_aug_mv: failed to parse reply header");
1709     return;
1710   }
1711   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1712     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1713       error (g, "guestfs_aug_mv: failed to parse reply error");
1714       return;
1715     }
1716     goto done;
1717   }
1718  done:
1719   rv->cb_done = 1;
1720   main_loop.main_loop_quit (g);
1721 }
1722
1723 int guestfs_aug_mv (guestfs_h *g,
1724                 const char *src,
1725                 const char *dest)
1726 {
1727   struct guestfs_aug_mv_args args;
1728   struct aug_mv_rv rv;
1729   int serial;
1730
1731   if (g->state != READY) {
1732     error (g, "guestfs_aug_mv called from the wrong state, %d != READY",
1733       g->state);
1734     return -1;
1735   }
1736
1737   memset (&rv, 0, sizeof rv);
1738
1739   args.src = (char *) src;
1740   args.dest = (char *) dest;
1741   serial = dispatch (g, GUESTFS_PROC_AUG_MV,
1742                      (xdrproc_t) xdr_guestfs_aug_mv_args, (char *) &args);
1743   if (serial == -1)
1744     return -1;
1745
1746   rv.cb_done = 0;
1747   g->reply_cb_internal = aug_mv_cb;
1748   g->reply_cb_internal_data = &rv;
1749   main_loop.main_loop_run (g);
1750   g->reply_cb_internal = NULL;
1751   g->reply_cb_internal_data = NULL;
1752   if (!rv.cb_done) {
1753     error (g, "guestfs_aug_mv failed, see earlier error messages");
1754     return -1;
1755   }
1756
1757   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_MV, serial) == -1)
1758     return -1;
1759
1760   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1761     error (g, "%s", rv.err.error);
1762     return -1;
1763   }
1764
1765   return 0;
1766 }
1767
1768 struct aug_match_rv {
1769   int cb_done;  /* flag to indicate callback was called */
1770   struct guestfs_message_header hdr;
1771   struct guestfs_message_error err;
1772   struct guestfs_aug_match_ret ret;
1773 };
1774
1775 static void aug_match_cb (guestfs_h *g, void *data, XDR *xdr)
1776 {
1777   struct aug_match_rv *rv = (struct aug_match_rv *) data;
1778
1779   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1780     error (g, "guestfs_aug_match: failed to parse reply header");
1781     return;
1782   }
1783   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1784     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1785       error (g, "guestfs_aug_match: failed to parse reply error");
1786       return;
1787     }
1788     goto done;
1789   }
1790   if (!xdr_guestfs_aug_match_ret (xdr, &rv->ret)) {
1791     error (g, "guestfs_aug_match: failed to parse reply");
1792     return;
1793   }
1794  done:
1795   rv->cb_done = 1;
1796   main_loop.main_loop_quit (g);
1797 }
1798
1799 char **guestfs_aug_match (guestfs_h *g,
1800                 const char *path)
1801 {
1802   struct guestfs_aug_match_args args;
1803   struct aug_match_rv rv;
1804   int serial;
1805
1806   if (g->state != READY) {
1807     error (g, "guestfs_aug_match called from the wrong state, %d != READY",
1808       g->state);
1809     return NULL;
1810   }
1811
1812   memset (&rv, 0, sizeof rv);
1813
1814   args.path = (char *) path;
1815   serial = dispatch (g, GUESTFS_PROC_AUG_MATCH,
1816                      (xdrproc_t) xdr_guestfs_aug_match_args, (char *) &args);
1817   if (serial == -1)
1818     return NULL;
1819
1820   rv.cb_done = 0;
1821   g->reply_cb_internal = aug_match_cb;
1822   g->reply_cb_internal_data = &rv;
1823   main_loop.main_loop_run (g);
1824   g->reply_cb_internal = NULL;
1825   g->reply_cb_internal_data = NULL;
1826   if (!rv.cb_done) {
1827     error (g, "guestfs_aug_match failed, see earlier error messages");
1828     return NULL;
1829   }
1830
1831   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_MATCH, serial) == -1)
1832     return NULL;
1833
1834   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1835     error (g, "%s", rv.err.error);
1836     return NULL;
1837   }
1838
1839   /* caller will free this, but we need to add a NULL entry */
1840   rv.ret.matches.matches_val =    safe_realloc (g, rv.ret.matches.matches_val,
1841                   sizeof (char *) * (rv.ret.matches.matches_len + 1));
1842   rv.ret.matches.matches_val[rv.ret.matches.matches_len] = NULL;
1843   return rv.ret.matches.matches_val;
1844 }
1845
1846 struct aug_save_rv {
1847   int cb_done;  /* flag to indicate callback was called */
1848   struct guestfs_message_header hdr;
1849   struct guestfs_message_error err;
1850 };
1851
1852 static void aug_save_cb (guestfs_h *g, void *data, XDR *xdr)
1853 {
1854   struct aug_save_rv *rv = (struct aug_save_rv *) data;
1855
1856   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1857     error (g, "guestfs_aug_save: failed to parse reply header");
1858     return;
1859   }
1860   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1861     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1862       error (g, "guestfs_aug_save: failed to parse reply error");
1863       return;
1864     }
1865     goto done;
1866   }
1867  done:
1868   rv->cb_done = 1;
1869   main_loop.main_loop_quit (g);
1870 }
1871
1872 int guestfs_aug_save (guestfs_h *g)
1873 {
1874   struct aug_save_rv rv;
1875   int serial;
1876
1877   if (g->state != READY) {
1878     error (g, "guestfs_aug_save called from the wrong state, %d != READY",
1879       g->state);
1880     return -1;
1881   }
1882
1883   memset (&rv, 0, sizeof rv);
1884
1885   serial = dispatch (g, GUESTFS_PROC_AUG_SAVE, NULL, NULL);
1886   if (serial == -1)
1887     return -1;
1888
1889   rv.cb_done = 0;
1890   g->reply_cb_internal = aug_save_cb;
1891   g->reply_cb_internal_data = &rv;
1892   main_loop.main_loop_run (g);
1893   g->reply_cb_internal = NULL;
1894   g->reply_cb_internal_data = NULL;
1895   if (!rv.cb_done) {
1896     error (g, "guestfs_aug_save failed, see earlier error messages");
1897     return -1;
1898   }
1899
1900   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_SAVE, serial) == -1)
1901     return -1;
1902
1903   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1904     error (g, "%s", rv.err.error);
1905     return -1;
1906   }
1907
1908   return 0;
1909 }
1910
1911 struct aug_load_rv {
1912   int cb_done;  /* flag to indicate callback was called */
1913   struct guestfs_message_header hdr;
1914   struct guestfs_message_error err;
1915 };
1916
1917 static void aug_load_cb (guestfs_h *g, void *data, XDR *xdr)
1918 {
1919   struct aug_load_rv *rv = (struct aug_load_rv *) data;
1920
1921   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
1922     error (g, "guestfs_aug_load: failed to parse reply header");
1923     return;
1924   }
1925   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
1926     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
1927       error (g, "guestfs_aug_load: failed to parse reply error");
1928       return;
1929     }
1930     goto done;
1931   }
1932  done:
1933   rv->cb_done = 1;
1934   main_loop.main_loop_quit (g);
1935 }
1936
1937 int guestfs_aug_load (guestfs_h *g)
1938 {
1939   struct aug_load_rv rv;
1940   int serial;
1941
1942   if (g->state != READY) {
1943     error (g, "guestfs_aug_load called from the wrong state, %d != READY",
1944       g->state);
1945     return -1;
1946   }
1947
1948   memset (&rv, 0, sizeof rv);
1949
1950   serial = dispatch (g, GUESTFS_PROC_AUG_LOAD, NULL, NULL);
1951   if (serial == -1)
1952     return -1;
1953
1954   rv.cb_done = 0;
1955   g->reply_cb_internal = aug_load_cb;
1956   g->reply_cb_internal_data = &rv;
1957   main_loop.main_loop_run (g);
1958   g->reply_cb_internal = NULL;
1959   g->reply_cb_internal_data = NULL;
1960   if (!rv.cb_done) {
1961     error (g, "guestfs_aug_load failed, see earlier error messages");
1962     return -1;
1963   }
1964
1965   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_AUG_LOAD, serial) == -1)
1966     return -1;
1967
1968   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
1969     error (g, "%s", rv.err.error);
1970     return -1;
1971   }
1972
1973   return 0;
1974 }
1975