X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lib%2Flibnfs.c;h=6e7cd214a3fefa3d47244048c1fc0db2c19cc674;hb=e59193c9f9ee42265eabd92a8b20e81c6eac2776;hp=c2c20d4481b20945e8f30e3f8b2f28aef020a2bb;hpb=22a0f15bee336aadddd53fa58fa27ff5a890672b;p=deb_libnfs.git diff --git a/lib/libnfs.c b/lib/libnfs.c index c2c20d4..6e7cd21 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -422,7 +422,7 @@ static void rpc_connect_program_3_cb(struct rpc_context *rpc, int status, void * 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; @@ -774,7 +774,7 @@ static void nfs_mount_3_cb(struct rpc_context *rpc, int status, void *command_da 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; @@ -999,7 +999,7 @@ static int nfs_normalize_path(struct nfs_context *nfs, char *path) int len; /* // -> / */ - while (str = strstr(path, "//")) { + while ((str = strstr(path, "//"))) { while(*str) { *str = *(str + 1); str++; @@ -1007,7 +1007,7 @@ static int nfs_normalize_path(struct nfs_context *nfs, char *path) } /* /./ -> / */ - while (str = strstr(path, "/./")) { + while ((str = strstr(path, "/./"))) { while(*(str + 1)) { *str = *(str + 2); str++; @@ -1030,7 +1030,7 @@ static int nfs_normalize_path(struct nfs_context *nfs, char *path) } /* /string/../ -> / */ - while (str = strstr(path, "/../")) { + while ((str = strstr(path, "/../"))) { char *tmp; if (!strncmp(path, "/../", 4)) { @@ -1086,7 +1086,7 @@ static int nfs_normalize_path(struct nfs_context *nfs, char *path) char *tmp = &path[len - 3]; while (*--tmp != '/') ; - *tmp = '\0'; + *tmp = '\0'; } } @@ -1105,6 +1105,8 @@ static int nfs_lookuppath_async(struct nfs_context *nfs, const char *path, nfs_c 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)); @@ -1203,7 +1205,7 @@ static void nfs_stat_1_cb(struct rpc_context *rpc, int status, void *command_dat #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; @@ -1247,6 +1249,7 @@ static void nfs_open_trunc_cb(struct rpc_context *rpc, int status, void *command { struct nfs_cb_data *data = private_data; struct nfs_context *nfs = data->nfs; + struct nfsfh *nfsfh; SETATTR3res *res; assert(rpc->magic == RPC_CONTEXT_MAGIC); @@ -1270,7 +1273,24 @@ static void nfs_open_trunc_cb(struct rpc_context *rpc, int status, void *command return; } - data->cb(0, nfs, NULL, data->private_data); + 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); } @@ -1327,30 +1347,13 @@ static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_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; - /* 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 = nfsfh->fh; + args.object = data->fh; args.new_attributes.size.set_it = 1; args.new_attributes.size.set_size3_u.size = 0; @@ -1366,6 +1369,23 @@ static void nfs_open_cb(struct rpc_context *rpc, int status, void *command_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); } @@ -1829,7 +1849,7 @@ int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t count /* * 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){ @@ -2052,7 +2072,7 @@ static void nfs_mkdir_cb(struct rpc_context *rpc, int status, void *command_data 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]; @@ -2142,7 +2162,7 @@ static void nfs_rmdir_cb(struct rpc_context *rpc, int status, void *command_data 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]; @@ -2376,7 +2396,7 @@ static void nfs_unlink_cb(struct rpc_context *rpc, int status, void *command_dat 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]; @@ -2474,7 +2494,7 @@ static void nfs_mknod_cb(struct rpc_context *rpc, int status, void *command_data 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]; @@ -2507,7 +2527,7 @@ static int nfs_mknod_continue_internal(struct nfs_context *nfs, struct nfs_cb_da 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; @@ -2565,7 +2585,7 @@ int nfs_mknod_async(struct nfs_context *nfs, const char *path, int mode, int dev 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; } @@ -2676,7 +2696,7 @@ static void nfs_opendir2_cb(struct rpc_context *rpc, int status, void *command_d 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) { @@ -2803,7 +2823,7 @@ static void nfs_opendir_cb(struct rpc_context *rpc, int status, void *command_da 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) ){ @@ -2858,6 +2878,7 @@ static void nfs_opendir_cb(struct rpc_context *rpc, int status, void *command_da 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); @@ -3174,7 +3195,7 @@ static void nfs_readlink_1_cb(struct rpc_context *rpc, int status, void *command return; } - + data->cb(0, nfs, res->READLINK3res_u.resok.data, data->private_data); free_nfs_cb_data(data); } @@ -3686,7 +3707,7 @@ static void nfs_symlink_cb(struct rpc_context *rpc, int status, void *command_da 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) { @@ -3822,7 +3843,7 @@ static void nfs_rename_cb(struct rpc_context *rpc, int status, void *command_dat 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) { @@ -3983,7 +4004,7 @@ static void nfs_link_cb(struct rpc_context *rpc, int status, void *command_data, 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) { @@ -4200,7 +4221,7 @@ static void mount_export_4_cb(struct rpc_context *rpc, int status, void *command /* 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; @@ -4320,7 +4341,7 @@ int mount_getexports_async(struct rpc_context *rpc, const char *server, rpc_cb c 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;