From: Ronnie Sahlberg Date: Mon, 3 Feb 2014 01:39:04 +0000 (-0800) Subject: We need to pass a filehandle back for open(O_TRUNC) or else the app will X-Git-Tag: upstream/1.9.6^2~118 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=be7b4360ace50da1e8687b3eaa31305ee259140b;p=deb_libnfs.git We need to pass a filehandle back for open(O_TRUNC) or else the app will be unhappy --- diff --git a/lib/libnfs.c b/lib/libnfs.c index c2c20d4..68e0d03 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -1247,6 +1247,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 +1271,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 +1345,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 +1367,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); }