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