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/>.
18 * High level api to nfs filesystems
21 #include "win32_compat.h"
25 #include <sys/statvfs.h>
37 #include <sys/types.h>
41 #include "libnfs-raw.h"
42 #include "libnfs-raw-mount.h"
43 #include "libnfs-raw-nfs.h"
44 #include "libnfs-private.h"
47 struct nfsdirent
*entries
;
48 struct nfsdirent
*current
;
58 struct rpc_context
*rpc
;
61 struct nfs_fh3 rootfh
;
66 void nfs_free_nfsdir(struct nfsdir
*nfsdir
)
68 while (nfsdir
->entries
) {
69 struct nfsdirent
*dirent
= nfsdir
->entries
->next
;
70 if (nfsdir
->entries
->name
!= NULL
) {
71 free(nfsdir
->entries
->name
);
73 free(nfsdir
->entries
);
74 nfsdir
->entries
= dirent
;
80 typedef int (*continue_func
)(struct nfs_context
*nfs
, struct nfs_cb_data
*data
);
83 struct nfs_context
*nfs
;
85 char *saved_path
, *path
;
90 continue_func continue_cb
;
92 void (*free_continue_data
)(void *);
97 /* for multi-read/write calls. */
101 off_t start_offset
, max_offset
;
105 struct nfs_mcb_data
{
106 struct nfs_cb_data
*data
;
111 static int nfs_lookup_path_async_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
, struct nfs_fh3
*fh
);
114 void nfs_set_auth(struct nfs_context
*nfs
, struct AUTH
*auth
)
116 rpc_set_auth(nfs
->rpc
, auth
);
119 int nfs_get_fd(struct nfs_context
*nfs
)
121 return rpc_get_fd(nfs
->rpc
);
124 int nfs_queue_length(struct nfs_context
*nfs
)
126 return rpc_queue_length(nfs
->rpc
);
129 int nfs_which_events(struct nfs_context
*nfs
)
131 return rpc_which_events(nfs
->rpc
);
134 int nfs_service(struct nfs_context
*nfs
, int revents
)
136 return rpc_service(nfs
->rpc
, revents
);
139 char *nfs_get_error(struct nfs_context
*nfs
)
141 return rpc_get_error(nfs
->rpc
);
144 struct nfs_context
*nfs_init_context(void)
146 struct nfs_context
*nfs
;
148 nfs
= malloc(sizeof(struct nfs_context
));
152 nfs
->rpc
= rpc_init_context();
153 if (nfs
->rpc
== NULL
) {
161 nfs
->rootfh
.data
.data_len
= 0;
162 nfs
->rootfh
.data
.data_val
= NULL
;
167 void nfs_destroy_context(struct nfs_context
*nfs
)
169 rpc_destroy_context(nfs
->rpc
);
182 if (nfs
->rootfh
.data
.data_val
!= NULL
) {
183 free(nfs
->rootfh
.data
.data_val
);
184 nfs
->rootfh
.data
.data_val
= NULL
;
190 void free_nfs_cb_data(struct nfs_cb_data
*data
)
192 if (data
->saved_path
!= NULL
) {
193 free(data
->saved_path
);
194 data
->saved_path
= NULL
;
197 if (data
->continue_data
!= NULL
) {
198 data
->free_continue_data(data
->continue_data
);
199 data
->continue_data
= NULL
;
202 if (data
->fh
.data
.data_val
!= NULL
) {
203 free(data
->fh
.data
.data_val
);
204 data
->fh
.data
.data_val
= NULL
;
207 if (data
->buffer
!= NULL
) {
219 static void nfs_mount_10_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
221 struct nfs_cb_data
*data
= private_data
;
222 struct nfs_context
*nfs
= data
->nfs
;
224 if (status
== RPC_STATUS_ERROR
) {
225 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
226 free_nfs_cb_data(data
);
229 if (status
== RPC_STATUS_CANCEL
) {
230 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
231 free_nfs_cb_data(data
);
235 data
->cb(0, nfs
, NULL
, data
->private_data
);
236 free_nfs_cb_data(data
);
239 static void nfs_mount_9_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
241 struct nfs_cb_data
*data
= private_data
;
242 struct nfs_context
*nfs
= data
->nfs
;
243 FSINFO3res
*res
= command_data
;
245 if (status
== RPC_STATUS_ERROR
) {
246 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
247 free_nfs_cb_data(data
);
250 if (status
== RPC_STATUS_CANCEL
) {
251 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
252 free_nfs_cb_data(data
);
256 nfs
->readmax
= res
->FSINFO3res_u
.resok
.rtmax
;
257 nfs
->writemax
= res
->FSINFO3res_u
.resok
.wtmax
;
259 if (rpc_nfs_getattr_async(rpc
, nfs_mount_10_cb
, &nfs
->rootfh
, data
) != 0) {
260 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
261 free_nfs_cb_data(data
);
266 static void nfs_mount_8_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
268 struct nfs_cb_data
*data
= private_data
;
269 struct nfs_context
*nfs
= data
->nfs
;
271 if (status
== RPC_STATUS_ERROR
) {
272 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
273 free_nfs_cb_data(data
);
276 if (status
== RPC_STATUS_CANCEL
) {
277 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
278 free_nfs_cb_data(data
);
282 if (rpc_nfs_fsinfo_async(rpc
, nfs_mount_9_cb
, &nfs
->rootfh
, data
) != 0) {
283 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
284 free_nfs_cb_data(data
);
290 static void nfs_mount_7_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
292 struct nfs_cb_data
*data
= private_data
;
293 struct nfs_context
*nfs
= data
->nfs
;
295 if (status
== RPC_STATUS_ERROR
) {
296 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
297 free_nfs_cb_data(data
);
300 if (status
== RPC_STATUS_CANCEL
) {
301 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
302 free_nfs_cb_data(data
);
306 if (rpc_nfs_null_async(rpc
, nfs_mount_8_cb
, data
) != 0) {
307 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
308 free_nfs_cb_data(data
);
314 static void nfs_mount_6_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
316 struct nfs_cb_data
*data
= private_data
;
317 struct nfs_context
*nfs
= data
->nfs
;
320 if (status
== RPC_STATUS_ERROR
) {
321 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
322 free_nfs_cb_data(data
);
325 if (status
== RPC_STATUS_CANCEL
) {
326 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
327 free_nfs_cb_data(data
);
332 if (res
->fhs_status
!= MNT3_OK
) {
333 rpc_set_error(rpc
, "RPC error: Mount failed with error %s(%d) %s(%d)", mountstat3_to_str(res
->fhs_status
), res
->fhs_status
, strerror(-mountstat3_to_errno(res
->fhs_status
)), -mountstat3_to_errno(res
->fhs_status
));
334 data
->cb(mountstat3_to_errno(res
->fhs_status
), nfs
, rpc_get_error(rpc
), data
->private_data
);
335 free_nfs_cb_data(data
);
339 nfs
->rootfh
.data
.data_len
= res
->mountres3_u
.mountinfo
.fhandle
.fhandle3_len
;
340 nfs
->rootfh
.data
.data_val
= malloc(nfs
->rootfh
.data
.data_len
);
341 if (nfs
->rootfh
.data
.data_val
== NULL
) {
342 rpc_set_error(rpc
, "Out of memory. Could not allocate memory to store root filehandle");
343 data
->cb(-ENOMEM
, nfs
, rpc_get_error(rpc
), data
->private_data
);
344 free_nfs_cb_data(data
);
347 memcpy(nfs
->rootfh
.data
.data_val
, res
->mountres3_u
.mountinfo
.fhandle
.fhandle3_val
, nfs
->rootfh
.data
.data_len
);
349 rpc_disconnect(rpc
, "normal disconnect");
350 if (rpc_connect_async(rpc
, nfs
->server
, 2049, nfs_mount_7_cb
, data
) != 0) {
351 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
352 free_nfs_cb_data(data
);
355 /* NFS TCP connections we want to autoreconnect after sessions are torn down (due to inactivity or error) */
356 rpc_set_autoreconnect(rpc
);
360 static void nfs_mount_5_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
362 struct nfs_cb_data
*data
= private_data
;
363 struct nfs_context
*nfs
= data
->nfs
;
365 if (status
== RPC_STATUS_ERROR
) {
366 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
367 free_nfs_cb_data(data
);
370 if (status
== RPC_STATUS_CANCEL
) {
371 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
372 free_nfs_cb_data(data
);
376 if (rpc_mount_mnt_async(rpc
, nfs_mount_6_cb
, nfs
->export
, data
) != 0) {
377 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
378 free_nfs_cb_data(data
);
383 static void nfs_mount_4_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
385 struct nfs_cb_data
*data
= private_data
;
386 struct nfs_context
*nfs
= data
->nfs
;
388 if (status
== RPC_STATUS_ERROR
) {
389 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
390 free_nfs_cb_data(data
);
393 if (status
== RPC_STATUS_CANCEL
) {
394 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
395 free_nfs_cb_data(data
);
399 if (rpc_mount_null_async(rpc
, nfs_mount_5_cb
, data
) != 0) {
400 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
401 free_nfs_cb_data(data
);
406 static void nfs_mount_3_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
408 struct nfs_cb_data
*data
= private_data
;
409 struct nfs_context
*nfs
= data
->nfs
;
412 if (status
== RPC_STATUS_ERROR
) {
413 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
414 free_nfs_cb_data(data
);
417 if (status
== RPC_STATUS_CANCEL
) {
418 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
419 free_nfs_cb_data(data
);
423 mount_port
= *(uint32_t *)command_data
;
424 if (mount_port
== 0) {
425 rpc_set_error(rpc
, "RPC error. Mount program is not available on %s", nfs
->server
);
426 data
->cb(-ENOENT
, nfs
, command_data
, data
->private_data
);
427 free_nfs_cb_data(data
);
431 rpc_disconnect(rpc
, "normal disconnect");
432 if (rpc_connect_async(rpc
, nfs
->server
, mount_port
, nfs_mount_4_cb
, data
) != 0) {
433 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
434 free_nfs_cb_data(data
);
440 static void nfs_mount_2_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
442 struct nfs_cb_data
*data
= private_data
;
443 struct nfs_context
*nfs
= data
->nfs
;
445 if (status
== RPC_STATUS_ERROR
) {
446 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
447 free_nfs_cb_data(data
);
450 if (status
== RPC_STATUS_CANCEL
) {
451 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
452 free_nfs_cb_data(data
);
456 if (rpc_pmap_getport_async(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, nfs_mount_3_cb
, private_data
) != 0) {
457 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
458 free_nfs_cb_data(data
);
463 static void nfs_mount_1_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
465 struct nfs_cb_data
*data
= private_data
;
466 struct nfs_context
*nfs
= data
->nfs
;
468 if (status
== RPC_STATUS_ERROR
) {
469 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
470 free_nfs_cb_data(data
);
473 if (status
== RPC_STATUS_CANCEL
) {
474 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
475 free_nfs_cb_data(data
);
479 if (rpc_pmap_null_async(rpc
, nfs_mount_2_cb
, data
) != 0) {
480 data
->cb(-ENOMEM
, nfs
, command_data
, data
->private_data
);
481 free_nfs_cb_data(data
);
487 * Async call for mounting an nfs share and geting the root filehandle
489 int nfs_mount_async(struct nfs_context
*nfs
, const char *server
, const char *export
, nfs_cb cb
, void *private_data
)
491 struct nfs_cb_data
*data
;
492 char *new_server
, *new_export
;
494 data
= malloc(sizeof(struct nfs_cb_data
));
496 rpc_set_error(nfs
->rpc
, "out of memory. failed to allocate memory for nfs mount data");
499 memset(data
, 0, sizeof(struct nfs_cb_data
));
500 new_server
= strdup(server
);
501 new_export
= strdup(export
);
502 if (nfs
->server
!= NULL
) {
505 nfs
->server
= new_server
;
506 if (nfs
->export
!= NULL
) {
509 nfs
->export
= new_export
;
512 data
->private_data
= private_data
;
514 if (rpc_connect_async(nfs
->rpc
, server
, 111, nfs_mount_1_cb
, data
) != 0) {
515 rpc_set_error(nfs
->rpc
, "Failed to start connection");
516 free_nfs_cb_data(data
);
526 * Functions to first look up a path, component by component, and then finally call a specific function once
527 * the filehandle for the final component is found.
529 static void nfs_lookup_path_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
531 struct nfs_cb_data
*data
= private_data
;
532 struct nfs_context
*nfs
= data
->nfs
;
535 if (status
== RPC_STATUS_ERROR
) {
536 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
537 free_nfs_cb_data(data
);
540 if (status
== RPC_STATUS_CANCEL
) {
541 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
542 free_nfs_cb_data(data
);
547 if (res
->status
!= NFS3_OK
) {
548 rpc_set_error(nfs
->rpc
, "NFS: Lookup of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
549 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
550 free_nfs_cb_data(data
);
554 if (nfs_lookup_path_async_internal(nfs
, data
, &res
->LOOKUP3res_u
.resok
.object
) != 0) {
555 rpc_set_error(nfs
->rpc
, "Failed to create lookup pdu");
556 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
557 free_nfs_cb_data(data
);
562 static int nfs_lookup_path_async_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
, struct nfs_fh3
*fh
)
566 while (*data
->path
== '/') {
571 str
= strchr(path
, '/');
576 while (*data
->path
!= 0) {
582 data
->fh
.data
.data_len
= fh
->data
.data_len
;
583 data
->fh
.data
.data_val
= malloc(data
->fh
.data
.data_len
);
584 if (data
->fh
.data
.data_val
== NULL
) {
585 rpc_set_error(nfs
->rpc
, "Out of memory: Failed to allocate fh for %s", data
->path
);
586 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
587 free_nfs_cb_data(data
);
590 memcpy(data
->fh
.data
.data_val
, fh
->data
.data_val
, data
->fh
.data
.data_len
);
591 data
->continue_cb(nfs
, data
);
595 if (rpc_nfs_lookup_async(nfs
->rpc
, nfs_lookup_path_1_cb
, fh
, path
, data
) != 0) {
596 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send lookup call for %s", data
->path
);
597 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
598 free_nfs_cb_data(data
);
604 static int nfs_lookuppath_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
, continue_func continue_cb
, void *continue_data
, void (*free_continue_data
)(void *), int continue_int
)
606 struct nfs_cb_data
*data
;
608 if (path
[0] != '/') {
609 rpc_set_error(nfs
->rpc
, "Pathname is not absulute %s", path
);
613 data
= malloc(sizeof(struct nfs_cb_data
));
615 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
618 memset(data
, 0, sizeof(struct nfs_cb_data
));
621 data
->continue_cb
= continue_cb
;
622 data
->continue_data
= continue_data
;
623 data
->free_continue_data
= free_continue_data
;
624 data
->continue_int
= continue_int
;
625 data
->private_data
= private_data
;
626 data
->saved_path
= strdup(path
);
627 if (data
->saved_path
== NULL
) {
628 rpc_set_error(nfs
->rpc
, "out of memory: failed to copy path string");
629 free_nfs_cb_data(data
);
632 data
->path
= data
->saved_path
;
634 if (nfs_lookup_path_async_internal(nfs
, data
, &nfs
->rootfh
) != 0) {
635 /* return 0 here since the callback will be invoked if there is a failure */
648 static void nfs_stat_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
651 struct nfs_cb_data
*data
= private_data
;
652 struct nfs_context
*nfs
= data
->nfs
;
655 if (status
== RPC_STATUS_ERROR
) {
656 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
657 free_nfs_cb_data(data
);
660 if (status
== RPC_STATUS_CANCEL
) {
661 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
662 free_nfs_cb_data(data
);
667 if (res
->status
!= NFS3_OK
) {
668 rpc_set_error(nfs
->rpc
, "NFS: GETATTR of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
669 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
670 free_nfs_cb_data(data
);
675 st
.st_ino
= res
->GETATTR3res_u
.resok
.obj_attributes
.fileid
;
676 st
.st_mode
= res
->GETATTR3res_u
.resok
.obj_attributes
.mode
;
677 if (res
->GETATTR3res_u
.resok
.obj_attributes
.type
== NF3DIR
) {
678 st
.st_mode
|= S_IFDIR
;
680 st
.st_nlink
= res
->GETATTR3res_u
.resok
.obj_attributes
.nlink
;
681 st
.st_uid
= res
->GETATTR3res_u
.resok
.obj_attributes
.uid
;
682 st
.st_gid
= res
->GETATTR3res_u
.resok
.obj_attributes
.gid
;
684 st
.st_size
= res
->GETATTR3res_u
.resok
.obj_attributes
.size
;
686 st
.st_blksize
= 4096;
687 st
.st_blocks
= res
->GETATTR3res_u
.resok
.obj_attributes
.size
/ 4096;
689 st
.st_atime
= res
->GETATTR3res_u
.resok
.obj_attributes
.atime
.seconds
;
690 st
.st_mtime
= res
->GETATTR3res_u
.resok
.obj_attributes
.mtime
.seconds
;
691 st
.st_ctime
= res
->GETATTR3res_u
.resok
.obj_attributes
.ctime
.seconds
;
693 data
->cb(0, nfs
, &st
, data
->private_data
);
694 free_nfs_cb_data(data
);
697 static int nfs_stat_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
699 if (rpc_nfs_getattr_async(nfs
->rpc
, nfs_stat_1_cb
, &data
->fh
, data
) != 0) {
700 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send STAT GETATTR call for %s", data
->path
);
701 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
702 free_nfs_cb_data(data
);
708 int nfs_stat_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
710 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_stat_continue_internal
, NULL
, NULL
, 0) != 0) {
711 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
725 static void nfs_open_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
728 struct nfs_cb_data
*data
= private_data
;
729 struct nfs_context
*nfs
= data
->nfs
;
731 unsigned int nfsmode
= 0;
733 if (status
== RPC_STATUS_ERROR
) {
734 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
735 free_nfs_cb_data(data
);
738 if (status
== RPC_STATUS_CANCEL
) {
739 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
740 free_nfs_cb_data(data
);
745 if (res
->status
!= NFS3_OK
) {
746 rpc_set_error(nfs
->rpc
, "NFS: ACCESS of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
747 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
748 free_nfs_cb_data(data
);
752 if (data
->continue_int
& O_WRONLY
) {
753 nfsmode
|= ACCESS3_MODIFY
;
755 if (data
->continue_int
& O_RDWR
) {
756 nfsmode
|= ACCESS3_READ
|ACCESS3_MODIFY
;
758 if (!(data
->continue_int
& (O_WRONLY
|O_RDWR
))) {
759 nfsmode
|= ACCESS3_READ
;
763 if (res
->ACCESS3res_u
.resok
.access
!= nfsmode
) {
764 rpc_set_error(nfs
->rpc
, "NFS: ACCESS denied. Required access %c%c%c. Allowed access %c%c%c",
765 nfsmode
&ACCESS3_READ
?'r':'-',
766 nfsmode
&ACCESS3_MODIFY
?'w':'-',
767 nfsmode
&ACCESS3_EXECUTE
?'x':'-',
768 res
->ACCESS3res_u
.resok
.access
&ACCESS3_READ
?'r':'-',
769 res
->ACCESS3res_u
.resok
.access
&ACCESS3_MODIFY
?'w':'-',
770 res
->ACCESS3res_u
.resok
.access
&ACCESS3_EXECUTE
?'x':'-');
771 data
->cb(-EACCES
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
772 free_nfs_cb_data(data
);
776 nfsfh
= malloc(sizeof(struct nfsfh
));
778 rpc_set_error(nfs
->rpc
, "NFS: Failed to allocate nfsfh structure");
779 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
780 free_nfs_cb_data(data
);
783 memset(nfsfh
, 0, sizeof(struct nfsfh
));
785 if (data
->continue_int
& O_SYNC
) {
789 /* steal the filehandle */
790 nfsfh
->fh
.data
.data_len
= data
->fh
.data
.data_len
;
791 nfsfh
->fh
.data
.data_val
= data
->fh
.data
.data_val
;
792 data
->fh
.data
.data_val
= NULL
;
794 data
->cb(0, nfs
, nfsfh
, data
->private_data
);
795 free_nfs_cb_data(data
);
798 static int nfs_open_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
802 if (data
->continue_int
& O_WRONLY
) {
803 nfsmode
|= ACCESS3_MODIFY
;
805 if (data
->continue_int
& O_RDWR
) {
806 nfsmode
|= ACCESS3_READ
|ACCESS3_MODIFY
;
808 if (!(data
->continue_int
& (O_WRONLY
|O_RDWR
))) {
809 nfsmode
|= ACCESS3_READ
;
812 if (rpc_nfs_access_async(nfs
->rpc
, nfs_open_cb
, &data
->fh
, nfsmode
, data
) != 0) {
813 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send OPEN ACCESS call for %s", data
->path
);
814 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
815 free_nfs_cb_data(data
);
821 int nfs_open_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
)
823 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_open_continue_internal
, NULL
, NULL
, mode
) != 0) {
824 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
838 static void nfs_pread_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
840 struct nfs_cb_data
*data
= private_data
;
841 struct nfs_context
*nfs
= data
->nfs
;
844 if (status
== RPC_STATUS_ERROR
) {
845 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
846 free_nfs_cb_data(data
);
849 if (status
== RPC_STATUS_CANCEL
) {
850 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
851 free_nfs_cb_data(data
);
856 if (res
->status
!= NFS3_OK
) {
857 rpc_set_error(nfs
->rpc
, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
858 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
859 free_nfs_cb_data(data
);
863 data
->nfsfh
->offset
+= res
->READ3res_u
.resok
.count
;
864 data
->cb(res
->READ3res_u
.resok
.count
, nfs
, res
->READ3res_u
.resok
.data
.data_val
, data
->private_data
);
865 free_nfs_cb_data(data
);
868 static void nfs_pread_mcb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
870 struct nfs_mcb_data
*mdata
= private_data
;
871 struct nfs_cb_data
*data
= mdata
->data
;
872 struct nfs_context
*nfs
= data
->nfs
;
877 if (status
== RPC_STATUS_ERROR
) {
878 /* flag the failure but do not invoke callback until we have received all responses */
881 if (status
== RPC_STATUS_CANCEL
) {
882 /* flag the cancellation but do not invoke callback until we have received all responses */
886 /* reassemble the data into the buffer */
887 if (status
== RPC_STATUS_SUCCESS
) {
889 if (res
->status
!= NFS3_OK
) {
890 rpc_set_error(nfs
->rpc
, "NFS: Read failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
893 if (res
->READ3res_u
.resok
.count
> 0) {
894 memcpy(&data
->buffer
[mdata
->offset
- data
->start_offset
], res
->READ3res_u
.resok
.data
.data_val
, res
->READ3res_u
.resok
.count
);
895 if ((unsigned)data
->max_offset
< mdata
->offset
+ res
->READ3res_u
.resok
.count
) {
896 data
->max_offset
= mdata
->offset
+ res
->READ3res_u
.resok
.count
;
902 if (data
->num_calls
> 0) {
903 /* still waiting for more replies */
908 if (data
->error
!= 0) {
909 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
910 free_nfs_cb_data(data
);
914 if (data
->cancel
!= 0) {
915 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
916 free_nfs_cb_data(data
);
921 data
->nfsfh
->offset
= data
->max_offset
;
922 data
->cb(data
->max_offset
- data
->start_offset
, nfs
, data
->buffer
, data
->private_data
);
924 free_nfs_cb_data(data
);
928 int nfs_pread_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, nfs_cb cb
, void *private_data
)
930 struct nfs_cb_data
*data
;
932 data
= malloc(sizeof(struct nfs_cb_data
));
934 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
937 memset(data
, 0, sizeof(struct nfs_cb_data
));
940 data
->private_data
= private_data
;
943 nfsfh
->offset
= offset
;
945 if (count
<= nfs_get_readmax(nfs
)) {
946 if (rpc_nfs_read_async(nfs
->rpc
, nfs_pread_cb
, &nfsfh
->fh
, offset
, count
, data
) != 0) {
947 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READ call for %s", data
->path
);
948 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
949 free_nfs_cb_data(data
);
955 /* trying to read more than maximum server read size, we has to chop it up into smaller
956 * reads and collect into a reassembly buffer.
957 * we send all reads in parallell so that performance is still good.
959 data
->max_offset
= offset
;
960 data
->start_offset
= offset
;
962 data
->buffer
= malloc(count
);
963 if (data
->buffer
== NULL
) {
964 rpc_set_error(nfs
->rpc
, "Out-Of-Memory: Failed to allocate reassembly buffer for %d bytes", (int)count
);
965 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
966 free_nfs_cb_data(data
);
971 size_t readcount
= count
;
972 struct nfs_mcb_data
*mdata
;
974 if (readcount
> nfs_get_readmax(nfs
)) {
975 readcount
= nfs_get_readmax(nfs
);
978 mdata
= malloc(sizeof(struct nfs_mcb_data
));
980 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_mcb_data structure");
983 memset(mdata
, 0, sizeof(struct nfs_mcb_data
));
985 mdata
->offset
= offset
;
986 mdata
->count
= readcount
;
987 if (rpc_nfs_read_async(nfs
->rpc
, nfs_pread_mcb
, &nfsfh
->fh
, offset
, readcount
, mdata
) != 0) {
988 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READ call for %s", data
->path
);
989 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1005 int nfs_read_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, nfs_cb cb
, void *private_data
)
1007 return nfs_pread_async(nfs
, nfsfh
, nfsfh
->offset
, count
, cb
, private_data
);
1015 static void nfs_pwrite_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1017 struct nfs_cb_data
*data
= private_data
;
1018 struct nfs_context
*nfs
= data
->nfs
;
1021 if (status
== RPC_STATUS_ERROR
) {
1022 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1023 free_nfs_cb_data(data
);
1026 if (status
== RPC_STATUS_CANCEL
) {
1027 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1028 free_nfs_cb_data(data
);
1033 if (res
->status
!= NFS3_OK
) {
1034 rpc_set_error(nfs
->rpc
, "NFS: Write failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1035 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1036 free_nfs_cb_data(data
);
1040 data
->nfsfh
->offset
+= res
->WRITE3res_u
.resok
.count
;
1041 data
->cb(res
->WRITE3res_u
.resok
.count
, nfs
, NULL
, data
->private_data
);
1042 free_nfs_cb_data(data
);
1045 static void nfs_pwrite_mcb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1047 struct nfs_mcb_data
*mdata
= private_data
;
1048 struct nfs_cb_data
*data
= mdata
->data
;
1049 struct nfs_context
*nfs
= data
->nfs
;
1054 if (status
== RPC_STATUS_ERROR
) {
1055 /* flag the failure but do not invoke callback until we have received all responses */
1058 if (status
== RPC_STATUS_CANCEL
) {
1059 /* flag the cancellation but do not invoke callback until we have received all responses */
1063 if (status
== RPC_STATUS_SUCCESS
) {
1065 if (res
->status
!= NFS3_OK
) {
1066 rpc_set_error(nfs
->rpc
, "NFS: Write failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1069 if (res
->WRITE3res_u
.resok
.count
> 0) {
1070 if ((unsigned)data
->max_offset
< mdata
->offset
+ res
->WRITE3res_u
.resok
.count
) {
1071 data
->max_offset
= mdata
->offset
+ res
->WRITE3res_u
.resok
.count
;
1077 if (data
->num_calls
> 0) {
1078 /* still waiting for more replies */
1083 if (data
->error
!= 0) {
1084 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1085 free_nfs_cb_data(data
);
1089 if (data
->cancel
!= 0) {
1090 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1091 free_nfs_cb_data(data
);
1096 data
->nfsfh
->offset
= data
->max_offset
;
1097 data
->cb(data
->max_offset
- data
->start_offset
, nfs
, NULL
, data
->private_data
);
1099 free_nfs_cb_data(data
);
1104 int nfs_pwrite_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
)
1106 struct nfs_cb_data
*data
;
1108 data
= malloc(sizeof(struct nfs_cb_data
));
1110 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
1113 memset(data
, 0, sizeof(struct nfs_cb_data
));
1116 data
->private_data
= private_data
;
1117 data
->nfsfh
= nfsfh
;
1119 nfsfh
->offset
= offset
;
1121 if (count
<= nfs_get_writemax(nfs
)) {
1122 if (rpc_nfs_write_async(nfs
->rpc
, nfs_pwrite_cb
, &nfsfh
->fh
, buf
, offset
, count
, nfsfh
->is_sync
?FILE_SYNC
:UNSTABLE
, data
) != 0) {
1123 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send WRITE call for %s", data
->path
);
1124 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1125 free_nfs_cb_data(data
);
1131 /* trying to write more than maximum server write size, we has to chop it up into smaller
1133 * we send all writes in parallell so that performance is still good.
1135 data
->max_offset
= offset
;
1136 data
->start_offset
= offset
;
1139 size_t writecount
= count
;
1140 struct nfs_mcb_data
*mdata
;
1142 if (writecount
> nfs_get_writemax(nfs
)) {
1143 writecount
= nfs_get_writemax(nfs
);
1146 mdata
= malloc(sizeof(struct nfs_mcb_data
));
1147 if (mdata
== NULL
) {
1148 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_mcb_data structure");
1151 memset(mdata
, 0, sizeof(struct nfs_mcb_data
));
1153 mdata
->offset
= offset
;
1154 mdata
->count
= writecount
;
1156 if (rpc_nfs_write_async(nfs
->rpc
, nfs_pwrite_mcb
, &nfsfh
->fh
, &buf
[offset
- data
->start_offset
], offset
, writecount
, nfsfh
->is_sync
?FILE_SYNC
:UNSTABLE
, mdata
) != 0) {
1157 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send WRITE call for %s", data
->path
);
1158 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1163 count
-= writecount
;
1164 offset
+= writecount
;
1174 int nfs_write_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, size_t count
, char *buf
, nfs_cb cb
, void *private_data
)
1176 return nfs_pwrite_async(nfs
, nfsfh
, nfsfh
->offset
, count
, buf
, cb
, private_data
);
1186 int nfs_close_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
)
1188 if (nfsfh
->fh
.data
.data_val
!= NULL
){
1189 free(nfsfh
->fh
.data
.data_val
);
1190 nfsfh
->fh
.data
.data_val
= NULL
;
1194 cb(0, nfs
, NULL
, private_data
);
1205 int nfs_fstat_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
)
1207 struct nfs_cb_data
*data
;
1209 data
= malloc(sizeof(struct nfs_cb_data
));
1211 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
1214 memset(data
, 0, sizeof(struct nfs_cb_data
));
1217 data
->private_data
= private_data
;
1219 if (rpc_nfs_getattr_async(nfs
->rpc
, nfs_stat_1_cb
, &nfsfh
->fh
, data
) != 0) {
1220 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send STAT GETATTR call for %s", data
->path
);
1221 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1222 free_nfs_cb_data(data
);
1233 static void nfs_fsync_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1235 struct nfs_cb_data
*data
= private_data
;
1236 struct nfs_context
*nfs
= data
->nfs
;
1239 if (status
== RPC_STATUS_ERROR
) {
1240 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1241 free_nfs_cb_data(data
);
1244 if (status
== RPC_STATUS_CANCEL
) {
1245 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1246 free_nfs_cb_data(data
);
1251 if (res
->status
!= NFS3_OK
) {
1252 rpc_set_error(nfs
->rpc
, "NFS: Commit failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1253 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1254 free_nfs_cb_data(data
);
1258 data
->cb(0, nfs
, NULL
, data
->private_data
);
1259 free_nfs_cb_data(data
);
1262 int nfs_fsync_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, nfs_cb cb
, void *private_data
)
1264 struct nfs_cb_data
*data
;
1266 data
= malloc(sizeof(struct nfs_cb_data
));
1268 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
1271 memset(data
, 0, sizeof(struct nfs_cb_data
));
1274 data
->private_data
= private_data
;
1276 if (rpc_nfs_commit_async(nfs
->rpc
, nfs_fsync_cb
, &nfsfh
->fh
, data
) != 0) {
1277 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send COMMIT call for %s", data
->path
);
1278 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1279 free_nfs_cb_data(data
);
1291 static void nfs_ftruncate_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1293 struct nfs_cb_data
*data
= private_data
;
1294 struct nfs_context
*nfs
= data
->nfs
;
1297 if (status
== RPC_STATUS_ERROR
) {
1298 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1299 free_nfs_cb_data(data
);
1302 if (status
== RPC_STATUS_CANCEL
) {
1303 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1304 free_nfs_cb_data(data
);
1309 if (res
->status
!= NFS3_OK
) {
1310 rpc_set_error(nfs
->rpc
, "NFS: Setattr failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1311 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1312 free_nfs_cb_data(data
);
1316 data
->cb(0, nfs
, NULL
, data
->private_data
);
1317 free_nfs_cb_data(data
);
1320 int nfs_ftruncate_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t length
, nfs_cb cb
, void *private_data
)
1322 struct nfs_cb_data
*data
;
1325 data
= malloc(sizeof(struct nfs_cb_data
));
1327 rpc_set_error(nfs
->rpc
, "out of memory: failed to allocate nfs_cb_data structure");
1330 memset(data
, 0, sizeof(struct nfs_cb_data
));
1333 data
->private_data
= private_data
;
1335 memset(&args
, 0, sizeof(SETATTR3args
));
1336 args
.object
.data
.data_len
= nfsfh
->fh
.data
.data_len
;
1337 args
.object
.data
.data_val
= nfsfh
->fh
.data
.data_val
;
1338 args
.new_attributes
.size
.set_it
= 1;
1339 args
.new_attributes
.size
.set_size3_u
.size
= length
;
1341 if (rpc_nfs_setattr_async(nfs
->rpc
, nfs_ftruncate_cb
, &args
, data
) != 0) {
1342 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SETATTR call for %s", data
->path
);
1343 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1344 free_nfs_cb_data(data
);
1354 static int nfs_truncate_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
1356 off_t offset
= data
->continue_int
;
1359 nfsfh
.fh
.data
.data_val
= data
->fh
.data
.data_val
;
1360 nfsfh
.fh
.data
.data_len
= data
->fh
.data
.data_len
;
1362 if (nfs_ftruncate_async(nfs
, &nfsfh
, offset
, data
->cb
, data
->private_data
) != 0) {
1363 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SETATTR call for %s", data
->path
);
1364 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1365 free_nfs_cb_data(data
);
1368 free_nfs_cb_data(data
);
1372 int nfs_truncate_async(struct nfs_context
*nfs
, const char *path
, off_t length
, nfs_cb cb
, void *private_data
)
1378 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_truncate_continue_internal
, NULL
, NULL
, offset
) != 0) {
1379 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
1392 static void nfs_mkdir_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1395 struct nfs_cb_data
*data
= private_data
;
1396 struct nfs_context
*nfs
= data
->nfs
;
1397 char *str
= data
->continue_data
;
1399 str
= &str
[strlen(str
) + 1];
1401 if (status
== RPC_STATUS_ERROR
) {
1402 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1403 free_nfs_cb_data(data
);
1406 if (status
== RPC_STATUS_CANCEL
) {
1407 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1408 free_nfs_cb_data(data
);
1413 if (res
->status
!= NFS3_OK
) {
1414 rpc_set_error(nfs
->rpc
, "NFS: MKDIR of %s/%s failed with %s(%d)", data
->saved_path
, str
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1415 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1416 free_nfs_cb_data(data
);
1420 data
->cb(0, nfs
, NULL
, data
->private_data
);
1421 free_nfs_cb_data(data
);
1424 static int nfs_mkdir_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
1426 char *str
= data
->continue_data
;
1428 str
= &str
[strlen(str
) + 1];
1430 if (rpc_nfs_mkdir_async(nfs
->rpc
, nfs_mkdir_cb
, &data
->fh
, str
, data
) != 0) {
1431 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send MKDIR call for %s", data
->path
);
1432 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1433 free_nfs_cb_data(data
);
1439 int nfs_mkdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
1444 new_path
= strdup(path
);
1445 if (new_path
== NULL
) {
1446 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for path");
1450 ptr
= strrchr(new_path
, '/');
1452 rpc_set_error(nfs
->rpc
, "Invalid path %s", path
);
1457 /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
1458 if (nfs_lookuppath_async(nfs
, new_path
, cb
, private_data
, nfs_mkdir_continue_internal
, new_path
, free
, 0) != 0) {
1459 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path component");
1473 static void nfs_rmdir_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1476 struct nfs_cb_data
*data
= private_data
;
1477 struct nfs_context
*nfs
= data
->nfs
;
1478 char *str
= data
->continue_data
;
1480 str
= &str
[strlen(str
) + 1];
1482 if (status
== RPC_STATUS_ERROR
) {
1483 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1484 free_nfs_cb_data(data
);
1487 if (status
== RPC_STATUS_CANCEL
) {
1488 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1489 free_nfs_cb_data(data
);
1494 if (res
->status
!= NFS3_OK
) {
1495 rpc_set_error(nfs
->rpc
, "NFS: RMDIR of %s/%s failed with %s(%d)", data
->saved_path
, str
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1496 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1497 free_nfs_cb_data(data
);
1501 data
->cb(0, nfs
, NULL
, data
->private_data
);
1502 free_nfs_cb_data(data
);
1505 static int nfs_rmdir_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
1507 char *str
= data
->continue_data
;
1509 str
= &str
[strlen(str
) + 1];
1511 if (rpc_nfs_rmdir_async(nfs
->rpc
, nfs_rmdir_cb
, &data
->fh
, str
, data
) != 0) {
1512 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send RMDIR call for %s", data
->path
);
1513 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1514 free_nfs_cb_data(data
);
1520 int nfs_rmdir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
1525 new_path
= strdup(path
);
1526 if (new_path
== NULL
) {
1527 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for path");
1531 ptr
= strrchr(new_path
, '/');
1533 rpc_set_error(nfs
->rpc
, "Invalid path %s", path
);
1538 /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
1539 if (nfs_lookuppath_async(nfs
, new_path
, cb
, private_data
, nfs_rmdir_continue_internal
, new_path
, free
, 0) != 0) {
1540 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
1553 static void nfs_create_2_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1556 struct nfs_cb_data
*data
= private_data
;
1557 struct nfs_context
*nfs
= data
->nfs
;
1558 struct nfsfh
*nfsfh
;
1559 char *str
= data
->continue_data
;
1561 if (status
== RPC_STATUS_ERROR
) {
1562 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1563 free_nfs_cb_data(data
);
1566 if (status
== RPC_STATUS_CANCEL
) {
1567 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1568 free_nfs_cb_data(data
);
1572 str
= &str
[strlen(str
) + 1];
1574 if (res
->status
!= NFS3_OK
) {
1575 rpc_set_error(nfs
->rpc
, "NFS: CREATE of %s/%s failed with %s(%d)", data
->saved_path
, str
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1576 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1581 nfsfh
= malloc(sizeof(struct nfsfh
));
1582 if (nfsfh
== NULL
) {
1583 rpc_set_error(nfs
->rpc
, "NFS: Failed to allocate nfsfh structure");
1584 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1585 free_nfs_cb_data(data
);
1588 memset(nfsfh
, 0, sizeof(struct nfsfh
));
1590 /* steal the filehandle */
1591 nfsfh
->fh
.data
.data_len
= data
->fh
.data
.data_len
;
1592 nfsfh
->fh
.data
.data_val
= data
->fh
.data
.data_val
;
1593 data
->fh
.data
.data_val
= NULL
;
1595 data
->cb(0, nfs
, nfsfh
, data
->private_data
);
1596 free_nfs_cb_data(data
);
1601 static void nfs_creat_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1604 struct nfs_cb_data
*data
= private_data
;
1605 struct nfs_context
*nfs
= data
->nfs
;
1606 char *str
= data
->continue_data
;
1608 if (status
== RPC_STATUS_ERROR
) {
1609 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1610 free_nfs_cb_data(data
);
1613 if (status
== RPC_STATUS_CANCEL
) {
1614 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1615 free_nfs_cb_data(data
);
1619 str
= &str
[strlen(str
) + 1];
1621 if (res
->status
!= NFS3_OK
) {
1622 rpc_set_error(nfs
->rpc
, "NFS: CREATE of %s/%s failed with %s(%d)", data
->saved_path
, str
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1623 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1628 if (rpc_nfs_lookup_async(nfs
->rpc
, nfs_create_2_cb
, &data
->fh
, str
, data
) != 0) {
1629 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send lookup call for %s/%s", data
->saved_path
, str
);
1630 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1631 free_nfs_cb_data(data
);
1637 static int nfs_creat_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
1639 char *str
= data
->continue_data
;
1641 str
= &str
[strlen(str
) + 1];
1643 if (rpc_nfs_create_async(nfs
->rpc
, nfs_creat_1_cb
, &data
->fh
, str
, data
->continue_int
, data
) != 0) {
1644 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send CREATE call for %s/%s", data
->path
, str
);
1645 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1646 free_nfs_cb_data(data
);
1652 int nfs_creat_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
)
1657 new_path
= strdup(path
);
1658 if (new_path
== NULL
) {
1659 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for path");
1663 ptr
= strrchr(new_path
, '/');
1665 rpc_set_error(nfs
->rpc
, "Invalid path %s", path
);
1670 /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
1671 if (nfs_lookuppath_async(nfs
, new_path
, cb
, private_data
, nfs_creat_continue_internal
, new_path
, free
, mode
) != 0) {
1672 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
1685 static void nfs_unlink_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1688 struct nfs_cb_data
*data
= private_data
;
1689 struct nfs_context
*nfs
= data
->nfs
;
1690 char *str
= data
->continue_data
;
1692 str
= &str
[strlen(str
) + 1];
1694 if (status
== RPC_STATUS_ERROR
) {
1695 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1696 free_nfs_cb_data(data
);
1699 if (status
== RPC_STATUS_CANCEL
) {
1700 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1701 free_nfs_cb_data(data
);
1706 if (res
->status
!= NFS3_OK
) {
1707 rpc_set_error(nfs
->rpc
, "NFS: REMOVE of %s/%s failed with %s(%d)", data
->saved_path
, str
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1708 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1709 free_nfs_cb_data(data
);
1713 data
->cb(0, nfs
, NULL
, data
->private_data
);
1714 free_nfs_cb_data(data
);
1717 static int nfs_unlink_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
1719 char *str
= data
->continue_data
;
1721 str
= &str
[strlen(str
) + 1];
1723 if (rpc_nfs_remove_async(nfs
->rpc
, nfs_unlink_cb
, &data
->fh
, str
, data
) != 0) {
1724 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send REMOVE call for %s", data
->path
);
1725 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1726 free_nfs_cb_data(data
);
1732 int nfs_unlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
1737 new_path
= strdup(path
);
1738 if (new_path
== NULL
) {
1739 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for path");
1743 ptr
= strrchr(new_path
, '/');
1745 rpc_set_error(nfs
->rpc
, "Invalid path %s", path
);
1750 /* new_path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
1751 if (nfs_lookuppath_async(nfs
, new_path
, cb
, private_data
, nfs_unlink_continue_internal
, new_path
, free
, 0) != 0) {
1752 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
1765 /* ReadDirPlus Emulation Callback data */
1766 struct rdpe_cb_data
{
1769 struct nfs_cb_data
*data
;
1772 /* ReadDirPlus Emulation LOOKUP Callback data */
1773 struct rdpe_lookup_cb_data
{
1774 struct rdpe_cb_data
*rdpe_cb_data
;
1775 struct nfsdirent
*nfsdirent
;
1778 /* Workaround for servers lacking READDIRPLUS, use READDIR instead and a GETATTR-loop */
1779 static void nfs_opendir3_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1781 LOOKUP3res
*res
= command_data
;
1782 struct rdpe_lookup_cb_data
*rdpe_lookup_cb_data
= private_data
;
1783 struct rdpe_cb_data
*rdpe_cb_data
= rdpe_lookup_cb_data
->rdpe_cb_data
;
1784 struct nfs_cb_data
*data
= rdpe_cb_data
->data
;
1785 struct nfsdir
*nfsdir
= data
->continue_data
;
1786 struct nfs_context
*nfs
= data
->nfs
;
1787 struct nfsdirent
*nfsdirent
= rdpe_lookup_cb_data
->nfsdirent
;
1789 free(rdpe_lookup_cb_data
);
1791 rdpe_cb_data
->getattrcount
--;
1793 if (status
== RPC_STATUS_ERROR
) {
1794 rdpe_cb_data
->status
= RPC_STATUS_ERROR
;
1796 if (status
== RPC_STATUS_CANCEL
) {
1797 rdpe_cb_data
->status
= RPC_STATUS_CANCEL
;
1799 if (status
== RPC_STATUS_SUCCESS
&& res
->status
!= NFS3_OK
) {
1800 rdpe_cb_data
->status
= RPC_STATUS_ERROR
;
1802 if (status
== RPC_STATUS_SUCCESS
&& res
->status
== NFS3_OK
) {
1803 if (res
->LOOKUP3res_u
.resok
.obj_attributes
.attributes_follow
) {
1804 fattr3
*attributes
= &res
->LOOKUP3res_u
.resok
.obj_attributes
.post_op_attr_u
.attributes
;
1806 nfsdirent
->type
= attributes
->type
;
1807 nfsdirent
->mode
= attributes
->mode
;
1808 nfsdirent
->size
= attributes
->size
;
1810 nfsdirent
->atime
.tv_sec
= attributes
->atime
.seconds
;
1811 nfsdirent
->atime
.tv_usec
= attributes
->atime
.nseconds
/1000;
1812 nfsdirent
->mtime
.tv_sec
= attributes
->mtime
.seconds
;
1813 nfsdirent
->mtime
.tv_usec
= attributes
->mtime
.nseconds
/1000;
1814 nfsdirent
->ctime
.tv_sec
= attributes
->ctime
.seconds
;
1815 nfsdirent
->ctime
.tv_usec
= attributes
->ctime
.nseconds
/1000;
1819 if (rdpe_cb_data
->getattrcount
== 0) {
1820 if (rdpe_cb_data
->status
!= RPC_STATUS_SUCCESS
) {
1821 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1822 nfs_free_nfsdir(nfsdir
);
1824 data
->cb(0, nfs
, nfsdir
, data
->private_data
);
1828 data
->continue_data
= NULL
;
1829 free_nfs_cb_data(data
);
1833 static void nfs_opendir2_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1835 READDIR3res
*res
= command_data
;
1836 struct nfs_cb_data
*data
= private_data
;
1837 struct nfs_context
*nfs
= data
->nfs
;
1838 struct nfsdir
*nfsdir
= data
->continue_data
;
1839 struct nfsdirent
*nfsdirent
;
1840 struct entry3
*entry
;
1842 struct rdpe_cb_data
*rdpe_cb_data
;
1844 if (status
== RPC_STATUS_ERROR
) {
1845 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
1846 nfs_free_nfsdir(nfsdir
);
1847 data
->continue_data
= NULL
;
1848 free_nfs_cb_data(data
);
1852 if (status
== RPC_STATUS_CANCEL
) {
1853 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1854 nfs_free_nfsdir(nfsdir
);
1855 data
->continue_data
= NULL
;
1856 free_nfs_cb_data(data
);
1860 if (res
->status
!= NFS3_OK
) {
1861 rpc_set_error(nfs
->rpc
, "NFS: READDIR of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1862 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1863 nfs_free_nfsdir(nfsdir
);
1864 data
->continue_data
= NULL
;
1865 free_nfs_cb_data(data
);
1869 entry
=res
->READDIR3res_u
.resok
.reply
.entries
;
1870 while (entry
!= NULL
) {
1871 nfsdirent
= malloc(sizeof(struct nfsdirent
));
1872 if (nfsdirent
== NULL
) {
1873 data
->cb(-ENOMEM
, nfs
, "Failed to allocate dirent", data
->private_data
);
1874 nfs_free_nfsdir(nfsdir
);
1875 data
->continue_data
= NULL
;
1876 free_nfs_cb_data(data
);
1879 memset(nfsdirent
, 0, sizeof(struct nfsdirent
));
1880 nfsdirent
->name
= strdup(entry
->name
);
1881 if (nfsdirent
->name
== NULL
) {
1882 data
->cb(-ENOMEM
, nfs
, "Failed to allocate dirent->name", data
->private_data
);
1883 nfs_free_nfsdir(nfsdir
);
1884 data
->continue_data
= NULL
;
1885 free_nfs_cb_data(data
);
1888 nfsdirent
->inode
= entry
->fileid
;
1890 nfsdirent
->next
= nfsdir
->entries
;
1891 nfsdir
->entries
= nfsdirent
;
1893 cookie
= entry
->cookie
;
1894 entry
= entry
->nextentry
;
1897 if (res
->READDIR3res_u
.resok
.reply
.eof
== 0) {
1898 if (rpc_nfs_readdir_async(nfs
->rpc
, nfs_opendir2_cb
, &data
->fh
, cookie
, res
->READDIR3res_u
.resok
.cookieverf
, 8192, data
) != 0) {
1899 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READDIR call for %s", data
->path
);
1900 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1901 nfs_free_nfsdir(nfsdir
);
1902 data
->continue_data
= NULL
;
1903 free_nfs_cb_data(data
);
1909 /* steal the dirhandle */
1910 nfsdir
->current
= nfsdir
->entries
;
1912 rdpe_cb_data
= malloc(sizeof(struct rdpe_cb_data
));
1913 rdpe_cb_data
->getattrcount
= 0;
1914 rdpe_cb_data
->status
= RPC_STATUS_SUCCESS
;
1915 rdpe_cb_data
->data
= data
;
1916 for (nfsdirent
= nfsdir
->entries
; nfsdirent
; nfsdirent
= nfsdirent
->next
) {
1917 struct rdpe_lookup_cb_data
*rdpe_lookup_cb_data
;
1919 rdpe_lookup_cb_data
= malloc(sizeof(struct rdpe_lookup_cb_data
));
1920 rdpe_lookup_cb_data
->rdpe_cb_data
= rdpe_cb_data
;
1921 rdpe_lookup_cb_data
->nfsdirent
= nfsdirent
;
1923 if (rpc_nfs_lookup_async(nfs
->rpc
, nfs_opendir3_cb
, &data
->fh
, nfsdirent
->name
, rdpe_lookup_cb_data
) != 0) {
1924 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READDIR LOOKUP call");
1926 /* if we have already commands in flight, we cant just stop, we have to wait for the
1927 * commands in flight to complete
1929 if (rdpe_cb_data
->getattrcount
> 0) {
1930 rdpe_cb_data
->status
= RPC_STATUS_ERROR
;
1931 free(rdpe_lookup_cb_data
);
1935 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1936 nfs_free_nfsdir(nfsdir
);
1937 data
->continue_data
= NULL
;
1938 free_nfs_cb_data(data
);
1939 free(rdpe_lookup_cb_data
);
1943 rdpe_cb_data
->getattrcount
++;
1948 static void nfs_opendir_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
1950 READDIRPLUS3res
*res
= command_data
;
1951 struct nfs_cb_data
*data
= private_data
;
1952 struct nfs_context
*nfs
= data
->nfs
;
1953 struct nfsdir
*nfsdir
= data
->continue_data
;
1954 struct entryplus3
*entry
;
1958 if (status
== RPC_STATUS_ERROR
|| (status
== RPC_STATUS_SUCCESS
&& res
->status
== NFS3ERR_NOTSUPP
) ){
1961 if (rpc_nfs_readdir_async(nfs
->rpc
, nfs_opendir2_cb
, &data
->fh
, 0, (char *)&cv
, 8192, data
) != 0) {
1962 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READDIR call for %s", data
->path
);
1963 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1964 nfs_free_nfsdir(nfsdir
);
1965 data
->continue_data
= NULL
;
1966 free_nfs_cb_data(data
);
1972 if (status
== RPC_STATUS_CANCEL
) {
1973 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
1974 nfs_free_nfsdir(nfsdir
);
1975 data
->continue_data
= NULL
;
1976 free_nfs_cb_data(data
);
1980 if (res
->status
!= NFS3_OK
) {
1981 rpc_set_error(nfs
->rpc
, "NFS: READDIRPLUS of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
1982 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
1983 nfs_free_nfsdir(nfsdir
);
1984 data
->continue_data
= NULL
;
1985 free_nfs_cb_data(data
);
1989 entry
=res
->READDIRPLUS3res_u
.resok
.reply
.entries
;
1990 while (entry
!= NULL
) {
1991 struct nfsdirent
*nfsdirent
;
1993 nfsdirent
= malloc(sizeof(struct nfsdirent
));
1994 if (nfsdirent
== NULL
) {
1995 data
->cb(-ENOMEM
, nfs
, "Failed to allocate dirent", data
->private_data
);
1996 nfs_free_nfsdir(nfsdir
);
1997 data
->continue_data
= NULL
;
1998 free_nfs_cb_data(data
);
2001 memset(nfsdirent
, 0, sizeof(struct nfsdirent
));
2002 nfsdirent
->name
= strdup(entry
->name
);
2003 if (nfsdirent
->name
== NULL
) {
2004 data
->cb(-ENOMEM
, nfs
, "Failed to allocate dirent->name", data
->private_data
);
2005 nfs_free_nfsdir(nfsdir
);
2006 data
->continue_data
= NULL
;
2007 free_nfs_cb_data(data
);
2010 nfsdirent
->inode
= entry
->fileid
;
2011 if (entry
->name_attributes
.attributes_follow
) {
2012 nfsdirent
->type
= entry
->name_attributes
.post_op_attr_u
.attributes
.type
;
2013 nfsdirent
->mode
= entry
->name_attributes
.post_op_attr_u
.attributes
.mode
;
2014 nfsdirent
->size
= entry
->name_attributes
.post_op_attr_u
.attributes
.size
;
2016 nfsdirent
->atime
.tv_sec
= entry
->name_attributes
.post_op_attr_u
.attributes
.atime
.seconds
;
2017 nfsdirent
->atime
.tv_usec
= entry
->name_attributes
.post_op_attr_u
.attributes
.atime
.nseconds
/1000;
2018 nfsdirent
->mtime
.tv_sec
= entry
->name_attributes
.post_op_attr_u
.attributes
.mtime
.seconds
;
2019 nfsdirent
->mtime
.tv_usec
= entry
->name_attributes
.post_op_attr_u
.attributes
.mtime
.nseconds
/1000;
2020 nfsdirent
->ctime
.tv_sec
= entry
->name_attributes
.post_op_attr_u
.attributes
.ctime
.seconds
;
2021 nfsdirent
->ctime
.tv_usec
= entry
->name_attributes
.post_op_attr_u
.attributes
.ctime
.nseconds
/1000;
2024 nfsdirent
->next
= nfsdir
->entries
;
2025 nfsdir
->entries
= nfsdirent
;
2027 cookie
= entry
->cookie
;
2028 entry
= entry
->nextentry
;
2031 if (res
->READDIRPLUS3res_u
.resok
.reply
.eof
== 0) {
2032 if (rpc_nfs_readdirplus_async(nfs
->rpc
, nfs_opendir_cb
, &data
->fh
, cookie
, res
->READDIRPLUS3res_u
.resok
.cookieverf
, 8192, data
) != 0) {
2033 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READDIRPLUS call for %s", data
->path
);
2034 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2035 nfs_free_nfsdir(nfsdir
);
2036 data
->continue_data
= NULL
;
2037 free_nfs_cb_data(data
);
2043 /* steal the dirhandle */
2044 data
->continue_data
= NULL
;
2045 nfsdir
->current
= nfsdir
->entries
;
2047 data
->cb(0, nfs
, nfsdir
, data
->private_data
);
2048 free_nfs_cb_data(data
);
2051 static int nfs_opendir_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2055 memset(cv
, 0, sizeof(cookieverf3
));
2056 if (rpc_nfs_readdirplus_async(nfs
->rpc
, nfs_opendir_cb
, &data
->fh
, 0, (char *)&cv
, 8192, data
) != 0) {
2057 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READDIRPLUS call for %s", data
->path
);
2058 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2059 free_nfs_cb_data(data
);
2065 int nfs_opendir_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
2067 struct nfsdir
*nfsdir
;
2069 nfsdir
= malloc(sizeof(struct nfsdir
));
2070 if (nfsdir
== NULL
) {
2071 rpc_set_error(nfs
->rpc
, "failed to allocate buffer for nfsdir");
2074 memset(nfsdir
, 0, sizeof(struct nfsdir
));
2076 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_opendir_continue_internal
, nfsdir
, free
, 0) != 0) {
2077 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2085 struct nfsdirent
*nfs_readdir(struct nfs_context
*nfs _U_
, struct nfsdir
*nfsdir
)
2087 struct nfsdirent
*nfsdirent
= nfsdir
->current
;
2089 if (nfsdir
->current
!= NULL
) {
2090 nfsdir
->current
= nfsdir
->current
->next
;
2096 void nfs_closedir(struct nfs_context
*nfs _U_
, struct nfsdir
*nfsdir
)
2098 nfs_free_nfsdir(nfsdir
);
2110 struct lseek_cb_data
{
2111 struct nfs_context
*nfs
;
2112 struct nfsfh
*nfsfh
;
2118 static void nfs_lseek_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2121 struct lseek_cb_data
*data
= private_data
;
2122 struct nfs_context
*nfs
= data
->nfs
;
2124 if (status
== RPC_STATUS_ERROR
) {
2125 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2129 if (status
== RPC_STATUS_CANCEL
) {
2130 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2136 if (res
->status
!= NFS3_OK
) {
2137 rpc_set_error(nfs
->rpc
, "NFS: GETATTR failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2138 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2143 data
->nfsfh
->offset
= data
->offset
+ res
->GETATTR3res_u
.resok
.obj_attributes
.size
;
2144 data
->cb(0, nfs
, &data
->nfsfh
->offset
, data
->private_data
);
2148 int nfs_lseek_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, off_t offset
, int whence
, nfs_cb cb
, void *private_data
)
2150 struct lseek_cb_data
*data
;
2152 if (whence
== SEEK_SET
) {
2153 nfsfh
->offset
= offset
;
2154 cb(0, nfs
, &nfsfh
->offset
, private_data
);
2157 if (whence
== SEEK_CUR
) {
2158 nfsfh
->offset
+= offset
;
2159 cb(0, nfs
, &nfsfh
->offset
, private_data
);
2163 data
= malloc(sizeof(struct lseek_cb_data
));
2165 rpc_set_error(nfs
->rpc
, "Out Of Memory: Failed to malloc lseek cb data");
2170 data
->nfsfh
= nfsfh
;
2171 data
->offset
= offset
;
2173 data
->private_data
= private_data
;
2175 if (rpc_nfs_getattr_async(nfs
->rpc
, nfs_lseek_1_cb
, &nfsfh
->fh
, data
) != 0) {
2176 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send LSEEK GETATTR call");
2189 static void nfs_statvfs_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2192 struct nfs_cb_data
*data
= private_data
;
2193 struct nfs_context
*nfs
= data
->nfs
;
2194 struct statvfs svfs
;
2196 if (status
== RPC_STATUS_ERROR
) {
2197 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2198 free_nfs_cb_data(data
);
2201 if (status
== RPC_STATUS_CANCEL
) {
2202 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2203 free_nfs_cb_data(data
);
2208 if (res
->status
!= NFS3_OK
) {
2209 rpc_set_error(nfs
->rpc
, "NFS: FSSTAT of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2210 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2211 free_nfs_cb_data(data
);
2215 svfs
.f_bsize
= 4096;
2216 svfs
.f_frsize
= 4096;
2217 svfs
.f_blocks
= res
->FSSTAT3res_u
.resok
.tbytes
/4096;
2218 svfs
.f_bfree
= res
->FSSTAT3res_u
.resok
.fbytes
/4096;
2219 svfs
.f_bavail
= res
->FSSTAT3res_u
.resok
.abytes
/4096;
2220 svfs
.f_files
= res
->FSSTAT3res_u
.resok
.tfiles
;
2221 svfs
.f_ffree
= res
->FSSTAT3res_u
.resok
.ffiles
;
2222 svfs
.f_favail
= res
->FSSTAT3res_u
.resok
.afiles
;
2225 svfs
.f_namemax
= 256;
2227 data
->cb(0, nfs
, &svfs
, data
->private_data
);
2228 free_nfs_cb_data(data
);
2231 static int nfs_statvfs_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2233 if (rpc_nfs_fsstat_async(nfs
->rpc
, nfs_statvfs_1_cb
, &data
->fh
, data
) != 0) {
2234 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send FSSTAT call for %s", data
->path
);
2235 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2236 free_nfs_cb_data(data
);
2242 int nfs_statvfs_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
2244 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_statvfs_continue_internal
, NULL
, NULL
, 0) != 0) {
2245 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2258 static void nfs_readlink_1_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2261 struct nfs_cb_data
*data
= private_data
;
2262 struct nfs_context
*nfs
= data
->nfs
;
2264 if (status
== RPC_STATUS_ERROR
) {
2265 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2266 free_nfs_cb_data(data
);
2269 if (status
== RPC_STATUS_CANCEL
) {
2270 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2271 free_nfs_cb_data(data
);
2276 if (res
->status
!= NFS3_OK
) {
2277 rpc_set_error(nfs
->rpc
, "NFS: READLINK of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2278 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2279 free_nfs_cb_data(data
);
2284 data
->cb(0, nfs
, res
->READLINK3res_u
.resok
.data
, data
->private_data
);
2285 free_nfs_cb_data(data
);
2288 static int nfs_readlink_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2290 if (rpc_nfs_readlink_async(nfs
->rpc
, nfs_readlink_1_cb
, &data
->fh
, data
) != 0) {
2291 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send READLINK call for %s", data
->path
);
2292 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2293 free_nfs_cb_data(data
);
2299 int nfs_readlink_async(struct nfs_context
*nfs
, const char *path
, nfs_cb cb
, void *private_data
)
2301 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_readlink_continue_internal
, NULL
, NULL
, 0) != 0) {
2302 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2315 static void nfs_chmod_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2317 struct nfs_cb_data
*data
= private_data
;
2318 struct nfs_context
*nfs
= data
->nfs
;
2321 if (status
== RPC_STATUS_ERROR
) {
2322 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2323 free_nfs_cb_data(data
);
2326 if (status
== RPC_STATUS_CANCEL
) {
2327 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2328 free_nfs_cb_data(data
);
2333 if (res
->status
!= NFS3_OK
) {
2334 rpc_set_error(nfs
->rpc
, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2335 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2336 free_nfs_cb_data(data
);
2340 data
->cb(0, nfs
, NULL
, data
->private_data
);
2341 free_nfs_cb_data(data
);
2344 static int nfs_chmod_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2348 memset(&args
, 0, sizeof(SETATTR3args
));
2349 args
.object
.data
.data_len
= data
->fh
.data
.data_len
;
2350 args
.object
.data
.data_val
= data
->fh
.data
.data_val
;
2351 args
.new_attributes
.mode
.set_it
= 1;
2352 args
.new_attributes
.mode
.set_mode3_u
.mode
= data
->continue_int
;
2354 if (rpc_nfs_setattr_async(nfs
->rpc
, nfs_chmod_cb
, &args
, data
) != 0) {
2355 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SETATTR call for %s", data
->path
);
2356 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2357 free_nfs_cb_data(data
);
2364 int nfs_chmod_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
)
2366 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_chmod_continue_internal
, NULL
, NULL
, mode
) != 0) {
2367 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2377 int nfs_fchmod_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int mode
, nfs_cb cb
, void *private_data
)
2379 struct nfs_cb_data
*data
;
2381 data
= malloc(sizeof(struct nfs_cb_data
));
2383 rpc_set_error(nfs
->rpc
, "out of memory. failed to allocate memory for nfs mount data");
2386 memset(data
, 0, sizeof(struct nfs_cb_data
));
2389 data
->private_data
= private_data
;
2390 data
->continue_int
= mode
;
2391 data
->fh
.data
.data_len
= nfsfh
->fh
.data
.data_len
;
2392 data
->fh
.data
.data_val
= malloc(data
->fh
.data
.data_len
);
2393 if (data
->fh
.data
.data_val
== NULL
) {
2394 rpc_set_error(nfs
->rpc
, "Out of memory: Failed to allocate fh");
2395 free_nfs_cb_data(data
);
2398 memcpy(data
->fh
.data
.data_val
, nfsfh
->fh
.data
.data_val
, data
->fh
.data
.data_len
);
2400 if (nfs_chmod_continue_internal(nfs
, data
) != 0) {
2401 free_nfs_cb_data(data
);
2413 static void nfs_chown_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2415 struct nfs_cb_data
*data
= private_data
;
2416 struct nfs_context
*nfs
= data
->nfs
;
2419 if (status
== RPC_STATUS_ERROR
) {
2420 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2421 free_nfs_cb_data(data
);
2424 if (status
== RPC_STATUS_CANCEL
) {
2425 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2426 free_nfs_cb_data(data
);
2431 if (res
->status
!= NFS3_OK
) {
2432 rpc_set_error(nfs
->rpc
, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2433 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2434 free_nfs_cb_data(data
);
2438 data
->cb(0, nfs
, NULL
, data
->private_data
);
2439 free_nfs_cb_data(data
);
2442 struct nfs_chown_data
{
2447 static int nfs_chown_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2450 struct nfs_chown_data
*chown_data
= data
->continue_data
;
2452 memset(&args
, 0, sizeof(SETATTR3args
));
2453 args
.object
.data
.data_len
= data
->fh
.data
.data_len
;
2454 args
.object
.data
.data_val
= data
->fh
.data
.data_val
;
2455 if (chown_data
->uid
!= (uid_t
)-1) {
2456 args
.new_attributes
.uid
.set_it
= 1;
2457 args
.new_attributes
.uid
.set_uid3_u
.uid
= chown_data
->uid
;
2459 if (chown_data
->gid
!= (gid_t
)-1) {
2460 args
.new_attributes
.gid
.set_it
= 1;
2461 args
.new_attributes
.gid
.set_gid3_u
.gid
= chown_data
->gid
;
2464 if (rpc_nfs_setattr_async(nfs
->rpc
, nfs_chown_cb
, &args
, data
) != 0) {
2465 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SETATTR call for %s", data
->path
);
2466 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2467 free_nfs_cb_data(data
);
2474 int nfs_chown_async(struct nfs_context
*nfs
, const char *path
, int uid
, int gid
, nfs_cb cb
, void *private_data
)
2476 struct nfs_chown_data
*chown_data
;
2478 chown_data
= malloc(sizeof(struct nfs_chown_data
));
2479 if (chown_data
== NULL
) {
2480 rpc_set_error(nfs
->rpc
, "Failed to allocate memory for chown data structure");
2484 chown_data
->uid
= uid
;
2485 chown_data
->gid
= gid
;
2487 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_chown_continue_internal
, chown_data
, free
, 0) != 0) {
2488 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2499 int nfs_fchown_async(struct nfs_context
*nfs
, struct nfsfh
*nfsfh
, int uid
, int gid
, nfs_cb cb
, void *private_data
)
2501 struct nfs_cb_data
*data
;
2502 struct nfs_chown_data
*chown_data
;
2504 chown_data
= malloc(sizeof(struct nfs_chown_data
));
2505 if (chown_data
== NULL
) {
2506 rpc_set_error(nfs
->rpc
, "Failed to allocate memory for chown data structure");
2510 chown_data
->uid
= uid
;
2511 chown_data
->gid
= gid
;
2514 data
= malloc(sizeof(struct nfs_cb_data
));
2516 rpc_set_error(nfs
->rpc
, "out of memory. failed to allocate memory for fchown data");
2519 memset(data
, 0, sizeof(struct nfs_cb_data
));
2522 data
->private_data
= private_data
;
2523 data
->continue_data
= chown_data
;
2524 data
->fh
.data
.data_len
= nfsfh
->fh
.data
.data_len
;
2525 data
->fh
.data
.data_val
= malloc(data
->fh
.data
.data_len
);
2526 if (data
->fh
.data
.data_val
== NULL
) {
2527 rpc_set_error(nfs
->rpc
, "Out of memory: Failed to allocate fh");
2528 free_nfs_cb_data(data
);
2531 memcpy(data
->fh
.data
.data_val
, nfsfh
->fh
.data
.data_val
, data
->fh
.data
.data_len
);
2534 if (nfs_chown_continue_internal(nfs
, data
) != 0) {
2535 free_nfs_cb_data(data
);
2549 static void nfs_utimes_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2551 struct nfs_cb_data
*data
= private_data
;
2552 struct nfs_context
*nfs
= data
->nfs
;
2555 if (status
== RPC_STATUS_ERROR
) {
2556 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2557 free_nfs_cb_data(data
);
2560 if (status
== RPC_STATUS_CANCEL
) {
2561 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2562 free_nfs_cb_data(data
);
2567 if (res
->status
!= NFS3_OK
) {
2568 rpc_set_error(nfs
->rpc
, "NFS: SETATTR failed with %s(%d)", nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2569 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2570 free_nfs_cb_data(data
);
2574 data
->cb(0, nfs
, NULL
, data
->private_data
);
2575 free_nfs_cb_data(data
);
2578 static int nfs_utimes_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2581 struct timeval
*utimes_data
= data
->continue_data
;
2583 memset(&args
, 0, sizeof(SETATTR3args
));
2584 args
.object
.data
.data_len
= data
->fh
.data
.data_len
;
2585 args
.object
.data
.data_val
= data
->fh
.data
.data_val
;
2586 if (utimes_data
!= NULL
) {
2587 args
.new_attributes
.atime
.set_it
= SET_TO_CLIENT_TIME
;
2588 args
.new_attributes
.atime
.set_atime_u
.atime
.seconds
= utimes_data
[0].tv_sec
;
2589 args
.new_attributes
.atime
.set_atime_u
.atime
.nseconds
= utimes_data
[0].tv_usec
* 1000;
2590 args
.new_attributes
.mtime
.set_it
= SET_TO_CLIENT_TIME
;
2591 args
.new_attributes
.mtime
.set_mtime_u
.mtime
.seconds
= utimes_data
[1].tv_sec
;
2592 args
.new_attributes
.mtime
.set_mtime_u
.mtime
.nseconds
= utimes_data
[1].tv_usec
* 1000;
2594 args
.new_attributes
.atime
.set_it
= SET_TO_SERVER_TIME
;
2595 args
.new_attributes
.mtime
.set_it
= SET_TO_SERVER_TIME
;
2598 if (rpc_nfs_setattr_async(nfs
->rpc
, nfs_utimes_cb
, &args
, data
) != 0) {
2599 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SETATTR call for %s", data
->path
);
2600 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2601 free_nfs_cb_data(data
);
2608 int nfs_utimes_async(struct nfs_context
*nfs
, const char *path
, struct timeval
*times
, nfs_cb cb
, void *private_data
)
2610 struct timeval
*new_times
= NULL
;
2612 if (times
!= NULL
) {
2613 new_times
= malloc(sizeof(struct timeval
)*2);
2614 if (new_times
== NULL
) {
2615 rpc_set_error(nfs
->rpc
, "Failed to allocate memory for timeval structure");
2619 memcpy(new_times
, times
, sizeof(struct timeval
)*2);
2622 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_utimes_continue_internal
, new_times
, free
, 0) != 0) {
2623 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2633 int nfs_utime_async(struct nfs_context
*nfs
, const char *path
, struct utimbuf
*times
, nfs_cb cb
, void *private_data
)
2635 struct timeval
*new_times
= NULL
;
2637 if (times
!= NULL
) {
2638 new_times
= malloc(sizeof(struct timeval
)*2);
2639 if (new_times
== NULL
) {
2640 rpc_set_error(nfs
->rpc
, "Failed to allocate memory for timeval structure");
2644 new_times
[0].tv_sec
= times
->actime
;
2645 new_times
[0].tv_usec
= 0;
2646 new_times
[1].tv_sec
= times
->modtime
;
2647 new_times
[1].tv_usec
= 0;
2650 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_utimes_continue_internal
, new_times
, free
, 0) != 0) {
2651 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2665 static void nfs_access_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2668 struct nfs_cb_data
*data
= private_data
;
2669 struct nfs_context
*nfs
= data
->nfs
;
2670 unsigned int nfsmode
= 0;
2672 if (status
== RPC_STATUS_ERROR
) {
2673 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2674 free_nfs_cb_data(data
);
2677 if (status
== RPC_STATUS_CANCEL
) {
2678 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2679 free_nfs_cb_data(data
);
2684 if (res
->status
!= NFS3_OK
) {
2685 rpc_set_error(nfs
->rpc
, "NFS: ACCESS of %s failed with %s(%d)", data
->saved_path
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2686 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2687 free_nfs_cb_data(data
);
2691 if (data
->continue_int
& R_OK
) {
2692 nfsmode
|= ACCESS3_READ
;
2694 if (data
->continue_int
& W_OK
) {
2695 nfsmode
|= ACCESS3_MODIFY
;
2697 if (data
->continue_int
& X_OK
) {
2698 nfsmode
|= ACCESS3_EXECUTE
;
2701 if (res
->ACCESS3res_u
.resok
.access
!= nfsmode
) {
2702 rpc_set_error(nfs
->rpc
, "NFS: ACCESS denied. Required access %c%c%c. Allowed access %c%c%c",
2703 nfsmode
&ACCESS3_READ
?'r':'-',
2704 nfsmode
&ACCESS3_MODIFY
?'w':'-',
2705 nfsmode
&ACCESS3_EXECUTE
?'x':'-',
2706 res
->ACCESS3res_u
.resok
.access
&ACCESS3_READ
?'r':'-',
2707 res
->ACCESS3res_u
.resok
.access
&ACCESS3_MODIFY
?'w':'-',
2708 res
->ACCESS3res_u
.resok
.access
&ACCESS3_EXECUTE
?'x':'-');
2709 data
->cb(-EACCES
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2710 free_nfs_cb_data(data
);
2714 data
->cb(0, nfs
, NULL
, data
->private_data
);
2715 free_nfs_cb_data(data
);
2718 static int nfs_access_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2722 if (data
->continue_int
& R_OK
) {
2723 nfsmode
|= ACCESS3_READ
;
2725 if (data
->continue_int
& W_OK
) {
2726 nfsmode
|= ACCESS3_MODIFY
;
2728 if (data
->continue_int
& X_OK
) {
2729 nfsmode
|= ACCESS3_EXECUTE
;
2732 if (rpc_nfs_access_async(nfs
->rpc
, nfs_access_cb
, &data
->fh
, nfsmode
, data
) != 0) {
2733 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send OPEN ACCESS call for %s", data
->path
);
2734 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2735 free_nfs_cb_data(data
);
2741 int nfs_access_async(struct nfs_context
*nfs
, const char *path
, int mode
, nfs_cb cb
, void *private_data
)
2743 if (nfs_lookuppath_async(nfs
, path
, cb
, private_data
, nfs_access_continue_internal
, NULL
, NULL
, mode
) != 0) {
2744 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2756 struct nfs_symlink_data
{
2758 char *newpathparent
;
2759 char *newpathobject
;
2762 static void free_nfs_symlink_data(void *mem
)
2764 struct nfs_symlink_data
*data
= mem
;
2766 if (data
->oldpath
!= NULL
) {
2767 free(data
->oldpath
);
2769 if (data
->newpathparent
!= NULL
) {
2770 free(data
->newpathparent
);
2772 if (data
->newpathobject
!= NULL
) {
2773 free(data
->newpathobject
);
2778 static void nfs_symlink_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2781 struct nfs_cb_data
*data
= private_data
;
2782 struct nfs_context
*nfs
= data
->nfs
;
2783 struct nfs_symlink_data
*symlink_data
= data
->continue_data
;
2785 if (status
== RPC_STATUS_ERROR
) {
2786 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2787 free_nfs_cb_data(data
);
2790 if (status
== RPC_STATUS_CANCEL
) {
2791 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2792 free_nfs_cb_data(data
);
2797 if (res
->status
!= NFS3_OK
) {
2798 rpc_set_error(nfs
->rpc
, "NFS: SYMLINK %s/%s -> %s failed with %s(%d)", symlink_data
->newpathparent
, symlink_data
->newpathobject
, symlink_data
->oldpath
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2799 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2800 free_nfs_cb_data(data
);
2804 data
->cb(0, nfs
, NULL
, data
->private_data
);
2805 free_nfs_cb_data(data
);
2808 static int nfs_symlink_continue_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2810 struct nfs_symlink_data
*symlink_data
= data
->continue_data
;
2812 if (rpc_nfs_symlink_async(nfs
->rpc
, nfs_symlink_cb
, &data
->fh
, symlink_data
->newpathobject
, symlink_data
->oldpath
, data
) != 0) {
2813 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send SYMLINK call for %s", data
->path
);
2814 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2815 free_nfs_cb_data(data
);
2821 int nfs_symlink_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
)
2824 struct nfs_symlink_data
*symlink_data
;
2826 symlink_data
= malloc(sizeof(struct nfs_symlink_data
));
2827 if (symlink_data
== NULL
) {
2828 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for symlink data");
2831 memset(symlink_data
, 0, sizeof(struct nfs_symlink_data
));
2833 symlink_data
->oldpath
= strdup(oldpath
);
2834 if (symlink_data
->oldpath
== NULL
) {
2835 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for oldpath");
2836 free_nfs_symlink_data(symlink_data
);
2840 symlink_data
->newpathparent
= strdup(newpath
);
2841 if (symlink_data
->newpathparent
== NULL
) {
2842 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for new path");
2843 free_nfs_symlink_data(symlink_data
);
2847 ptr
= strrchr(symlink_data
->newpathparent
, '/');
2849 rpc_set_error(nfs
->rpc
, "Invalid path %s", oldpath
);
2850 free_nfs_symlink_data(symlink_data
);
2856 symlink_data
->newpathobject
= strdup(ptr
);
2857 if (symlink_data
->newpathobject
== NULL
) {
2858 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate mode buffer for new path");
2859 free_nfs_symlink_data(symlink_data
);
2863 if (nfs_lookuppath_async(nfs
, symlink_data
->newpathparent
, cb
, private_data
, nfs_symlink_continue_internal
, symlink_data
, free_nfs_symlink_data
, 0) != 0) {
2864 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
2876 struct nfs_rename_data
{
2879 struct nfs_fh3 olddir
;
2882 struct nfs_fh3 newdir
;
2885 static void free_nfs_rename_data(void *mem
)
2887 struct nfs_rename_data
*data
= mem
;
2889 if (data
->oldpath
!= NULL
) {
2890 free(data
->oldpath
);
2892 if (data
->olddir
.data
.data_val
!= NULL
) {
2893 free(data
->olddir
.data
.data_val
);
2895 if (data
->newpath
!= NULL
) {
2896 free(data
->newpath
);
2898 if (data
->newdir
.data
.data_val
!= NULL
) {
2899 free(data
->newdir
.data
.data_val
);
2904 static void nfs_rename_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
2907 struct nfs_cb_data
*data
= private_data
;
2908 struct nfs_context
*nfs
= data
->nfs
;
2909 struct nfs_rename_data
*rename_data
= data
->continue_data
;
2911 if (status
== RPC_STATUS_ERROR
) {
2912 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
2913 free_nfs_cb_data(data
);
2916 if (status
== RPC_STATUS_CANCEL
) {
2917 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
2918 free_nfs_cb_data(data
);
2923 if (res
->status
!= NFS3_OK
) {
2924 rpc_set_error(nfs
->rpc
, "NFS: RENAME %s/%s -> %s/%s failed with %s(%d)", rename_data
->oldpath
, rename_data
->oldobject
, rename_data
->newpath
, rename_data
->newobject
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
2925 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2926 free_nfs_cb_data(data
);
2930 data
->cb(0, nfs
, NULL
, data
->private_data
);
2931 free_nfs_cb_data(data
);
2934 static int nfs_rename_continue_2_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2936 struct nfs_rename_data
*rename_data
= data
->continue_data
;
2938 /* steal the filehandle */
2939 rename_data
->newdir
.data
.data_len
= data
->fh
.data
.data_len
;
2940 rename_data
->newdir
.data
.data_val
= data
->fh
.data
.data_val
;
2941 data
->fh
.data
.data_val
= NULL
;
2943 if (rpc_nfs_rename_async(nfs
->rpc
, nfs_rename_cb
, &rename_data
->olddir
, rename_data
->oldobject
, &rename_data
->newdir
, rename_data
->newobject
, data
) != 0) {
2944 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send RENAME call for %s", data
->path
);
2945 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2946 free_nfs_cb_data(data
);
2953 static int nfs_rename_continue_1_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
2955 struct nfs_rename_data
*rename_data
= data
->continue_data
;
2957 /* steal the filehandle */
2958 rename_data
->olddir
.data
.data_len
= data
->fh
.data
.data_len
;
2959 rename_data
->olddir
.data
.data_val
= data
->fh
.data
.data_val
;
2960 data
->fh
.data
.data_val
= NULL
;
2962 if (nfs_lookuppath_async(nfs
, rename_data
->newpath
, data
->cb
, data
->private_data
, nfs_rename_continue_2_internal
, rename_data
, free_nfs_rename_data
, 0) != 0) {
2963 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send LOOKUP call for %s", rename_data
->newpath
);
2964 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
2965 free_nfs_cb_data(data
);
2968 data
->continue_data
= NULL
;
2969 free_nfs_cb_data(data
);
2975 int nfs_rename_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
)
2978 struct nfs_rename_data
*rename_data
;
2980 rename_data
= malloc(sizeof(struct nfs_rename_data
));
2981 if (rename_data
== NULL
) {
2982 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for rename data");
2985 memset(rename_data
, 0, sizeof(struct nfs_rename_data
));
2987 rename_data
->oldpath
= strdup(oldpath
);
2988 if (rename_data
->oldpath
== NULL
) {
2989 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for oldpath");
2990 free_nfs_rename_data(rename_data
);
2993 ptr
= strrchr(rename_data
->oldpath
, '/');
2995 rpc_set_error(nfs
->rpc
, "Invalid path %s", oldpath
);
2996 free_nfs_rename_data(rename_data
);
3001 rename_data
->oldobject
= ptr
;
3004 rename_data
->newpath
= strdup(newpath
);
3005 if (rename_data
->newpath
== NULL
) {
3006 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for newpath");
3007 free_nfs_rename_data(rename_data
);
3010 ptr
= strrchr(rename_data
->newpath
, '/');
3012 rpc_set_error(nfs
->rpc
, "Invalid path %s", newpath
);
3013 free_nfs_rename_data(rename_data
);
3018 rename_data
->newobject
= ptr
;
3021 if (nfs_lookuppath_async(nfs
, rename_data
->oldpath
, cb
, private_data
, nfs_rename_continue_1_internal
, rename_data
, free_nfs_rename_data
, 0) != 0) {
3022 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
3033 struct nfs_link_data
{
3035 struct nfs_fh3 oldfh
;
3038 struct nfs_fh3 newdir
;
3041 static void free_nfs_link_data(void *mem
)
3043 struct nfs_link_data
*data
= mem
;
3045 if (data
->oldpath
!= NULL
) {
3046 free(data
->oldpath
);
3048 if (data
->oldfh
.data
.data_val
!= NULL
) {
3049 free(data
->oldfh
.data
.data_val
);
3051 if (data
->newpath
!= NULL
) {
3052 free(data
->newpath
);
3054 if (data
->newdir
.data
.data_val
!= NULL
) {
3055 free(data
->newdir
.data
.data_val
);
3060 static void nfs_link_cb(struct rpc_context
*rpc _U_
, int status
, void *command_data
, void *private_data
)
3063 struct nfs_cb_data
*data
= private_data
;
3064 struct nfs_context
*nfs
= data
->nfs
;
3065 struct nfs_link_data
*link_data
= data
->continue_data
;
3067 if (status
== RPC_STATUS_ERROR
) {
3068 data
->cb(-EFAULT
, nfs
, command_data
, data
->private_data
);
3069 free_nfs_cb_data(data
);
3072 if (status
== RPC_STATUS_CANCEL
) {
3073 data
->cb(-EINTR
, nfs
, "Command was cancelled", data
->private_data
);
3074 free_nfs_cb_data(data
);
3079 if (res
->status
!= NFS3_OK
) {
3080 rpc_set_error(nfs
->rpc
, "NFS: LINK %s -> %s/%s failed with %s(%d)", link_data
->oldpath
, link_data
->newpath
, link_data
->newobject
, nfsstat3_to_str(res
->status
), nfsstat3_to_errno(res
->status
));
3081 data
->cb(nfsstat3_to_errno(res
->status
), nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
3082 free_nfs_cb_data(data
);
3086 data
->cb(0, nfs
, NULL
, data
->private_data
);
3087 free_nfs_cb_data(data
);
3090 static int nfs_link_continue_2_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
3092 struct nfs_link_data
*link_data
= data
->continue_data
;
3094 /* steal the filehandle */
3095 link_data
->newdir
.data
.data_len
= data
->fh
.data
.data_len
;
3096 link_data
->newdir
.data
.data_val
= data
->fh
.data
.data_val
;
3097 data
->fh
.data
.data_val
= NULL
;
3099 if (rpc_nfs_link_async(nfs
->rpc
, nfs_link_cb
, &link_data
->oldfh
, &link_data
->newdir
, link_data
->newobject
, data
) != 0) {
3100 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send LINK call for %s", data
->path
);
3101 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
3102 free_nfs_cb_data(data
);
3109 static int nfs_link_continue_1_internal(struct nfs_context
*nfs
, struct nfs_cb_data
*data
)
3111 struct nfs_link_data
*link_data
= data
->continue_data
;
3113 /* steal the filehandle */
3114 link_data
->oldfh
.data
.data_len
= data
->fh
.data
.data_len
;
3115 link_data
->oldfh
.data
.data_val
= data
->fh
.data
.data_val
;
3116 data
->fh
.data
.data_val
= NULL
;
3118 if (nfs_lookuppath_async(nfs
, link_data
->newpath
, data
->cb
, data
->private_data
, nfs_link_continue_2_internal
, link_data
, free_nfs_link_data
, 0) != 0) {
3119 rpc_set_error(nfs
->rpc
, "RPC error: Failed to send LOOKUP call for %s", link_data
->newpath
);
3120 data
->cb(-ENOMEM
, nfs
, rpc_get_error(nfs
->rpc
), data
->private_data
);
3121 free_nfs_cb_data(data
);
3124 data
->continue_data
= NULL
;
3125 free_nfs_cb_data(data
);
3131 int nfs_link_async(struct nfs_context
*nfs
, const char *oldpath
, const char *newpath
, nfs_cb cb
, void *private_data
)
3134 struct nfs_link_data
*link_data
;
3136 link_data
= malloc(sizeof(struct nfs_link_data
));
3137 if (link_data
== NULL
) {
3138 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for link data");
3141 memset(link_data
, 0, sizeof(struct nfs_link_data
));
3143 link_data
->oldpath
= strdup(oldpath
);
3144 if (link_data
->oldpath
== NULL
) {
3145 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for oldpath");
3146 free_nfs_link_data(link_data
);
3150 link_data
->newpath
= strdup(newpath
);
3151 if (link_data
->newpath
== NULL
) {
3152 rpc_set_error(nfs
->rpc
, "Out of memory, failed to allocate buffer for newpath");
3153 free_nfs_link_data(link_data
);
3156 ptr
= strrchr(link_data
->newpath
, '/');
3158 rpc_set_error(nfs
->rpc
, "Invalid path %s", newpath
);
3159 free_nfs_link_data(link_data
);
3164 link_data
->newobject
= ptr
;
3167 if (nfs_lookuppath_async(nfs
, link_data
->oldpath
, cb
, private_data
, nfs_link_continue_1_internal
, link_data
, free_nfs_link_data
, 0) != 0) {
3168 rpc_set_error(nfs
->rpc
, "Out of memory: failed to start parsing the path components");
3176 //qqq replace later with lseek()
3177 off_t
nfs_get_current_offset(struct nfsfh
*nfsfh
)
3179 return nfsfh
->offset
;
3185 * Get the maximum supported READ3 size by the server
3187 size_t nfs_get_readmax(struct nfs_context
*nfs
)
3189 return nfs
->readmax
;
3193 * Get the maximum supported WRITE3 size by the server
3195 size_t nfs_get_writemax(struct nfs_context
*nfs
)
3197 /* Some XDR libraries can not marshall PDUs bigger than this */
3198 if (nfs
->writemax
< 32768) {
3199 return nfs
->writemax
;
3204 void nfs_set_error(struct nfs_context
*nfs
, char *error_string
, ...)
3209 va_start(ap
, error_string
);
3211 vsnprintf(str
, 1024, error_string
, ap
);
3212 if (nfs
->rpc
->error_string
!= NULL
) {
3213 free(nfs
->rpc
->error_string
);
3215 nfs
->rpc
->error_string
= str
;
3221 struct mount_cb_data
{
3227 static void free_mount_cb_data(struct mount_cb_data
*data
)
3229 if (data
->server
!= NULL
) {
3231 data
->server
= NULL
;
3237 static void mount_export_5_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
3239 struct mount_cb_data
*data
= private_data
;
3241 if (status
== RPC_STATUS_ERROR
) {
3242 data
->cb(rpc
, -EFAULT
, command_data
, data
->private_data
);
3243 free_mount_cb_data(data
);
3246 if (status
== RPC_STATUS_CANCEL
) {
3247 data
->cb(rpc
, -EINTR
, "Command was cancelled", data
->private_data
);
3248 free_mount_cb_data(data
);
3252 data
->cb(rpc
, 0, command_data
, data
->private_data
);
3253 if (rpc_disconnect(rpc
, "normal disconnect") != 0) {
3254 rpc_set_error(rpc
, "Failed to disconnect\n");
3256 free_mount_cb_data(data
);
3259 static void mount_export_4_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
3261 struct mount_cb_data
*data
= private_data
;
3263 if (status
== RPC_STATUS_ERROR
) {
3264 data
->cb(rpc
, -EFAULT
, command_data
, data
->private_data
);
3265 free_mount_cb_data(data
);
3268 if (status
== RPC_STATUS_CANCEL
) {
3269 data
->cb(rpc
, -EINTR
, "Command was cancelled", data
->private_data
);
3270 free_mount_cb_data(data
);
3274 if (rpc_mount_export_async(rpc
, mount_export_5_cb
, data
) != 0) {
3275 data
->cb(rpc
, -ENOMEM
, command_data
, data
->private_data
);
3276 free_mount_cb_data(data
);
3281 static void mount_export_3_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
3283 struct mount_cb_data
*data
= private_data
;
3284 uint32_t mount_port
;
3286 if (status
== RPC_STATUS_ERROR
) {
3287 data
->cb(rpc
, -EFAULT
, command_data
, data
->private_data
);
3288 free_mount_cb_data(data
);
3291 if (status
== RPC_STATUS_CANCEL
) {
3292 data
->cb(rpc
, -EINTR
, "Command was cancelled", data
->private_data
);
3293 free_mount_cb_data(data
);
3297 mount_port
= *(uint32_t *)command_data
;
3298 if (mount_port
== 0) {
3299 rpc_set_error(rpc
, "RPC error. Mount program is not available");
3300 data
->cb(rpc
, -ENOENT
, command_data
, data
->private_data
);
3301 free_mount_cb_data(data
);
3305 rpc_disconnect(rpc
, "normal disconnect");
3306 if (rpc_connect_async(rpc
, data
->server
, mount_port
, mount_export_4_cb
, data
) != 0) {
3307 data
->cb(rpc
, -ENOMEM
, command_data
, data
->private_data
);
3308 free_mount_cb_data(data
);
3313 static void mount_export_2_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
3315 struct mount_cb_data
*data
= private_data
;
3317 if (status
== RPC_STATUS_ERROR
) {
3318 data
->cb(rpc
, -EFAULT
, command_data
, data
->private_data
);
3319 free_mount_cb_data(data
);
3322 if (status
== RPC_STATUS_CANCEL
) {
3323 data
->cb(rpc
, -EINTR
, "Command was cancelled", data
->private_data
);
3324 free_mount_cb_data(data
);
3328 if (rpc_pmap_getport_async(rpc
, MOUNT_PROGRAM
, MOUNT_V3
, mount_export_3_cb
, private_data
) != 0) {
3329 data
->cb(rpc
, -ENOMEM
, command_data
, data
->private_data
);
3330 free_mount_cb_data(data
);
3335 static void mount_export_1_cb(struct rpc_context
*rpc
, int status
, void *command_data
, void *private_data
)
3337 struct mount_cb_data
*data
= private_data
;
3339 if (status
== RPC_STATUS_ERROR
) {
3340 data
->cb(rpc
, -EFAULT
, command_data
, data
->private_data
);
3341 free_mount_cb_data(data
);
3344 if (status
== RPC_STATUS_CANCEL
) {
3345 data
->cb(rpc
, -EINTR
, "Command was cancelled", data
->private_data
);
3346 free_mount_cb_data(data
);
3350 if (rpc_pmap_null_async(rpc
, mount_export_2_cb
, data
) != 0) {
3351 data
->cb(rpc
, -ENOMEM
, command_data
, data
->private_data
);
3352 free_mount_cb_data(data
);
3357 int mount_getexports_async(struct rpc_context
*rpc
, const char *server
, rpc_cb cb
, void *private_data
)
3359 struct mount_cb_data
*data
;
3361 data
= malloc(sizeof(struct mount_cb_data
));
3365 memset(data
, 0, sizeof(struct mount_cb_data
));
3367 data
->private_data
= private_data
;
3368 data
->server
= strdup(server
);
3369 if (data
->server
== NULL
) {
3370 free_mount_cb_data(data
);
3373 if (rpc_connect_async(rpc
, data
->server
, 111, mount_export_1_cb
, data
) != 0) {
3374 free_mount_cb_data(data
);
3381 struct rpc_context
*nfs_get_rpc_context(struct nfs_context
*nfs
)
3386 const char *nfs_get_server(struct nfs_context
*nfs
) {
3390 const char *nfs_get_export(struct nfs_context
*nfs
) {