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 | ||
a8a1b858 M |
18 | #ifdef WIN32 |
19 | #include "win32_compat.h" | |
20 | #else | |
21 | #include <sys/stat.h> | |
22 | #endif/*WIN32*/ | |
eecdc4f3 | 23 | |
84004dbf RS |
24 | #include <stdio.h> |
25 | #include <errno.h> | |
98f5fee8 | 26 | #include <string.h> |
763cd6e3 | 27 | #include "libnfs-zdr.h" |
84004dbf RS |
28 | #include "libnfs.h" |
29 | #include "libnfs-raw.h" | |
30 | #include "libnfs-private.h" | |
31 | #include "libnfs-raw-nfs.h" | |
32 | ||
84004dbf RS |
33 | char *nfsstat3_to_str(int error) |
34 | { | |
35 | switch (error) { | |
36 | case NFS3_OK: return "NFS3_OK"; break; | |
37 | case NFS3ERR_PERM: return "NFS3ERR_PERM"; break; | |
38 | case NFS3ERR_NOENT: return "NFS3ERR_NOENT"; break; | |
39 | case NFS3ERR_IO: return "NFS3ERR_IO"; break; | |
40 | case NFS3ERR_NXIO: return "NFS3ERR_NXIO"; break; | |
41 | case NFS3ERR_ACCES: return "NFS3ERR_ACCES"; break; | |
42 | case NFS3ERR_EXIST: return "NFS3ERR_EXIST"; break; | |
43 | case NFS3ERR_XDEV: return "NFS3ERR_XDEV"; break; | |
44 | case NFS3ERR_NODEV: return "NFS3ERR_NODEV"; break; | |
45 | case NFS3ERR_NOTDIR: return "NFS3ERR_NOTDIR"; break; | |
46 | case NFS3ERR_ISDIR: return "NFS3ERR_ISDIR"; break; | |
47 | case NFS3ERR_INVAL: return "NFS3ERR_INVAL"; break; | |
48 | case NFS3ERR_FBIG: return "NFS3ERR_FBIG"; break; | |
49 | case NFS3ERR_NOSPC: return "NFS3ERR_NOSPC"; break; | |
50 | case NFS3ERR_ROFS: return "NFS3ERR_ROFS"; break; | |
51 | case NFS3ERR_MLINK: return "NFS3ERR_MLINK"; break; | |
52 | case NFS3ERR_NAMETOOLONG: return "NFS3ERR_NAMETOOLONG"; break; | |
53 | case NFS3ERR_NOTEMPTY: return "NFS3ERR_NOTEMPTY"; break; | |
54 | case NFS3ERR_DQUOT: return "NFS3ERR_DQUOT"; break; | |
55 | case NFS3ERR_STALE: return "NFS3ERR_STALE"; break; | |
56 | case NFS3ERR_REMOTE: return "NFS3ERR_REMOTE"; break; | |
57 | case NFS3ERR_BADHANDLE: return "NFS3ERR_BADHANDLE"; break; | |
58 | case NFS3ERR_NOT_SYNC: return "NFS3ERR_NOT_SYNC"; break; | |
59 | case NFS3ERR_BAD_COOKIE: return "NFS3ERR_BAD_COOKIE"; break; | |
60 | case NFS3ERR_NOTSUPP: return "NFS3ERR_NOTSUPP"; break; | |
61 | case NFS3ERR_TOOSMALL: return "NFS3ERR_TOOSMALL"; break; | |
62 | case NFS3ERR_SERVERFAULT: return "NFS3ERR_SERVERFAULT"; break; | |
63 | case NFS3ERR_BADTYPE: return "NFS3ERR_BADTYPE"; break; | |
64 | case NFS3ERR_JUKEBOX: return "NFS3ERR_JUKEBOX"; break; | |
65 | }; | |
66 | return "unknown nfs error"; | |
67 | } | |
68 | ||
69 | int nfsstat3_to_errno(int error) | |
70 | { | |
71 | switch (error) { | |
72 | case NFS3_OK: return 0; break; | |
73 | case NFS3ERR_PERM: return -EPERM; break; | |
74 | case NFS3ERR_NOENT: return -ENOENT; break; | |
75 | case NFS3ERR_IO: return -EIO; break; | |
76 | case NFS3ERR_NXIO: return -ENXIO; break; | |
77 | case NFS3ERR_ACCES: return -EACCES; break; | |
78 | case NFS3ERR_EXIST: return -EEXIST; break; | |
79 | case NFS3ERR_XDEV: return -EXDEV; break; | |
80 | case NFS3ERR_NODEV: return -ENODEV; break; | |
81 | case NFS3ERR_NOTDIR: return -ENOTDIR; break; | |
82 | case NFS3ERR_ISDIR: return -EISDIR; break; | |
83 | case NFS3ERR_INVAL: return -EINVAL; break; | |
84 | case NFS3ERR_FBIG: return -EFBIG; break; | |
85 | case NFS3ERR_NOSPC: return -ENOSPC; break; | |
86 | case NFS3ERR_ROFS: return -EROFS; break; | |
87 | case NFS3ERR_MLINK: return -EMLINK; break; | |
88 | case NFS3ERR_NAMETOOLONG: return -ENAMETOOLONG; break; | |
89 | case NFS3ERR_NOTEMPTY: return -EEXIST; break; | |
90 | case NFS3ERR_DQUOT: return -ERANGE; break; | |
91 | case NFS3ERR_STALE: return -EIO; break; | |
92 | case NFS3ERR_REMOTE: return -EIO; break; | |
93 | case NFS3ERR_BADHANDLE: return -EIO; break; | |
94 | case NFS3ERR_NOT_SYNC: return -EIO; break; | |
95 | case NFS3ERR_BAD_COOKIE: return -EIO; break; | |
96 | case NFS3ERR_NOTSUPP: return -EINVAL; break; | |
97 | case NFS3ERR_TOOSMALL: return -EIO; break; | |
98 | case NFS3ERR_SERVERFAULT: return -EIO; break; | |
99 | case NFS3ERR_BADTYPE: return -EINVAL; break; | |
100 | case NFS3ERR_JUKEBOX: return -EAGAIN; break; | |
101 | }; | |
102 | return -ERANGE; | |
103 | } | |
104 | ||
105 | ||
106 | int rpc_nfs_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
107 | { | |
108 | struct rpc_pdu *pdu; | |
109 | ||
763cd6e3 | 110 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_NULL, cb, private_data, (zdrproc_t)zdr_void, 0); |
84004dbf RS |
111 | if (pdu == NULL) { |
112 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/null call"); | |
113 | return -1; | |
114 | } | |
115 | ||
116 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
117 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/null call"); | |
118 | rpc_free_pdu(rpc, pdu); | |
119 | return -2; | |
120 | } | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | int rpc_nfs_getattr_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) | |
126 | { | |
127 | struct rpc_pdu *pdu; | |
128 | GETATTR3args args; | |
129 | ||
763cd6e3 | 130 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_GETATTR, cb, private_data, (zdrproc_t)zdr_GETATTR3res, sizeof(GETATTR3res)); |
84004dbf RS |
131 | if (pdu == NULL) { |
132 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/null call"); | |
133 | return -1; | |
134 | } | |
135 | ||
136 | args.object.data.data_len = fh->data.data_len; | |
137 | args.object.data.data_val = fh->data.data_val; | |
138 | ||
763cd6e3 RS |
139 | if (zdr_GETATTR3args(&pdu->zdr, &args) == 0) { |
140 | rpc_set_error(rpc, "ZDR error: Failed to encode GETATTR3args"); | |
84004dbf RS |
141 | rpc_free_pdu(rpc, pdu); |
142 | return -2; | |
143 | } | |
144 | ||
145 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
6f914247 RS |
146 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/getattr call"); |
147 | rpc_free_pdu(rpc, pdu); | |
148 | return -3; | |
149 | } | |
150 | ||
151 | return 0; | |
152 | } | |
153 | ||
154 | int rpc_nfs_pathconf_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) | |
155 | { | |
156 | struct rpc_pdu *pdu; | |
157 | PATHCONF3args args; | |
158 | ||
159 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_PATHCONF, cb, private_data, (zdrproc_t)zdr_PATHCONF3res, sizeof(PATHCONF3res)); | |
160 | if (pdu == NULL) { | |
161 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/pathconf call"); | |
162 | return -1; | |
163 | } | |
164 | ||
165 | args.object.data.data_len = fh->data.data_len; | |
166 | args.object.data.data_val = fh->data.data_val; | |
167 | ||
168 | if (zdr_PATHCONF3args(&pdu->zdr, &args) == 0) { | |
169 | rpc_set_error(rpc, "ZDR error: Failed to encode PATHCONF3args"); | |
170 | rpc_free_pdu(rpc, pdu); | |
171 | return -2; | |
172 | } | |
173 | ||
174 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
175 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/pathconf call"); | |
84004dbf RS |
176 | rpc_free_pdu(rpc, pdu); |
177 | return -3; | |
178 | } | |
179 | ||
180 | return 0; | |
181 | } | |
182 | ||
183 | int rpc_nfs_lookup_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *name, void *private_data) | |
184 | { | |
185 | struct rpc_pdu *pdu; | |
186 | LOOKUP3args args; | |
187 | ||
763cd6e3 | 188 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LOOKUP, cb, private_data, (zdrproc_t)zdr_LOOKUP3res, sizeof(LOOKUP3res)); |
84004dbf RS |
189 | if (pdu == NULL) { |
190 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/lookup call"); | |
191 | return -1; | |
192 | } | |
193 | ||
194 | args.what.dir.data.data_len = fh->data.data_len; | |
195 | args.what.dir.data.data_val = fh->data.data_val; | |
196 | args.what.name = name; | |
197 | ||
763cd6e3 RS |
198 | if (zdr_LOOKUP3args(&pdu->zdr, &args) == 0) { |
199 | rpc_set_error(rpc, "ZDR error: Failed to encode LOOKUP3args"); | |
84004dbf RS |
200 | rpc_free_pdu(rpc, pdu); |
201 | return -2; | |
202 | } | |
203 | ||
204 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
205 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/lookup call"); | |
206 | rpc_free_pdu(rpc, pdu); | |
207 | return -3; | |
208 | } | |
209 | ||
210 | return 0; | |
211 | } | |
212 | ||
213 | ||
214 | int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, int access, void *private_data) | |
215 | { | |
216 | struct rpc_pdu *pdu; | |
217 | ACCESS3args args; | |
218 | ||
763cd6e3 | 219 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_ACCESS, cb, private_data, (zdrproc_t)zdr_ACCESS3res, sizeof(ACCESS3res)); |
84004dbf RS |
220 | if (pdu == NULL) { |
221 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/access call"); | |
222 | return -1; | |
223 | } | |
224 | ||
225 | args.object.data.data_len = fh->data.data_len; | |
226 | args.object.data.data_val = fh->data.data_val; | |
227 | args.access = access; | |
228 | ||
763cd6e3 RS |
229 | if (zdr_ACCESS3args(&pdu->zdr, &args) == 0) { |
230 | rpc_set_error(rpc, "ZDR error: Failed to encode ACCESS3args"); | |
84004dbf RS |
231 | rpc_free_pdu(rpc, pdu); |
232 | return -2; | |
233 | } | |
234 | ||
235 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
236 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/access call"); | |
237 | rpc_free_pdu(rpc, pdu); | |
238 | return -3; | |
239 | } | |
240 | ||
241 | return 0; | |
242 | } | |
243 | ||
244 | ||
245 | ||
183451cf | 246 | int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t offset, uint64_t count, void *private_data) |
84004dbf RS |
247 | { |
248 | struct rpc_pdu *pdu; | |
249 | READ3args args; | |
250 | ||
763cd6e3 | 251 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READ, cb, private_data, (zdrproc_t)zdr_READ3res, sizeof(READ3res)); |
84004dbf RS |
252 | if (pdu == NULL) { |
253 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/read call"); | |
254 | return -1; | |
255 | } | |
256 | ||
257 | args.file.data.data_len = fh->data.data_len; | |
258 | args.file.data.data_val = fh->data.data_val; | |
259 | args.offset = offset; | |
260 | args.count = count; | |
261 | ||
763cd6e3 RS |
262 | if (zdr_READ3args(&pdu->zdr, &args) == 0) { |
263 | rpc_set_error(rpc, "ZDR error: Failed to encode READ3args"); | |
84004dbf RS |
264 | rpc_free_pdu(rpc, pdu); |
265 | return -2; | |
266 | } | |
267 | ||
268 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
269 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/read call"); | |
270 | rpc_free_pdu(rpc, pdu); | |
271 | return -3; | |
272 | } | |
273 | ||
274 | return 0; | |
275 | } | |
276 | ||
277 | ||
183451cf | 278 | int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, uint64_t offset, uint64_t count, int stable_how, void *private_data) |
84004dbf RS |
279 | { |
280 | struct rpc_pdu *pdu; | |
281 | WRITE3args args; | |
282 | ||
763cd6e3 | 283 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_WRITE, cb, private_data, (zdrproc_t)zdr_WRITE3res, sizeof(WRITE3res)); |
84004dbf RS |
284 | if (pdu == NULL) { |
285 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/write call"); | |
286 | return -1; | |
287 | } | |
288 | ||
289 | args.file.data.data_len = fh->data.data_len; | |
290 | args.file.data.data_val = fh->data.data_val; | |
291 | args.offset = offset; | |
292 | args.count = count; | |
e7b4eb0a | 293 | args.stable = stable_how; |
84004dbf RS |
294 | args.data.data_len = count; |
295 | args.data.data_val = buf; | |
296 | ||
763cd6e3 RS |
297 | if (zdr_WRITE3args(&pdu->zdr, &args) == 0) { |
298 | rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3args"); | |
84004dbf RS |
299 | rpc_free_pdu(rpc, pdu); |
300 | return -2; | |
301 | } | |
302 | ||
303 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
304 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/write call"); | |
305 | rpc_free_pdu(rpc, pdu); | |
306 | return -3; | |
307 | } | |
308 | ||
309 | return 0; | |
310 | } | |
311 | ||
312 | ||
313 | ||
314 | int rpc_nfs_commit_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) | |
315 | { | |
316 | struct rpc_pdu *pdu; | |
317 | COMMIT3args args; | |
318 | ||
763cd6e3 | 319 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_COMMIT, cb, private_data, (zdrproc_t)zdr_COMMIT3res, sizeof(COMMIT3res)); |
84004dbf RS |
320 | if (pdu == NULL) { |
321 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/commit call"); | |
322 | return -1; | |
323 | } | |
324 | ||
325 | args.file.data.data_len = fh->data.data_len; | |
326 | args.file.data.data_val = fh->data.data_val; | |
327 | args.offset = 0; | |
328 | args.count = 0; | |
329 | ||
763cd6e3 RS |
330 | if (zdr_COMMIT3args(&pdu->zdr, &args) == 0) { |
331 | rpc_set_error(rpc, "ZDR error: Failed to encode WRITE3args"); | |
84004dbf RS |
332 | rpc_free_pdu(rpc, pdu); |
333 | return -2; | |
334 | } | |
335 | ||
336 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
337 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/commit call"); | |
338 | rpc_free_pdu(rpc, pdu); | |
339 | return -3; | |
340 | } | |
341 | ||
342 | return 0; | |
343 | } | |
344 | ||
345 | ||
346 | int rpc_nfs_setattr_async(struct rpc_context *rpc, rpc_cb cb, SETATTR3args *args, void *private_data) | |
347 | { | |
348 | struct rpc_pdu *pdu; | |
349 | ||
763cd6e3 | 350 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SETATTR, cb, private_data, (zdrproc_t)zdr_SETATTR3res, sizeof(SETATTR3res)); |
84004dbf RS |
351 | if (pdu == NULL) { |
352 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/setattr call"); | |
353 | return -1; | |
354 | } | |
355 | ||
763cd6e3 RS |
356 | if (zdr_SETATTR3args(&pdu->zdr, args) == 0) { |
357 | rpc_set_error(rpc, "ZDR error: Failed to encode SETATTR3args"); | |
84004dbf RS |
358 | rpc_free_pdu(rpc, pdu); |
359 | return -2; | |
360 | } | |
361 | ||
362 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
363 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/setattr call"); | |
364 | rpc_free_pdu(rpc, pdu); | |
365 | return -3; | |
366 | } | |
367 | ||
368 | return 0; | |
369 | } | |
370 | ||
371 | ||
372 | ||
7edc9026 | 373 | int rpc_nfs_mkdir_async(struct rpc_context *rpc, rpc_cb cb, MKDIR3args *args, void *private_data) |
84004dbf RS |
374 | { |
375 | struct rpc_pdu *pdu; | |
84004dbf | 376 | |
763cd6e3 | 377 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKDIR, cb, private_data, (zdrproc_t)zdr_MKDIR3res, sizeof(MKDIR3res)); |
84004dbf RS |
378 | if (pdu == NULL) { |
379 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/setattr call"); | |
380 | return -1; | |
381 | } | |
382 | ||
763cd6e3 RS |
383 | if (zdr_MKDIR3args(&pdu->zdr, args) == 0) { |
384 | rpc_set_error(rpc, "ZDR error: Failed to encode MKDIR3args"); | |
84004dbf RS |
385 | rpc_free_pdu(rpc, pdu); |
386 | return -2; | |
387 | } | |
388 | ||
389 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
390 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/mkdir call"); | |
391 | rpc_free_pdu(rpc, pdu); | |
392 | return -3; | |
393 | } | |
394 | ||
395 | return 0; | |
396 | } | |
397 | ||
398 | ||
399 | ||
400 | ||
401 | int rpc_nfs_rmdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *dir, void *private_data) | |
402 | { | |
403 | struct rpc_pdu *pdu; | |
404 | RMDIR3args args; | |
405 | ||
763cd6e3 | 406 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RMDIR, cb, private_data, (zdrproc_t)zdr_RMDIR3res, sizeof(RMDIR3res)); |
84004dbf RS |
407 | if (pdu == NULL) { |
408 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/rmdir call"); | |
409 | return -1; | |
410 | } | |
411 | ||
ea98629a | 412 | memset(&args, 0, sizeof(RMDIR3args)); |
84004dbf RS |
413 | args.object.dir.data.data_len = fh->data.data_len; |
414 | args.object.dir.data.data_val = fh->data.data_val; | |
415 | args.object.name = dir; | |
416 | ||
763cd6e3 RS |
417 | if (zdr_RMDIR3args(&pdu->zdr, &args) == 0) { |
418 | rpc_set_error(rpc, "ZDR error: Failed to encode RMDIR3args"); | |
84004dbf RS |
419 | rpc_free_pdu(rpc, pdu); |
420 | return -2; | |
421 | } | |
422 | ||
423 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
424 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/rmdir call"); | |
425 | rpc_free_pdu(rpc, pdu); | |
426 | return -3; | |
427 | } | |
428 | ||
429 | return 0; | |
430 | } | |
431 | ||
432 | ||
433 | ||
c985c015 | 434 | int rpc_nfs_create_async(struct rpc_context *rpc, rpc_cb cb, CREATE3args *args, void *private_data) |
84004dbf RS |
435 | { |
436 | struct rpc_pdu *pdu; | |
84004dbf | 437 | |
763cd6e3 | 438 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_CREATE, cb, private_data, (zdrproc_t)zdr_CREATE3res, sizeof(CREATE3res)); |
84004dbf RS |
439 | if (pdu == NULL) { |
440 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/create call"); | |
441 | return -1; | |
442 | } | |
443 | ||
763cd6e3 RS |
444 | if (zdr_CREATE3args(&pdu->zdr, args) == 0) { |
445 | rpc_set_error(rpc, "ZDR error: Failed to encode CREATE3args"); | |
84004dbf RS |
446 | rpc_free_pdu(rpc, pdu); |
447 | return -2; | |
448 | } | |
449 | ||
450 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
451 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/create call"); | |
452 | rpc_free_pdu(rpc, pdu); | |
453 | return -3; | |
454 | } | |
455 | ||
456 | return 0; | |
457 | } | |
458 | ||
459 | ||
460 | ||
1ec6b50a RS |
461 | int rpc_nfs_mknod_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, int mode, int major, int minor, void *private_data) |
462 | { | |
463 | struct rpc_pdu *pdu; | |
464 | MKNOD3args args; | |
465 | ||
763cd6e3 | 466 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_MKNOD, cb, private_data, (zdrproc_t)zdr_MKNOD3res, sizeof(MKNOD3res)); |
1ec6b50a RS |
467 | if (pdu == NULL) { |
468 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/mknod call"); | |
469 | return -1; | |
470 | } | |
471 | ||
472 | memset(&args, 0, sizeof(MKNOD3args)); | |
473 | args.where.dir.data.data_len = fh->data.data_len; | |
474 | args.where.dir.data.data_val = fh->data.data_val; | |
475 | args.where.name = file; | |
476 | switch (mode & S_IFMT) { | |
477 | case S_IFCHR: | |
478 | args.what.type = NF3CHR; | |
479 | args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_it = 1; | |
480 | args.what.mknoddata3_u.chr_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
481 | args.what.mknoddata3_u.chr_device.spec.specdata1 = major; | |
482 | args.what.mknoddata3_u.chr_device.spec.specdata2 = minor; | |
483 | break; | |
484 | case S_IFBLK: | |
485 | args.what.type = NF3BLK; | |
486 | args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_it = 1; | |
487 | args.what.mknoddata3_u.blk_device.dev_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
488 | args.what.mknoddata3_u.blk_device.spec.specdata1 = major; | |
489 | args.what.mknoddata3_u.blk_device.spec.specdata2 = minor; | |
490 | case S_IFSOCK: | |
491 | args.what.type = NF3SOCK; | |
492 | args.what.mknoddata3_u.sock_attributes.mode.set_it = 1; | |
493 | args.what.mknoddata3_u.sock_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
494 | break; | |
495 | case S_IFIFO: | |
496 | args.what.type = NF3FIFO; | |
497 | args.what.mknoddata3_u.pipe_attributes.mode.set_it = 1; | |
498 | args.what.mknoddata3_u.pipe_attributes.mode.set_mode3_u.mode = mode & (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH); | |
499 | break; | |
500 | default: | |
501 | rpc_set_error(rpc, "Invalid file type for nfs/mknod call"); | |
502 | rpc_free_pdu(rpc, pdu); | |
503 | return -1; | |
504 | } | |
505 | ||
763cd6e3 RS |
506 | if (zdr_MKNOD3args(&pdu->zdr, &args) == 0) { |
507 | rpc_set_error(rpc, "ZDR error: Failed to encode MKNOD3args"); | |
1ec6b50a RS |
508 | rpc_free_pdu(rpc, pdu); |
509 | return -2; | |
510 | } | |
511 | ||
512 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
513 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/mknod call"); | |
514 | rpc_free_pdu(rpc, pdu); | |
515 | return -3; | |
516 | } | |
517 | ||
518 | return 0; | |
519 | } | |
520 | ||
84004dbf RS |
521 | |
522 | int rpc_nfs_remove_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *file, void *private_data) | |
523 | { | |
524 | struct rpc_pdu *pdu; | |
525 | REMOVE3args args; | |
526 | ||
763cd6e3 | 527 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_REMOVE, cb, private_data, (zdrproc_t)zdr_REMOVE3res, sizeof(REMOVE3res)); |
84004dbf RS |
528 | if (pdu == NULL) { |
529 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/remove call"); | |
530 | return -1; | |
531 | } | |
532 | ||
ea98629a | 533 | memset(&args, 0, sizeof(REMOVE3args)); |
84004dbf RS |
534 | args.object.dir.data.data_len = fh->data.data_len; |
535 | args.object.dir.data.data_val = fh->data.data_val; | |
536 | args.object.name = file; | |
537 | ||
763cd6e3 RS |
538 | if (zdr_REMOVE3args(&pdu->zdr, &args) == 0) { |
539 | rpc_set_error(rpc, "ZDR error: Failed to encode REMOVE3args"); | |
84004dbf RS |
540 | rpc_free_pdu(rpc, pdu); |
541 | return -2; | |
542 | } | |
543 | ||
544 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
545 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/remove call"); | |
546 | rpc_free_pdu(rpc, pdu); | |
547 | return -3; | |
548 | } | |
549 | ||
550 | return 0; | |
551 | } | |
552 | ||
84004dbf RS |
553 | int rpc_nfs_readdir_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) |
554 | { | |
555 | struct rpc_pdu *pdu; | |
556 | READDIR3args args; | |
557 | ||
763cd6e3 | 558 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIR, cb, private_data, (zdrproc_t)zdr_READDIR3res, sizeof(READDIR3res)); |
84004dbf RS |
559 | if (pdu == NULL) { |
560 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdir call"); | |
561 | return -1; | |
562 | } | |
563 | ||
ea98629a | 564 | memset(&args, 0, sizeof(READDIR3args)); |
84004dbf RS |
565 | args.dir.data.data_len = fh->data.data_len; |
566 | args.dir.data.data_val = fh->data.data_val; | |
567 | args.cookie = cookie; | |
568 | memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); | |
569 | args.count = count; | |
570 | ||
763cd6e3 RS |
571 | if (zdr_READDIR3args(&pdu->zdr, &args) == 0) { |
572 | rpc_set_error(rpc, "ZDR error: Failed to encode READDIR3args"); | |
84004dbf RS |
573 | rpc_free_pdu(rpc, pdu); |
574 | return -2; | |
575 | } | |
576 | ||
577 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
578 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdir call"); | |
579 | rpc_free_pdu(rpc, pdu); | |
580 | return -3; | |
581 | } | |
582 | ||
583 | return 0; | |
584 | } | |
585 | ||
f390f181 RS |
586 | int rpc_nfs_readdirplus_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, uint64_t cookie, char *cookieverf, int count, void *private_data) |
587 | { | |
588 | struct rpc_pdu *pdu; | |
589 | READDIRPLUS3args args; | |
590 | ||
763cd6e3 | 591 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READDIRPLUS, cb, private_data, (zdrproc_t)zdr_READDIRPLUS3res, sizeof(READDIRPLUS3res)); |
f390f181 RS |
592 | if (pdu == NULL) { |
593 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readdirplus call"); | |
594 | return -1; | |
595 | } | |
596 | ||
ea98629a | 597 | memset(&args, 0, sizeof(READDIRPLUS3args)); |
f390f181 RS |
598 | args.dir.data.data_len = fh->data.data_len; |
599 | args.dir.data.data_val = fh->data.data_val; | |
600 | args.cookie = cookie; | |
601 | memcpy(&args.cookieverf, cookieverf, sizeof(cookieverf3)); | |
602 | args.dircount = count; | |
603 | args.maxcount = count; | |
604 | ||
763cd6e3 RS |
605 | if (zdr_READDIRPLUS3args(&pdu->zdr, &args) == 0) { |
606 | rpc_set_error(rpc, "ZDR error: Failed to encode READDIRPLUS3args"); | |
f390f181 RS |
607 | rpc_free_pdu(rpc, pdu); |
608 | return -2; | |
609 | } | |
610 | ||
611 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
612 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readdirplus call"); | |
613 | rpc_free_pdu(rpc, pdu); | |
614 | return -3; | |
615 | } | |
616 | ||
617 | return 0; | |
618 | } | |
619 | ||
84004dbf RS |
620 | int rpc_nfs_fsstat_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) |
621 | { | |
622 | struct rpc_pdu *pdu; | |
623 | FSSTAT3args args; | |
624 | ||
763cd6e3 | 625 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSSTAT, cb, private_data, (zdrproc_t)zdr_FSSTAT3res, sizeof(FSSTAT3res)); |
84004dbf RS |
626 | if (pdu == NULL) { |
627 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/fsstat call"); | |
628 | return -1; | |
629 | } | |
630 | ||
631 | args.fsroot.data.data_len = fh->data.data_len; | |
632 | args.fsroot.data.data_val = fh->data.data_val; | |
633 | ||
763cd6e3 RS |
634 | if (zdr_FSSTAT3args(&pdu->zdr, &args) == 0) { |
635 | rpc_set_error(rpc, "ZDR error: Failed to encode FSSTAT3args"); | |
84004dbf RS |
636 | rpc_free_pdu(rpc, pdu); |
637 | return -2; | |
638 | } | |
639 | ||
640 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
641 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/fsstat call"); | |
642 | rpc_free_pdu(rpc, pdu); | |
643 | return -3; | |
644 | } | |
645 | ||
646 | return 0; | |
647 | } | |
648 | ||
1058201e RS |
649 | int rpc_nfs_fsinfo_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, void *private_data) |
650 | { | |
651 | struct rpc_pdu *pdu; | |
652 | FSINFO3args args; | |
653 | ||
763cd6e3 | 654 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_FSINFO, cb, private_data, (zdrproc_t)zdr_FSINFO3res, sizeof(FSINFO3res)); |
1058201e RS |
655 | if (pdu == NULL) { |
656 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/fsinfo call"); | |
657 | return -1; | |
658 | } | |
659 | ||
660 | args.fsroot.data.data_len = fh->data.data_len; | |
661 | args.fsroot.data.data_val = fh->data.data_val; | |
662 | ||
763cd6e3 RS |
663 | if (zdr_FSINFO3args(&pdu->zdr, &args) == 0) { |
664 | rpc_set_error(rpc, "ZDR error: Failed to encode FSINFO3args"); | |
1058201e RS |
665 | rpc_free_pdu(rpc, pdu); |
666 | return -2; | |
667 | } | |
668 | ||
669 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
670 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/fsinfo call"); | |
671 | rpc_free_pdu(rpc, pdu); | |
672 | return -3; | |
673 | } | |
674 | ||
675 | return 0; | |
676 | } | |
84004dbf | 677 | |
16104b27 | 678 | int rpc_nfs_readlink_async(struct rpc_context *rpc, rpc_cb cb, READLINK3args *args, void *private_data) |
84004dbf RS |
679 | { |
680 | struct rpc_pdu *pdu; | |
84004dbf | 681 | |
763cd6e3 | 682 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_READLINK, cb, private_data, (zdrproc_t)zdr_READLINK3res, sizeof(READLINK3res)); |
84004dbf RS |
683 | if (pdu == NULL) { |
684 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/readlink call"); | |
685 | return -1; | |
686 | } | |
687 | ||
763cd6e3 RS |
688 | if (zdr_READLINK3args(&pdu->zdr, args) == 0) { |
689 | rpc_set_error(rpc, "ZDR error: Failed to encode READLINK3args"); | |
84004dbf RS |
690 | rpc_free_pdu(rpc, pdu); |
691 | return -2; | |
692 | } | |
693 | ||
694 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
695 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/readlink call"); | |
696 | rpc_free_pdu(rpc, pdu); | |
697 | return -3; | |
698 | } | |
699 | ||
700 | return 0; | |
701 | } | |
702 | ||
703 | ||
8e255816 | 704 | int rpc_nfs_symlink_async(struct rpc_context *rpc, rpc_cb cb, SYMLINK3args *args, void *private_data) |
84004dbf RS |
705 | { |
706 | struct rpc_pdu *pdu; | |
84004dbf | 707 | |
763cd6e3 | 708 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_SYMLINK, cb, private_data, (zdrproc_t)zdr_SYMLINK3res, sizeof(SYMLINK3res)); |
84004dbf RS |
709 | if (pdu == NULL) { |
710 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/symlink call"); | |
711 | return -1; | |
712 | } | |
713 | ||
763cd6e3 RS |
714 | if (zdr_SYMLINK3args(&pdu->zdr, args) == 0) { |
715 | rpc_set_error(rpc, "ZDR error: Failed to encode SYMLINK3args"); | |
84004dbf RS |
716 | rpc_free_pdu(rpc, pdu); |
717 | return -2; | |
718 | } | |
719 | ||
720 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
721 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/symlink call"); | |
722 | rpc_free_pdu(rpc, pdu); | |
723 | return -3; | |
724 | } | |
725 | ||
726 | return 0; | |
727 | } | |
728 | ||
729 | ||
730 | ||
731 | ||
732 | int rpc_nfs_rename_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *olddir, char *oldname, struct nfs_fh3 *newdir, char *newname, void *private_data) | |
733 | { | |
734 | struct rpc_pdu *pdu; | |
735 | RENAME3args args; | |
736 | ||
763cd6e3 | 737 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_RENAME, cb, private_data, (zdrproc_t)zdr_RENAME3res, sizeof(RENAME3res)); |
84004dbf RS |
738 | if (pdu == NULL) { |
739 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/rename call"); | |
740 | return -1; | |
741 | } | |
742 | ||
ea98629a | 743 | memset(&args, 0, sizeof(RENAME3args)); |
84004dbf RS |
744 | args.from.dir.data.data_len = olddir->data.data_len; |
745 | args.from.dir.data.data_val = olddir->data.data_val; | |
746 | args.from.name = oldname; | |
747 | args.to.dir.data.data_len = newdir->data.data_len; | |
748 | args.to.dir.data.data_val = newdir->data.data_val; | |
749 | args.to.name = newname; | |
750 | ||
763cd6e3 RS |
751 | if (zdr_RENAME3args(&pdu->zdr, &args) == 0) { |
752 | rpc_set_error(rpc, "ZDR error: Failed to encode RENAME3args"); | |
84004dbf RS |
753 | rpc_free_pdu(rpc, pdu); |
754 | return -2; | |
755 | } | |
756 | ||
757 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
758 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/rename call"); | |
759 | rpc_free_pdu(rpc, pdu); | |
760 | return -3; | |
761 | } | |
762 | ||
763 | return 0; | |
764 | } | |
765 | ||
766 | ||
767 | ||
768 | ||
769 | int rpc_nfs_link_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *file, struct nfs_fh3 *newdir, char *newname, void *private_data) | |
770 | { | |
771 | struct rpc_pdu *pdu; | |
772 | LINK3args args; | |
773 | ||
763cd6e3 | 774 | pdu = rpc_allocate_pdu(rpc, NFS_PROGRAM, NFS_V3, NFS3_LINK, cb, private_data, (zdrproc_t)zdr_LINK3res, sizeof(LINK3res)); |
84004dbf RS |
775 | if (pdu == NULL) { |
776 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for nfs/link call"); | |
777 | return -1; | |
778 | } | |
779 | ||
ea98629a | 780 | memset(&args, 0, sizeof(LINK3args)); |
84004dbf RS |
781 | args.file.data.data_len = file->data.data_len; |
782 | args.file.data.data_val = file->data.data_val; | |
783 | args.link.dir.data.data_len = newdir->data.data_len; | |
784 | args.link.dir.data.data_val = newdir->data.data_val; | |
785 | args.link.name = newname; | |
786 | ||
763cd6e3 RS |
787 | if (zdr_LINK3args(&pdu->zdr, &args) == 0) { |
788 | rpc_set_error(rpc, "ZDR error: Failed to encode LINK3args"); | |
84004dbf RS |
789 | rpc_free_pdu(rpc, pdu); |
790 | return -2; | |
791 | } | |
792 | ||
793 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
794 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for nfs/link call"); | |
795 | rpc_free_pdu(rpc, pdu); | |
796 | return -3; | |
797 | } | |
798 | ||
799 | return 0; | |
800 | } | |
801 | ||
802 | ||
803 | ||
804 |