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_mount_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_mnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
53 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_MNT
, cb
, private_data
, (zdrproc_t
)zdr_mountres3
, sizeof(mountres3
));
55 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for mount/mnt call");
59 if (zdr_dirpath(&pdu
->zdr
, &export
) == 0) {
60 rpc_set_error(rpc
, "ZDR error. Failed to encode mount/mnt call");
61 rpc_free_pdu(rpc
, pdu
);
65 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
66 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for mount/mnt call");
67 rpc_free_pdu(rpc
, pdu
);
74 int rpc_mount_dump_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
78 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_DUMP
, cb
, private_data
, (zdrproc_t
)zdr_mountlist
, sizeof(mountlist
));
80 rpc_set_error(rpc
, "Failed to allocate pdu for mount/dump");
84 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
85 rpc_set_error(rpc
, "Failed to queue mount/dump pdu");
86 rpc_free_pdu(rpc
, pdu
);
93 int rpc_mount_umnt_async(struct rpc_context
*rpc
, rpc_cb cb
, char *export
, void *private_data
)
97 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_UMNT
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
99 rpc_set_error(rpc
, "Failed to allocate pdu for mount/umnt");
103 if (zdr_dirpath(&pdu
->zdr
, &export
) == 0) {
104 rpc_set_error(rpc
, "failed to encode dirpath for mount/umnt");
105 rpc_free_pdu(rpc
, pdu
);
109 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
110 rpc_set_error(rpc
, "Failed to queue mount/umnt pdu");
111 rpc_free_pdu(rpc
, pdu
);
118 int rpc_mount_umntall_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
122 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_UMNTALL
, cb
, private_data
, (zdrproc_t
)zdr_void
, 0);
124 rpc_set_error(rpc
, "Failed to allocate pdu for mount/umntall");
128 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
129 rpc_set_error(rpc
, "Failed to queue mount/umntall pdu");
130 rpc_free_pdu(rpc
, pdu
);
137 int rpc_mount_export_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
141 pdu
= rpc_allocate_pdu(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, MOUNT3_EXPORT
, cb
, private_data
, (zdrproc_t
)zdr_exports
, sizeof(exports
));
143 rpc_set_error(rpc
, "Failed to allocate pdu for mount/export");
147 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
148 rpc_set_error(rpc
, "Failed to queue mount/export pdu");
149 rpc_free_pdu(rpc
, pdu
);
156 char *mountstat3_to_str(int st
)
158 enum mountstat3 stat
= st
;
160 char *str
= "unknown mount stat";
162 case MNT3_OK
: str
="MNT3_OK"; break;
163 case MNT3ERR_PERM
: str
="MNT3ERR_PERM"; break;
164 case MNT3ERR_NOENT
: str
="MNT3ERR_NOENT"; break;
165 case MNT3ERR_IO
: str
="MNT3ERR_IO"; break;
166 case MNT3ERR_ACCES
: str
="MNT3ERR_ACCES"; break;
167 case MNT3ERR_NOTDIR
: str
="MNT3ERR_NOTDIR"; break;
168 case MNT3ERR_INVAL
: str
="MNT3ERR_INVAL"; break;
169 case MNT3ERR_NAMETOOLONG
: str
="MNT3ERR_NAMETOOLONG"; break;
170 case MNT3ERR_NOTSUPP
: str
="MNT3ERR_NOTSUPP"; break;
171 case MNT3ERR_SERVERFAULT
: str
="MNT3ERR_SERVERFAULT"; break;
177 int mountstat3_to_errno(int st
)
179 enum mountstat3 stat
= st
;
182 case MNT3_OK
: return 0; break;
183 case MNT3ERR_PERM
: return -EPERM
; break;
184 case MNT3ERR_NOENT
: return -EPERM
; break;
185 case MNT3ERR_IO
: return -EIO
; break;
186 case MNT3ERR_ACCES
: return -EACCES
; break;
187 case MNT3ERR_NOTDIR
: return -ENOTDIR
; break;
188 case MNT3ERR_INVAL
: return -EINVAL
; break;
189 case MNT3ERR_NAMETOOLONG
: return -E2BIG
; break;
190 case MNT3ERR_NOTSUPP
: return -EINVAL
; break;
191 case MNT3ERR_SERVERFAULT
: return -EIO
; break;