Small updates to the generator.
[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