From: Rusty Russell Date: Mon, 15 Nov 2010 02:45:36 +0000 (+1030) Subject: nfs: Add _info, remove -D_FILE_OFFSET_BITS=64, use nfs_off_t X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=42f0d95f79096702efbd79d8c422328078752302 nfs: Add _info, remove -D_FILE_OFFSET_BITS=64, use nfs_off_t This makes it closer to compiling under ccanlint. --- diff --git a/ccan/nfs/Makefile b/ccan/nfs/Makefile index 93f325bc..1cf35ca7 100644 --- a/ccan/nfs/Makefile +++ b/ccan/nfs/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))" -D_FILE_OFFSET_BITS=64 +CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))" LIBS= LIBNFS_OBJ = libnfs-raw-mount.o libnfs-raw-portmap.o libnfs-raw-nfs.o libnfs-raw-nfsacl.o mount.o nfs.o nfsacl.o portmap.o pdu.o init.o socket.o libnfs.o libnfs-sync.o diff --git a/ccan/nfs/_info b/ccan/nfs/_info new file mode 100644 index 00000000..fa77010b --- /dev/null +++ b/ccan/nfs/_info @@ -0,0 +1,58 @@ +#include +#include + +/** + * nfs - nfs client library + * + * This code offers a POSIX-like interface directly to an NFS server. + * + * Note: various files are generated from the XDR descriptions in the rpc/ + * directory using rpcgen. + * + * Example: + * #include + * #include + * #include + * #include + * #include + * #include + * + * int main(int argc, char *argv[]) + * { + * struct nfs_context *nfs; + * struct stat st; + * + * if (argc != 4) + * errx(1, "Usage: %s ", argv[0]); + * nfs = nfs_init_context(); + * if (!nfs) + * err(1, "Initializing nfs context"); + * + * if (nfs_mount_sync(nfs, argv[1], argv[2]) != 0) + * errx(1, "Failed to mount nfs share: %s", nfs_get_error(nfs)); + * + * if (nfs_stat_sync(nfs, argv[3], &st) != 0) + * errx(1, "Failed to stat(%s): %s", argv[3], nfs_get_error(nfs)); + * + * printf("Mode %04o\n", st.st_mode); + * printf("Size %u\n", (int)st.st_size); + * printf("Inode %u\n", (int)st.st_ino); + * + * nfs_destroy_context(nfs); + * printf("nfsclient finished\n"); + * return 0; + *} + */ +int main(int argc, char *argv[]) +{ + /* Expect exactly one argument */ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + printf("ccan/compiler\n"); + return 0; + } + + return 1; +} diff --git a/ccan/nfs/libnfs-raw.h b/ccan/nfs/libnfs-raw.h index c4589cb5..b68a92a9 100644 --- a/ccan/nfs/libnfs-raw.h +++ b/ccan/nfs/libnfs-raw.h @@ -298,7 +298,7 @@ int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. * data is NULL. */ -int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data); +int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, nfs_off_t offset, size_t count, void *private_data); /* * Call NFS/WRITE @@ -314,7 +314,7 @@ int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, o * RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete. * data is NULL. */ -int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data); +int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, nfs_off_t offset, size_t count, int stable_how, void *private_data); /* * Call NFS/COMMIT diff --git a/ccan/nfs/libnfs-sync.c b/ccan/nfs/libnfs-sync.c index d6f58f4e..12ed49e6 100644 --- a/ccan/nfs/libnfs-sync.c +++ b/ccan/nfs/libnfs-sync.c @@ -37,7 +37,7 @@ struct sync_cb_data { int is_finished; int status; - off_t offset; + nfs_off_t offset; void *return_data; int return_int; }; @@ -203,7 +203,7 @@ static void pread_cb(int status, struct nfs_context *nfs _U_, void *data, void * memcpy(buffer, (char *)data, status); } -int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buffer) +int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buffer) { struct sync_cb_data cb_data; @@ -298,7 +298,7 @@ static void pwrite_cb(int status, struct nfs_context *nfs _U_, void *data, void } } -int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf) +int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf) { struct sync_cb_data cb_data; @@ -372,7 +372,7 @@ static void ftruncate_cb(int status, struct nfs_context *nfs _U_, void *data, vo } } -int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length) +int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length) { struct sync_cb_data cb_data; @@ -405,7 +405,7 @@ static void truncate_cb(int status, struct nfs_context *nfs _U_, void *data, voi } } -int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length) +int nfs_truncate_sync(struct nfs_context *nfs, const char *path, nfs_off_t length) { struct sync_cb_data cb_data; @@ -623,11 +623,11 @@ static void lseek_cb(int status, struct nfs_context *nfs _U_, void *data, void * } if (cb_data->return_data != NULL) { - memcpy(cb_data->return_data, data, sizeof(off_t)); + memcpy(cb_data->return_data, data, sizeof(nfs_off_t)); } } -int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset) +int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_off_t *current_offset) { struct sync_cb_data cb_data; diff --git a/ccan/nfs/libnfs.c b/ccan/nfs/libnfs.c index 025b391d..6c2a5165 100644 --- a/ccan/nfs/libnfs.c +++ b/ccan/nfs/libnfs.c @@ -37,7 +37,7 @@ struct nfsfh { struct nfs_fh3 fh; int is_sync; - off_t offset; + nfs_off_t offset; }; struct nfsdir { @@ -811,7 +811,7 @@ static void nfs_pread_cb(struct rpc_context *rpc _U_, int status, void *command_ free_nfs_cb_data(data); } -int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data) +int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, nfs_cb cb, void *private_data) { struct nfs_cb_data *data; @@ -881,7 +881,7 @@ static void nfs_pwrite_cb(struct rpc_context *rpc _U_, int status, void *command free_nfs_cb_data(data); } -int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data) +int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data) { struct nfs_cb_data *data; @@ -1061,7 +1061,7 @@ static void nfs_ftruncate_cb(struct rpc_context *rpc _U_, int status, void *comm free_nfs_cb_data(data); } -int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data) +int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length, nfs_cb cb, void *private_data) { struct nfs_cb_data *data; SETATTR3args args; @@ -1099,7 +1099,7 @@ int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t leng */ static int nfs_truncate_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data) { - off_t offset = data->continue_int; + nfs_off_t offset = data->continue_int; struct nfsfh nfsfh; nfsfh.fh.data.data_val = data->fh.data.data_val; @@ -1115,9 +1115,9 @@ static int nfs_truncate_continue_internal(struct nfs_context *nfs, struct nfs_cb return 0; } -int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data) +int nfs_truncate_async(struct nfs_context *nfs, const char *path, nfs_off_t length, nfs_cb cb, void *private_data) { - off_t offset; + nfs_off_t offset; offset = length; @@ -1654,7 +1654,7 @@ void nfs_closedir(struct nfs_context *nfs _U_, struct nfsdir *nfsdir) struct lseek_cb_data { struct nfs_context *nfs; struct nfsfh *nfsfh; - off_t offset; + nfs_off_t offset; nfs_cb cb; void *private_data; }; @@ -1689,7 +1689,7 @@ static void nfs_lseek_1_cb(struct rpc_context *rpc _U_, int status, void *comman free(data); } -int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data) +int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_cb cb, void *private_data) { struct lseek_cb_data *data; @@ -2720,7 +2720,7 @@ int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *new //qqq replace later with lseek() -off_t nfs_get_current_offset(struct nfsfh *nfsfh) +nfs_off_t nfs_get_current_offset(struct nfsfh *nfsfh) { return nfsfh->offset; } diff --git a/ccan/nfs/nfs.c b/ccan/nfs/nfs.c index dd67be52..736095c5 100644 --- a/ccan/nfs/nfs.c +++ b/ccan/nfs/nfs.c @@ -210,7 +210,7 @@ int rpc_nfs_access_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, -int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data) +int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, nfs_off_t offset, size_t count, void *private_data) { struct rpc_pdu *pdu; READ3args args; @@ -242,7 +242,7 @@ int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, o } -int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data) +int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, nfs_off_t offset, size_t count, int stable_how, void *private_data) { struct rpc_pdu *pdu; WRITE3args args; diff --git a/ccan/nfs/nfs.h b/ccan/nfs/nfs.h index ec4b6053..803b175c 100644 --- a/ccan/nfs/nfs.h +++ b/ccan/nfs/nfs.h @@ -17,8 +17,11 @@ /* * This is the highlevel interface to access NFS resources using a posix-like interface */ +#include #include +typedef uint64_t nfs_off_t; + struct nfs_context; /* @@ -226,14 +229,14 @@ int nfs_close_sync(struct nfs_context *nfs, struct nfsfh *nfsfh); * -errno : An error occured. * data is the error string. */ -int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data); +int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, nfs_cb cb, void *private_data); /* * Sync pread() * Function returns * >=0 : numer of bytes read. * -errno : An error occured. */ -int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); +int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf); @@ -282,14 +285,14 @@ int nfs_read_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, ch * -errno : An error occured. * data is the error string. */ -int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data); +int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data); /* * Sync pwrite() * Function returns * >=0 : numer of bytes written. * -errno : An error occured. */ -int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf); +int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf); /* @@ -330,18 +333,18 @@ int nfs_write_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, c * * When the callback is invoked, status indicates the result: * >=0 : Success. - * data is off_t * for the current position. + * data is nfs_off_t * for the current position. * -errno : An error occured. * data is the error string. */ -int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data); +int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_cb cb, void *private_data); /* * Sync lseek() * Function returns * >=0 : numer of bytes read. * -errno : An error occured. */ -int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset); +int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_off_t *current_offset); /* @@ -385,14 +388,14 @@ int nfs_fsync_sync(struct nfs_context *nfs, struct nfsfh *nfsfh); * -errno : An error occured. * data is the error string. */ -int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data); +int nfs_truncate_async(struct nfs_context *nfs, const char *path, nfs_off_t length, nfs_cb cb, void *private_data); /* * Sync truncate() * Function returns * 0 : Success * -errno : An error occured. */ -int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length); +int nfs_truncate_sync(struct nfs_context *nfs, const char *path, nfs_off_t length); @@ -411,14 +414,14 @@ int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length); * -errno : An error occured. * data is the error string. */ -int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data); +int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length, nfs_cb cb, void *private_data); /* * Sync ftruncate() * Function returns * 0 : Success * -errno : An error occured. */ -int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length); +int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length); @@ -907,4 +910,4 @@ int nfs_link_sync(struct nfs_context *nfs, const char *oldpath, const char *newp //qqq replace later with lseek(cur, 0) -off_t nfs_get_current_offset(struct nfsfh *nfsfh); +nfs_off_t nfs_get_current_offset(struct nfsfh *nfsfh); diff --git a/ccan/nfs/tools/nfsclient-sync.c b/ccan/nfs/tools/nfsclient-sync.c index e7621092..5869f1cc 100644 --- a/ccan/nfs/tools/nfsclient-sync.c +++ b/ccan/nfs/tools/nfsclient-sync.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) client.export = EXPORT; client.is_finished = 0; char buf[16]; - off_t offset; + nfs_off_t offset; struct statvfs svfs; nfs = nfs_init_context();