2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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.
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.
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/>.
19 #include "win32_compat.h"
24 #include "libnfs-zdr.h"
26 #include "libnfs-raw.h"
27 #include "libnfs-private.h"
28 #include "libnfs-raw-mount.h"
30 int rpc_mount3_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
34 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_NULL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
36 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for mount/null call");
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
);
49 int rpc_mount_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
51 return rpc_mount3_null_async(rpc
, cb
, private_data
);
54 int rpc_mount3_mnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
58 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_MNT
, cb
, private_data
, (zdrproc_t
)zdr_mountres3
, sizeof(mountres3
));
60 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for mount/mnt call");
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
);
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
);
79 int rpc_mount_mnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
81 return rpc_mount3_mnt_async(rpc
, cb
, export
, private_data
);
84 int rpc_mount3_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
88 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_DUMP
, cb
, private_data
, (zdrproc_t
)zdr_mountlist
, sizeof(mountlist
));
90 rpc_set_error(rpc
, "Failed to allocate pdu for mount/dump");
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
);
103 int rpc_mount_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
105 return rpc_mount3_dump_async(rpc
, cb
, private_data
);
108 int rpc_mount3_umnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
112 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_UMNT
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
114 rpc_set_error(rpc
, "Failed to allocate pdu for mount/umnt");
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
);
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
);
133 int rpc_mount_umnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
135 return rpc_mount3_umnt_async(rpc
, cb
, export
, private_data
);
138 int rpc_mount3_umntall_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
142 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_UMNTALL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
144 rpc_set_error(rpc
, "Failed to allocate pdu for mount/umntall");
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
);
157 int rpc_mount_umntall_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
159 return rpc_mount3_umntall_async(rpc
, cb
, private_data
);
162 int rpc_mount3_export_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
166 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_EXPORT
, cb
, private_data
, (zdrproc_t
)zdr_exports
, sizeof(exports
));
168 rpc_set_error(rpc
, "Failed to allocate pdu for mount/export");
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
);
181 int rpc_mount_export_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
183 return rpc_mount3_export_async(rpc
, cb
, private_data
);
186 char *mountstat3_to_str(int st
)
188 enum mountstat3 stat
= st
;
190 char *str
= "unknown mount 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;
207 int mountstat3_to_errno(int st
)
209 enum mountstat3 stat
= st
;
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;
226 int rpc_mount1_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
230 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_NULL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
232 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for MOUNT1/NULL call");
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
);
245 int rpc_mount1_mnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
249 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_MNT
, cb
, private_data
, (zdrproc_t
)zdr_mountres1
, sizeof(mountres1
));
251 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for MOUNT1/MNT call");
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
);
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
);
270 int rpc_mount1_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
274 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_DUMP
, cb
, private_data
, (zdrproc_t
)zdr_mountlist
, sizeof(mountlist
));
276 rpc_set_error(rpc
, "Failed to allocate pdu for MOUNT1/DUMP");
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
);
289 int rpc_mount1_umnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
293 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_UMNT
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
295 rpc_set_error(rpc
, "Failed to allocate pdu for MOUNT1/UMNT");
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
);
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
);
314 int rpc_mount1_umntall_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
318 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_UMNTALL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
320 rpc_set_error(rpc
, "Failed to allocate pdu for MOUNT1/UMNTALL");
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
);
333 int rpc_mount1_export_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
337 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V1
, MOUNT1_EXPORT
, cb
, private_data
, (zdrproc_t
)zdr_exports
, sizeof(exports
));
339 rpc_set_error(rpc
, "Failed to allocate pdu for MOUNT1/EXPORT");
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
);