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