MOUNT: The wrappers for the old MOUNT rpc calls should call the new functions and...
[deb_libnfs.git] / mount / mount.c
1 /*
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifdef WIN32
19 #include "win32_compat.h"
20 #endif/*WIN32*/
21
22 #include <stdio.h>
23 #include <errno.h>
24 #include "libnfs-zdr.h"
25 #include "libnfs.h"
26 #include "libnfs-raw.h"
27 #include "libnfs-private.h"
28 #include "libnfs-raw-mount.h"
29
30 int rpc_mount3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
31 {
32 struct rpc_pdu *pdu;
33
34 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
35 if (pdu == NULL) {
36 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call");
37 return -1;
38 }
39
40 if (rpc_queue_pdu(rpc, pdu) != 0) {
41 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
42 rpc_free_pdu(rpc, pdu);
43 return -1;
44 }
45
46 return 0;
47 }
48
49 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
50 {
51 return rpc_mount3_null_async(rpc, cb, private_data);
52 }
53
54 int rpc_mount3_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
55 {
56 struct rpc_pdu *pdu;
57
58 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (zdrproc_t)zdr_mountres3, sizeof(mountres3));
59 if (pdu == NULL) {
60 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call");
61 return -1;
62 }
63
64 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
65 rpc_set_error(rpc, "ZDR error. Failed to encode mount/mnt call");
66 rpc_free_pdu(rpc, pdu);
67 return -1;
68 }
69
70 if (rpc_queue_pdu(rpc, pdu) != 0) {
71 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
72 rpc_free_pdu(rpc, pdu);
73 return -1;
74 }
75
76 return 0;
77 }
78
79 int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
80 {
81 return rpc_mount3_mnt_async(rpc, cb, export, private_data);
82 }
83
84 int rpc_mount3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
85 {
86 struct rpc_pdu *pdu;
87
88 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (zdrproc_t)zdr_mountlist, sizeof(mountlist));
89 if (pdu == NULL) {
90 rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
91 return -1;
92 }
93
94 if (rpc_queue_pdu(rpc, pdu) != 0) {
95 rpc_set_error(rpc, "Failed to queue mount/dump pdu");
96 rpc_free_pdu(rpc, pdu);
97 return -1;
98 }
99
100 return 0;
101 }
102
103 int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
104 {
105 return rpc_mount3_dump_async(rpc, cb, private_data);
106 }
107
108 int rpc_mount3_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
109 {
110 struct rpc_pdu *pdu;
111
112 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (zdrproc_t)zdr_void, 0);
113 if (pdu == NULL) {
114 rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
115 return -1;
116 }
117
118 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
119 rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
120 rpc_free_pdu(rpc, pdu);
121 return -1;
122 }
123
124 if (rpc_queue_pdu(rpc, pdu) != 0) {
125 rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
126 rpc_free_pdu(rpc, pdu);
127 return -1;
128 }
129
130 return 0;
131 }
132
133 int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
134 {
135 return rpc_mount3_umnt_async(rpc, cb, export, private_data);
136 }
137
138 int rpc_mount3_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
139 {
140 struct rpc_pdu *pdu;
141
142 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (zdrproc_t)zdr_void, 0);
143 if (pdu == NULL) {
144 rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
145 return -1;
146 }
147
148 if (rpc_queue_pdu(rpc, pdu) != 0) {
149 rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
150 rpc_free_pdu(rpc, pdu);
151 return -1;
152 }
153
154 return 0;
155 }
156
157 int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
158 {
159 return rpc_mount3_umntall_async(rpc, cb, private_data);
160 }
161
162 int rpc_mount3_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
163 {
164 struct rpc_pdu *pdu;
165
166 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (zdrproc_t)zdr_exports, sizeof(exports));
167 if (pdu == NULL) {
168 rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
169 return -1;
170 }
171
172 if (rpc_queue_pdu(rpc, pdu) != 0) {
173 rpc_set_error(rpc, "Failed to queue mount/export pdu");
174 rpc_free_pdu(rpc, pdu);
175 return -1;
176 }
177
178 return 0;
179 }
180
181 int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
182 {
183 return rpc_mount3_export_async(rpc, cb, private_data);
184 }
185
186 char *mountstat3_to_str(int st)
187 {
188 enum mountstat3 stat = st;
189
190 char *str = "unknown mount stat";
191 switch (stat) {
192 case MNT3_OK: str="MNT3_OK"; break;
193 case MNT3ERR_PERM: str="MNT3ERR_PERM"; break;
194 case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break;
195 case MNT3ERR_IO: str="MNT3ERR_IO"; break;
196 case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break;
197 case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break;
198 case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break;
199 case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break;
200 case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break;
201 case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break;
202 }
203 return str;
204 }
205
206
207 int mountstat3_to_errno(int st)
208 {
209 enum mountstat3 stat = st;
210
211 switch (stat) {
212 case MNT3_OK: return 0; break;
213 case MNT3ERR_PERM: return -EPERM; break;
214 case MNT3ERR_NOENT: return -EPERM; break;
215 case MNT3ERR_IO: return -EIO; break;
216 case MNT3ERR_ACCES: return -EACCES; break;
217 case MNT3ERR_NOTDIR: return -ENOTDIR; break;
218 case MNT3ERR_INVAL: return -EINVAL; break;
219 case MNT3ERR_NAMETOOLONG: return -E2BIG; break;
220 case MNT3ERR_NOTSUPP: return -EINVAL; break;
221 case MNT3ERR_SERVERFAULT: return -EIO; break;
222 }
223 return -ERANGE;
224 }
225
226 int rpc_mount1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
227 {
228 struct rpc_pdu *pdu;
229
230 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
231 if (pdu == NULL) {
232 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for MOUNT1/NULL call");
233 return -1;
234 }
235
236 if (rpc_queue_pdu(rpc, pdu) != 0) {
237 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for MOUNT1/NULL call");
238 rpc_free_pdu(rpc, pdu);
239 return -1;
240 }
241
242 return 0;
243 }
244
245 int rpc_mount1_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
246 {
247 struct rpc_pdu *pdu;
248
249 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_MNT, cb, private_data, (zdrproc_t)zdr_mountres1, sizeof(mountres1));
250 if (pdu == NULL) {
251 rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for MOUNT1/MNT call");
252 return -1;
253 }
254
255 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
256 rpc_set_error(rpc, "ZDR error. Failed to encode MOUNT1/MNT call");
257 rpc_free_pdu(rpc, pdu);
258 return -1;
259 }
260
261 if (rpc_queue_pdu(rpc, pdu) != 0) {
262 rpc_set_error(rpc, "Out of memory. Failed to queue pdu for MOUNT1/MNT call");
263 rpc_free_pdu(rpc, pdu);
264 return -1;
265 }
266
267 return 0;
268 }
269
270 int rpc_mount1_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
271 {
272 struct rpc_pdu *pdu;
273
274 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_DUMP, cb, private_data, (zdrproc_t)zdr_mountlist, sizeof(mountlist));
275 if (pdu == NULL) {
276 rpc_set_error(rpc, "Failed to allocate pdu for MOUNT1/DUMP");
277 return -1;
278 }
279
280 if (rpc_queue_pdu(rpc, pdu) != 0) {
281 rpc_set_error(rpc, "Failed to queue MOUNT1/DUMP pdu");
282 rpc_free_pdu(rpc, pdu);
283 return -1;
284 }
285
286 return 0;
287 }
288
289 int rpc_mount1_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
290 {
291 struct rpc_pdu *pdu;
292
293 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_UMNT, cb, private_data, (zdrproc_t)zdr_void, 0);
294 if (pdu == NULL) {
295 rpc_set_error(rpc, "Failed to allocate pdu for MOUNT1/UMNT");
296 return -1;
297 }
298
299 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
300 rpc_set_error(rpc, "failed to encode dirpath for MOUNT1/UMNT");
301 rpc_free_pdu(rpc, pdu);
302 return -1;
303 }
304
305 if (rpc_queue_pdu(rpc, pdu) != 0) {
306 rpc_set_error(rpc, "Failed to queue MOUNT1/UMNT pdu");
307 rpc_free_pdu(rpc, pdu);
308 return -1;
309 }
310
311 return 0;
312 }
313
314 int rpc_mount1_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
315 {
316 struct rpc_pdu *pdu;
317
318 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_UMNTALL, cb, private_data, (zdrproc_t)zdr_void, 0);
319 if (pdu == NULL) {
320 rpc_set_error(rpc, "Failed to allocate pdu for MOUNT1/UMNTALL");
321 return -1;
322 }
323
324 if (rpc_queue_pdu(rpc, pdu) != 0) {
325 rpc_set_error(rpc, "Failed to queue MOUNT1/UMNTALL pdu");
326 rpc_free_pdu(rpc, pdu);
327 return -1;
328 }
329
330 return 0;
331 }
332
333 int rpc_mount1_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
334 {
335 struct rpc_pdu *pdu;
336
337 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V1, MOUNT1_EXPORT, cb, private_data, (zdrproc_t)zdr_exports, sizeof(exports));
338 if (pdu == NULL) {
339 rpc_set_error(rpc, "Failed to allocate pdu for MOUNT1/EXPORT");
340 return -1;
341 }
342
343 if (rpc_queue_pdu(rpc, pdu) != 0) {
344 rpc_set_error(rpc, "Failed to queue MOUNT1/EXPORT pdu");
345 rpc_free_pdu(rpc, pdu);
346 return -1;
347 }
348
349 return 0;
350 }
351