Browse Source

nfs: Add _info, remove -D_FILE_OFFSET_BITS=64, use nfs_off_t

This makes it closer to compiling under ccanlint.
Rusty Russell 15 years ago
parent
commit
42f0d95f79
8 changed files with 96 additions and 35 deletions
  1. 1 1
      ccan/nfs/Makefile
  2. 58 0
      ccan/nfs/_info
  3. 2 2
      ccan/nfs/libnfs-raw.h
  4. 7 7
      ccan/nfs/libnfs-sync.c
  5. 10 10
      ccan/nfs/libnfs.c
  6. 2 2
      ccan/nfs/nfs.c
  7. 15 12
      ccan/nfs/nfs.h
  8. 1 1
      ccan/nfs/tools/nfsclient-sync.c

+ 1 - 1
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

+ 58 - 0
ccan/nfs/_info

@@ -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;
+}

+ 2 - 2
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

+ 7 - 7
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;
 

+ 10 - 10
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;
 }

+ 2 - 2
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;

+ 15 - 12
ccan/nfs/nfs.h

@@ -17,8 +17,11 @@
 /*
  * 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);

+ 1 - 1
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();