Parses return values and returned errors properly.
[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
65   args.device = (char *) device;
66   args.mountpoint = (char *) mountpoint;
67   serial = dispatch (g, GUESTFS_PROC_MOUNT,
68                      (xdrproc_t) xdr_guestfs_mount_args, (char *) &args);
69   if (serial == -1)
70     return -1;
71
72   rv.cb_done = 0;
73   g->reply_cb_internal = mount_cb;
74   g->reply_cb_internal_data = &rv;
75   main_loop.main_loop_run (g);
76   g->reply_cb_internal = NULL;
77   g->reply_cb_internal_data = NULL;
78   if (!rv.cb_done) {
79     error (g, "guestfs_mount failed, see earlier error messages");
80     return -1;
81   }
82
83   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_MOUNT, serial) == -1)
84     return -1;
85
86   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
87     error (g, "%s", rv.err.error);
88     return -1;
89   }
90
91   return 0;
92 }
93
94 struct sync_rv {
95   int cb_done;  /* flag to indicate callback was called */
96   struct guestfs_message_header hdr;
97   struct guestfs_message_error err;
98 };
99
100 static void sync_cb (guestfs_h *g, void *data, XDR *xdr)
101 {
102   struct sync_rv *rv = (struct sync_rv *) data;
103
104   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
105     error (g, "guestfs_sync: failed to parse reply header");
106     return;
107   }
108   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
109     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
110       error (g, "guestfs_sync: failed to parse reply error");
111       return;
112     }
113     goto done;
114   }
115  done:
116   rv->cb_done = 1;
117   main_loop.main_loop_quit (g);
118 }
119
120 int guestfs_sync (guestfs_h *g)
121 {
122   struct sync_rv rv;
123   int serial;
124
125   if (g->state != READY) {
126     error (g, "guestfs_sync called from the wrong state, %d != READY",
127       g->state);
128     return -1;
129   }
130
131   memset (&rv, 0, sizeof rv);
132
133   serial = dispatch (g, GUESTFS_PROC_SYNC, NULL, NULL);
134   if (serial == -1)
135     return -1;
136
137   rv.cb_done = 0;
138   g->reply_cb_internal = sync_cb;
139   g->reply_cb_internal_data = &rv;
140   main_loop.main_loop_run (g);
141   g->reply_cb_internal = NULL;
142   g->reply_cb_internal_data = NULL;
143   if (!rv.cb_done) {
144     error (g, "guestfs_sync failed, see earlier error messages");
145     return -1;
146   }
147
148   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_SYNC, serial) == -1)
149     return -1;
150
151   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
152     error (g, "%s", rv.err.error);
153     return -1;
154   }
155
156   return 0;
157 }
158
159 struct touch_rv {
160   int cb_done;  /* flag to indicate callback was called */
161   struct guestfs_message_header hdr;
162   struct guestfs_message_error err;
163 };
164
165 static void touch_cb (guestfs_h *g, void *data, XDR *xdr)
166 {
167   struct touch_rv *rv = (struct touch_rv *) data;
168
169   if (!xdr_guestfs_message_header (xdr, &rv->hdr)) {
170     error (g, "guestfs_touch: failed to parse reply header");
171     return;
172   }
173   if (rv->hdr.status == GUESTFS_STATUS_ERROR) {
174     if (!xdr_guestfs_message_error (xdr, &rv->err)) {
175       error (g, "guestfs_touch: failed to parse reply error");
176       return;
177     }
178     goto done;
179   }
180  done:
181   rv->cb_done = 1;
182   main_loop.main_loop_quit (g);
183 }
184
185 int guestfs_touch (guestfs_h *g,
186                 const char *path)
187 {
188   struct guestfs_touch_args args;
189   struct touch_rv rv;
190   int serial;
191
192   if (g->state != READY) {
193     error (g, "guestfs_touch called from the wrong state, %d != READY",
194       g->state);
195     return -1;
196   }
197
198   memset (&rv, 0, sizeof rv);
199
200
201   args.path = (char *) path;
202   serial = dispatch (g, GUESTFS_PROC_TOUCH,
203                      (xdrproc_t) xdr_guestfs_touch_args, (char *) &args);
204   if (serial == -1)
205     return -1;
206
207   rv.cb_done = 0;
208   g->reply_cb_internal = touch_cb;
209   g->reply_cb_internal_data = &rv;
210   main_loop.main_loop_run (g);
211   g->reply_cb_internal = NULL;
212   g->reply_cb_internal_data = NULL;
213   if (!rv.cb_done) {
214     error (g, "guestfs_touch failed, see earlier error messages");
215     return -1;
216   }
217
218   if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_TOUCH, serial) == -1)
219     return -1;
220
221   if (rv.hdr.status == GUESTFS_STATUS_ERROR) {
222     error (g, "%s", rv.err.error);
223     return -1;
224   }
225
226   return 0;
227 }
228