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