Implement list-devices and list-partitions.
[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, rv.ret.listing.listing_len + 1);
448   rv.ret.listing.listing_val[rv.ret.listing.listing_len] = NULL;
449   return rv.ret.listing.listing_val;
450 }
451
452 struct list_devices_rv {
453   int cb_done;  /* flag to indicate callback was called */
454   struct guestfs_message_header hdr;
455   struct guestfs_message_error err;
456   struct guestfs_list_devices_ret ret;
457 };
458
459 static void list_devices_cb (guestfs_h *g, void *data, XDR *xdr)
460 {
461   struct list_devices_rv *rv = (struct list_devices_rv *) data;
462
463   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
464     error (g, "guestfs_list_devices: failed to parse reply header");
465     return;
466   }
467   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
468     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
469       error (g, "guestfs_list_devices: failed to parse reply error");
470       return;
471     }
472     goto done;
473   }
474   if (!xdr_guestfs_list_devices_ret (xdr, &rv->ret)) {
475     error (g, "guestfs_list_devices: failed to parse reply");
476     return;
477   }
478  done:
479   rv->cb_done = 1;
480   main_loop.main_loop_quit (g);
481 }
482
483 char **guestfs_list_devices (guestfs_h *g)
484 {
485   struct list_devices_rv rv;
486   int serial;
487
488   if (g->state != READY) {
489     error (g, "guestfs_list_devices called from the wrong state, %d != READY",
490       g->state);
491     return NULL;
492   }
493
494   memset (&rv, 0, sizeof rv);
495
496   serial = dispatch (g, GUESTFS_PROC_LIST_DEVICES, NULL, NULL);
497   if (serial == -1)
498     return NULL;
499
500   rv.cb_done = 0;
501   g->reply_cb_internal = list_devices_cb;
502   g->reply_cb_internal_data = &rv;
503   main_loop.main_loop_run (g);
504   g->reply_cb_internal = NULL;
505   g->reply_cb_internal_data = NULL;
506   if (!rv.cb_done) {
507     error (g, "guestfs_list_devices failed, see earlier error messages");
508     return NULL;
509   }
510
511   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LIST_DEVICES, serial) == -1)
512     return NULL;
513
514   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
515     error (g, "%s", rv.err.error);
516     return NULL;
517   }
518
519   /* caller will free this, but we need to add a NULL entry */
520   rv.ret.devices.devices_val = safe_realloc (g, rv.ret.devices.devices_val, rv.ret.devices.devices_len + 1);
521   rv.ret.devices.devices_val[rv.ret.devices.devices_len] = NULL;
522   return rv.ret.devices.devices_val;
523 }
524
525 struct list_partitions_rv {
526   int cb_done;  /* flag to indicate callback was called */
527   struct guestfs_message_header hdr;
528   struct guestfs_message_error err;
529   struct guestfs_list_partitions_ret ret;
530 };
531
532 static void list_partitions_cb (guestfs_h *g, void *data, XDR *xdr)
533 {
534   struct list_partitions_rv *rv = (struct list_partitions_rv *) data;
535
536   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
537     error (g, "guestfs_list_partitions: failed to parse reply header");
538     return;
539   }
540   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
541     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
542       error (g, "guestfs_list_partitions: failed to parse reply error");
543       return;
544     }
545     goto done;
546   }
547   if (!xdr_guestfs_list_partitions_ret (xdr, &rv->ret)) {
548     error (g, "guestfs_list_partitions: failed to parse reply");
549     return;
550   }
551  done:
552   rv->cb_done = 1;
553   main_loop.main_loop_quit (g);
554 }
555
556 char **guestfs_list_partitions (guestfs_h *g)
557 {
558   struct list_partitions_rv rv;
559   int serial;
560
561   if (g->state != READY) {
562     error (g, "guestfs_list_partitions called from the wrong state, %d != READY",
563       g->state);
564     return NULL;
565   }
566
567   memset (&rv, 0, sizeof rv);
568
569   serial = dispatch (g, GUESTFS_PROC_LIST_PARTITIONS, NULL, NULL);
570   if (serial == -1)
571     return NULL;
572
573   rv.cb_done = 0;
574   g->reply_cb_internal = list_partitions_cb;
575   g->reply_cb_internal_data = &rv;
576   main_loop.main_loop_run (g);
577   g->reply_cb_internal = NULL;
578   g->reply_cb_internal_data = NULL;
579   if (!rv.cb_done) {
580     error (g, "guestfs_list_partitions failed, see earlier error messages");
581     return NULL;
582   }
583
584   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LIST_PARTITIONS, serial) == -1)
585     return NULL;
586
587   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
588     error (g, "%s", rv.err.error);
589     return NULL;
590   }
591
592   /* caller will free this, but we need to add a NULL entry */
593   rv.ret.partitions.partitions_val = safe_realloc (g, rv.ret.partitions.partitions_val, rv.ret.partitions.partitions_len + 1);
594   rv.ret.partitions.partitions_val[rv.ret.partitions.partitions_len] = NULL;
595   return rv.ret.partitions.partitions_val;
596 }
597