989424d1ab1939d3c86788c306e1658572520877
[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 cat_rv {
23   int cb_done;  /* flag to indicate callback was called */
24   struct guestfs_message_header hdr;
25   struct guestfs_message_error err;
26   struct guestfs_cat_ret ret;
27 };
28
29 static void cat_cb (guestfs_h *g, void *data, XDR *xdr)
30 {
31   struct cat_rv *rv = (struct cat_rv *) data;
32
33   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
34     error (g, "guestfs_cat: failed to parse reply header");
35     return;
36   }
37   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
38     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
39       error (g, "guestfs_cat: failed to parse reply error");
40       return;
41     }
42     goto done;
43   }
44   if (!xdr_guestfs_cat_ret (xdr, &rv->ret)) {
45     error (g, "guestfs_cat: failed to parse reply");
46     return;
47   }
48  done:
49   rv->cb_done = 1;
50   main_loop.main_loop_quit (g);
51 }
52
53 char *guestfs_cat (guestfs_h *g,
54                 const char *path)
55 {
56   struct guestfs_cat_args args;
57   struct cat_rv rv;
58   int serial;
59
60   if (g->state != READY) {
61     error (g, "guestfs_cat called from the wrong state, %d != READY",
62       g->state);
63     return NULL;
64   }
65
66   memset (&rv, 0, sizeof rv);
67
68   args.path = (char *) path;
69   serial = dispatch (g, GUESTFS_PROC_CAT,
70                      (xdrproc_t) xdr_guestfs_cat_args, (char *) &args);
71   if (serial == -1)
72     return NULL;
73
74   rv.cb_done = 0;
75   g->reply_cb_internal = cat_cb;
76   g->reply_cb_internal_data = &rv;
77   main_loop.main_loop_run (g);
78   g->reply_cb_internal = NULL;
79   g->reply_cb_internal_data = NULL;
80   if (!rv.cb_done) {
81     error (g, "guestfs_cat failed, see earlier error messages");
82     return NULL;
83   }
84
85   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_CAT, serial) == -1)
86     return NULL;
87
88   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
89     error (g, "%s", rv.err.error);
90     return NULL;
91   }
92
93   return rv.ret.content; /* caller will free */
94 }
95
96 struct ll_rv {
97   int cb_done;  /* flag to indicate callback was called */
98   struct guestfs_message_header hdr;
99   struct guestfs_message_error err;
100   struct guestfs_ll_ret ret;
101 };
102
103 static void ll_cb (guestfs_h *g, void *data, XDR *xdr)
104 {
105   struct ll_rv *rv = (struct ll_rv *) data;
106
107   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
108     error (g, "guestfs_ll: failed to parse reply header");
109     return;
110   }
111   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
112     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
113       error (g, "guestfs_ll: failed to parse reply error");
114       return;
115     }
116     goto done;
117   }
118   if (!xdr_guestfs_ll_ret (xdr, &rv->ret)) {
119     error (g, "guestfs_ll: failed to parse reply");
120     return;
121   }
122  done:
123   rv->cb_done = 1;
124   main_loop.main_loop_quit (g);
125 }
126
127 char *guestfs_ll (guestfs_h *g,
128                 const char *directory)
129 {
130   struct guestfs_ll_args args;
131   struct ll_rv rv;
132   int serial;
133
134   if (g->state != READY) {
135     error (g, "guestfs_ll called from the wrong state, %d != READY",
136       g->state);
137     return NULL;
138   }
139
140   memset (&rv, 0, sizeof rv);
141
142   args.directory = (char *) directory;
143   serial = dispatch (g, GUESTFS_PROC_LL,
144                      (xdrproc_t) xdr_guestfs_ll_args, (char *) &args);
145   if (serial == -1)
146     return NULL;
147
148   rv.cb_done = 0;
149   g->reply_cb_internal = ll_cb;
150   g->reply_cb_internal_data = &rv;
151   main_loop.main_loop_run (g);
152   g->reply_cb_internal = NULL;
153   g->reply_cb_internal_data = NULL;
154   if (!rv.cb_done) {
155     error (g, "guestfs_ll failed, see earlier error messages");
156     return NULL;
157   }
158
159   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LL, serial) == -1)
160     return NULL;
161
162   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
163     error (g, "%s", rv.err.error);
164     return NULL;
165   }
166
167   return rv.ret.listing; /* caller will free */
168 }
169
170 struct ls_rv {
171   int cb_done;  /* flag to indicate callback was called */
172   struct guestfs_message_header hdr;
173   struct guestfs_message_error err;
174   struct guestfs_ls_ret ret;
175 };
176
177 static void ls_cb (guestfs_h *g, void *data, XDR *xdr)
178 {
179   struct ls_rv *rv = (struct ls_rv *) data;
180
181   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
182     error (g, "guestfs_ls: failed to parse reply header");
183     return;
184   }
185   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
186     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
187       error (g, "guestfs_ls: failed to parse reply error");
188       return;
189     }
190     goto done;
191   }
192   if (!xdr_guestfs_ls_ret (xdr, &rv->ret)) {
193     error (g, "guestfs_ls: failed to parse reply");
194     return;
195   }
196  done:
197   rv->cb_done = 1;
198   main_loop.main_loop_quit (g);
199 }
200
201 char **guestfs_ls (guestfs_h *g,
202                 const char *directory)
203 {
204   struct guestfs_ls_args args;
205   struct ls_rv rv;
206   int serial;
207
208   if (g->state != READY) {
209     error (g, "guestfs_ls called from the wrong state, %d != READY",
210       g->state);
211     return NULL;
212   }
213
214   memset (&rv, 0, sizeof rv);
215
216   args.directory = (char *) directory;
217   serial = dispatch (g, GUESTFS_PROC_LS,
218                      (xdrproc_t) xdr_guestfs_ls_args, (char *) &args);
219   if (serial == -1)
220     return NULL;
221
222   rv.cb_done = 0;
223   g->reply_cb_internal = ls_cb;
224   g->reply_cb_internal_data = &rv;
225   main_loop.main_loop_run (g);
226   g->reply_cb_internal = NULL;
227   g->reply_cb_internal_data = NULL;
228   if (!rv.cb_done) {
229     error (g, "guestfs_ls failed, see earlier error messages");
230     return NULL;
231   }
232
233   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LS, serial) == -1)
234     return NULL;
235
236   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
237     error (g, "%s", rv.err.error);
238     return NULL;
239   }
240
241   /* caller will free this, but we need to add a NULL entry */
242   rv.ret.listing.listing_val = safe_realloc (g, rv.ret.listing.listing_val, rv.ret.listing.listing_len + 1);
243   rv.ret.listing.listing_val[rv.ret.listing.listing_len] = NULL;
244   return rv.ret.listing.listing_val;
245 }
246
247 struct mount_rv {
248   int cb_done;  /* flag to indicate callback was called */
249   struct guestfs_message_header hdr;
250   struct guestfs_message_error err;
251 };
252
253 static void mount_cb (guestfs_h *g, void *data, XDR *xdr)
254 {
255   struct mount_rv *rv = (struct mount_rv *) data;
256
257   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
258     error (g, "guestfs_mount: failed to parse reply header");
259     return;
260   }
261   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
262     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
263       error (g, "guestfs_mount: failed to parse reply error");
264       return;
265     }
266     goto done;
267   }
268  done:
269   rv->cb_done = 1;
270   main_loop.main_loop_quit (g);
271 }
272
273 int guestfs_mount (guestfs_h *g,
274                 const char *device,
275                 const char *mountpoint)
276 {
277   struct guestfs_mount_args args;
278   struct mount_rv rv;
279   int serial;
280
281   if (g->state != READY) {
282     error (g, "guestfs_mount called from the wrong state, %d != READY",
283       g->state);
284     return -1;
285   }
286
287   memset (&rv, 0, sizeof rv);
288
289   args.device = (char *) device;
290   args.mountpoint = (char *) mountpoint;
291   serial = dispatch (g, GUESTFS_PROC_MOUNT,
292                      (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
293   if (serial == -1)
294     return -1;
295
296   rv.cb_done = 0;
297   g->reply_cb_internal = mount_cb;
298   g->reply_cb_internal_data = &rv;
299   main_loop.main_loop_run (g);
300   g->reply_cb_internal = NULL;
301   g->reply_cb_internal_data = NULL;
302   if (!rv.cb_done) {
303     error (g, "guestfs_mount failed, see earlier error messages");
304     return -1;
305   }
306
307   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
308     return -1;
309
310   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
311     error (g, "%s", rv.err.error);
312     return -1;
313   }
314
315   return 0;
316 }
317
318 struct sync_rv {
319   int cb_done;  /* flag to indicate callback was called */
320   struct guestfs_message_header hdr;
321   struct guestfs_message_error err;
322 };
323
324 static void sync_cb (guestfs_h *g, void *data, XDR *xdr)
325 {
326   struct sync_rv *rv = (struct sync_rv *) data;
327
328   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
329     error (g, "guestfs_sync: failed to parse reply header");
330     return;
331   }
332   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
333     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
334       error (g, "guestfs_sync: failed to parse reply error");
335       return;
336     }
337     goto done;
338   }
339  done:
340   rv->cb_done = 1;
341   main_loop.main_loop_quit (g);
342 }
343
344 int guestfs_sync (guestfs_h *g)
345 {
346   struct sync_rv rv;
347   int serial;
348
349   if (g->state != READY) {
350     error (g, "guestfs_sync called from the wrong state, %d != READY",
351       g->state);
352     return -1;
353   }
354
355   memset (&rv, 0, sizeof rv);
356
357   serial = dispatch (g, GUESTFS_PROC_SYNC, NULL, NULL);
358   if (serial == -1)
359     return -1;
360
361   rv.cb_done = 0;
362   g->reply_cb_internal = sync_cb;
363   g->reply_cb_internal_data = &rv;
364   main_loop.main_loop_run (g);
365   g->reply_cb_internal = NULL;
366   g->reply_cb_internal_data = NULL;
367   if (!rv.cb_done) {
368     error (g, "guestfs_sync failed, see earlier error messages");
369     return -1;
370   }
371
372   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_SYNC, serial) == -1)
373     return -1;
374
375   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
376     error (g, "%s", rv.err.error);
377     return -1;
378   }
379
380   return 0;
381 }
382
383 struct touch_rv {
384   int cb_done;  /* flag to indicate callback was called */
385   struct guestfs_message_header hdr;
386   struct guestfs_message_error err;
387 };
388
389 static void touch_cb (guestfs_h *g, void *data, XDR *xdr)
390 {
391   struct touch_rv *rv = (struct touch_rv *) data;
392
393   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
394     error (g, "guestfs_touch: failed to parse reply header");
395     return;
396   }
397   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
398     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
399       error (g, "guestfs_touch: failed to parse reply error");
400       return;
401     }
402     goto done;
403   }
404  done:
405   rv->cb_done = 1;
406   main_loop.main_loop_quit (g);
407 }
408
409 int guestfs_touch (guestfs_h *g,
410                 const char *path)
411 {
412   struct guestfs_touch_args args;
413   struct touch_rv rv;
414   int serial;
415
416   if (g->state != READY) {
417     error (g, "guestfs_touch called from the wrong state, %d != READY",
418       g->state);
419     return -1;
420   }
421
422   memset (&rv, 0, sizeof rv);
423
424   args.path = (char *) path;
425   serial = dispatch (g, GUESTFS_PROC_TOUCH,
426                      (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
427   if (serial == -1)
428     return -1;
429
430   rv.cb_done = 0;
431   g->reply_cb_internal = touch_cb;
432   g->reply_cb_internal_data = &rv;
433   main_loop.main_loop_run (g);
434   g->reply_cb_internal = NULL;
435   g->reply_cb_internal_data = NULL;
436   if (!rv.cb_done) {
437     error (g, "guestfs_touch failed, see earlier error messages");
438     return -1;
439   }
440
441   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
442     return -1;
443
444   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
445     error (g, "%s", rv.err.error);
446     return -1;
447   }
448
449   return 0;
450 }
451