59452521f9eaf570d893943e6b92371e9d7739b0
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"
34 char *nfsstat3_to_str(int error
)
37 case NFS3_OK
: return "NFS3_OK"; break;
38 case NFS3ERR_PERM
: return "NFS3ERR_PERM"; break;
39 case NFS3ERR_NOENT
: return "NFS3ERR_NOENT"; break;
40 case NFS3ERR_IO
: return "NFS3ERR_IO"; break;
41 case NFS3ERR_NXIO
: return "NFS3ERR_NXIO"; break;
42 case NFS3ERR_ACCES
: return "NFS3ERR_ACCES"; break;
43 case NFS3ERR_EXIST
: return "NFS3ERR_EXIST"; break;
44 case NFS3ERR_XDEV
: return "NFS3ERR_XDEV"; break;
45 case NFS3ERR_NODEV
: return "NFS3ERR_NODEV"; break;
46 case NFS3ERR_NOTDIR
: return "NFS3ERR_NOTDIR"; break;
47 case NFS3ERR_ISDIR
: return "NFS3ERR_ISDIR"; break;
48 case NFS3ERR_INVAL
: return "NFS3ERR_INVAL"; break;
49 case NFS3ERR_FBIG
: return "NFS3ERR_FBIG"; break;
50 case NFS3ERR_NOSPC
: return "NFS3ERR_NOSPC"; break;
51 case NFS3ERR_ROFS
: return "NFS3ERR_ROFS"; break;
52 case NFS3ERR_MLINK
: return "NFS3ERR_MLINK"; break;
53 case NFS3ERR_NAMETOOLONG
: return "NFS3ERR_NAMETOOLONG"; break;
54 case NFS3ERR_NOTEMPTY
: return "NFS3ERR_NOTEMPTY"; break;
55 case NFS3ERR_DQUOT
: return "NFS3ERR_DQUOT"; break;
56 case NFS3ERR_STALE
: return "NFS3ERR_STALE"; break;
57 case NFS3ERR_REMOTE
: return "NFS3ERR_REMOTE"; break;
58 case NFS3ERR_BADHANDLE
: return "NFS3ERR_BADHANDLE"; break;
59 case NFS3ERR_NOT_SYNC
: return "NFS3ERR_NOT_SYNC"; break;
60 case NFS3ERR_BAD_COOKIE
: return "NFS3ERR_BAD_COOKIE"; break;
61 case NFS3ERR_NOTSUPP
: return "NFS3ERR_NOTSUPP"; break;
62 case NFS3ERR_TOOSMALL
: return "NFS3ERR_TOOSMALL"; break;
63 case NFS3ERR_SERVERFAULT
: return "NFS3ERR_SERVERFAULT"; break;
64 case NFS3ERR_BADTYPE
: return "NFS3ERR_BADTYPE"; break;
65 case NFS3ERR_JUKEBOX
: return "NFS3ERR_JUKEBOX"; break;
67 return "unknown nfs error";
70 int nfsstat3_to_errno(int error
)
73 case NFS3_OK
: return 0; break;
74 case NFS3ERR_PERM
: return -EPERM
; break;
75 case NFS3ERR_NOENT
: return -ENOENT
; break;
76 case NFS3ERR_IO
: return -EIO
; break;
77 case NFS3ERR_NXIO
: return -ENXIO
; break;
78 case NFS3ERR_ACCES
: return -EACCES
; break;
79 case NFS3ERR_EXIST
: return -EEXIST
; break;
80 case NFS3ERR_XDEV
: return -EXDEV
; break;
81 case NFS3ERR_NODEV
: return -ENODEV
; break;
82 case NFS3ERR_NOTDIR
: return -ENOTDIR
; break;
83 case NFS3ERR_ISDIR
: return -EISDIR
; break;
84 case NFS3ERR_INVAL
: return -EINVAL
; break;
85 case NFS3ERR_FBIG
: return -EFBIG
; break;
86 case NFS3ERR_NOSPC
: return -ENOSPC
; break;
87 case NFS3ERR_ROFS
: return -EROFS
; break;
88 case NFS3ERR_MLINK
: return -EMLINK
; break;
89 case NFS3ERR_NAMETOOLONG
: return -ENAMETOOLONG
; break;
90 case NFS3ERR_NOTEMPTY
: return -EEXIST
; break;
91 case NFS3ERR_DQUOT
: return -ERANGE
; break;
92 case NFS3ERR_STALE
: return -EIO
; break;
93 case NFS3ERR_REMOTE
: return -EIO
; break;
94 case NFS3ERR_BADHANDLE
: return -EIO
; break;
95 case NFS3ERR_NOT_SYNC
: return -EIO
; break;
96 case NFS3ERR_BAD_COOKIE
: return -EIO
; break;
97 case NFS3ERR_NOTSUPP
: return -EINVAL
; break;
98 case NFS3ERR_TOOSMALL
: return -EIO
; break;
99 case NFS3ERR_SERVERFAULT
: return -EIO
; break;
100 case NFS3ERR_BADTYPE
: return -EINVAL
; break;
101 case NFS3ERR_JUKEBOX
: return -EAGAIN
; break;
107 int rpc_nfs_null_async(struct rpc_context
*rpc
, rpc_cb cb
, void *private_data
)
111 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_NULL
, cb
, private_data
, (xdrproc_t
)xdr_void
, 0);
113 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
117 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
118 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/null call");
119 rpc_free_pdu(rpc
, pdu
);
126 int rpc_nfs_getattr_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
131 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_GETATTR
, cb
, private_data
, (xdrproc_t
)xdr_GETATTR3res
, sizeof(GETATTR3res
));
133 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/null call");
137 args
.object
.data
.data_len
= fh
->data
.data_len
;
138 args
.object
.data
.data_val
= fh
->data
.data_val
;
140 if (xdr_GETATTR3args(&pdu
->xdr
, &args
) == 0) {
141 rpc_set_error(rpc
, "XDR error: Failed to encode GETATTR3args");
142 rpc_free_pdu(rpc
, pdu
);
146 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
147 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/null call");
148 rpc_free_pdu(rpc
, pdu
);
155 int rpc_nfs_lookup_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *name
, void *private_data
)
160 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LOOKUP
, cb
, private_data
, (xdrproc_t
)xdr_LOOKUP3res
, sizeof(LOOKUP3res
));
162 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/lookup call");
166 args
.what
.dir
.data
.data_len
= fh
->data
.data_len
;
167 args
.what
.dir
.data
.data_val
= fh
->data
.data_val
;
168 args
.what
.name
= name
;
170 if (xdr_LOOKUP3args(&pdu
->xdr
, &args
) == 0) {
171 rpc_set_error(rpc
, "XDR error: Failed to encode LOOKUP3args");
172 rpc_free_pdu(rpc
, pdu
);
176 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
177 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/lookup call");
178 rpc_free_pdu(rpc
, pdu
);
186 int rpc_nfs_access_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, int access
, void *private_data
)
191 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_ACCESS
, cb
, private_data
, (xdrproc_t
)xdr_ACCESS3res
, sizeof(ACCESS3res
));
193 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/access call");
197 args
.object
.data
.data_len
= fh
->data
.data_len
;
198 args
.object
.data
.data_val
= fh
->data
.data_val
;
199 args
.access
= access
;
201 if (xdr_ACCESS3args(&pdu
->xdr
, &args
) == 0) {
202 rpc_set_error(rpc
, "XDR error: Failed to encode ACCESS3args");
203 rpc_free_pdu(rpc
, pdu
);
207 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
208 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/access call");
209 rpc_free_pdu(rpc
, pdu
);
218 int rpc_nfs_read_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, uint64_t offset
, uint64_t count
, void *private_data
)
223 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READ
, cb
, private_data
, (xdrproc_t
)xdr_READ3res
, sizeof(READ3res
));
225 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/read call");
229 args
.file
.data
.data_len
= fh
->data
.data_len
;
230 args
.file
.data
.data_val
= fh
->data
.data_val
;
231 args
.offset
= offset
;
234 if (xdr_READ3args(&pdu
->xdr
, &args
) == 0) {
235 rpc_set_error(rpc
, "XDR error: Failed to encode READ3args");
236 rpc_free_pdu(rpc
, pdu
);
240 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
241 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/read call");
242 rpc_free_pdu(rpc
, pdu
);
250 int rpc_nfs_write_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *buf
, uint64_t offset
, uint64_t count
, int stable_how
, void *private_data
)
255 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_WRITE
, cb
, private_data
, (xdrproc_t
)xdr_WRITE3res
, sizeof(WRITE3res
));
257 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/write call");
261 args
.file
.data
.data_len
= fh
->data
.data_len
;
262 args
.file
.data
.data_val
= fh
->data
.data_val
;
263 args
.offset
= offset
;
265 args
.stable
= stable_how
;;
266 args
.data
.data_len
= count
;
267 args
.data
.data_val
= buf
;
269 if (xdr_WRITE3args(&pdu
->xdr
, &args
) == 0) {
270 rpc_set_error(rpc
, "XDR error: Failed to encode WRITE3args");
271 rpc_free_pdu(rpc
, pdu
);
275 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
276 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/write call");
277 rpc_free_pdu(rpc
, pdu
);
286 int rpc_nfs_commit_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
291 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_COMMIT
, cb
, private_data
, (xdrproc_t
)xdr_COMMIT3res
, sizeof(COMMIT3res
));
293 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/commit call");
297 args
.file
.data
.data_len
= fh
->data
.data_len
;
298 args
.file
.data
.data_val
= fh
->data
.data_val
;
302 if (xdr_COMMIT3args(&pdu
->xdr
, &args
) == 0) {
303 rpc_set_error(rpc
, "XDR error: Failed to encode WRITE3args");
304 rpc_free_pdu(rpc
, pdu
);
308 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
309 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/commit call");
310 rpc_free_pdu(rpc
, pdu
);
318 int rpc_nfs_setattr_async(struct rpc_context
*rpc
, rpc_cb cb
, SETATTR3args
*args
, void *private_data
)
322 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SETATTR
, cb
, private_data
, (xdrproc_t
)xdr_SETATTR3res
, sizeof(SETATTR3res
));
324 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
328 if (xdr_SETATTR3args(&pdu
->xdr
, args
) == 0) {
329 rpc_set_error(rpc
, "XDR error: Failed to encode SETATTR3args");
330 rpc_free_pdu(rpc
, pdu
);
334 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
335 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/setattr call");
336 rpc_free_pdu(rpc
, pdu
);
345 int rpc_nfs_mkdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
350 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_MKDIR
, cb
, private_data
, (xdrproc_t
)xdr_MKDIR3res
, sizeof(MKDIR3res
));
352 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/setattr call");
356 memset(&args
, 0, sizeof(MKDIR3args
));
357 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
358 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
359 args
.where
.name
= dir
;
360 args
.attributes
.mode
.set_it
= 1;
361 args
.attributes
.mode
.set_mode3_u
.mode
= 0755;
363 if (xdr_MKDIR3args(&pdu
->xdr
, &args
) == 0) {
364 rpc_set_error(rpc
, "XDR error: Failed to encode MKDIR3args");
365 rpc_free_pdu(rpc
, pdu
);
369 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
370 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/mkdir call");
371 rpc_free_pdu(rpc
, pdu
);
381 int rpc_nfs_rmdir_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *dir
, void *private_data
)
386 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RMDIR
, cb
, private_data
, (xdrproc_t
)xdr_RMDIR3res
, sizeof(RMDIR3res
));
388 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rmdir call");
392 memset(&args
, 0, sizeof(RMDIR3args
));
393 args
.object
.dir
.data
.data_len
= fh
->data
.data_len
;
394 args
.object
.dir
.data
.data_val
= fh
->data
.data_val
;
395 args
.object
.name
= dir
;
397 if (xdr_RMDIR3args(&pdu
->xdr
, &args
) == 0) {
398 rpc_set_error(rpc
, "XDR error: Failed to encode RMDIR3args");
399 rpc_free_pdu(rpc
, pdu
);
403 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
404 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/rmdir call");
405 rpc_free_pdu(rpc
, pdu
);
414 int rpc_nfs_create_async(struct rpc_context
*rpc
, rpc_cb cb
, CREATE3args
*args
, void *private_data
)
418 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_CREATE
, cb
, private_data
, (xdrproc_t
)xdr_CREATE3res
, sizeof(CREATE3res
));
420 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/create call");
424 if (xdr_CREATE3args(&pdu
->xdr
, &args
) == 0) {
425 rpc_set_error(rpc
, "XDR error: Failed to encode CREATE3args");
426 rpc_free_pdu(rpc
, pdu
);
430 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
431 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/create call");
432 rpc_free_pdu(rpc
, pdu
);
441 int rpc_nfs_mknod_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, int mode
, int major
, int minor
, void *private_data
)
446 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_MKNOD
, cb
, private_data
, (xdrproc_t
)xdr_MKNOD3res
, sizeof(MKNOD3res
));
448 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/mknod call");
452 memset(&args
, 0, sizeof(MKNOD3args
));
453 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
454 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
455 args
.where
.name
= file
;
456 switch (mode
& S_IFMT
) {
458 args
.what
.type
= NF3CHR
;
459 args
.what
.mknoddata3_u
.chr_device
.dev_attributes
.mode
.set_it
= 1;
460 args
.what
.mknoddata3_u
.chr_device
.dev_attributes
.mode
.set_mode3_u
.mode
= mode
& (S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IWGRP
|S_IXGRP
|S_IROTH
|S_IWOTH
|S_IXOTH
);
461 args
.what
.mknoddata3_u
.chr_device
.spec
.specdata1
= major
;
462 args
.what
.mknoddata3_u
.chr_device
.spec
.specdata2
= minor
;
465 args
.what
.type
= NF3BLK
;
466 args
.what
.mknoddata3_u
.blk_device
.dev_attributes
.mode
.set_it
= 1;
467 args
.what
.mknoddata3_u
.blk_device
.dev_attributes
.mode
.set_mode3_u
.mode
= mode
& (S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IWGRP
|S_IXGRP
|S_IROTH
|S_IWOTH
|S_IXOTH
);
468 args
.what
.mknoddata3_u
.blk_device
.spec
.specdata1
= major
;
469 args
.what
.mknoddata3_u
.blk_device
.spec
.specdata2
= minor
;
471 args
.what
.type
= NF3SOCK
;
472 args
.what
.mknoddata3_u
.sock_attributes
.mode
.set_it
= 1;
473 args
.what
.mknoddata3_u
.sock_attributes
.mode
.set_mode3_u
.mode
= mode
& (S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IWGRP
|S_IXGRP
|S_IROTH
|S_IWOTH
|S_IXOTH
);
476 args
.what
.type
= NF3FIFO
;
477 args
.what
.mknoddata3_u
.pipe_attributes
.mode
.set_it
= 1;
478 args
.what
.mknoddata3_u
.pipe_attributes
.mode
.set_mode3_u
.mode
= mode
& (S_IRUSR
|S_IWUSR
|S_IXUSR
|S_IRGRP
|S_IWGRP
|S_IXGRP
|S_IROTH
|S_IWOTH
|S_IXOTH
);
481 rpc_set_error(rpc
, "Invalid file type for nfs/mknod call");
482 rpc_free_pdu(rpc
, pdu
);
486 if (xdr_MKNOD3args(&pdu
->xdr
, &args
) == 0) {
487 rpc_set_error(rpc
, "XDR error: Failed to encode MKNOD3args");
488 rpc_free_pdu(rpc
, pdu
);
492 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
493 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/mknod call");
494 rpc_free_pdu(rpc
, pdu
);
502 int rpc_nfs_remove_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *file
, void *private_data
)
507 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_REMOVE
, cb
, private_data
, (xdrproc_t
)xdr_REMOVE3res
, sizeof(REMOVE3res
));
509 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/remove call");
513 memset(&args
, 0, sizeof(REMOVE3args
));
514 args
.object
.dir
.data
.data_len
= fh
->data
.data_len
;
515 args
.object
.dir
.data
.data_val
= fh
->data
.data_val
;
516 args
.object
.name
= file
;
518 if (xdr_REMOVE3args(&pdu
->xdr
, &args
) == 0) {
519 rpc_set_error(rpc
, "XDR error: Failed to encode REMOVE3args");
520 rpc_free_pdu(rpc
, pdu
);
524 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
525 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/remove call");
526 rpc_free_pdu(rpc
, pdu
);
533 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
)
538 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READDIR
, cb
, private_data
, (xdrproc_t
)xdr_READDIR3res
, sizeof(READDIR3res
));
540 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readdir call");
544 memset(&args
, 0, sizeof(READDIR3args
));
545 args
.dir
.data
.data_len
= fh
->data
.data_len
;
546 args
.dir
.data
.data_val
= fh
->data
.data_val
;
547 args
.cookie
= cookie
;
548 memcpy(&args
.cookieverf
, cookieverf
, sizeof(cookieverf3
));
551 if (xdr_READDIR3args(&pdu
->xdr
, &args
) == 0) {
552 rpc_set_error(rpc
, "XDR error: Failed to encode READDIR3args");
553 rpc_free_pdu(rpc
, pdu
);
557 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
558 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readdir call");
559 rpc_free_pdu(rpc
, pdu
);
566 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
)
569 READDIRPLUS3args args
;
571 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READDIRPLUS
, cb
, private_data
, (xdrproc_t
)xdr_READDIRPLUS3res
, sizeof(READDIRPLUS3res
));
573 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readdirplus call");
577 memset(&args
, 0, sizeof(READDIRPLUS3args
));
578 args
.dir
.data
.data_len
= fh
->data
.data_len
;
579 args
.dir
.data
.data_val
= fh
->data
.data_val
;
580 args
.cookie
= cookie
;
581 memcpy(&args
.cookieverf
, cookieverf
, sizeof(cookieverf3
));
582 args
.dircount
= count
;
583 args
.maxcount
= count
;
585 if (xdr_READDIRPLUS3args(&pdu
->xdr
, &args
) == 0) {
586 rpc_set_error(rpc
, "XDR error: Failed to encode READDIRPLUS3args");
587 rpc_free_pdu(rpc
, pdu
);
591 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
592 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readdirplus call");
593 rpc_free_pdu(rpc
, pdu
);
600 int rpc_nfs_fsstat_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
605 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSSTAT
, cb
, private_data
, (xdrproc_t
)xdr_FSSTAT3res
, sizeof(FSSTAT3res
));
607 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsstat call");
611 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
612 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
614 if (xdr_FSSTAT3args(&pdu
->xdr
, &args
) == 0) {
615 rpc_set_error(rpc
, "XDR error: Failed to encode FSSTAT3args");
616 rpc_free_pdu(rpc
, pdu
);
620 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
621 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/fsstat call");
622 rpc_free_pdu(rpc
, pdu
);
629 int rpc_nfs_fsinfo_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
634 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_FSINFO
, cb
, private_data
, (xdrproc_t
)xdr_FSINFO3res
, sizeof(FSINFO3res
));
636 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/fsinfo call");
640 args
.fsroot
.data
.data_len
= fh
->data
.data_len
;
641 args
.fsroot
.data
.data_val
= fh
->data
.data_val
;
643 if (xdr_FSINFO3args(&pdu
->xdr
, &args
) == 0) {
644 rpc_set_error(rpc
, "XDR error: Failed to encode FSINFO3args");
645 rpc_free_pdu(rpc
, pdu
);
649 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
650 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/fsinfo call");
651 rpc_free_pdu(rpc
, pdu
);
658 int rpc_nfs_readlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, void *private_data
)
663 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_READLINK
, cb
, private_data
, (xdrproc_t
)xdr_READLINK3res
, sizeof(READLINK3res
));
665 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/readlink call");
669 args
.symlink
.data
.data_len
= fh
->data
.data_len
;
670 args
.symlink
.data
.data_val
= fh
->data
.data_val
;
672 if (xdr_READLINK3args(&pdu
->xdr
, &args
) == 0) {
673 rpc_set_error(rpc
, "XDR error: Failed to encode READLINK3args");
674 rpc_free_pdu(rpc
, pdu
);
678 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
679 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/readlink call");
680 rpc_free_pdu(rpc
, pdu
);
688 int rpc_nfs_symlink_async(struct rpc_context
*rpc
, rpc_cb cb
, struct nfs_fh3
*fh
, char *newname
, char *oldpath
, void *private_data
)
693 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_SYMLINK
, cb
, private_data
, (xdrproc_t
)xdr_SYMLINK3res
, sizeof(SYMLINK3res
));
695 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/symlink call");
699 memset(&args
, 0, sizeof(SYMLINK3args
));
700 args
.where
.dir
.data
.data_len
= fh
->data
.data_len
;
701 args
.where
.dir
.data
.data_val
= fh
->data
.data_val
;
702 args
.where
.name
= newname
;
703 args
.symlink
.symlink_attributes
.mode
.set_it
= 1;
704 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
;
705 args
.symlink
.symlink_data
= oldpath
;
707 if (xdr_SYMLINK3args(&pdu
->xdr
, &args
) == 0) {
708 rpc_set_error(rpc
, "XDR error: Failed to encode SYMLINK3args");
709 rpc_free_pdu(rpc
, pdu
);
713 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
714 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/symlink call");
715 rpc_free_pdu(rpc
, pdu
);
725 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
)
730 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_RENAME
, cb
, private_data
, (xdrproc_t
)xdr_RENAME3res
, sizeof(RENAME3res
));
732 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/rename call");
736 memset(&args
, 0, sizeof(RENAME3args
));
737 args
.from
.dir
.data
.data_len
= olddir
->data
.data_len
;
738 args
.from
.dir
.data
.data_val
= olddir
->data
.data_val
;
739 args
.from
.name
= oldname
;
740 args
.to
.dir
.data
.data_len
= newdir
->data
.data_len
;
741 args
.to
.dir
.data
.data_val
= newdir
->data
.data_val
;
742 args
.to
.name
= newname
;
744 if (xdr_RENAME3args(&pdu
->xdr
, &args
) == 0) {
745 rpc_set_error(rpc
, "XDR error: Failed to encode RENAME3args");
746 rpc_free_pdu(rpc
, pdu
);
750 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
751 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/rename call");
752 rpc_free_pdu(rpc
, pdu
);
762 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
)
767 pdu
= rpc_allocate_pdu(rpc
, NFS_PROGRAM
, NFS_V3
, NFS3_LINK
, cb
, private_data
, (xdrproc_t
)xdr_LINK3res
, sizeof(LINK3res
));
769 rpc_set_error(rpc
, "Out of memory. Failed to allocate pdu for nfs/link call");
773 memset(&args
, 0, sizeof(LINK3args
));
774 args
.file
.data
.data_len
= file
->data
.data_len
;
775 args
.file
.data
.data_val
= file
->data
.data_val
;
776 args
.link
.dir
.data
.data_len
= newdir
->data
.data_len
;
777 args
.link
.dir
.data
.data_val
= newdir
->data
.data_val
;
778 args
.link
.name
= newname
;
780 if (xdr_LINK3args(&pdu
->xdr
, &args
) == 0) {
781 rpc_set_error(rpc
, "XDR error: Failed to encode LINK3args");
782 rpc_free_pdu(rpc
, pdu
);
786 if (rpc_queue_pdu(rpc
, pdu
) != 0) {
787 rpc_set_error(rpc
, "Out of memory. Failed to queue pdu for nfs/link call");
788 rpc_free_pdu(rpc
, pdu
);