+ memset(data, 0, sizeof(struct nfs_cb_data));
+ data->nfs = nfs;
+ data->cb = cb;
+ data->continue_cb = continue_cb;
+ data->continue_data = continue_data;
+ data->free_continue_data = free_continue_data;
+ data->continue_int = continue_int;
+ data->private_data = private_data;
+ data->no_follow = no_follow;
+ if (path[0] == '/') {
+ data->saved_path = strdup(path);
+ } else {
+ data->saved_path = malloc(strlen(path) + strlen(nfs->cwd) + 2);
+ if (data->saved_path == NULL) {
+ rpc_set_error(nfs->rpc, "out of memory: failed to "
+ "malloc path string");
+ free_nfs_cb_data(data);
+ return -1;
+ }
+ sprintf(data->saved_path, "%s/%s", nfs->cwd, path);
+ }
+
+ if (data->saved_path == NULL) {
+ rpc_set_error(nfs->rpc, "out of memory: failed to copy path string");
+ free_nfs_cb_data(data);
+ return -1;
+ }
+ if (nfs_normalize_path(nfs, data->saved_path) != 0) {
+ free_nfs_cb_data(data);
+ return -1;
+ }
+
+ data->path = data->saved_path;
+ if (data->path[0]) {
+ /* This function will always invoke the callback and cleanup
+ * for failures. So no need to check the return value.
+ */
+ nfs_lookup_path_async_internal(nfs, NULL, data, &nfs->rootfh);
+ return 0;
+ }
+
+ /* We have a request for "", so just perform a GETATTR3 so we can
+ * return the attributes to the caller.
+ */
+ memset(&args, 0, sizeof(GETATTR3args));
+ args.object = nfs->rootfh;
+ if (rpc_nfs3_getattr_async(nfs->rpc, nfs_lookup_path_getattr_cb, &args, data) != 0) {
+ free_nfs_cb_data(data);
+ return -1;
+ }
+ return 0;
+}
+
+
+/*
+ * Async stat()
+ */
+static dev_t specdata3_to_rdev(struct specdata3 *rdev)
+{
+#ifdef makedev
+ return makedev(rdev->specdata1, rdev->specdata2);
+#else
+ return 0;
+#endif
+}
+
+static void nfs_stat_1_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ GETATTR3res *res;
+ struct nfs_cb_data *data = private_data;
+ struct nfs_context *nfs = data->nfs;
+#ifdef WIN32
+ struct __stat64 st;
+#else
+ struct stat st;
+#endif
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(-EFAULT, nfs, command_data, data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(-EINTR, nfs, "Command was cancelled", data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+
+ res = command_data;
+ if (res->status != NFS3_OK) {
+ 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));
+ data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+
+ st.st_dev = res->GETATTR3res_u.resok.obj_attributes.fsid;
+ st.st_ino = res->GETATTR3res_u.resok.obj_attributes.fileid;
+ st.st_mode = res->GETATTR3res_u.resok.obj_attributes.mode;
+ switch (res->GETATTR3res_u.resok.obj_attributes.type) {
+ case NF3REG:
+ st.st_mode |= S_IFREG;
+ break;
+ case NF3DIR:
+ st.st_mode |= S_IFDIR;
+ break;
+ case NF3BLK:
+ st.st_mode |= S_IFBLK;
+ break;
+ case NF3CHR:
+ st.st_mode |= S_IFCHR;
+ break;
+ case NF3LNK:
+ st.st_mode |= S_IFLNK;
+ break;
+ case NF3SOCK:
+ st.st_mode |= S_IFSOCK;
+ break;
+ case NF3FIFO:
+ st.st_mode |= S_IFIFO;
+ break;
+ }
+ st.st_nlink = res->GETATTR3res_u.resok.obj_attributes.nlink;
+ st.st_uid = res->GETATTR3res_u.resok.obj_attributes.uid;
+ st.st_gid = res->GETATTR3res_u.resok.obj_attributes.gid;
+ st.st_rdev = specdata3_to_rdev(&res->GETATTR3res_u.resok.obj_attributes.rdev);
+ st.st_size = res->GETATTR3res_u.resok.obj_attributes.size;
+#ifndef WIN32
+ st.st_blksize = NFS_BLKSIZE;
+ st.st_blocks = (res->GETATTR3res_u.resok.obj_attributes.used + 512 - 1) / 512;
+#endif//WIN32
+ st.st_atime = res->GETATTR3res_u.resok.obj_attributes.atime.seconds;
+ st.st_mtime = res->GETATTR3res_u.resok.obj_attributes.mtime.seconds;
+ st.st_ctime = res->GETATTR3res_u.resok.obj_attributes.ctime.seconds;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
+ st.st_atim.tv_nsec = res->GETATTR3res_u.resok.obj_attributes.atime.nseconds;
+ st.st_mtim.tv_nsec = res->GETATTR3res_u.resok.obj_attributes.mtime.nseconds;
+ st.st_ctim.tv_nsec = res->GETATTR3res_u.resok.obj_attributes.ctime.nseconds;
+#endif
+
+ data->cb(0, nfs, &st, data->private_data);
+ free_nfs_cb_data(data);
+}
+
+static int nfs_stat_continue_internal(struct nfs_context *nfs, fattr3 *attr _U_, struct nfs_cb_data *data)
+{
+ struct GETATTR3args args;
+
+ memset(&args, 0, sizeof(GETATTR3args));
+ args.object = data->fh;
+
+ if (rpc_nfs3_getattr_async(nfs->rpc, nfs_stat_1_cb, &args, data) != 0) {
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send STAT GETATTR call for %s", data->path);
+ data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+ free_nfs_cb_data(data);
+ return -1;
+ }
+ return 0;
+}
+
+int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data)
+{
+ if (nfs_lookuppath_async(nfs, path, 0, cb, private_data, nfs_stat_continue_internal, NULL, NULL, 0) != 0) {
+ rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/*
+ * Async nfs_stat64()
+ */
+static void nfs_stat64_1_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ GETATTR3res *res;
+ struct nfs_cb_data *data = private_data;
+ struct nfs_context *nfs = data->nfs;
+ struct nfs_stat_64 st;
+
+ assert(rpc->magic == RPC_CONTEXT_MAGIC);
+
+ if (status == RPC_STATUS_ERROR) {
+ data->cb(-EFAULT, nfs, command_data, data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+ if (status == RPC_STATUS_CANCEL) {
+ data->cb(-EINTR, nfs, "Command was cancelled", data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+
+ res = command_data;
+ if (res->status != NFS3_OK) {
+ 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));
+ data->cb(nfsstat3_to_errno(res->status), nfs, rpc_get_error(nfs->rpc), data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+
+ st.nfs_dev = res->GETATTR3res_u.resok.obj_attributes.fsid;
+ st.nfs_ino = res->GETATTR3res_u.resok.obj_attributes.fileid;
+ st.nfs_mode = res->GETATTR3res_u.resok.obj_attributes.mode;
+ switch (res->GETATTR3res_u.resok.obj_attributes.type) {
+ case NF3REG:
+ st.nfs_mode |= S_IFREG;
+ break;
+ case NF3DIR:
+ st.nfs_mode |= S_IFDIR;
+ break;
+ case NF3BLK:
+ st.nfs_mode |= S_IFBLK;
+ break;
+ case NF3CHR:
+ st.nfs_mode |= S_IFCHR;
+ break;
+ case NF3LNK:
+ st.nfs_mode |= S_IFLNK;
+ break;
+ case NF3SOCK:
+ st.nfs_mode |= S_IFSOCK;
+ break;
+ case NF3FIFO:
+ st.nfs_mode |= S_IFIFO;
+ break;
+ }
+ st.nfs_nlink = res->GETATTR3res_u.resok.obj_attributes.nlink;
+ st.nfs_uid = res->GETATTR3res_u.resok.obj_attributes.uid;
+ st.nfs_gid = res->GETATTR3res_u.resok.obj_attributes.gid;
+ st.nfs_rdev = specdata3_to_rdev(&res->GETATTR3res_u.resok.obj_attributes.rdev);
+ st.nfs_size = res->GETATTR3res_u.resok.obj_attributes.size;
+ st.nfs_blksize = NFS_BLKSIZE;
+ st.nfs_blocks = (res->GETATTR3res_u.resok.obj_attributes.used + 512 - 1) / 512;
+ st.nfs_atime = res->GETATTR3res_u.resok.obj_attributes.atime.seconds;
+ st.nfs_mtime = res->GETATTR3res_u.resok.obj_attributes.mtime.seconds;
+ st.nfs_ctime = res->GETATTR3res_u.resok.obj_attributes.ctime.seconds;
+ st.nfs_atime_nsec = res->GETATTR3res_u.resok.obj_attributes.atime.nseconds;
+ st.nfs_mtime_nsec = res->GETATTR3res_u.resok.obj_attributes.mtime.nseconds;
+ st.nfs_ctime_nsec = res->GETATTR3res_u.resok.obj_attributes.ctime.nseconds;
+ st.nfs_used = res->GETATTR3res_u.resok.obj_attributes.used;
+
+ data->cb(0, nfs, &st, data->private_data);
+ free_nfs_cb_data(data);
+}
+
+static int nfs_stat64_continue_internal(struct nfs_context *nfs, fattr3 *attr _U_, struct nfs_cb_data *data)
+{
+ struct GETATTR3args args;
+
+ memset(&args, 0, sizeof(GETATTR3args));
+ args.object = data->fh;
+
+ if (rpc_nfs3_getattr_async(nfs->rpc, nfs_stat64_1_cb, &args, data) != 0) {
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send STAT GETATTR call for %s", data->path);
+ data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+ free_nfs_cb_data(data);
+ return -1;
+ }
+ return 0;
+}
+
+int nfs_stat64_async_internal(struct nfs_context *nfs, const char *path, int no_follow, nfs_cb cb, void *private_data)
+{
+ if (nfs_lookuppath_async(nfs, path, no_follow, cb, private_data, nfs_stat64_continue_internal, NULL, NULL, 0) != 0) {
+ rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
+ return -1;
+ }
+
+ return 0;
+}
+
+int nfs_stat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data)
+{
+ return nfs_stat64_async_internal(nfs, path, 0, cb, private_data);
+}
+
+int nfs_lstat64_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data)
+{
+ return nfs_stat64_async_internal(nfs, path, 1, cb, private_data);
+}
+
+/*
+ * Async open()