c21046a20bd9d5720a928c25c6327a87d349d054
2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
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.
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.
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/>.
23 #include "libnfs-raw.h"
24 #include "libnfs-private.h"
25 #include "libnfs-raw-nfs.h"
29 char *nfsstat3_to_str(int 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;
62 return "unknown nfs error";
65 int nfsstat3_to_errno(int 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;
102 int rpc_nfs_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
106 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_NULL
, cb
, private_data
, (xdrproc_t
)xdr_void
, 0);
108 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
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
);
121 int rpc_nfs_getattr_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
126 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_GETATTR
, cb
, private_data
, (xdrproc_t
)xdr_GETATTR3res
, sizeof(GETATTR3res
));
128 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
132 args
.object
.data
.data_len
= fh
->data
.data_len
;
133 args
.object
.data
.data_val
= fh
->data
.data_val
;
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
);
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
);
150 int rpc_nfs_lookup_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, void *private_data
)
155 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LOOKUP
, cb
, private_data
, (xdrproc_t
)xdr_LOOKUP3res
, sizeof(LOOKUP3res
));
157 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/lookup call");
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
;
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
);
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
);
181 int rpc_nfs_access_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, int access
, void *private_data
)
186 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_ACCESS
, cb
, private_data
, (xdrproc_t
)xdr_ACCESS3res
, sizeof(ACCESS3res
));
188 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/access call");
192 args
.object
.data
.data_len
= fh
->data
.data_len
;
193 args
.object
.data
.data_val
= fh
->data
.data_val
;
194 args
.access
= access
;
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
);
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
);
213 int rpc_nfs_read_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, off_t offset
, size_t count
, void *private_data
)
218 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READ
, cb
, private_data
, (xdrproc_t
)xdr_READ3res
, sizeof(READ3res
));
220 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/read call");
224 args
.file
.data
.data_len
= fh
->data
.data_len
;
225 args
.file
.data
.data_val
= fh
->data
.data_val
;
226 args
.offset
= offset
;
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
);
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
);
245 int 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
)
250 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_WRITE
, cb
, private_data
, (xdrproc_t
)xdr_WRITE3res
, sizeof(WRITE3res
));
252 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/write call");
256 args
.file
.data
.data_len
= fh
->data
.data_len
;
257 args
.file
.data
.data_val
= fh
->data
.data_val
;
258 args
.offset
= offset
;
260 args
.stable
= stable_how
;;
261 args
.data
.data_len
= count
;
262 args
.data
.data_val
= buf
;
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
);
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
);
281 int rpc_nfs_commit_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
286 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_COMMIT
, cb
, private_data
, (xdrproc_t
)xdr_COMMIT3res
, sizeof(COMMIT3res
));
288 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/commit call");
292 args
.file
.data
.data_len
= fh
->data
.data_len
;
293 args
.file
.data
.data_val
= fh
->data
.data_val
;
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
);
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
);
313 int rpc_nfs_setattr_async(struct rpc_context
*rpc
, rpc_cb cb
, SETATTR3args
*args
, void *private_data
)
317 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SETATTR
, cb
, private_data
, (xdrproc_t
)xdr_SETATTR3res
, sizeof(SETATTR3res
));
319 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
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
);
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
);
340 int rpc_nfs_mkdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
345 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_MKDIR
, cb
, private_data
, (xdrproc_t
)xdr_MKDIR3res
, sizeof(MKDIR3res
));
347 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
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;
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
);
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
);
376 int rpc_nfs_rmdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
381 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RMDIR
, cb
, private_data
, (xdrproc_t
)xdr_RMDIR3res
, sizeof(RMDIR3res
));
383 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rmdir call");
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
;
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
);
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
);
409 int rpc_nfs_create_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, int mode
, void *private_data
)
414 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_CREATE
, cb
, private_data
, (xdrproc_t
)xdr_CREATE3res
, sizeof(CREATE3res
));
416 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/create call");
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
;
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
);
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
);
446 int rpc_nfs_remove_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, void *private_data
)
451 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_REMOVE
, cb
, private_data
, (xdrproc_t
)xdr_REMOVE3res
, sizeof(REMOVE3res
));
453 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/remove call");
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
;
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
);
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
);
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
)
483 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READDIR
, cb
, private_data
, (xdrproc_t
)xdr_READDIR3res
, sizeof(READDIR3res
));
485 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readdir call");
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
));
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
);
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
);
511 int rpc_nfs_fsstat_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
516 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSSTAT
, cb
, private_data
, (xdrproc_t
)xdr_FSSTAT3res
, sizeof(FSSTAT3res
));
518 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsstat call");
522 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
523 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
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
);
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
);
540 int rpc_nfs_fsinfo_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
545 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSINFO
, cb
, private_data
, (xdrproc_t
)xdr_FSINFO3res
, sizeof(FSINFO3res
));
547 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsinfo call");
551 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
552 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
554 if (xdr_FSINFO3args(&pdu
->xdr
, &args
) == 0) {
555 rpc_set_error(rpc
, "XDR error: Failed to encode FSINFO3args");
556 rpc_free_pdu(rpc
, pdu
);
560 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
561 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/fsinfo call");
562 rpc_free_pdu(rpc
, pdu
);
569 int rpc_nfs_readlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
574 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READLINK
, cb
, private_data
, (xdrproc_t
)xdr_READLINK3res
, sizeof(READLINK3res
));
576 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readlink call");
580 args
.symlink
.data
.data_len
= fh
->data
.data_len
;
581 args
.symlink
.data
.data_val
= fh
->data
.data_val
;
583 if (xdr_READLINK3args(&pdu
->xdr
, &args
) == 0) {
584 rpc_set_error(rpc
, "XDR error: Failed to encode READLINK3args");
585 rpc_free_pdu(rpc
, pdu
);
589 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
590 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readlink call");
591 rpc_free_pdu(rpc
, pdu
);
599 int rpc_nfs_symlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *newname
, char *oldpath
, void *private_data
)
604 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SYMLINK
, cb
, private_data
, (xdrproc_t
)xdr_SYMLINK3res
, sizeof(SYMLINK3res
));
606 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/symlink call");
610 bzero(&args
, sizeof(SYMLINK3args
));
611 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
612 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
613 args
.where
.name
= newname
;
614 args
.symlink
.symlink_attributes
.mode
.set_it
= 1;
615 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
;
616 args
.symlink
.symlink_data
= oldpath
;
618 if (xdr_SYMLINK3args(&pdu
->xdr
, &args
) == 0) {
619 rpc_set_error(rpc
, "XDR error: Failed to encode SYMLINK3args");
620 rpc_free_pdu(rpc
, pdu
);
624 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
625 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/symlink call");
626 rpc_free_pdu(rpc
, pdu
);
636 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
)
641 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RENAME
, cb
, private_data
, (xdrproc_t
)xdr_RENAME3res
, sizeof(RENAME3res
));
643 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rename call");
647 bzero(&args
, sizeof(RENAME3args
));
648 args
.from
.dir
.data
.data_len
= olddir
->data
.data_len
;
649 args
.from
.dir
.data
.data_val
= olddir
->data
.data_val
;
650 args
.from
.name
= oldname
;
651 args
.to
.dir
.data
.data_len
= newdir
->data
.data_len
;
652 args
.to
.dir
.data
.data_val
= newdir
->data
.data_val
;
653 args
.to
.name
= newname
;
655 if (xdr_RENAME3args(&pdu
->xdr
, &args
) == 0) {
656 rpc_set_error(rpc
, "XDR error: Failed to encode RENAME3args");
657 rpc_free_pdu(rpc
, pdu
);
661 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
662 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/rename call");
663 rpc_free_pdu(rpc
, pdu
);
673 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
)
678 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LINK
, cb
, private_data
, (xdrproc_t
)xdr_LINK3res
, sizeof(LINK3res
));
680 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/link call");
684 bzero(&args
, sizeof(LINK3args
));
685 args
.file
.data
.data_len
= file
->data
.data_len
;
686 args
.file
.data
.data_val
= file
->data
.data_val
;
687 args
.link
.dir
.data
.data_len
= newdir
->data
.data_len
;
688 args
.link
.dir
.data
.data_val
= newdir
->data
.data_val
;
689 args
.link
.name
= newname
;
691 if (xdr_LINK3args(&pdu
->xdr
, &args
) == 0) {
692 rpc_set_error(rpc
, "XDR error: Failed to encode LINK3args");
693 rpc_free_pdu(rpc
, pdu
);
697 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
698 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/link call");
699 rpc_free_pdu(rpc
, pdu
);