Commit | Line | Data |
---|---|---|
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 | ||
eecdc4f3 RS |
18 | #if defined(WIN32) |
19 | #include <winsock2.h> | |
20 | #endif | |
21 | ||
84004dbf RS |
22 | #include <stdio.h> |
23 | #include <errno.h> | |
98f5fee8 | 24 | #include <rpc/rpc.h> |
84004dbf RS |
25 | #include <rpc/xdr.h> |
26 | #include "libnfs.h" | |
27 | #include "libnfs-raw.h" | |
28 | #include "libnfs-private.h" | |
29 | #include "libnfs-raw-mount.h" | |
30 | ||
31 | ||
32 | int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
33 | { | |
34 | struct rpc_pdu *pdu; | |
35 | ||
36 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
37 | if (pdu == NULL) { | |
38 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call"); | |
39 | return -1; | |
40 | } | |
41 | ||
42 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
43 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call"); | |
44 | rpc_free_pdu(rpc, pdu); | |
1896d37b | 45 | return -1; |
84004dbf RS |
46 | } |
47 | ||
48 | return 0; | |
49 | } | |
50 | ||
51 | int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data) | |
52 | { | |
53 | struct rpc_pdu *pdu; | |
54 | ||
55 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (xdrproc_t)xdr_mountres3, sizeof(mountres3)); | |
56 | if (pdu == NULL) { | |
57 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call"); | |
58 | return -1; | |
59 | } | |
60 | ||
61 | if (xdr_dirpath(&pdu->xdr, &export) == 0) { | |
62 | rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call"); | |
63 | rpc_free_pdu(rpc, pdu); | |
1896d37b | 64 | return -1; |
84004dbf RS |
65 | } |
66 | ||
67 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
68 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call"); | |
69 | rpc_free_pdu(rpc, pdu); | |
1896d37b | 70 | return -1; |
84004dbf RS |
71 | } |
72 | ||
73 | return 0; | |
74 | } | |
75 | ||
76 | int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
77 | { | |
78 | struct rpc_pdu *pdu; | |
79 | ||
80 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist)); | |
81 | if (pdu == NULL) { | |
1896d37b | 82 | rpc_set_error(rpc, "Failed to allocate pdu for mount/dump"); |
84004dbf RS |
83 | return -1; |
84 | } | |
85 | ||
86 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
1896d37b | 87 | rpc_set_error(rpc, "Failed to queue mount/dump pdu"); |
84004dbf | 88 | rpc_free_pdu(rpc, pdu); |
1896d37b | 89 | return -1; |
84004dbf RS |
90 | } |
91 | ||
92 | return 0; | |
93 | } | |
94 | ||
95 | int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data) | |
96 | { | |
97 | struct rpc_pdu *pdu; | |
98 | ||
99 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0); | |
100 | if (pdu == NULL) { | |
1896d37b | 101 | rpc_set_error(rpc, "Failed to allocate pdu for mount/umnt"); |
84004dbf RS |
102 | return -1; |
103 | } | |
104 | ||
105 | if (xdr_dirpath(&pdu->xdr, &export) == 0) { | |
1896d37b | 106 | rpc_set_error(rpc, "failed to encode dirpath for mount/umnt"); |
84004dbf | 107 | rpc_free_pdu(rpc, pdu); |
1896d37b | 108 | return -1; |
84004dbf RS |
109 | } |
110 | ||
111 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
1896d37b | 112 | rpc_set_error(rpc, "Failed to queue mount/umnt pdu"); |
84004dbf | 113 | rpc_free_pdu(rpc, pdu); |
1896d37b | 114 | return -1; |
84004dbf RS |
115 | } |
116 | ||
117 | return 0; | |
118 | } | |
119 | ||
120 | int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
121 | { | |
122 | struct rpc_pdu *pdu; | |
123 | ||
124 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
125 | if (pdu == NULL) { | |
1896d37b | 126 | rpc_set_error(rpc, "Failed to allocate pdu for mount/umntall"); |
84004dbf RS |
127 | return -1; |
128 | } | |
129 | ||
130 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
1896d37b | 131 | rpc_set_error(rpc, "Failed to queue mount/umntall pdu"); |
84004dbf | 132 | rpc_free_pdu(rpc, pdu); |
1896d37b | 133 | return -1; |
84004dbf RS |
134 | } |
135 | ||
136 | return 0; | |
137 | } | |
138 | ||
139 | int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
140 | { | |
141 | struct rpc_pdu *pdu; | |
142 | ||
143 | pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports)); | |
144 | if (pdu == NULL) { | |
1896d37b | 145 | rpc_set_error(rpc, "Failed to allocate pdu for mount/export"); |
84004dbf RS |
146 | return -1; |
147 | } | |
148 | ||
149 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
1896d37b | 150 | rpc_set_error(rpc, "Failed to queue mount/export pdu"); |
84004dbf | 151 | rpc_free_pdu(rpc, pdu); |
1896d37b | 152 | return -1; |
84004dbf RS |
153 | } |
154 | ||
155 | return 0; | |
156 | } | |
157 | ||
158 | char *mountstat3_to_str(int st) | |
159 | { | |
160 | enum mountstat3 stat = st; | |
161 | ||
162 | char *str = "unknown mount stat"; | |
163 | switch (stat) { | |
164 | case MNT3_OK: str="MNT3_OK"; break; | |
165 | case MNT3ERR_PERM: str="MNT3ERR_PERM"; break; | |
166 | case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break; | |
167 | case MNT3ERR_IO: str="MNT3ERR_IO"; break; | |
168 | case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break; | |
169 | case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break; | |
170 | case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break; | |
171 | case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break; | |
172 | case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break; | |
173 | case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break; | |
174 | } | |
175 | return str; | |
176 | } | |
177 | ||
178 | ||
179 | int mountstat3_to_errno(int st) | |
180 | { | |
181 | enum mountstat3 stat = st; | |
182 | ||
183 | switch (stat) { | |
184 | case MNT3_OK: return 0; break; | |
185 | case MNT3ERR_PERM: return -EPERM; break; | |
186 | case MNT3ERR_NOENT: return -EPERM; break; | |
187 | case MNT3ERR_IO: return -EIO; break; | |
188 | case MNT3ERR_ACCES: return -EACCES; break; | |
189 | case MNT3ERR_NOTDIR: return -ENOTDIR; break; | |
190 | case MNT3ERR_INVAL: return -EINVAL; break; | |
191 | case MNT3ERR_NAMETOOLONG: return -E2BIG; break; | |
192 | case MNT3ERR_NOTSUPP: return -EINVAL; break; | |
193 | case MNT3ERR_SERVERFAULT: return -EIO; break; | |
194 | } | |
195 | return -ERANGE; | |
196 | } | |
7f0242ca RS |
197 | |
198 | ||
199 |