New version : 1.9.0
[deb_libnfs.git] / mount / mount.c
CommitLineData
84004dbf
RS
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
a8a1b858
M
18#ifdef WIN32
19#include "win32_compat.h"
20#endif/*WIN32*/
eecdc4f3 21
84004dbf
RS
22#include <stdio.h>
23#include <errno.h>
763cd6e3 24#include "libnfs-zdr.h"
84004dbf
RS
25#include "libnfs.h"
26#include "libnfs-raw.h"
27#include "libnfs-private.h"
28#include "libnfs-raw-mount.h"
29
04e90341 30int rpc_mount3_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
84004dbf
RS
31{
32 struct rpc_pdu *pdu;
33
763cd6e3 34 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0);
84004dbf
RS
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);
1896d37b 43 return -1;
84004dbf
RS
44 }
45
46 return 0;
47}
48
04e90341
RS
49int 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
54int rpc_mount3_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
84004dbf
RS
55{
56 struct rpc_pdu *pdu;
57
763cd6e3 58 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (zdrproc_t)zdr_mountres3, sizeof(mountres3));
84004dbf
RS
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
763cd6e3
RS
64 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
65 rpc_set_error(rpc, "ZDR error. Failed to encode mount/mnt call");
84004dbf 66 rpc_free_pdu(rpc, pdu);
1896d37b 67 return -1;
84004dbf
RS
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);
1896d37b 73 return -1;
84004dbf
RS
74 }
75
76 return 0;
77}
78
04e90341
RS
79int 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
84int rpc_mount3_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
84004dbf
RS
85{
86 struct rpc_pdu *pdu;
87
763cd6e3 88 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (zdrproc_t)zdr_mountlist, sizeof(mountlist));
84004dbf 89 if (pdu == NULL) {
1896d37b 90 rpc_set_error(rpc, "Failed to allocate pdu for mount/dump");
84004dbf
RS
91 return -1;
92 }
93
94 if (rpc_queue_pdu(rpc, pdu) != 0) {
1896d37b 95 rpc_set_error(rpc, "Failed to queue mount/dump pdu");
84004dbf 96 rpc_free_pdu(rpc, pdu);
1896d37b 97 return -1;
84004dbf
RS
98 }
99
100 return 0;
101}
102
04e90341
RS
103int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
104{
eca51465 105 return rpc_mount3_dump_async(rpc, cb, private_data);
04e90341
RS
106}
107
108int rpc_mount3_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
84004dbf
RS
109{
110 struct rpc_pdu *pdu;
111
763cd6e3 112 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (zdrproc_t)zdr_void, 0);
84004dbf 113 if (pdu == NULL) {
1896d37b 114 rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt");
84004dbf
RS
115 return -1;
116 }
117
763cd6e3 118 if (zdr_dirpath(&pdu->zdr, &export) == 0) {
1896d37b 119 rpc_set_error(rpc, "failed to encode dirpath for mount/umnt");
84004dbf 120 rpc_free_pdu(rpc, pdu);
1896d37b 121 return -1;
84004dbf
RS
122 }
123
124 if (rpc_queue_pdu(rpc, pdu) != 0) {
1896d37b 125 rpc_set_error(rpc, "Failed to queue mount/umnt pdu");
84004dbf 126 rpc_free_pdu(rpc, pdu);
1896d37b 127 return -1;
84004dbf
RS
128 }
129
130 return 0;
131}
132
04e90341
RS
133int 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
138int rpc_mount3_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
84004dbf
RS
139{
140 struct rpc_pdu *pdu;
141
763cd6e3 142 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (zdrproc_t)zdr_void, 0);
84004dbf 143 if (pdu == NULL) {
1896d37b 144 rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall");
84004dbf
RS
145 return -1;
146 }
147
148 if (rpc_queue_pdu(rpc, pdu) != 0) {
1896d37b 149 rpc_set_error(rpc, "Failed to queue mount/umntall pdu");
84004dbf 150 rpc_free_pdu(rpc, pdu);
1896d37b 151 return -1;
84004dbf
RS
152 }
153
154 return 0;
155}
156
04e90341
RS
157int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
158{
eca51465 159 return rpc_mount3_umntall_async(rpc, cb, private_data);
04e90341
RS
160}
161
162int rpc_mount3_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
84004dbf
RS
163{
164 struct rpc_pdu *pdu;
165
763cd6e3 166 pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (zdrproc_t)zdr_exports, sizeof(exports));
84004dbf 167 if (pdu == NULL) {
1896d37b 168 rpc_set_error(rpc, "Failed to allocate pdu for mount/export");
84004dbf
RS
169 return -1;
170 }
171
172 if (rpc_queue_pdu(rpc, pdu) != 0) {
1896d37b 173 rpc_set_error(rpc, "Failed to queue mount/export pdu");
84004dbf 174 rpc_free_pdu(rpc, pdu);
1896d37b 175 return -1;
84004dbf
RS
176 }
177
178 return 0;
179}
180
04e90341
RS
181int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
182{
eca51465 183 return rpc_mount3_export_async(rpc, cb, private_data);
04e90341
RS
184}
185
84004dbf
RS
186char *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
207int 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}
7f0242ca 225
04e90341
RS
226int 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
245int 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
270int 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
289int 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
314int 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
333int 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 }
7f0242ca 348
04e90341
RS
349 return 0;
350}
7f0242ca 351