static int nfs_lookup_path_async_internal(struct nfs_context *nfs, struct nfs_cb_data *data, struct nfs_fh3 *fh);
-
void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth)
{
rpc_set_auth(nfs->rpc, auth);
assert(rpc->magic == RPC_CONTEXT_MAGIC);
- if (status == RPC_STATUS_ERROR) {
+ if (status == RPC_STATUS_ERROR) {
data->cb(rpc, status, command_data, data->private_data);
free_rpc_cb_data(data);
return;
return 0;
}
-void free_nfs_cb_data(struct nfs_cb_data *data)
+static void free_nfs_cb_data(struct nfs_cb_data *data)
{
- if (data->saved_path != NULL) {
- free(data->saved_path);
- data->saved_path = NULL;
- }
-
if (data->continue_data != NULL) {
+ assert(data->free_continue_data);
data->free_continue_data(data->continue_data);
- data->continue_data = NULL;
}
- if (data->fh.data.data_val != NULL) {
- free(data->fh.data.data_val);
- data->fh.data.data_val = NULL;
- }
-
- if (data->buffer != NULL) {
- free(data->buffer);
- data->buffer = NULL;
- }
+ free(data->saved_path);
+ free(data->fh.data.data_val);
+ free(data->buffer);
free(data);
}
assert(rpc->magic == RPC_CONTEXT_MAGIC);
- if (status == RPC_STATUS_ERROR) {
+ if (status == RPC_STATUS_ERROR) {
data->cb(-EFAULT, nfs, command_data, data->private_data);
free_nfs_cb_data(data);
return;
int len;
/* // -> / */
- while (str = strstr(path, "//")) {
+ while ((str = strstr(path, "//"))) {
while(*str) {
*str = *(str + 1);
str++;
}
/* /./ -> / */
- while (str = strstr(path, "/./")) {
+ while ((str = strstr(path, "/./"))) {
while(*(str + 1)) {
*str = *(str + 2);
str++;
}
/* /string/../ -> / */
- while (str = strstr(path, "/../")) {
+ while ((str = strstr(path, "/../"))) {
char *tmp;
if (!strncmp(path, "/../", 4)) {
char *tmp = &path[len - 3];
while (*--tmp != '/')
;
- *tmp = '\0';
+ *tmp = '\0';
}
}
if (data == NULL) {
rpc_set_error(nfs->rpc, "out of memory: failed to allocate "
"nfs_cb_data structure");
+ if (free_continue_data)
+ free_continue_data(continue_data);
return -1;
}
memset(data, 0, sizeof(struct nfs_cb_data));
#ifndef WIN32
st.st_blksize = 4096;
st.st_blocks = res->GETATTR3res_u.resok.obj_attributes.size / 4096;
-#endif//WIN32
+#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;
/*
* Async open()
*/
+static void nfs_open_trunc_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
+{
+ struct nfs_cb_data *data = private_data;
+ struct nfs_context *nfs = data->nfs;
+ struct nfsfh *nfsfh;
+ SETATTR3res *res;
+
+ 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: Setattr failed with %s(%d)", 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;
+ }
+
+ nfsfh = malloc(sizeof(struct nfsfh));
+ if (nfsfh == NULL) {
+ rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure");
+ data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+ memset(nfsfh, 0, sizeof(struct nfsfh));
+
+ if (data->continue_int & O_SYNC) {
+ nfsfh->is_sync = 1;
+ }
+
+ /* steal the filehandle */
+ nfsfh->fh = data->fh;
+ data->fh.data.data_val = NULL;
+
+ data->cb(0, nfs, nfsfh, data->private_data);
+ free_nfs_cb_data(data);
+}
+
static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
{
ACCESS3res *res;
return;
}
+ /* Try to truncate it if we were requested to */
+ if ((data->continue_int & O_TRUNC) &&
+ (data->continue_int & (O_RDWR|O_WRONLY))) {
+ SETATTR3args args;
+
+ memset(&args, 0, sizeof(SETATTR3args));
+ args.object = data->fh;
+ args.new_attributes.size.set_it = 1;
+ args.new_attributes.size.set_size3_u.size = 0;
+
+ if (rpc_nfs3_setattr_async(nfs->rpc, nfs_open_trunc_cb, &args,
+ data) != 0) {
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send "
+ "SETATTR call for %s", data->path);
+ data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc),
+ data->private_data);
+ free_nfs_cb_data(data);
+ return;
+ }
+ return;
+ }
+
nfsfh = malloc(sizeof(struct nfsfh));
if (nfsfh == NULL) {
rpc_set_error(nfs->rpc, "NFS: Failed to allocate nfsfh structure");
args.access = nfsmode;
if (rpc_nfs3_access_async(nfs->rpc, nfs_open_cb, &args, data) != 0) {
- rpc_set_error(nfs->rpc, "RPC error: Failed to send OPEN ACCESS call for %s", data->path);
- data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+ rpc_set_error(nfs->rpc, "RPC error: Failed to send OPEN ACCESS "
+ "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_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data)
+int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data)
{
- if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_open_continue_internal, NULL, NULL, mode) != 0) {
+ if (nfs_lookuppath_async(nfs, path, cb, private_data, nfs_open_continue_internal, NULL, NULL, flags) != 0) {
rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
return -1;
}
/*
* close
*/
-
+
int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data)
{
if (nfsfh->fh.data.data_val != NULL){
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
char *str = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
str = &str[strlen(str) + 1];
ptr = strrchr(new_path, '/');
if (ptr == NULL) {
+ free(new_path);
rpc_set_error(nfs->rpc, "Invalid path %s", path);
return -1;
}
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
char *str = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
str = &str[strlen(str) + 1];
ptr = strrchr(new_path, '/');
if (ptr == NULL) {
+ free(new_path);
rpc_set_error(nfs->rpc, "Invalid path %s", path);
return -1;
}
ptr = strrchr(new_path, '/');
if (ptr == NULL) {
rpc_set_error(nfs->rpc, "Invalid path %s", path);
+ free(new_path);
return -1;
}
*ptr = 0;
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
char *str = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
str = &str[strlen(str) + 1];
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
char *str = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
str = &str[strlen(str) + 1];
struct mknod_cb_data *cb_data = data->continue_data;
char *str = cb_data->path;
MKNOD3args args;
-
+
str = &str[strlen(str) + 1];
args.where.dir = data->fh;
cb_data->path = strdup(path);
if (cb_data->path == NULL) {
rpc_set_error(nfs->rpc, "Out of memory, failed to allocate mode buffer for path");
- free(cb_data);
+ free(cb_data);
return -1;
}
ptr = strrchr(cb_data->path, '/');
if (ptr == NULL) {
rpc_set_error(nfs->rpc, "Invalid path %s", path);
+ free_mknod_cb_data(cb_data);
return -1;
}
*ptr = 0;
/* data->path now points to the parent directory, and beyond the nul terminateor is the new directory to create */
if (nfs_lookuppath_async(nfs, cb_data->path, cb, private_data, nfs_mknod_continue_internal, cb_data, free_mknod_cb_data, 0) != 0) {
rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
- free_mknod_cb_data(cb_data);
return -1;
}
struct entry3 *entry;
uint64_t cookie = 0;
struct rdpe_cb_data *rdpe_cb_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (status == RPC_STATUS_ERROR) {
nfsdirent->name = strdup(entry->name);
if (nfsdirent->name == NULL) {
data->cb(-ENOMEM, nfs, "Failed to allocate dirent->name", data->private_data);
+ free(nfsdirent);
nfs_free_nfsdir(nfsdir);
data->continue_data = NULL;
free_nfs_cb_data(data);
* commands in flight to complete
*/
if (rdpe_cb_data->getattrcount > 0) {
+ nfs_free_nfsdir(nfsdir);
+ data->continue_data = NULL;
+ free_nfs_cb_data(data);
rdpe_cb_data->status = RPC_STATUS_ERROR;
free(rdpe_lookup_cb_data);
return;
}
}
-
static void nfs_opendir_cb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
{
READDIRPLUS3res *res = command_data;
struct nfsdir *nfsdir = data->continue_data;
struct entryplus3 *entry;
uint64_t cookie = 0;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (status == RPC_STATUS_ERROR || (status == RPC_STATUS_SUCCESS && res->status == NFS3ERR_NOTSUPP) ){
nfsdirent->name = strdup(entry->name);
if (nfsdirent->name == NULL) {
data->cb(-ENOMEM, nfs, "Failed to allocate dirent->name", data->private_data);
+ free(nfsdirent);
nfs_free_nfsdir(nfsdir);
data->continue_data = NULL;
free_nfs_cb_data(data);
return;
}
-
+
data->cb(0, nfs, res->READLINK3res_u.resok.data, data->private_data);
free_nfs_cb_data(data);
}
memcpy(data->fh.data.data_val, nfsfh->fh.data.data_val, data->fh.data.data_len);
if (nfs_chmod_continue_internal(nfs, data) != 0) {
- free_nfs_cb_data(data);
return -1;
}
chown_data->uid = uid;
chown_data->gid = gid;
-
data = malloc(sizeof(struct nfs_cb_data));
if (data == NULL) {
rpc_set_error(nfs->rpc, "out of memory. failed to allocate memory for fchown data");
+ free(chown_data);
return -1;
}
memset(data, 0, sizeof(struct nfs_cb_data));
data->cb = cb;
data->private_data = private_data;
data->continue_data = chown_data;
+ data->free_continue_data = free;
data->fh.data.data_len = nfsfh->fh.data.data_len;
data->fh.data.data_val = malloc(data->fh.data.data_len);
if (data->fh.data.data_val == NULL) {
}
memcpy(data->fh.data.data_val, nfsfh->fh.data.data_val, data->fh.data.data_len);
-
if (nfs_chown_continue_internal(nfs, data) != 0) {
- free_nfs_cb_data(data);
return -1;
}
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
struct nfs_symlink_data *symlink_data = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (status == RPC_STATUS_ERROR) {
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
struct nfs_rename_data *rename_data = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (status == RPC_STATUS_ERROR) {
struct nfs_cb_data *data = private_data;
struct nfs_context *nfs = data->nfs;
struct nfs_link_data *link_data = data->continue_data;
-
+
assert(rpc->magic == RPC_CONTEXT_MAGIC);
if (status == RPC_STATUS_ERROR) {
/* Dont want any more callbacks even if the socket is closed */
rpc->connect_cb = NULL;
- if (status == RPC_STATUS_ERROR) {
+ if (status == RPC_STATUS_ERROR) {
data->cb(rpc, -EFAULT, command_data, data->private_data);
free_mount_cb_data(data);
return;
if (data->server == NULL) {
free_mount_cb_data(data);
return -1;
- }
+ }
if (rpc_connect_async(rpc, data->server, 111, mount_export_1_cb, data) != 0) {
free_mount_cb_data(data);
return -1;