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/>.
19 #include "win32_compat.h"
30 #include "libnfs-raw.h"
31 #include "libnfs-private.h"
32 #include "libnfs-raw-nfs.h"
35 #define bzero(a,b) memset((a),(0),(b))
38 char *nfsstat3_to_str(int error
)
41 case NFS3_OK
: return "NFS3_OK"; break;
42 case NFS3ERR_PERM
: return "NFS3ERR_PERM"; break;
43 case NFS3ERR_NOENT
: return "NFS3ERR_NOENT"; break;
44 case NFS3ERR_IO
: return "NFS3ERR_IO"; break;
45 case NFS3ERR_NXIO
: return "NFS3ERR_NXIO"; break;
46 case NFS3ERR_ACCES
: return "NFS3ERR_ACCES"; break;
47 case NFS3ERR_EXIST
: return "NFS3ERR_EXIST"; break;
48 case NFS3ERR_XDEV
: return "NFS3ERR_XDEV"; break;
49 case NFS3ERR_NODEV
: return "NFS3ERR_NODEV"; break;
50 case NFS3ERR_NOTDIR
: return "NFS3ERR_NOTDIR"; break;
51 case NFS3ERR_ISDIR
: return "NFS3ERR_ISDIR"; break;
52 case NFS3ERR_INVAL
: return "NFS3ERR_INVAL"; break;
53 case NFS3ERR_FBIG
: return "NFS3ERR_FBIG"; break;
54 case NFS3ERR_NOSPC
: return "NFS3ERR_NOSPC"; break;
55 case NFS3ERR_ROFS
: return "NFS3ERR_ROFS"; break;
56 case NFS3ERR_MLINK
: return "NFS3ERR_MLINK"; break;
57 case NFS3ERR_NAMETOOLONG
: return "NFS3ERR_NAMETOOLONG"; break;
58 case NFS3ERR_NOTEMPTY
: return "NFS3ERR_NOTEMPTY"; break;
59 case NFS3ERR_DQUOT
: return "NFS3ERR_DQUOT"; break;
60 case NFS3ERR_STALE
: return "NFS3ERR_STALE"; break;
61 case NFS3ERR_REMOTE
: return "NFS3ERR_REMOTE"; break;
62 case NFS3ERR_BADHANDLE
: return "NFS3ERR_BADHANDLE"; break;
63 case NFS3ERR_NOT_SYNC
: return "NFS3ERR_NOT_SYNC"; break;
64 case NFS3ERR_BAD_COOKIE
: return "NFS3ERR_BAD_COOKIE"; break;
65 case NFS3ERR_NOTSUPP
: return "NFS3ERR_NOTSUPP"; break;
66 case NFS3ERR_TOOSMALL
: return "NFS3ERR_TOOSMALL"; break;
67 case NFS3ERR_SERVERFAULT
: return "NFS3ERR_SERVERFAULT"; break;
68 case NFS3ERR_BADTYPE
: return "NFS3ERR_BADTYPE"; break;
69 case NFS3ERR_JUKEBOX
: return "NFS3ERR_JUKEBOX"; break;
71 return "unknown nfs error";
74 int nfsstat3_to_errno(int error
)
77 case NFS3_OK
: return 0; break;
78 case NFS3ERR_PERM
: return -EPERM
; break;
79 case NFS3ERR_NOENT
: return -ENOENT
; break;
80 case NFS3ERR_IO
: return -EIO
; break;
81 case NFS3ERR_NXIO
: return -ENXIO
; break;
82 case NFS3ERR_ACCES
: return -EACCES
; break;
83 case NFS3ERR_EXIST
: return -EEXIST
; break;
84 case NFS3ERR_XDEV
: return -EXDEV
; break;
85 case NFS3ERR_NODEV
: return -ENODEV
; break;
86 case NFS3ERR_NOTDIR
: return -ENOTDIR
; break;
87 case NFS3ERR_ISDIR
: return -EISDIR
; break;
88 case NFS3ERR_INVAL
: return -EINVAL
; break;
89 case NFS3ERR_FBIG
: return -EFBIG
; break;
90 case NFS3ERR_NOSPC
: return -ENOSPC
; break;
91 case NFS3ERR_ROFS
: return -EROFS
; break;
92 case NFS3ERR_MLINK
: return -EMLINK
; break;
93 case NFS3ERR_NAMETOOLONG
: return -ENAMETOOLONG
; break;
94 case NFS3ERR_NOTEMPTY
: return -EEXIST
; break;
95 case NFS3ERR_DQUOT
: return -ERANGE
; break;
96 case NFS3ERR_STALE
: return -EIO
; break;
97 case NFS3ERR_REMOTE
: return -EIO
; break;
98 case NFS3ERR_BADHANDLE
: return -EIO
; break;
99 case NFS3ERR_NOT_SYNC
: return -EIO
; break;
100 case NFS3ERR_BAD_COOKIE
: return -EIO
; break;
101 case NFS3ERR_NOTSUPP
: return -EINVAL
; break;
102 case NFS3ERR_TOOSMALL
: return -EIO
; break;
103 case NFS3ERR_SERVERFAULT
: return -EIO
; break;
104 case NFS3ERR_BADTYPE
: return -EINVAL
; break;
105 case NFS3ERR_JUKEBOX
: return -EAGAIN
; break;
111 int rpc_nfs_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
115 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_NULL
, cb
, private_data
, (xdrproc_t
)xdr_void
, 0);
117 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
121 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
122 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/null call");
123 rpc_free_pdu(rpc
, pdu
);
130 int rpc_nfs_getattr_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
135 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_GETATTR
, cb
, private_data
, (xdrproc_t
)xdr_GETATTR3res
, sizeof(GETATTR3res
));
137 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
141 args
.object
.data
.data_len
= fh
->data
.data_len
;
142 args
.object
.data
.data_val
= fh
->data
.data_val
;
144 if (xdr_GETATTR3args(&pdu
->xdr
, &args
) == 0) {
145 rpc_set_error(rpc
, "XDR error: Failed to encode GETATTR3args");
146 rpc_free_pdu(rpc
, pdu
);
150 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
151 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/null call");
152 rpc_free_pdu(rpc
, pdu
);
159 int rpc_nfs_lookup_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, void *private_data
)
164 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LOOKUP
, cb
, private_data
, (xdrproc_t
)xdr_LOOKUP3res
, sizeof(LOOKUP3res
));
166 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/lookup call");
170 args
.what
.dir
.data
.data_len
= fh
->data
.data_len
;
171 args
.what
.dir
.data
.data_val
= fh
->data
.data_val
;
172 args
.what
.name
= name
;
174 if (xdr_LOOKUP3args(&pdu
->xdr
, &args
) == 0) {
175 rpc_set_error(rpc
, "XDR error: Failed to encode LOOKUP3args");
176 rpc_free_pdu(rpc
, pdu
);
180 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
181 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/lookup call");
182 rpc_free_pdu(rpc
, pdu
);
190 int rpc_nfs_access_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, int access
, void *private_data
)
195 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_ACCESS
, cb
, private_data
, (xdrproc_t
)xdr_ACCESS3res
, sizeof(ACCESS3res
));
197 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/access call");
201 args
.object
.data
.data_len
= fh
->data
.data_len
;
202 args
.object
.data
.data_val
= fh
->data
.data_val
;
203 args
.access
= access
;
205 if (xdr_ACCESS3args(&pdu
->xdr
, &args
) == 0) {
206 rpc_set_error(rpc
, "XDR error: Failed to encode ACCESS3args");
207 rpc_free_pdu(rpc
, pdu
);
211 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
212 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/access call");
213 rpc_free_pdu(rpc
, pdu
);
222 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
)
227 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READ
, cb
, private_data
, (xdrproc_t
)xdr_READ3res
, sizeof(READ3res
));
229 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/read call");
233 args
.file
.data
.data_len
= fh
->data
.data_len
;
234 args
.file
.data
.data_val
= fh
->data
.data_val
;
235 args
.offset
= offset
;
238 if (xdr_READ3args(&pdu
->xdr
, &args
) == 0) {
239 rpc_set_error(rpc
, "XDR error: Failed to encode READ3args");
240 rpc_free_pdu(rpc
, pdu
);
244 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
245 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/read call");
246 rpc_free_pdu(rpc
, pdu
);
254 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
)
259 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_WRITE
, cb
, private_data
, (xdrproc_t
)xdr_WRITE3res
, sizeof(WRITE3res
));
261 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/write call");
265 args
.file
.data
.data_len
= fh
->data
.data_len
;
266 args
.file
.data
.data_val
= fh
->data
.data_val
;
267 args
.offset
= offset
;
269 args
.stable
= stable_how
;;
270 args
.data
.data_len
= count
;
271 args
.data
.data_val
= buf
;
273 if (xdr_WRITE3args(&pdu
->xdr
, &args
) == 0) {
274 rpc_set_error(rpc
, "XDR error: Failed to encode WRITE3args");
275 rpc_free_pdu(rpc
, pdu
);
279 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
280 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/write call");
281 rpc_free_pdu(rpc
, pdu
);
290 int rpc_nfs_commit_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
295 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_COMMIT
, cb
, private_data
, (xdrproc_t
)xdr_COMMIT3res
, sizeof(COMMIT3res
));
297 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/commit call");
301 args
.file
.data
.data_len
= fh
->data
.data_len
;
302 args
.file
.data
.data_val
= fh
->data
.data_val
;
306 if (xdr_COMMIT3args(&pdu
->xdr
, &args
) == 0) {
307 rpc_set_error(rpc
, "XDR error: Failed to encode WRITE3args");
308 rpc_free_pdu(rpc
, pdu
);
312 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
313 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/commit call");
314 rpc_free_pdu(rpc
, pdu
);
322 int rpc_nfs_setattr_async(struct rpc_context
*rpc
, rpc_cb cb
, SETATTR3args
*args
, void *private_data
)
326 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SETATTR
, cb
, private_data
, (xdrproc_t
)xdr_SETATTR3res
, sizeof(SETATTR3res
));
328 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
332 if (xdr_SETATTR3args(&pdu
->xdr
, args
) == 0) {
333 rpc_set_error(rpc
, "XDR error: Failed to encode SETATTR3args");
334 rpc_free_pdu(rpc
, pdu
);
338 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
339 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/setattr call");
340 rpc_free_pdu(rpc
, pdu
);
349 int rpc_nfs_mkdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
354 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_MKDIR
, cb
, private_data
, (xdrproc_t
)xdr_MKDIR3res
, sizeof(MKDIR3res
));
356 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
360 memset(&args
, 0, sizeof(MKDIR3args
));
361 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
362 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
363 args
.where
.name
= dir
;
364 args
.attributes
.mode
.set_it
= 1;
365 args
.attributes
.mode
.set_mode3_u
.mode
= 0755;
367 if (xdr_MKDIR3args(&pdu
->xdr
, &args
) == 0) {
368 rpc_set_error(rpc
, "XDR error: Failed to encode MKDIR3args");
369 rpc_free_pdu(rpc
, pdu
);
373 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
374 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/mkdir call");
375 rpc_free_pdu(rpc
, pdu
);
385 int rpc_nfs_rmdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
390 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RMDIR
, cb
, private_data
, (xdrproc_t
)xdr_RMDIR3res
, sizeof(RMDIR3res
));
392 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rmdir call");
396 memset(&args
, 0, sizeof(RMDIR3args
));
397 args
.object
.dir
.data
.data_len
= fh
->data
.data_len
;
398 args
.object
.dir
.data
.data_val
= fh
->data
.data_val
;
399 args
.object
.name
= dir
;
401 if (xdr_RMDIR3args(&pdu
->xdr
, &args
) == 0) {
402 rpc_set_error(rpc
, "XDR error: Failed to encode RMDIR3args");
403 rpc_free_pdu(rpc
, pdu
);
407 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
408 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/rmdir call");
409 rpc_free_pdu(rpc
, pdu
);
418 int rpc_nfs_create_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, int mode
, void *private_data
)
423 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_CREATE
, cb
, private_data
, (xdrproc_t
)xdr_CREATE3res
, sizeof(CREATE3res
));
425 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/create call");
429 memset(&args
, 0, sizeof(CREATE3args
));
430 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
431 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
432 args
.where
.name
= file
;
433 args
.how
.mode
= UNCHECKED
;
434 args
.how
.createhow3_u
.obj_attributes
.mode
.set_it
= 1;
435 args
.how
.createhow3_u
.obj_attributes
.mode
.set_mode3_u
.mode
= mode
;
437 if (xdr_CREATE3args(&pdu
->xdr
, &args
) == 0) {
438 rpc_set_error(rpc
, "XDR error: Failed to encode CREATE3args");
439 rpc_free_pdu(rpc
, pdu
);
443 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
444 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/create call");
445 rpc_free_pdu(rpc
, pdu
);
455 int rpc_nfs_remove_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, void *private_data
)
460 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_REMOVE
, cb
, private_data
, (xdrproc_t
)xdr_REMOVE3res
, sizeof(REMOVE3res
));
462 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/remove call");
466 memset(&args
, 0, sizeof(REMOVE3args
));
467 args
.object
.dir
.data
.data_len
= fh
->data
.data_len
;
468 args
.object
.dir
.data
.data_val
= fh
->data
.data_val
;
469 args
.object
.name
= file
;
471 if (xdr_REMOVE3args(&pdu
->xdr
, &args
) == 0) {
472 rpc_set_error(rpc
, "XDR error: Failed to encode REMOVE3args");
473 rpc_free_pdu(rpc
, pdu
);
477 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
478 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/remove call");
479 rpc_free_pdu(rpc
, pdu
);
486 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
)
491 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READDIR
, cb
, private_data
, (xdrproc_t
)xdr_READDIR3res
, sizeof(READDIR3res
));
493 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readdir call");
497 memset(&args
, 0, sizeof(READDIR3args
));
498 args
.dir
.data
.data_len
= fh
->data
.data_len
;
499 args
.dir
.data
.data_val
= fh
->data
.data_val
;
500 args
.cookie
= cookie
;
501 memcpy(&args
.cookieverf
, cookieverf
, sizeof(cookieverf3
));
504 if (xdr_READDIR3args(&pdu
->xdr
, &args
) == 0) {
505 rpc_set_error(rpc
, "XDR error: Failed to encode READDIR3args");
506 rpc_free_pdu(rpc
, pdu
);
510 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
511 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readdir call");
512 rpc_free_pdu(rpc
, pdu
);
519 int rpc_nfs_readdirplus_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, uint64_t cookie
, char *cookieverf
, int count
, void *private_data
)
522 READDIRPLUS3args args
;
524 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READDIRPLUS
, cb
, private_data
, (xdrproc_t
)xdr_READDIRPLUS3res
, sizeof(READDIRPLUS3res
));
526 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readdirplus call");
530 memset(&args
, 0, sizeof(READDIRPLUS3args
));
531 args
.dir
.data
.data_len
= fh
->data
.data_len
;
532 args
.dir
.data
.data_val
= fh
->data
.data_val
;
533 args
.cookie
= cookie
;
534 memcpy(&args
.cookieverf
, cookieverf
, sizeof(cookieverf3
));
535 args
.dircount
= count
;
536 args
.maxcount
= count
;
538 if (xdr_READDIRPLUS3args(&pdu
->xdr
, &args
) == 0) {
539 rpc_set_error(rpc
, "XDR error: Failed to encode READDIRPLUS3args");
540 rpc_free_pdu(rpc
, pdu
);
544 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
545 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readdirplus call");
546 rpc_free_pdu(rpc
, pdu
);
553 int rpc_nfs_fsstat_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
558 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSSTAT
, cb
, private_data
, (xdrproc_t
)xdr_FSSTAT3res
, sizeof(FSSTAT3res
));
560 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsstat call");
564 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
565 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
567 if (xdr_FSSTAT3args(&pdu
->xdr
, &args
) == 0) {
568 rpc_set_error(rpc
, "XDR error: Failed to encode FSSTAT3args");
569 rpc_free_pdu(rpc
, pdu
);
573 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
574 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/fsstat call");
575 rpc_free_pdu(rpc
, pdu
);
582 int rpc_nfs_fsinfo_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
587 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSINFO
, cb
, private_data
, (xdrproc_t
)xdr_FSINFO3res
, sizeof(FSINFO3res
));
589 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsinfo call");
593 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
594 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
596 if (xdr_FSINFO3args(&pdu
->xdr
, &args
) == 0) {
597 rpc_set_error(rpc
, "XDR error: Failed to encode FSINFO3args");
598 rpc_free_pdu(rpc
, pdu
);
602 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
603 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/fsinfo call");
604 rpc_free_pdu(rpc
, pdu
);
611 int rpc_nfs_readlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
616 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READLINK
, cb
, private_data
, (xdrproc_t
)xdr_READLINK3res
, sizeof(READLINK3res
));
618 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readlink call");
622 args
.symlink
.data
.data_len
= fh
->data
.data_len
;
623 args
.symlink
.data
.data_val
= fh
->data
.data_val
;
625 if (xdr_READLINK3args(&pdu
->xdr
, &args
) == 0) {
626 rpc_set_error(rpc
, "XDR error: Failed to encode READLINK3args");
627 rpc_free_pdu(rpc
, pdu
);
631 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
632 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readlink call");
633 rpc_free_pdu(rpc
, pdu
);
641 int rpc_nfs_symlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *newname
, char *oldpath
, void *private_data
)
646 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SYMLINK
, cb
, private_data
, (xdrproc_t
)xdr_SYMLINK3res
, sizeof(SYMLINK3res
));
648 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/symlink call");
652 memset(&args
, 0, sizeof(SYMLINK3args
));
653 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
654 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
655 args
.where
.name
= newname
;
656 args
.symlink
.symlink_attributes
.mode
.set_it
= 1;
657 args
.symlink
.symlink_attributes
.mode
.set_mode3_u
.mode
= S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IWGRP
|S_IXGRP
|S_IROTH
|S_IWOTH
|S_IXOTH
;
658 args
.symlink
.symlink_data
= oldpath
;
660 if (xdr_SYMLINK3args(&pdu
->xdr
, &args
) == 0) {
661 rpc_set_error(rpc
, "XDR error: Failed to encode SYMLINK3args");
662 rpc_free_pdu(rpc
, pdu
);
666 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
667 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/symlink call");
668 rpc_free_pdu(rpc
, pdu
);
678 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
)
683 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RENAME
, cb
, private_data
, (xdrproc_t
)xdr_RENAME3res
, sizeof(RENAME3res
));
685 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rename call");
689 memset(&args
, 0, sizeof(RENAME3args
));
690 args
.from
.dir
.data
.data_len
= olddir
->data
.data_len
;
691 args
.from
.dir
.data
.data_val
= olddir
->data
.data_val
;
692 args
.from
.name
= oldname
;
693 args
.to
.dir
.data
.data_len
= newdir
->data
.data_len
;
694 args
.to
.dir
.data
.data_val
= newdir
->data
.data_val
;
695 args
.to
.name
= newname
;
697 if (xdr_RENAME3args(&pdu
->xdr
, &args
) == 0) {
698 rpc_set_error(rpc
, "XDR error: Failed to encode RENAME3args");
699 rpc_free_pdu(rpc
, pdu
);
703 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
704 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/rename call");
705 rpc_free_pdu(rpc
, pdu
);
715 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
)
720 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LINK
, cb
, private_data
, (xdrproc_t
)xdr_LINK3res
, sizeof(LINK3res
));
722 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/link call");
726 memset(&args
, 0, sizeof(LINK3args
));
727 args
.file
.data
.data_len
= file
->data
.data_len
;
728 args
.file
.data
.data_val
= file
->data
.data_val
;
729 args
.link
.dir
.data
.data_len
= newdir
->data
.data_len
;
730 args
.link
.dir
.data
.data_val
= newdir
->data
.data_val
;
731 args
.link
.name
= newname
;
733 if (xdr_LINK3args(&pdu
->xdr
, &args
) == 0) {
734 rpc_set_error(rpc
, "XDR error: Failed to encode LINK3args");
735 rpc_free_pdu(rpc
, pdu
);
739 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
740 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/link call");
741 rpc_free_pdu(rpc
, pdu
);