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