]> git.ozlabs.org Git - ccan-lca-2011.git/commitdiff
nfs: Add _info, remove -D_FILE_OFFSET_BITS=64, use nfs_off_t
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 02:45:36 +0000 (13:15 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 15 Nov 2010 02:45:36 +0000 (13:15 +1030)
This makes it closer to compiling under ccanlint.

ccan/nfs/Makefile
ccan/nfs/_info [new file with mode: 0644]
ccan/nfs/libnfs-raw.h
ccan/nfs/libnfs-sync.c
ccan/nfs/libnfs.c
ccan/nfs/nfs.c
ccan/nfs/nfs.h
ccan/nfs/tools/nfsclient-sync.c

index 93f325bc72edb78f7ba72a7124d96a948943c64c..1cf35ca74c525457ea2e2147b381eafc9a423b41 100644 (file)
@@ -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 (file)
index 0000000..fa77010
--- /dev/null
@@ -0,0 +1,58 @@
+#include <string.h>
+#include <stdio.h>
+
+/**
+ * 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 <ccan/nfs/nfs.h>
+ * #include <err.h>
+ * #include <stdio.h>
+ * #include <sys/types.h>
+ * #include <sys/stat.h>
+ * #include <unistd.h>
+ *
+ * int main(int argc, char *argv[])
+ * {
+ *     struct nfs_context *nfs;
+ *     struct stat st;
+ *
+ *     if (argc != 4)
+ *             errx(1, "Usage: %s <serveraddr> <export> <filename>", 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;
+}
index c4589cb5a1b0708da80fd4c64ae25860750190b1..b68a92a91a14bd1f7df8570d4f991e73b8d67254 100644 (file)
@@ -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
index d6f58f4e87a9a573680207045eaa0ecca5001030..12ed49e67ef0203d41380abe3ae77949c5be3e78 100644 (file)
@@ -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;
 
index 025b391da4607e810d6d6eaabdb0a50c9d08a69b..6c2a5165fe3fcaf91d175aa5705512ce9fd60029 100644 (file)
@@ -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;
 }
index dd67be523bf66b7be29b736ac321ebf28daae7a1..736095c5161821502c3b8873b0120b34f3ea3f1b 100644 (file)
@@ -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;
index ec4b6053c1ab97557a49c51759d158014ce73a6b..803b175cb6c78250f73f3666ddcae70a895506db 100644 (file)
 /*
  * This is the highlevel interface to access NFS resources using a posix-like interface
  */
+#include <sys/types.h>
 #include <stdint.h>
 
+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);
index e7621092273dea7028c6fce0cff477e5c13ca3ae..5869f1cc4c978e29b4a25a076ac9a10eac483479 100644 (file)
@@ -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();