From: Ross Lagerwall Date: Sun, 20 Jul 2014 22:12:59 +0000 (+0100) Subject: libnfs: Add fstat64, analagous to stat64 X-Git-Tag: upstream/1.9.6^2~16^2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3e020c15fd041aea4918103c00c9143a0667c79b;p=deb_libnfs.git libnfs: Add fstat64, analagous to stat64 Signed-off-by: Ross Lagerwall --- diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index 5d5d542..df102d9 100644 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -312,6 +312,7 @@ EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat * -errno : An error occured. * data is the error string. */ +/* This function is deprecated. Use nfs_fstat64_async() instead */ EXTERN int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); /* * Sync fstat(nfsfh *) @@ -325,6 +326,35 @@ EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct __stat EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st); #endif +/* nfs_fstat64 + * 64 bit version of fstat. All fields are always 64bit. + * Use these functions instead of nfs_fstat[_async](), especially if you + * have weird stat structures. + */ +/* + * FSTAT() + */ +/* + * Async fstat(nfsfh *) + * Function returns + * 0 : The operation was initiated. Once the operation finishes, the callback will be invoked. + * <0 : An error occured when trying to set up the operation. The callback will not be invoked. + * + * When the callback is invoked, status indicates the result: + * 0 : Success. + * data is struct stat * + * -errno : An error occured. + * data is the error string. + */ +EXTERN int nfs_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data); +/* + * Sync fstat(nfsfh *) + * Function returns + * 0 : The operation was successfull. + * -errno : The command failed. + */ +EXTERN int nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh, struct nfs_stat_64 *st); + /* diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 39c68c6..9d351f7 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -453,6 +453,26 @@ int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st) return cb_data.status; } +/* + * fstat64() + */ +int nfs_fstat64(struct nfs_context *nfs, struct nfsfh *nfsfh, struct nfs_stat_64 *st) +{ + struct sync_cb_data cb_data; + + cb_data.is_finished = 0; + cb_data.return_data = st; + + if (nfs_fstat64_async(nfs, nfsfh, stat64_cb, &cb_data) != 0) { + nfs_set_error(nfs, "nfs_fstat64_async failed"); + return -1; + } + + wait_for_nfs_reply(nfs, &cb_data); + + return cb_data.status; +} + /* * pwrite() diff --git a/lib/libnfs.c b/lib/libnfs.c index e9a5526..30ad41f 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -2242,6 +2242,36 @@ int nfs_fstat_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, voi return 0; } +/* + * Async fstat64() + */ +int nfs_fstat64_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data) +{ + struct nfs_cb_data *data; + struct GETATTR3args args; + + data = malloc(sizeof(struct nfs_cb_data)); + if (data == NULL) { + rpc_set_error(nfs->rpc, "out of memory: failed to allocate nfs_cb_data structure"); + return -1; + } + memset(data, 0, sizeof(struct nfs_cb_data)); + data->nfs = nfs; + data->cb = cb; + data->private_data = private_data; + + memset(&args, 0, sizeof(GETATTR3args)); + args.object = nfsfh->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; +} + /*