]> git.ozlabs.org Git - ccan/commitdiff
nfs: ccanize a little more.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 9 Nov 2010 08:24:45 +0000 (18:54 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 9 Nov 2010 08:24:45 +0000 (18:54 +1030)
rename libnfs.h to nfs.h (CCAN expects "main" header to match module name).
tools move into tools/, .x file move into rpc/
Don't sed the rpcgen files, generate headers in rpc/
Make tools use <ccan/nfs/nfs.h> as per normal ccan usage.

26 files changed:
ccan/nfs/Makefile
ccan/nfs/init.c
ccan/nfs/libnfs-sync.c
ccan/nfs/libnfs.c
ccan/nfs/libnfs.h [deleted file]
ccan/nfs/mount.c
ccan/nfs/mount.x [deleted file]
ccan/nfs/nfs.c
ccan/nfs/nfs.h [new file with mode: 0644]
ccan/nfs/nfs.x [deleted file]
ccan/nfs/nfsacl.c
ccan/nfs/nfsacl.x [deleted file]
ccan/nfs/nfsclient-async.c [deleted file]
ccan/nfs/nfsclient-raw.c [deleted file]
ccan/nfs/nfsclient-sync.c [deleted file]
ccan/nfs/pdu.c
ccan/nfs/portmap.c
ccan/nfs/portmap.x [deleted file]
ccan/nfs/rpc/mount.x [new file with mode: 0644]
ccan/nfs/rpc/nfs.x [new file with mode: 0755]
ccan/nfs/rpc/nfsacl.x [new file with mode: 0644]
ccan/nfs/rpc/portmap.x [new file with mode: 0644]
ccan/nfs/socket.c
ccan/nfs/tools/nfsclient-async.c [new file with mode: 0644]
ccan/nfs/tools/nfsclient-raw.c [new file with mode: 0644]
ccan/nfs/tools/nfsclient-sync.c [new file with mode: 0644]

index f4425d7e420e75bd52cbcf5c895c57ac6945a79a..93f325bc72edb78f7ba72a7124d96a948943c64c 100644 (file)
@@ -1,79 +1,79 @@
 CC=gcc
 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))" -D_FILE_OFFSET_BITS=64
 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
 
 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
 
-all: nfsclient-raw nfsclient-async nfsclient-sync
+all: tools/nfsclient-raw tools/nfsclient-async tools/nfsclient-sync
 
 
-nfsclient-async: nfsclient-async.c libnfs.a
-       $(CC) -o $@ nfsclient-async.c libnfs.a $(LIBS)
+tools/nfsclient-async: tools/nfsclient-async.c libnfs.a
+       $(CC) $(CFLAGS) -o $@ tools/nfsclient-async.c libnfs.a $(LIBS)
 
 
-nfsclient-sync: nfsclient-sync.c libnfs.a
-       $(CC) -o $@ nfsclient-sync.c libnfs.a $(LIBS)
+tools/nfsclient-sync: tools/nfsclient-sync.c libnfs.a
+       $(CC) $(CFLAGS) -o $@ tools/nfsclient-sync.c libnfs.a $(LIBS)
 
 
-nfsclient-raw: nfsclient-raw.c libnfs.a
-       $(CC) -o $@ nfsclient-raw.c libnfs.a $(LIBS)
+tools/nfsclient-raw: tools/nfsclient-raw.c libnfs.a
+       $(CC) $(CFLAGS) -o $@ tools/nfsclient-raw.c libnfs.a $(LIBS)
 
 libnfs.a: $(LIBNFS_OBJ)
        @echo Creating library $@
        ar r libnfs.a $(LIBNFS_OBJ) 
        ranlib libnfs.a
 
 
 libnfs.a: $(LIBNFS_OBJ)
        @echo Creating library $@
        ar r libnfs.a $(LIBNFS_OBJ) 
        ranlib libnfs.a
 
-libnfs-raw-mount.h: mount.x
+rpc/mount.h: rpc/mount.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -h mount.x > libnfs-raw-mount.h
+       rpcgen -h rpc/mount.x > $@
 
 
-libnfs-raw-mount.c: mount.x
+libnfs-raw-mount.c: rpc/mount.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -c mount.x | sed -e "s/#include \"mount.h\"/#include \"libnfs-raw-mount.h\"/" > libnfs-raw-mount.c
+       rpcgen -c rpc/mount.x > libnfs-raw-mount.c
 
 
-libnfs-raw-mount.o: libnfs-raw-mount.c libnfs-raw-mount.h
+libnfs-raw-mount.o: libnfs-raw-mount.c rpc/mount.h
        @echo Compiling $@
        gcc -g -c libnfs-raw-mount.c -o $@
 
        @echo Compiling $@
        gcc -g -c libnfs-raw-mount.c -o $@
 
-libnfs-raw-nfs.h: nfs.x
+rpc/nfs.h: rpc/nfs.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -h nfs.x > libnfs-raw-nfs.h
+       rpcgen -h rpc/nfs.x > $@
 
 
-libnfs-raw-nfs.c: nfs.x
+libnfs-raw-nfs.c: rpc/nfs.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -c nfs.x | sed -e "s/#include \"nfs.h\"/#include \"libnfs-raw-nfs.h\"/" > libnfs-raw-nfs.c
+       rpcgen -c rpc/nfs.x > $@
 
 
-libnfs-raw-nfs.o: libnfs-raw-nfs.c libnfs-raw-nfs.h
+libnfs-raw-nfs.o: libnfs-raw-nfs.c rpc/nfs.h
        @echo Compiling $@
        gcc -g -c libnfs-raw-nfs.c -o $@
 
        @echo Compiling $@
        gcc -g -c libnfs-raw-nfs.c -o $@
 
-libnfs-raw-nfsacl.h: nfsacl.x
+rpc/nfsacl.h: rpc/nfsacl.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -h nfsacl.x > libnfs-raw-nfsacl.h
+       rpcgen -h rpc/nfsacl.x > $@
 
 
-libnfs-raw-nfsacl.c: nfsacl.x
+libnfs-raw-nfsacl.c: rpc/nfsacl.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -c nfsacl.x | sed -e "s/#include \"nfsacl.h\"/#include \"libnfs-raw-nfsacl.h\"/" > libnfs-raw-nfsacl.c
+       rpcgen -c rpc/nfsacl.x > $@
 
 
-libnfs-raw-nfsacl.o: libnfs-raw-nfsacl.c libnfs-raw-nfsacl.h
+libnfs-raw-nfsacl.o: libnfs-raw-nfsacl.c rpc/nfsacl.h
        @echo Compiling $@
        gcc -g -c libnfs-raw-nfsacl.c -o $@
 
        @echo Compiling $@
        gcc -g -c libnfs-raw-nfsacl.c -o $@
 
-libnfs-raw-portmap.h: portmap.x
+rpc/portmap.h: rpc/portmap.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -h portmap.x > libnfs-raw-portmap.h
+       rpcgen -h rpc/portmap.x > $@
 
 
-libnfs-raw-portmap.c: portmap.x
+libnfs-raw-portmap.c: rpc/portmap.x
        @echo Generating $@
        @echo Generating $@
-       rpcgen -c portmap.x | sed -e "s/#include \"portmap.h\"/#include \"libnfs-raw-portmap.h\"/" > libnfs-raw-portmap.c
+       rpcgen -c rpc/portmap.x > $@
 
 
-libnfs-raw-portmap.o: libnfs-raw-portmap.c libnfs-raw-portmap.h
+libnfs-raw-portmap.o: libnfs-raw-portmap.c rpc/portmap.h
        @echo Compiling $@
        gcc -g -c libnfs-raw-portmap.c -o $@
 
 clean:
        rm -f *.o
        rm -f *.a
        @echo Compiling $@
        gcc -g -c libnfs-raw-portmap.c -o $@
 
 clean:
        rm -f *.o
        rm -f *.a
-       rm -f libnfs-raw-mount.h libnfs-raw-mount.c
-       rm -f libnfs-raw-nfs.h libnfs-raw-nfs.c
-       rm -f libnfs-raw-nfsacl.h libnfs-raw-nfsacl.c
-       rm -f libnfs-raw-portmap.h libnfs-raw-portmap.c
-       rm -f nfsclient-raw nfsclient-async nfsclient-sync
+       rm -f rpc/mount.h libnfs-raw-mount.c
+       rm -f rpc/nfs.h libnfs-raw-nfs.c
+       rm -f rpc/nfsacl.h libnfs-raw-nfsacl.c
+       rm -f rpc/portmap.h libnfs-raw-portmap.c
+       rm -f tools/nfsclient-raw tools/nfsclient-async tools/nfsclient-sync
 
 
index ae0c7878b9d47c89c730cd5d1b009742a17318ae..9bc3c7e8d18331cd7199500a6cb725a780b79ba8 100644 (file)
@@ -23,7 +23,7 @@
 #include <strings.h>
 #include <rpc/xdr.h>
 #include "dlinklist.h"
 #include <strings.h>
 #include <rpc/xdr.h>
 #include "dlinklist.h"
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 
index f8f98bc13a3b34afda99931b6e721e986af45bf7..d6f58f4e87a9a573680207045eaa0ecca5001030 100644 (file)
 #include <fcntl.h>
 #include <errno.h>
 #include <poll.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <poll.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-raw.h"
-#include "libnfs-raw-mount.h"
-#include "libnfs-raw-nfs.h"
+#include "rpc/mount.h"
+#include "rpc/nfs.h"
 
 struct sync_cb_data {
        int is_finished;
 
 struct sync_cb_data {
        int is_finished;
index d32572475b4ff9b0261c1aeb84645ce248c68e1a..025b391da4607e810d6d6eaabdb0a50c9d08a69b 100644 (file)
 #include <utime.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <utime.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-raw.h"
-#include "libnfs-raw-mount.h"
-#include "libnfs-raw-nfs.h"
+#include "rpc/mount.h"
+#include "rpc/nfs.h"
 
 struct nfsfh {
        struct nfs_fh3 fh;
 
 struct nfsfh {
        struct nfs_fh3 fh;
diff --git a/ccan/nfs/libnfs.h b/ccan/nfs/libnfs.h
deleted file mode 100644 (file)
index ec4b605..0000000
+++ /dev/null
@@ -1,910 +0,0 @@
-/* 
-   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
-/*
- * This is the highlevel interface to access NFS resources using a posix-like interface
- */
-#include <stdint.h>
-
-struct nfs_context;
-
-/*
- * Used for interfacing the async version of the api into an external eventsystem
- */
-int nfs_get_fd(struct nfs_context *nfs);
-int nfs_which_events(struct nfs_context *nfs);
-int nfs_service(struct nfs_context *nfs, int revents);
-
-/*
- * Used if you need different credentials than the default for the current user.
- */
-struct AUTH;
-void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
-
-
-/*
- * When an operation failed, this function can extract a detailed error string.
- */
-char *nfs_get_error(struct nfs_context *nfs);
-
-
-/*
- * Callback for all async nfs functions
- */
-typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
-
-
-
-
-/*
- * NFS CONTEXT.
- */
-/*
- * Create an NFS context.
- * Function returns
- *  NULL                 : Failed to create a context.
- *  struct nfs_context * : A pointer to an nfs context.
- */
-struct nfs_context *nfs_init_context(void);
-/*
- * Destroy an nfs context.
- */
-void nfs_destroy_context(struct nfs_context *nfs);
-
-
-/*
- * A libnfs filehandle
- */
-struct nfsfh;
-
-
-
-/*
- * MOUNT THE EXPORT
- */
-/*
- * Async nfs mount.
- * This function will try to connect to the server and mount the export.
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data);
-/*
- * Sync nfs mount.
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_mount_sync(struct nfs_context *nfs, const char *server, const char *export);
-
-
-
-
-/*
- * STAT()
- */
-/*
- * Async stat(<filename>)
- * 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.
- */
-struct stat;
-int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync stat(<filename>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_stat_sync(struct nfs_context *nfs, const char *path, struct stat *st);
-
-
-/*
- * 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.
- */
-int nfs_fstat_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.
- */
-int nfs_fstat_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
-
-
-
-/*
- * OPEN()
- */
-/*
- * Async open(<filename>)
- *
- * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
- *
- * 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 a struct *nfsfh;
- *          The nfsfh is close using nfs_close().
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
-/*
- * Sync open(<filename>)
- * Function returns
- *      0 : The operation was successfull. *nfsfh is filled in.
- * -errno : The command failed.
- */
-int nfs_open_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
-
-
-
-
-/*
- * CLOSE
- */
-/*
- * Async close(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 NULL.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
-/*
- * Sync close(nfsfh)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_close_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
-
-
-/*
- * PREAD()
- */
-/*
- * Async pread()
- *
- * 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.
- *          status is numer of bytes read.
- *          data is a pointer to the returned data.
- * -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);
-/*
- * 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);
-
-
-
-/*
- * READ()
- */
-/*
- * Async read()
- *
- * 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.
- *          status is numer of bytes read.
- *          data is a pointer to the returned data.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data);
-/*
- * Sync read()
- * Function returns
- *    >=0 : numer of bytes read.
- * -errno : An error occured.
- */
-int nfs_read_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
-
-
-
-
-/*
- * PWRITE()
- */
-/*
- * Async pwrite()
- *
- * 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.
- *          status is numer of bytes written.
- * -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);
-/*
- * 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);
-
-
-/*
- * WRITE()
- */
-/*
- * Async write()
- *
- * 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.
- *          status is numer of bytes written.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data);
-/*
- * Sync write()
- * Function returns
- *    >=0 : numer of bytes written.
- * -errno : An error occured.
- */
-int nfs_write_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
-
-
-/*
- * LSEEK()
- */
-/*
- * Async lseek()
- *
- * 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 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);
-/*
- * 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);
-
-
-/*
- * FSYNC()
- */
-/*
- * Async fsync()
- *
- * 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.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
-/*
- * Sync fsync()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_fsync_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
-
-
-
-/*
- * TRUNCATE()
- */
-/*
- * Async truncate()
- *
- * 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.
- * -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);
-/*
- * Sync truncate()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length);
-
-
-
-/*
- * FTRUNCATE()
- */
-/*
- * Async ftruncate()
- *
- * 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.
- * -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);
-/*
- * Sync ftruncate()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length);
-
-
-
-
-
-
-/*
- * MKDIR()
- */
-/*
- * Async mkdir()
- *
- * 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.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync mkdir()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_mkdir_sync(struct nfs_context *nfs, const char *path);
-
-
-
-/*
- * RMDIR()
- */
-/*
- * Async rmdir()
- *
- * 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.
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync rmdir()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_rmdir_sync(struct nfs_context *nfs, const char *path);
-
-
-
-
-/*
- * CREAT()
- */
-/*
- * Async creat()
- *
- * 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 a struct *nfsfh;
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
-/*
- * Sync creat()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_creat_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
-
-
-
-
-
-/*
- * UNLINK()
- */
-/*
- * Async unlink()
- *
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync unlink()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_unlink_sync(struct nfs_context *nfs, const char *path);
-
-
-
-
-/*
- * OPENDIR()
- */
-struct nfsdir;
-/*
- * Async opendir()
- *
- * 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 struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
- *
- * When the callback is invoked, status indicates the result:
- *      0 : Success.
- *          data is struct nfsdir *
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync opendir()
- * Function returns
- *      0 : Success
- * -errno : An error occured.
- */
-int nfs_opendir_sync(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
-
-
-
-/*
- * READDIR()
- */
-struct nfsdirent  {
-       struct nfsdirent *next;
-       char *name;
-       uint64_t inode;
-};
-/*
- * nfs_readdir() never blocks, so no special sync/async versions are available
- */
-struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
-
-
-
-/*
- * READDIR()
- */
-/*
- * nfs_closedir() never blocks, so no special sync/async versions are available
- */
-void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
-
-
-
-/*
- * STATVFS()
- */
-/*
- * Async statvfs(<dirname>)
- * 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 statvfs *
- * -errno : An error occured.
- *          data is the error string.
- */
-struct statvfs;
-int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync statvfs(<dirname>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_statvfs_sync(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
-
-
-/*
- * READLINK()
- */
-/*
- * Async readlink(<name>)
- * 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 a char *
- *          data is only valid during the callback and is automatically freed when the callback returns.
- * -errno : An error occured.
- *          data is the error string.
- */
-struct statvfs;
-int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
-/*
- * Sync readlink(<name>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_readlink_sync(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
-
-
-
-/*
- * CHMOD()
- */
-/*
- * Async chmod(<name>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
-/*
- * Sync chmod(<name>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_chmod_sync(struct nfs_context *nfs, const char *path, int mode);
-
-
-
-/*
- * FCHMOD()
- */
-/*
- * Async fchmod(<handle>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
-/*
- * Sync fchmod(<handle>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_fchmod_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
-
-
-
-/*
- * CHOWN()
- */
-/*
- * Async chown(<name>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
-/*
- * Sync chown(<name>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_chown_sync(struct nfs_context *nfs, const char *path, int uid, int gid);
-
-
-
-/*
- * FCHOWN()
- */
-/*
- * Async fchown(<handle>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
-/*
- * Sync fchown(<handle>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_fchown_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
-
-
-
-
-/*
- * UTIMES()
- */
-/*
- * Async utimes(<path>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
-/*
- * Sync utimes(<path>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_utimes_sync(struct nfs_context *nfs, const char *path, struct timeval *times);
-
-
-/*
- * UTIME()
- */
-/*
- * Async utime(<path>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-struct utimbuf;
-int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
-/*
- * Sync utime(<path>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_utime_sync(struct nfs_context *nfs, const char *path, struct utimbuf *times);
-
-
-
-
-/*
- * ACCESS()
- */
-/*
- * Async access(<path>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
-/*
- * Sync access(<path>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_access_sync(struct nfs_context *nfs, const char *path, int mode);
-
-
-
-
-/*
- * SYMLINK()
- */
-/*
- * Async symlink(<path>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
-/*
- * Sync symlink(<path>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_symlink_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
-
-
-/*
- * RENAME()
- */
-/*
- * Async rename(<oldpath>, <newpath>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
-/*
- * Sync rename(<oldpath>, <newpath>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_rename_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
-
-
-
-/*
- * LINK()
- */
-/*
- * Async link(<oldpath>, <newpath>)
- * 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 NULL
- * -errno : An error occured.
- *          data is the error string.
- */
-int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
-/*
- * Sync link(<oldpath>, <newpath>)
- * Function returns
- *      0 : The operation was successfull.
- * -errno : The command failed.
- */
-int nfs_link_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
-
-
-
-//qqq replace later with lseek(cur, 0)
-off_t nfs_get_current_offset(struct nfsfh *nfsfh);
index 212eaedcf346b898f1c6c310a70b363b5a265931..7c7ac7ec7b73e1c8da4ee4dacc1df20e1b03910b 100644 (file)
 #include <stdio.h>
 #include <errno.h>
 #include <rpc/xdr.h>
 #include <stdio.h>
 #include <errno.h>
 #include <rpc/xdr.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
-#include "libnfs-raw-mount.h"
+#include "rpc/mount.h"
 
 
 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
 
 
 int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
diff --git a/ccan/nfs/mount.x b/ccan/nfs/mount.x
deleted file mode 100644 (file)
index 6c2f071..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/* copied from RFC1813 */
-
-const MNTPATHLEN = 1024;  /* Maximum bytes in a path name */
-const MNTNAMLEN  = 255;   /* Maximum bytes in a name */
-const FHSIZE3    = 64;    /* Maximum bytes in a V3 file handle */
-
-
-typedef opaque fhandle3<FHSIZE3>;
-typedef string dirpath<MNTPATHLEN>;
-typedef string name<MNTNAMLEN>;
-
-enum mountstat3 {
-       MNT3_OK = 0,                 /* no error */
-       MNT3ERR_PERM = 1,            /* Not owner */
-       MNT3ERR_NOENT = 2,           /* No such file or directory */
-       MNT3ERR_IO = 5,              /* I/O error */
-       MNT3ERR_ACCES = 13,          /* Permission denied */
-       MNT3ERR_NOTDIR = 20,         /* Not a directory */
-       MNT3ERR_INVAL = 22,          /* Invalid argument */
-       MNT3ERR_NAMETOOLONG = 63,    /* Filename too long */
-       MNT3ERR_NOTSUPP = 10004,     /* Operation not supported */
-       MNT3ERR_SERVERFAULT = 10006  /* A failure on the server */
-};
-
-
-typedef struct mountbody *mountlist;
-
-struct mountbody {
-       name       ml_hostname;
-       dirpath    ml_directory;
-       mountlist  ml_next;
-};
-
-typedef struct groupnode *groups;
-
-struct groupnode {
-       name     gr_name;
-       groups   gr_next;
-};
-
-
-typedef struct exportnode *exports;
-
-struct exportnode {
-       dirpath  ex_dir;
-       groups   ex_groups;
-       exports  ex_next;
-};
-
-struct mountres3_ok {
-       fhandle3   fhandle;
-       int        auth_flavors<>;
-};
-
-union mountres3 switch (mountstat3 fhs_status) {
-       case MNT3_OK:
-               mountres3_ok  mountinfo;
-       default:
-               void;
-};
-
-program MOUNT_PROGRAM {
-       version MOUNT_V3 {
-       void      MOUNT3_NULL(void)    = 0;
-       mountres3 MOUNT3_MNT(dirpath)  = 1;
-       mountlist MOUNT3_DUMP(void)    = 2;
-       void      MOUNT3_UMNT(dirpath) = 3;
-       void      MOUNT3_UMNTALL(void) = 4;
-       exports   MOUNT3_EXPORT(void)  = 5;
-       } = 3;
-} = 100005;
index 6d3e82f914a327dc097c28eee02dd4dbb825916e..dd67be523bf66b7be29b736ac321ebf28daae7a1 100644 (file)
 #include <errno.h>
 #include <sys/stat.h>
 #include <rpc/xdr.h>
 #include <errno.h>
 #include <sys/stat.h>
 #include <rpc/xdr.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
-#include "libnfs-raw-nfs.h"
+#include "rpc/nfs.h"
 
 
 
 
 
 
diff --git a/ccan/nfs/nfs.h b/ccan/nfs/nfs.h
new file mode 100644 (file)
index 0000000..ec4b605
--- /dev/null
@@ -0,0 +1,910 @@
+/* 
+   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+/*
+ * This is the highlevel interface to access NFS resources using a posix-like interface
+ */
+#include <stdint.h>
+
+struct nfs_context;
+
+/*
+ * Used for interfacing the async version of the api into an external eventsystem
+ */
+int nfs_get_fd(struct nfs_context *nfs);
+int nfs_which_events(struct nfs_context *nfs);
+int nfs_service(struct nfs_context *nfs, int revents);
+
+/*
+ * Used if you need different credentials than the default for the current user.
+ */
+struct AUTH;
+void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth);
+
+
+/*
+ * When an operation failed, this function can extract a detailed error string.
+ */
+char *nfs_get_error(struct nfs_context *nfs);
+
+
+/*
+ * Callback for all async nfs functions
+ */
+typedef void (*nfs_cb)(int err, struct nfs_context *nfs, void *data, void *private_data);
+
+
+
+
+/*
+ * NFS CONTEXT.
+ */
+/*
+ * Create an NFS context.
+ * Function returns
+ *  NULL                 : Failed to create a context.
+ *  struct nfs_context * : A pointer to an nfs context.
+ */
+struct nfs_context *nfs_init_context(void);
+/*
+ * Destroy an nfs context.
+ */
+void nfs_destroy_context(struct nfs_context *nfs);
+
+
+/*
+ * A libnfs filehandle
+ */
+struct nfsfh;
+
+
+
+/*
+ * MOUNT THE EXPORT
+ */
+/*
+ * Async nfs mount.
+ * This function will try to connect to the server and mount the export.
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_mount_async(struct nfs_context *nfs, const char *server, const char *export, nfs_cb cb, void *private_data);
+/*
+ * Sync nfs mount.
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_mount_sync(struct nfs_context *nfs, const char *server, const char *export);
+
+
+
+
+/*
+ * STAT()
+ */
+/*
+ * Async stat(<filename>)
+ * 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.
+ */
+struct stat;
+int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync stat(<filename>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_stat_sync(struct nfs_context *nfs, const char *path, struct stat *st);
+
+
+/*
+ * 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.
+ */
+int nfs_fstat_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.
+ */
+int nfs_fstat_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *st);
+
+
+
+/*
+ * OPEN()
+ */
+/*
+ * Async open(<filename>)
+ *
+ * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
+ *
+ * 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 a struct *nfsfh;
+ *          The nfsfh is close using nfs_close().
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync open(<filename>)
+ * Function returns
+ *      0 : The operation was successfull. *nfsfh is filled in.
+ * -errno : The command failed.
+ */
+int nfs_open_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
+
+
+
+
+/*
+ * CLOSE
+ */
+/*
+ * Async close(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 NULL.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_close_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
+/*
+ * Sync close(nfsfh)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_close_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
+
+
+/*
+ * PREAD()
+ */
+/*
+ * Async pread()
+ *
+ * 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.
+ *          status is numer of bytes read.
+ *          data is a pointer to the returned data.
+ * -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);
+/*
+ * 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);
+
+
+
+/*
+ * READ()
+ */
+/*
+ * Async read()
+ *
+ * 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.
+ *          status is numer of bytes read.
+ *          data is a pointer to the returned data.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_read_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, nfs_cb cb, void *private_data);
+/*
+ * Sync read()
+ * Function returns
+ *    >=0 : numer of bytes read.
+ * -errno : An error occured.
+ */
+int nfs_read_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
+
+
+
+
+/*
+ * PWRITE()
+ */
+/*
+ * Async pwrite()
+ *
+ * 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.
+ *          status is numer of bytes written.
+ * -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);
+/*
+ * 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);
+
+
+/*
+ * WRITE()
+ */
+/*
+ * Async write()
+ *
+ * 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.
+ *          status is numer of bytes written.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_write_async(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf, nfs_cb cb, void *private_data);
+/*
+ * Sync write()
+ * Function returns
+ *    >=0 : numer of bytes written.
+ * -errno : An error occured.
+ */
+int nfs_write_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, size_t count, char *buf);
+
+
+/*
+ * LSEEK()
+ */
+/*
+ * Async lseek()
+ *
+ * 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 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);
+/*
+ * 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);
+
+
+/*
+ * FSYNC()
+ */
+/*
+ * Async fsync()
+ *
+ * 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.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_fsync_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_cb cb, void *private_data);
+/*
+ * Sync fsync()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_fsync_sync(struct nfs_context *nfs, struct nfsfh *nfsfh);
+
+
+
+/*
+ * TRUNCATE()
+ */
+/*
+ * Async truncate()
+ *
+ * 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.
+ * -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);
+/*
+ * Sync truncate()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length);
+
+
+
+/*
+ * FTRUNCATE()
+ */
+/*
+ * Async ftruncate()
+ *
+ * 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.
+ * -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);
+/*
+ * Sync ftruncate()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length);
+
+
+
+
+
+
+/*
+ * MKDIR()
+ */
+/*
+ * Async mkdir()
+ *
+ * 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.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_mkdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync mkdir()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_mkdir_sync(struct nfs_context *nfs, const char *path);
+
+
+
+/*
+ * RMDIR()
+ */
+/*
+ * Async rmdir()
+ *
+ * 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.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_rmdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync rmdir()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_rmdir_sync(struct nfs_context *nfs, const char *path);
+
+
+
+
+/*
+ * CREAT()
+ */
+/*
+ * Async creat()
+ *
+ * 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 a struct *nfsfh;
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync creat()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_creat_sync(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
+
+
+
+
+
+/*
+ * UNLINK()
+ */
+/*
+ * Async unlink()
+ *
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_unlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync unlink()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_unlink_sync(struct nfs_context *nfs, const char *path);
+
+
+
+
+/*
+ * OPENDIR()
+ */
+struct nfsdir;
+/*
+ * Async opendir()
+ *
+ * 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 struct nfsdir * is returned, this resource is closed/freed by calling nfs_closedir()
+ *
+ * When the callback is invoked, status indicates the result:
+ *      0 : Success.
+ *          data is struct nfsdir *
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_opendir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync opendir()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+int nfs_opendir_sync(struct nfs_context *nfs, const char *path, struct nfsdir **nfsdir);
+
+
+
+/*
+ * READDIR()
+ */
+struct nfsdirent  {
+       struct nfsdirent *next;
+       char *name;
+       uint64_t inode;
+};
+/*
+ * nfs_readdir() never blocks, so no special sync/async versions are available
+ */
+struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfsdir);
+
+
+
+/*
+ * READDIR()
+ */
+/*
+ * nfs_closedir() never blocks, so no special sync/async versions are available
+ */
+void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
+
+
+
+/*
+ * STATVFS()
+ */
+/*
+ * Async statvfs(<dirname>)
+ * 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 statvfs *
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+struct statvfs;
+int nfs_statvfs_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync statvfs(<dirname>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_statvfs_sync(struct nfs_context *nfs, const char *path, struct statvfs *svfs);
+
+
+/*
+ * READLINK()
+ */
+/*
+ * Async readlink(<name>)
+ * 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 a char *
+ *          data is only valid during the callback and is automatically freed when the callback returns.
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+struct statvfs;
+int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync readlink(<name>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_readlink_sync(struct nfs_context *nfs, const char *path, char *buf, int bufsize);
+
+
+
+/*
+ * CHMOD()
+ */
+/*
+ * Async chmod(<name>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_chmod_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync chmod(<name>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_chmod_sync(struct nfs_context *nfs, const char *path, int mode);
+
+
+
+/*
+ * FCHMOD()
+ */
+/*
+ * Async fchmod(<handle>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_fchmod_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync fchmod(<handle>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_fchmod_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int mode);
+
+
+
+/*
+ * CHOWN()
+ */
+/*
+ * Async chown(<name>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_chown_async(struct nfs_context *nfs, const char *path, int uid, int gid, nfs_cb cb, void *private_data);
+/*
+ * Sync chown(<name>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_chown_sync(struct nfs_context *nfs, const char *path, int uid, int gid);
+
+
+
+/*
+ * FCHOWN()
+ */
+/*
+ * Async fchown(<handle>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_fchown_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid, nfs_cb cb, void *private_data);
+/*
+ * Sync fchown(<handle>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_fchown_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, int uid, int gid);
+
+
+
+
+/*
+ * UTIMES()
+ */
+/*
+ * Async utimes(<path>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_utimes_async(struct nfs_context *nfs, const char *path, struct timeval *times, nfs_cb cb, void *private_data);
+/*
+ * Sync utimes(<path>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_utimes_sync(struct nfs_context *nfs, const char *path, struct timeval *times);
+
+
+/*
+ * UTIME()
+ */
+/*
+ * Async utime(<path>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+struct utimbuf;
+int nfs_utime_async(struct nfs_context *nfs, const char *path, struct utimbuf *times, nfs_cb cb, void *private_data);
+/*
+ * Sync utime(<path>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_utime_sync(struct nfs_context *nfs, const char *path, struct utimbuf *times);
+
+
+
+
+/*
+ * ACCESS()
+ */
+/*
+ * Async access(<path>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_access_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync access(<path>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_access_sync(struct nfs_context *nfs, const char *path, int mode);
+
+
+
+
+/*
+ * SYMLINK()
+ */
+/*
+ * Async symlink(<path>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_symlink_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
+/*
+ * Sync symlink(<path>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_symlink_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
+
+
+/*
+ * RENAME()
+ */
+/*
+ * Async rename(<oldpath>, <newpath>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_rename_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
+/*
+ * Sync rename(<oldpath>, <newpath>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_rename_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
+
+
+
+/*
+ * LINK()
+ */
+/*
+ * Async link(<oldpath>, <newpath>)
+ * 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 NULL
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+int nfs_link_async(struct nfs_context *nfs, const char *oldpath, const char *newpath, nfs_cb cb, void *private_data);
+/*
+ * Sync link(<oldpath>, <newpath>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+int nfs_link_sync(struct nfs_context *nfs, const char *oldpath, const char *newpath);
+
+
+
+//qqq replace later with lseek(cur, 0)
+off_t nfs_get_current_offset(struct nfsfh *nfsfh);
diff --git a/ccan/nfs/nfs.x b/ccan/nfs/nfs.x
deleted file mode 100755 (executable)
index 58fc34e..0000000
+++ /dev/null
@@ -1,840 +0,0 @@
-/* copied from rfc 1813 */
-
-const NFS3_FHSIZE    = 64;    /* Maximum bytes in a V3 file handle */
-const NFS3_WRITEVERFSIZE = 8;
-const NFS3_CREATEVERFSIZE = 8;
-const NFS3_COOKIEVERFSIZE = 8;
-
-typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
-
-typedef unsigned hyper uint64;
-typedef uint64 cookie3;
-
-struct nfs_fh3 {
-       opaque       data<NFS3_FHSIZE>;
-};
-
-typedef string filename3<>;
-
-struct diropargs3 {
-       nfs_fh3     dir;
-       filename3   name;
-};
-
-enum ftype3 {
-       NF3REG    = 1,
-       NF3DIR    = 2,
-       NF3BLK    = 3,
-       NF3CHR    = 4,
-       NF3LNK    = 5,
-       NF3SOCK   = 6,
-       NF3FIFO   = 7
-};
-
-typedef unsigned long uint32;
-
-typedef long int32;
-
-typedef uint32 mode3;
-
-typedef uint32 uid3;
-
-typedef uint32 gid3;
-
-typedef uint64 size3;
-
-typedef uint64 fileid3;
-
-struct specdata3 {
-       uint32     specdata1;
-       uint32     specdata2;
-};
-
-struct nfstime3 {
-       uint32   seconds;
-       uint32   nseconds;
-};
-
-struct fattr3 {
-       ftype3     type;
-       mode3      mode;
-       uint32     nlink;
-       uid3       uid;
-       gid3       gid;
-       size3      size;
-       size3      used;
-       specdata3  rdev;
-       uint64     fsid;
-       fileid3    fileid;
-       nfstime3   atime;
-       nfstime3   mtime;
-       nfstime3   ctime;
-};
-
-union post_op_attr switch (bool attributes_follow) {
-       case TRUE:
-               fattr3   attributes;
-       case FALSE:
-               void;
-};
-
-
-enum nfsstat3 {
-       NFS3_OK             = 0,
-       NFS3ERR_PERM        = 1,
-       NFS3ERR_NOENT       = 2,
-       NFS3ERR_IO          = 5,
-       NFS3ERR_NXIO        = 6,
-       NFS3ERR_ACCES       = 13,
-       NFS3ERR_EXIST       = 17,
-       NFS3ERR_XDEV        = 18,
-       NFS3ERR_NODEV       = 19,
-       NFS3ERR_NOTDIR      = 20,
-       NFS3ERR_ISDIR       = 21,
-       NFS3ERR_INVAL       = 22,
-       NFS3ERR_FBIG        = 27,
-       NFS3ERR_NOSPC       = 28,
-       NFS3ERR_ROFS        = 30,
-       NFS3ERR_MLINK       = 31,
-       NFS3ERR_NAMETOOLONG = 63,
-       NFS3ERR_NOTEMPTY    = 66,
-       NFS3ERR_DQUOT       = 69,
-       NFS3ERR_STALE       = 70,
-       NFS3ERR_REMOTE      = 71,
-       NFS3ERR_BADHANDLE   = 10001,
-       NFS3ERR_NOT_SYNC    = 10002,
-       NFS3ERR_BAD_COOKIE  = 10003,
-       NFS3ERR_NOTSUPP     = 10004,
-       NFS3ERR_TOOSMALL    = 10005,
-       NFS3ERR_SERVERFAULT = 10006,
-       NFS3ERR_BADTYPE     = 10007,
-       NFS3ERR_JUKEBOX     = 10008
-};     
-
-enum stable_how {
-       UNSTABLE  = 0,
-       DATA_SYNC = 1,
-       FILE_SYNC = 2
-};
-
-typedef uint64 offset3;
-
-typedef uint32 count3;
-
-struct wcc_attr {
-       size3       size;
-       nfstime3    mtime;
-       nfstime3    ctime;
-};
-
-union pre_op_attr switch (bool attributes_follow) {
-       case TRUE:
-               wcc_attr  attributes;
-       case FALSE:
-               void;
-};
-
-struct wcc_data {
-       pre_op_attr    before;
-       post_op_attr   after;
-};
-
-struct WRITE3args {
-       nfs_fh3     file;
-       offset3     offset;
-       count3      count;
-       stable_how  stable;
-       opaque      data<>;
-};
-
-typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
-
-struct WRITE3resok {
-       wcc_data    file_wcc;
-       count3      count;
-       stable_how  committed;
-       writeverf3  verf;
-};
-
-struct WRITE3resfail {
-       wcc_data    file_wcc;
-};
-
-union WRITE3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               WRITE3resok    resok;
-       default:
-               WRITE3resfail  resfail;
-};
-
-struct LOOKUP3args {
-       diropargs3  what;
-};
-
-struct LOOKUP3resok {
-       nfs_fh3      object;
-       post_op_attr obj_attributes;
-       post_op_attr dir_attributes;
-};
-
-struct LOOKUP3resfail {
-       post_op_attr dir_attributes;
-};
-
-
-
-union LOOKUP3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               LOOKUP3resok    resok;
-       default:
-               LOOKUP3resfail  resfail;
-};
-
-struct COMMIT3args {
-       nfs_fh3    file;
-       offset3    offset;
-       count3     count;
-};
-
-struct COMMIT3resok {
-       wcc_data   file_wcc;
-       writeverf3 verf;
-};
-
-struct COMMIT3resfail {
-       wcc_data   file_wcc;
-};
-
-union COMMIT3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               COMMIT3resok   resok;
-       default:
-               COMMIT3resfail resfail;
-};
-
-const ACCESS3_READ    = 0x0001;
-const ACCESS3_LOOKUP  = 0x0002;
-const ACCESS3_MODIFY  = 0x0004;
-const ACCESS3_EXTEND  = 0x0008;
-const ACCESS3_DELETE  = 0x0010;
-const ACCESS3_EXECUTE = 0x0020;
-
-struct ACCESS3args {
-     nfs_fh3  object;
-     uint32   access;
-};
-
-struct ACCESS3resok {
-     post_op_attr   obj_attributes;
-     uint32         access;
-};
-
-struct ACCESS3resfail {
-     post_op_attr   obj_attributes;
-};
-
-union ACCESS3res switch (nfsstat3 status) {
-case NFS3_OK:
-     ACCESS3resok   resok;
-default:
-     ACCESS3resfail resfail;
-};
-
-struct GETATTR3args {
-       nfs_fh3  object;
-};
-
-struct GETATTR3resok {
-        fattr3   obj_attributes;
-};
-
-union GETATTR3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               GETATTR3resok  resok;
-       default:
-               void;
-};
-
-
-
-enum time_how {
-       DONT_CHANGE        = 0,
-       SET_TO_SERVER_TIME = 1,
-       SET_TO_CLIENT_TIME = 2
-};
-
-union set_mode3 switch (bool set_it) {
-       case TRUE:
-               mode3    mode;
-       default:
-       void;
-};
-
-union set_uid3 switch (bool set_it) {
-       case TRUE:
-               uid3     uid;
-       default:
-               void;
-};
-
-union set_gid3 switch (bool set_it) {
-       case TRUE:
-               gid3     gid;
-       default:
-               void;
-};
-
-union set_size3 switch (bool set_it) {
-       case TRUE:
-               size3    size;
-       default:
-               void;
-};
-
-union set_atime switch (time_how set_it) {
-       case SET_TO_CLIENT_TIME:
-               nfstime3  atime;
-       default:
-               void;
-};
-
-union set_mtime switch (time_how set_it) {
-       case SET_TO_CLIENT_TIME:
-               nfstime3  mtime;
-       default:
-               void;
-};
-
-struct sattr3 {
-       set_mode3   mode;
-       set_uid3    uid;
-       set_gid3    gid;
-       set_size3   size;
-       set_atime   atime;
-       set_mtime   mtime;
-};
-
-enum createmode3 {
-       UNCHECKED = 0,
-       GUARDED   = 1,
-       EXCLUSIVE = 2
-};
-
-
-typedef opaque createverf3[NFS3_CREATEVERFSIZE];
-
-union createhow3 switch (createmode3 mode) {
-       case UNCHECKED:
-       case GUARDED:
-               sattr3       obj_attributes;
-       case EXCLUSIVE:
-               createverf3  verf;
-};
-
-struct CREATE3args {
-       diropargs3   where;
-       createhow3   how;
-};
-
-union post_op_fh3 switch (bool handle_follows) {
-       case TRUE:
-               nfs_fh3  handle;
-       case FALSE:
-               void;
-};
-
-struct CREATE3resok {
-       post_op_fh3   obj;
-       post_op_attr  obj_attributes;
-       wcc_data      dir_wcc;
-};
-
-struct CREATE3resfail {
-       wcc_data      dir_wcc;
-       };
-
-union CREATE3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               CREATE3resok    resok;
-       default:
-               CREATE3resfail  resfail;
-};
-
-struct REMOVE3args {
-       diropargs3  object;
-};
-
-struct REMOVE3resok {
-       wcc_data    dir_wcc;
-};
-
-struct REMOVE3resfail {
-       wcc_data    dir_wcc;
-};
-
-union REMOVE3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               REMOVE3resok   resok;
-       default:
-       REMOVE3resfail resfail;
-};
-
-struct READ3args {
-       nfs_fh3  file;
-       offset3  offset;
-       count3   count;
-};
-
-struct READ3resok {
-       post_op_attr   file_attributes;
-       count3         count;
-       bool           eof;
-       opaque         data<>;
-};
-
-struct READ3resfail {
-       post_op_attr   file_attributes;
-};
-
-union READ3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               READ3resok   resok;
-       default:
-               READ3resfail resfail;
-};
-
-
-const FSF3_LINK        = 0x0001;
-const FSF3_SYMLINK     = 0x0002;
-const FSF3_HOMOGENEOUS = 0x0008;
-const FSF3_CANSETTIME  = 0x0010;
-
-struct FSINFO3args {
-       nfs_fh3   fsroot;
-};
-
-struct FSINFO3resok {
-       post_op_attr obj_attributes;
-       uint32       rtmax;
-       uint32       rtpref;
-       uint32       rtmult;
-       uint32       wtmax;
-       uint32       wtpref;
-       uint32       wtmult;
-       uint32       dtpref;
-       size3        maxfilesize;
-       nfstime3     time_delta;
-       uint32       properties;
-};
-
-struct FSINFO3resfail {
-       post_op_attr obj_attributes;
-};
-
-union FSINFO3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               FSINFO3resok   resok;
-       default:
-               FSINFO3resfail resfail;
-};
-
-
-struct FSSTAT3args {
-       nfs_fh3   fsroot;
-};
-
-struct FSSTAT3resok {
-       post_op_attr obj_attributes;
-       size3        tbytes;
-       size3        fbytes;
-       size3        abytes;
-       size3        tfiles;
-       size3        ffiles;
-       size3        afiles;
-       uint32       invarsec;
-};
-
-struct FSSTAT3resfail {
-       post_op_attr obj_attributes;
-};
-
-union FSSTAT3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               FSSTAT3resok   resok;
-       default:
-               FSSTAT3resfail resfail;
-};
-
-struct PATHCONF3args {
-       nfs_fh3   object;
-};
-
-struct PATHCONF3resok {
-       post_op_attr obj_attributes;
-       uint32       linkmax;
-       uint32       name_max;
-       bool         no_trunc;
-       bool         chown_restricted;
-       bool         case_insensitive;
-       bool         case_preserving;
-};
-
-struct PATHCONF3resfail {
-       post_op_attr obj_attributes;
-};
-
-union PATHCONF3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               PATHCONF3resok   resok;
-       default:
-               PATHCONF3resfail resfail;
-};
-
-typedef string nfspath3<>;
-
-struct symlinkdata3 {
-       sattr3    symlink_attributes;
-       nfspath3  symlink_data;
-};
-
-struct SYMLINK3args {
-       diropargs3    where;
-       symlinkdata3  symlink;
-};
-
-struct SYMLINK3resok {
-       post_op_fh3   obj;
-       post_op_attr  obj_attributes;
-       wcc_data      dir_wcc;
-};
-
-struct SYMLINK3resfail {
-       wcc_data      dir_wcc;
-};
-
-union SYMLINK3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               SYMLINK3resok   resok;
-       default:
-               SYMLINK3resfail resfail;
-};
-
-
-struct READLINK3args {
-       nfs_fh3  symlink;
-};
-
-struct READLINK3resok {
-       post_op_attr   symlink_attributes;
-       nfspath3       data;
-};
-
-struct READLINK3resfail {
-       post_op_attr   symlink_attributes;
-};
-
-union READLINK3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               READLINK3resok   resok;
-       default:
-       READLINK3resfail resfail;
-};
-
-
-struct devicedata3 {
-       sattr3     dev_attributes;
-       specdata3  spec;
-};
-
-union mknoddata3 switch (ftype3 type) {
-       case NF3CHR:
-       case NF3BLK:
-               devicedata3  device;
-       case NF3SOCK:
-       case NF3FIFO:
-               sattr3       pipe_attributes;
-       default:
-               void;
-};
-
-struct MKNOD3args {
-       diropargs3   where;
-       mknoddata3   what;
-};
-
-struct MKNOD3resok {
-       post_op_fh3   obj;
-       post_op_attr  obj_attributes;
-       wcc_data      dir_wcc;
-};
-
-struct MKNOD3resfail {
-       wcc_data      dir_wcc;
-};
-
-union MKNOD3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               MKNOD3resok   resok;
-       default:
-               MKNOD3resfail resfail;
-};
-
-
-struct MKDIR3args {
-       diropargs3   where;
-       sattr3       attributes;
-};
-
-struct MKDIR3resok {
-       post_op_fh3   obj;
-       post_op_attr  obj_attributes;
-       wcc_data      dir_wcc;
-};
-
-struct MKDIR3resfail {
-       wcc_data      dir_wcc;
-};
-
-union MKDIR3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               MKDIR3resok   resok;
-       default:
-               MKDIR3resfail resfail;
-};
-
-struct RMDIR3args {
-       diropargs3  object;
-};
-
-struct RMDIR3resok {
-       wcc_data    dir_wcc;
-};
-
-struct RMDIR3resfail {
-       wcc_data    dir_wcc;
-};
-
-union RMDIR3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               RMDIR3resok   resok;
-       default:
-               RMDIR3resfail resfail;
-};
-
-struct RENAME3args {
-       diropargs3   from;
-       diropargs3   to;
-};
-
-struct RENAME3resok {
-       wcc_data     fromdir_wcc;
-       wcc_data     todir_wcc;
-};
-
-struct RENAME3resfail {
-       wcc_data     fromdir_wcc;
-       wcc_data     todir_wcc;
-};
-
-union RENAME3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               RENAME3resok   resok;
-       default:
-               RENAME3resfail resfail;
-};
-
-struct READDIRPLUS3args {
-       nfs_fh3      dir;
-       cookie3      cookie;
-       cookieverf3  cookieverf;
-       count3       dircount;
-       count3       maxcount;
-};
-
-struct entryplus3 {
-       fileid3      fileid;
-       filename3    name;
-       cookie3      cookie;
-       post_op_attr name_attributes;
-       post_op_fh3  name_handle;
-       entryplus3   *nextentry;
-};
-
-struct dirlistplus3 {
-       entryplus3   *entries;
-       bool         eof;
-};
-
-struct READDIRPLUS3resok {
-       post_op_attr dir_attributes;
-       cookieverf3  cookieverf;
-       dirlistplus3 reply;
-};
-
-
-struct READDIRPLUS3resfail {
-       post_op_attr dir_attributes;
-};
-
-union READDIRPLUS3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               READDIRPLUS3resok   resok;
-       default:
-               READDIRPLUS3resfail resfail;
-};
-
-struct READDIR3args {
-       nfs_fh3      dir;
-       cookie3      cookie;
-       cookieverf3  cookieverf;
-       count3       count;
-};
-
-
-struct entry3 {
-       fileid3      fileid;
-       filename3    name;
-       cookie3      cookie;
-       entry3       *nextentry;
-};
-
-struct dirlist3 {
-       entry3  *entries;
-       bool    eof;
-};
-
-struct READDIR3resok {
-       post_op_attr dir_attributes;
-       cookieverf3  cookieverf;
-       dirlist3     reply;
-};
-
-struct READDIR3resfail {
-       post_op_attr dir_attributes;
-};
-
-union READDIR3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               READDIR3resok   resok;
-       default:
-               READDIR3resfail resfail;
-};
-
-struct LINK3args {
-       nfs_fh3     file;
-       diropargs3  link;
-};
-
-struct LINK3resok {
-       post_op_attr   file_attributes;
-       wcc_data       linkdir_wcc;
-};
-
-struct LINK3resfail {
-       post_op_attr   file_attributes;
-       wcc_data       linkdir_wcc;
-};
-
-union LINK3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               LINK3resok    resok;
-       default:
-               LINK3resfail  resfail;
-};
-
-union sattrguard3 switch (bool check) {
-       case TRUE:
-               nfstime3  obj_ctime;
-       case FALSE:
-               void;
-};
-
-struct SETATTR3args {
-       nfs_fh3      object;
-       sattr3       new_attributes;
-       sattrguard3  guard;
-};
-
-struct SETATTR3resok {
-       wcc_data  obj_wcc;
-};
-
-struct SETATTR3resfail {
-       wcc_data  obj_wcc;
-};
-
-union SETATTR3res switch (nfsstat3 status) {
-       case NFS3_OK:
-               SETATTR3resok   resok;
-       default:
-               SETATTR3resfail resfail;
-};
-
-program NFS_PROGRAM {
-       version NFS_V3 {
-               void
-               NFS3_NULL(void)                    = 0;
-
-               GETATTR3res
-               NFS3_GETATTR(GETATTR3args)         = 1;
-
-               SETATTR3res
-               NFS3_SETATTR(SETATTR3args)         = 2;
-
-               LOOKUP3res
-               NFS3_LOOKUP(LOOKUP3args)           = 3;
-
-               ACCESS3res
-               NFS3_ACCESS(ACCESS3args)           = 4;
-
-               READLINK3res
-               NFS3_READLINK(READLINK3args)       = 5;
-
-               READ3res
-               NFS3_READ(READ3args)               = 6;
-
-               WRITE3res
-               NFS3_WRITE(WRITE3args)             = 7;
-
-               CREATE3res
-               NFS3_CREATE(CREATE3args)           = 8;
-
-               MKDIR3res
-               NFS3_MKDIR(MKDIR3args)             = 9;
-
-               SYMLINK3res
-               NFS3_SYMLINK(SYMLINK3args)         = 10;
-
-/*             MKNOD3res NFSPROC3_MKNOD(MKNOD3args)             = 11;*/
-
-               REMOVE3res
-               NFS3_REMOVE(REMOVE3args)           = 12;
-
-               RMDIR3res
-               NFS3_RMDIR(RMDIR3args)             = 13;
-
-               RENAME3res
-               NFS3_RENAME(RENAME3args)           = 14;
-
-               LINK3res
-               NFS3_LINK(LINK3args)               = 15;
-
-               READDIR3res
-               NFS3_READDIR(READDIR3args)         = 16;
-
-               READDIRPLUS3res
-               NFS3_READDIRPLUS(READDIRPLUS3args) = 17;
-
-               FSSTAT3res
-               NFS3_FSSTAT(FSSTAT3args)           = 18;
-
-               FSINFO3res
-               NFS3_FSINFO(FSINFO3args)           = 19;
-
-               PATHCONF3res
-               NFS3_PATHCONF(PATHCONF3args)       = 20;
-
-               COMMIT3res
-               NFS3_COMMIT(COMMIT3args)           = 21;
-       } = 3;
-} = 100003;
index c1053340c6bf29a457f4ba733ff882d91e78ec38..71c72cd415a56b513ccd44a4eb2ee1b2931ab407 100644 (file)
 #include <stdio.h>
 #include <errno.h>
 #include <rpc/xdr.h>
 #include <stdio.h>
 #include <errno.h>
 #include <rpc/xdr.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
-#include "libnfs-raw-nfsacl.h"
+#include "rpc/nfsacl.h"
 
 
 int rpc_nfsacl_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
 
 
 int rpc_nfsacl_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
diff --git a/ccan/nfs/nfsacl.x b/ccan/nfs/nfsacl.x
deleted file mode 100644 (file)
index 68313c9..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-/* deducted from wireshark traces */
-
-
-program NFSACL_PROGRAM {
-       version NFSACL_V3 {
-       void      NFSACL3_NULL(void)    = 0;
-       } = 3;
-} = 100227;
diff --git a/ccan/nfs/nfsclient-async.c b/ccan/nfs/nfsclient-async.c
deleted file mode 100644 (file)
index 4abb901..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-/* 
-   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Example program using the highlevel async interface.
- */
-
-#define SERVER "10.1.1.27"
-#define EXPORT "/VIRTUAL"
-#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
-#define NFSDIR "/BOOKS/Classics/"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <poll.h>
-#include "libnfs.h"
-
-struct client {
-       char *server;
-       char *export;
-       uint32_t mount_port;
-       struct nfsfh *nfsfh;
-       int is_finished;
-};
-
-void nfs_opendir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       struct nfsdir *nfsdir = data;
-       struct nfsdirent *nfsdirent;
-
-       if (status < 0) {
-               printf("opendir failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("opendir successful\n");
-       while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
-               printf("Inode:%d Name:%s\n", (int)nfsdirent->inode, nfsdirent->name);
-       }
-       nfs_closedir(nfs, nfsdir);
-
-       client->is_finished = 1;
-}
-
-void nfs_close_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       if (status < 0) {
-               printf("close failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("close successful\n");
-       printf("call opendir(%s)\n", NFSDIR);
-       if (nfs_opendir_async(nfs, NFSDIR, nfs_opendir_cb, client) != 0) {
-               printf("Failed to start async nfs close\n");
-               exit(10);
-       }
-}
-
-void nfs_fstat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       struct stat *st;
-       if (status < 0) {
-               printf("fstat call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("Got reply from server for fstat(%s).\n", NFSFILE);
-       st = (struct stat *)data;
-       printf("Mode %04o\n", st->st_mode);
-       printf("Size %d\n", (int)st->st_size);
-       printf("Inode %04o\n", (int)st->st_ino);
-
-       printf("Close file\n");
-       if (nfs_close_async(nfs, client->nfsfh, nfs_close_cb, client) != 0) {
-               printf("Failed to start async nfs close\n");
-               exit(10);
-       }
-}
-
-void nfs_read_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       char *read_data;
-       int i;
-
-       if (status < 0) {
-               printf("read failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("read successful with %d bytes of data\n", status);
-       read_data = data;
-       for (i=0;i<16;i++) {
-               printf("%02x ", read_data[i]&0xff);
-       }
-       printf("\n");
-       printf("Fstat file :%s\n", NFSFILE);
-       if (nfs_fstat_async(nfs, client->nfsfh, nfs_fstat_cb, client) != 0) {
-               printf("Failed to start async nfs fstat\n");
-               exit(10);
-       }
-}
-
-void nfs_open_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       struct nfsfh *nfsfh;
-
-       if (status < 0) {
-               printf("open call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       nfsfh         = data;
-       client->nfsfh = nfsfh;
-       printf("Got reply from server for open(%s). Handle:%p\n", NFSFILE, data);
-       printf("Read first 16 bytes\n");
-       if (nfs_pread_async(nfs, nfsfh, 0, 16, nfs_read_cb, client) != 0) {
-               printf("Failed to start async nfs open\n");
-               exit(10);
-       }
-}
-
-void nfs_stat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       struct stat *st;
-       if (status < 0) {
-               printf("stat call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("Got reply from server for stat(%s).\n", NFSFILE);
-       st = (struct stat *)data;
-       printf("Mode %04o\n", st->st_mode);
-       printf("Size %d\n", (int)st->st_size);
-       printf("Inode %04o\n", (int)st->st_ino);
-
-       printf("Open file for reading :%s\n", NFSFILE);
-       if (nfs_open_async(nfs, NFSFILE, O_RDONLY, nfs_open_cb, client) != 0) {
-               printf("Failed to start async nfs open\n");
-               exit(10);
-       }
-}
-
-void nfs_mount_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       if (status < 0) {
-               printf("mount/mnt call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-
-       printf("Got reply from server for MOUNT/MNT procedure.\n");
-       printf("Stat file :%s\n", NFSFILE);
-       if (nfs_stat_async(nfs, NFSFILE, nfs_stat_cb, client) != 0) {
-               printf("Failed to start async nfs stat\n");
-               exit(10);
-       }
-}
-
-
-
-int main(int argc, char *argv[])
-{
-       struct nfs_context *nfs;
-       struct pollfd pfd;
-       int ret;
-       struct client client;
-
-       client.server = SERVER;
-       client.export = EXPORT;
-       client.is_finished = 0;
-
-       nfs = nfs_init_context();
-       if (nfs == NULL) {
-               printf("failed to init context\n");
-               exit(10);
-       }
-
-       ret = nfs_mount_async(nfs, client.server, client.export, nfs_mount_cb, &client);
-       if (ret != 0) {
-               printf("Failed to start async nfs mount\n");
-               exit(10);
-       }
-
-       for (;;) {
-               pfd.fd = nfs_get_fd(nfs);
-               pfd.events = nfs_which_events(nfs);
-
-               if (poll(&pfd, 1, -1) < 0) {
-                       printf("Poll failed");
-                       exit(10);
-               }
-               if (nfs_service(nfs, pfd.revents) < 0) {
-                       printf("nfs_service failed\n");
-                       break;
-               }
-               if (client.is_finished) {
-                       break;
-               }
-       }
-       
-       nfs_destroy_context(nfs);
-       printf("nfsclient finished\n");
-       return 0;
-}
diff --git a/ccan/nfs/nfsclient-raw.c b/ccan/nfs/nfsclient-raw.c
deleted file mode 100644 (file)
index 4738bdf..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/* 
-   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Example program using the lowlevel raw interface.
- * This allow accurate control of the exact commands that are being used.
- */
-
-#define SERVER "10.1.1.27"
-#define EXPORT "/VIRTUAL"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <poll.h>
-#include "libnfs.h"
-#include "libnfs-raw.h"
-#include "libnfs-raw-mount.h"
-
-struct client {
-       char *server;
-       char *export;
-       uint32_t mount_port;
-       int is_finished;
-};
-
-void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       mountres3 *res;
-       struct client *client = private_data;
-
-       if (status == RPC_STATUS_ERROR) {
-               printf("mount/mnt call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-       if (status != RPC_STATUS_SUCCESS) {
-               printf("mount/mnt call to server %s failed, status:%d\n", client->server, status);
-               exit(10);
-       }
-
-       res = data;
-       if (res->fhs_status != MNT3_OK) {
-               printf("RPC error: Mount failed with error %s(%d) %s(%d)", mountstat3_to_str(res->fhs_status), res->fhs_status, strerror(-mountstat3_to_errno(res->fhs_status)), -mountstat3_to_errno(res->fhs_status));
-               exit(10);
-       }
-
-       printf("Got reply from server for MOUNT/MNT procedure.\n");
-       client->is_finished = 1;
-}
-
-
-void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       if (status == RPC_STATUS_ERROR) {
-               printf("mount null call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-       if (status != RPC_STATUS_SUCCESS) {
-               printf("mount null call to server %s failed, status:%d\n", client->server, status);
-               exit(10);
-       }
-
-       printf("Got reply from server for MOUNT/NULL procedure.\n");
-       printf("Send MOUNT/MNT command for %s\n", client->export);
-       if (rpc_mount_mnt_async(rpc, mount_mnt_cb, client->export, client) != 0) {
-               printf("Failed to send mnt request\n");
-               exit(10);
-       }
-
-}
-
-void mount_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       if (status != RPC_STATUS_SUCCESS) {
-               printf("connection to RPC.MOUNTD on server %s failed\n", client->server);
-               exit(10);
-       }
-
-       printf("Connected to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
-       printf("Send NULL request to check if RPC.MOUNTD is actually running\n");
-       if (rpc_mount_null_async(rpc, mount_null_cb, client) != 0) {
-               printf("Failed to send null request\n");
-               exit(10);
-       }
-}
-
-
-void pmap_getport_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       struct client *client = private_data;
-       uint32_t port;
-
-       if (status == RPC_STATUS_ERROR) {
-               printf("portmapper getport call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-               if (status != RPC_STATUS_SUCCESS) {
-               printf("portmapper getport call to server %s failed, status:%d\n", client->server, status);
-               exit(10);
-       }
-
-       client->mount_port = *(uint32_t *)data;
-       printf("GETPORT returned Port:%d\n", client->mount_port);
-       if (client->mount_port == 0) {
-               printf("RPC.MOUNTD is not available on server : %s\n", client->server, client->mount_port);
-               exit(10);
-       }               
-
-       printf("Disconnect socket from portmap server\n");
-       if (rpc_disconnect(rpc, "normal disconnect") != 0) {
-               printf("Failed to disconnect socket to portmapper\n");
-               exit(10);
-       }
-
-       printf("Connect to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
-       if (rpc_connect_async(rpc, client->server, client->mount_port, 1, mount_connect_cb, client) != 0) {
-               printf("Failed to start connection\n");
-               exit(10);
-       }
-}
-
-
-void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       if (status == RPC_STATUS_ERROR) {
-               printf("portmapper null call failed with \"%s\"\n", (char *)data);
-               exit(10);
-       }
-       if (status != RPC_STATUS_SUCCESS) {
-               printf("portmapper null call to server %s failed, status:%d\n", client->server, status);
-               exit(10);
-       }
-
-       printf("Got reply from server for PORTMAP/NULL procedure.\n");
-       printf("Send getport request asking for MOUNT port\n");
-       if (rpc_pmap_getport_async(rpc, MOUNT_PROGRAM, MOUNT_V3, pmap_getport_cb, client) != 0) {
-               printf("Failed to send getport request\n");
-               exit(10);
-       }
-}
-
-void pmap_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
-{
-       struct client *client = private_data;
-
-       printf("pmap_connect_cb    status:%d.\n", status);
-       if (status != RPC_STATUS_SUCCESS) {
-               printf("connection to portmapper on server %s failed\n", client->server);
-               exit(10);
-       }
-
-       printf("Send NULL request to check if portmapper is actually running\n");
-       if (rpc_pmap_null_async(rpc, pmap_null_cb, client) != 0) {
-               printf("Failed to send null request\n");
-               exit(10);
-       }
-}
-
-
-int main(int argc, char *argv[])
-{
-       struct rpc_context *rpc;
-       struct pollfd pfd;
-       int ret;
-       struct client client;
-
-       rpc = rpc_init_context();
-       if (rpc == NULL) {
-               printf("failed to init context\n");
-               exit(10);
-       }
-
-       client.server = SERVER;
-       client.export = EXPORT;
-       client.is_finished = 0;
-       if (rpc_connect_async(rpc, client.server, 111, 0, pmap_connect_cb, &client) != 0) {
-               printf("Failed to start connection\n");
-               exit(10);
-       }
-
-       for (;;) {
-               pfd.fd = rpc_get_fd(rpc);
-               pfd.events = rpc_which_events(rpc);
-
-               if (poll(&pfd, 1, -1) < 0) {
-                       printf("Poll failed");
-                       exit(10);
-               }
-               if (rpc_service(rpc, pfd.revents) < 0) {
-                       printf("rpc_service failed\n");
-                       break;
-               }
-               if (client.is_finished) {
-                       break;
-               }
-       }
-       
-       rpc_destroy_context(rpc);
-       rpc=NULL;
-       printf("nfsclient finished\n");
-       return 0;
-}
diff --git a/ccan/nfs/nfsclient-sync.c b/ccan/nfs/nfsclient-sync.c
deleted file mode 100644 (file)
index a9f5265..0000000
+++ /dev/null
@@ -1,202 +0,0 @@
-/* 
-   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
-   
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-   
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-   
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-/* Example program using the highlevel sync interface
- */
-
-#define SERVER "10.1.1.27"
-#define EXPORT "/VIRTUAL"
-#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
-#define NFSFILER "/BOOKS/Classics/Dracula.djvu.renamed"
-#define NFSFILEW "/BOOKS/Classics/foo"
-#define NFSDIR "/BOOKS/Classics/"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/statvfs.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include "libnfs.h"
-#include <rpc/rpc.h>            /* for authunix_create() */
-
-struct client {
-       char *server;
-       char *export;
-       uint32_t mount_port;
-       int is_finished;
-};
-
-
-int main(int argc, char *argv[])
-{
-       struct nfs_context *nfs;
-       int i, ret;
-       struct client client;
-       struct stat st;
-       struct nfsfh  *nfsfh;
-       struct nfsdir *nfsdir;
-       struct nfsdirent *nfsdirent;
-       client.server = SERVER;
-       client.export = EXPORT;
-       client.is_finished = 0;
-       char buf[16];
-       off_t offset;
-       struct statvfs svfs;
-
-       nfs = nfs_init_context();
-       if (nfs == NULL) {
-               printf("failed to init context\n");
-               exit(10);
-       }
-
-       ret = nfs_mount_sync(nfs, client.server, client.export);
-       if (ret != 0) {
-               printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("mounted share successfully\n");
-exit(10);
-
-       ret = nfs_stat_sync(nfs, NFSFILE, &st);
-       if (ret != 0) {
-               printf("Failed to stat(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("Mode %04o\n", st.st_mode);
-       printf("Size %d\n", (int)st.st_size);
-       printf("Inode %04o\n", (int)st.st_ino);
-
-       ret = nfs_open_sync(nfs, NFSFILE, O_RDONLY, &nfsfh);
-       if (ret != 0) {
-               printf("Failed to open(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-
-       ret = nfs_read_sync(nfs, nfsfh, 16, buf);
-       if (ret < 0) {
-               printf("Failed to pread(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("read %d bytes\n", ret);
-       for (i=0;i<16;i++) {
-               printf("%02x ", buf[i]&0xff);
-       }
-       printf("\n");
-       ret = nfs_read_sync(nfs, nfsfh, 16, buf);
-       if (ret < 0) {
-               printf("Failed to pread(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("read %d bytes\n", ret);
-       for (i=0;i<16;i++) {
-               printf("%02x ", buf[i]&0xff);
-       }
-       printf("\n");
-
-       ret = (int)nfs_lseek_sync(nfs, nfsfh, 0, SEEK_CUR, &offset);
-       if (ret < 0) {
-               printf("Failed to lseek(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("File position is %d\n", (int)offset);
-
-       printf("seek to end of file\n");
-       ret = (int)nfs_lseek_sync(nfs, nfsfh, 0, SEEK_END, &offset);
-       if (ret < 0) {
-               printf("Failed to lseek(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("File position is %d\n", (int)offset);
-
-       ret = nfs_fstat_sync(nfs, nfsfh, &st);
-       if (ret != 0) {
-               printf("Failed to stat(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("Mode %04o\n", st.st_mode);
-       printf("Size %d\n", (int)st.st_size);
-       printf("Inode %04o\n", (int)st.st_ino);
-
-
-       ret = nfs_close_sync(nfs, nfsfh);
-       if (ret < 0) {
-               printf("Failed to close(%s)\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-
-       ret = nfs_opendir_sync(nfs, NFSDIR, &nfsdir);
-       if (ret != 0) {
-               printf("Failed to open(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-               exit(10);
-       }
-       while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
-               printf("Inode:%d Name:%s\n", (int)nfsdirent->inode, nfsdirent->name);
-       }
-       nfs_closedir(nfs, nfsdir);
-
-
-       ret = nfs_open_sync(nfs, NFSFILEW, O_WRONLY, &nfsfh);
-       if (ret != 0) {
-               printf("Failed to open(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
-               exit(10);
-       }
-       ret = nfs_pwrite_sync(nfs, nfsfh, 0, 16, buf);
-       if (ret < 0) {
-               printf("Failed to pwrite(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
-               exit(10);
-       }
-       ret = nfs_fsync_sync(nfs, nfsfh);
-       if (ret < 0) {
-               printf("Failed to fsync(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
-               exit(10);
-       }
-       ret = nfs_close_sync(nfs, nfsfh);
-       if (ret < 0) {
-               printf("Failed to close(%s)\n", NFSFILEW, nfs_get_error(nfs));
-               exit(10);
-       }
-
-
-       ret = nfs_statvfs_sync(nfs, NFSDIR, &svfs);
-       if (ret < 0) {
-               printf("Failed to statvfs(%s)\n", NFSDIR, nfs_get_error(nfs));
-               exit(10);
-       }
-       printf("files %d/%d/%d\n", (int)svfs.f_files, (int)svfs.f_ffree, (int)svfs.f_favail);
-
-
-       ret = nfs_access_sync(nfs, NFSFILE, R_OK);
-       if (ret != 0) {
-               printf("Failed to access(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-       }
-
-       /* become root */
-       nfs_set_auth(nfs, authunix_create("Ronnies-Laptop", 0, 0, 0, NULL));
-
-       ret = nfs_link_sync(nfs, NFSFILE, NFSFILER);
-       if (ret != 0) {
-               printf("Failed to link(%s) %s\n", NFSFILE, nfs_get_error(nfs));
-       }
-
-
-       nfs_destroy_context(nfs);
-       printf("nfsclient finished\n");
-       return 0;
-}
index 0f32d7e074fbec8b774bb704fb36fd726d65bc52..79c0392fb758022ac6054592add0d09ccbd27d2f 100644 (file)
@@ -20,7 +20,7 @@
 #include <rpc/xdr.h>
 #include <rpc/rpc_msg.h>
 #include "dlinklist.h"
 #include <rpc/xdr.h>
 #include <rpc/rpc_msg.h>
 #include "dlinklist.h"
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 
index 269aded6781464c9938fa5d7a3fe18e4691edcf9..5753736e13964b9b1c38f495767e6c94b61c6dc6 100644 (file)
 
 #include <stdio.h>
 #include <rpc/xdr.h>
 
 #include <stdio.h>
 #include <rpc/xdr.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
-#include "libnfs-raw-portmap.h"
+#include "rpc/portmap.h"
 
 
 int rpc_pmap_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
 
 
 int rpc_pmap_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
diff --git a/ccan/nfs/portmap.x b/ccan/nfs/portmap.x
deleted file mode 100644 (file)
index 8921b92..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * From RFC1833
- */
-
-const PMAP_PORT = 111;      /* portmapper port number */
-
-struct mapping {
-       unsigned int prog;
-       unsigned int vers;
-       unsigned int prot;
-       unsigned int port;
-};
-
-struct call_args {
-       unsigned int prog;
-       unsigned int vers;
-       unsigned int proc;
-       opaque args<>;
-};
-
-
-program PMAP_PROGRAM {
-       version PMAP_V2 {
-               void
-               PMAP_NULL(void)         = 0;
-
-               bool
-               PMAP_SET(mapping)       = 1;
-
-               bool
-               PMAP_UNSET(mapping)     = 2;
-
-               unsigned int
-               PMAP_GETPORT(mapping)   = 3;
-       } = 2;
-} = 100000;
-
diff --git a/ccan/nfs/rpc/mount.x b/ccan/nfs/rpc/mount.x
new file mode 100644 (file)
index 0000000..6c2f071
--- /dev/null
@@ -0,0 +1,71 @@
+/* copied from RFC1813 */
+
+const MNTPATHLEN = 1024;  /* Maximum bytes in a path name */
+const MNTNAMLEN  = 255;   /* Maximum bytes in a name */
+const FHSIZE3    = 64;    /* Maximum bytes in a V3 file handle */
+
+
+typedef opaque fhandle3<FHSIZE3>;
+typedef string dirpath<MNTPATHLEN>;
+typedef string name<MNTNAMLEN>;
+
+enum mountstat3 {
+       MNT3_OK = 0,                 /* no error */
+       MNT3ERR_PERM = 1,            /* Not owner */
+       MNT3ERR_NOENT = 2,           /* No such file or directory */
+       MNT3ERR_IO = 5,              /* I/O error */
+       MNT3ERR_ACCES = 13,          /* Permission denied */
+       MNT3ERR_NOTDIR = 20,         /* Not a directory */
+       MNT3ERR_INVAL = 22,          /* Invalid argument */
+       MNT3ERR_NAMETOOLONG = 63,    /* Filename too long */
+       MNT3ERR_NOTSUPP = 10004,     /* Operation not supported */
+       MNT3ERR_SERVERFAULT = 10006  /* A failure on the server */
+};
+
+
+typedef struct mountbody *mountlist;
+
+struct mountbody {
+       name       ml_hostname;
+       dirpath    ml_directory;
+       mountlist  ml_next;
+};
+
+typedef struct groupnode *groups;
+
+struct groupnode {
+       name     gr_name;
+       groups   gr_next;
+};
+
+
+typedef struct exportnode *exports;
+
+struct exportnode {
+       dirpath  ex_dir;
+       groups   ex_groups;
+       exports  ex_next;
+};
+
+struct mountres3_ok {
+       fhandle3   fhandle;
+       int        auth_flavors<>;
+};
+
+union mountres3 switch (mountstat3 fhs_status) {
+       case MNT3_OK:
+               mountres3_ok  mountinfo;
+       default:
+               void;
+};
+
+program MOUNT_PROGRAM {
+       version MOUNT_V3 {
+       void      MOUNT3_NULL(void)    = 0;
+       mountres3 MOUNT3_MNT(dirpath)  = 1;
+       mountlist MOUNT3_DUMP(void)    = 2;
+       void      MOUNT3_UMNT(dirpath) = 3;
+       void      MOUNT3_UMNTALL(void) = 4;
+       exports   MOUNT3_EXPORT(void)  = 5;
+       } = 3;
+} = 100005;
diff --git a/ccan/nfs/rpc/nfs.x b/ccan/nfs/rpc/nfs.x
new file mode 100755 (executable)
index 0000000..58fc34e
--- /dev/null
@@ -0,0 +1,840 @@
+/* copied from rfc 1813 */
+
+const NFS3_FHSIZE    = 64;    /* Maximum bytes in a V3 file handle */
+const NFS3_WRITEVERFSIZE = 8;
+const NFS3_CREATEVERFSIZE = 8;
+const NFS3_COOKIEVERFSIZE = 8;
+
+typedef opaque cookieverf3[NFS3_COOKIEVERFSIZE];
+
+typedef unsigned hyper uint64;
+typedef uint64 cookie3;
+
+struct nfs_fh3 {
+       opaque       data<NFS3_FHSIZE>;
+};
+
+typedef string filename3<>;
+
+struct diropargs3 {
+       nfs_fh3     dir;
+       filename3   name;
+};
+
+enum ftype3 {
+       NF3REG    = 1,
+       NF3DIR    = 2,
+       NF3BLK    = 3,
+       NF3CHR    = 4,
+       NF3LNK    = 5,
+       NF3SOCK   = 6,
+       NF3FIFO   = 7
+};
+
+typedef unsigned long uint32;
+
+typedef long int32;
+
+typedef uint32 mode3;
+
+typedef uint32 uid3;
+
+typedef uint32 gid3;
+
+typedef uint64 size3;
+
+typedef uint64 fileid3;
+
+struct specdata3 {
+       uint32     specdata1;
+       uint32     specdata2;
+};
+
+struct nfstime3 {
+       uint32   seconds;
+       uint32   nseconds;
+};
+
+struct fattr3 {
+       ftype3     type;
+       mode3      mode;
+       uint32     nlink;
+       uid3       uid;
+       gid3       gid;
+       size3      size;
+       size3      used;
+       specdata3  rdev;
+       uint64     fsid;
+       fileid3    fileid;
+       nfstime3   atime;
+       nfstime3   mtime;
+       nfstime3   ctime;
+};
+
+union post_op_attr switch (bool attributes_follow) {
+       case TRUE:
+               fattr3   attributes;
+       case FALSE:
+               void;
+};
+
+
+enum nfsstat3 {
+       NFS3_OK             = 0,
+       NFS3ERR_PERM        = 1,
+       NFS3ERR_NOENT       = 2,
+       NFS3ERR_IO          = 5,
+       NFS3ERR_NXIO        = 6,
+       NFS3ERR_ACCES       = 13,
+       NFS3ERR_EXIST       = 17,
+       NFS3ERR_XDEV        = 18,
+       NFS3ERR_NODEV       = 19,
+       NFS3ERR_NOTDIR      = 20,
+       NFS3ERR_ISDIR       = 21,
+       NFS3ERR_INVAL       = 22,
+       NFS3ERR_FBIG        = 27,
+       NFS3ERR_NOSPC       = 28,
+       NFS3ERR_ROFS        = 30,
+       NFS3ERR_MLINK       = 31,
+       NFS3ERR_NAMETOOLONG = 63,
+       NFS3ERR_NOTEMPTY    = 66,
+       NFS3ERR_DQUOT       = 69,
+       NFS3ERR_STALE       = 70,
+       NFS3ERR_REMOTE      = 71,
+       NFS3ERR_BADHANDLE   = 10001,
+       NFS3ERR_NOT_SYNC    = 10002,
+       NFS3ERR_BAD_COOKIE  = 10003,
+       NFS3ERR_NOTSUPP     = 10004,
+       NFS3ERR_TOOSMALL    = 10005,
+       NFS3ERR_SERVERFAULT = 10006,
+       NFS3ERR_BADTYPE     = 10007,
+       NFS3ERR_JUKEBOX     = 10008
+};     
+
+enum stable_how {
+       UNSTABLE  = 0,
+       DATA_SYNC = 1,
+       FILE_SYNC = 2
+};
+
+typedef uint64 offset3;
+
+typedef uint32 count3;
+
+struct wcc_attr {
+       size3       size;
+       nfstime3    mtime;
+       nfstime3    ctime;
+};
+
+union pre_op_attr switch (bool attributes_follow) {
+       case TRUE:
+               wcc_attr  attributes;
+       case FALSE:
+               void;
+};
+
+struct wcc_data {
+       pre_op_attr    before;
+       post_op_attr   after;
+};
+
+struct WRITE3args {
+       nfs_fh3     file;
+       offset3     offset;
+       count3      count;
+       stable_how  stable;
+       opaque      data<>;
+};
+
+typedef opaque writeverf3[NFS3_WRITEVERFSIZE];
+
+struct WRITE3resok {
+       wcc_data    file_wcc;
+       count3      count;
+       stable_how  committed;
+       writeverf3  verf;
+};
+
+struct WRITE3resfail {
+       wcc_data    file_wcc;
+};
+
+union WRITE3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               WRITE3resok    resok;
+       default:
+               WRITE3resfail  resfail;
+};
+
+struct LOOKUP3args {
+       diropargs3  what;
+};
+
+struct LOOKUP3resok {
+       nfs_fh3      object;
+       post_op_attr obj_attributes;
+       post_op_attr dir_attributes;
+};
+
+struct LOOKUP3resfail {
+       post_op_attr dir_attributes;
+};
+
+
+
+union LOOKUP3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               LOOKUP3resok    resok;
+       default:
+               LOOKUP3resfail  resfail;
+};
+
+struct COMMIT3args {
+       nfs_fh3    file;
+       offset3    offset;
+       count3     count;
+};
+
+struct COMMIT3resok {
+       wcc_data   file_wcc;
+       writeverf3 verf;
+};
+
+struct COMMIT3resfail {
+       wcc_data   file_wcc;
+};
+
+union COMMIT3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               COMMIT3resok   resok;
+       default:
+               COMMIT3resfail resfail;
+};
+
+const ACCESS3_READ    = 0x0001;
+const ACCESS3_LOOKUP  = 0x0002;
+const ACCESS3_MODIFY  = 0x0004;
+const ACCESS3_EXTEND  = 0x0008;
+const ACCESS3_DELETE  = 0x0010;
+const ACCESS3_EXECUTE = 0x0020;
+
+struct ACCESS3args {
+     nfs_fh3  object;
+     uint32   access;
+};
+
+struct ACCESS3resok {
+     post_op_attr   obj_attributes;
+     uint32         access;
+};
+
+struct ACCESS3resfail {
+     post_op_attr   obj_attributes;
+};
+
+union ACCESS3res switch (nfsstat3 status) {
+case NFS3_OK:
+     ACCESS3resok   resok;
+default:
+     ACCESS3resfail resfail;
+};
+
+struct GETATTR3args {
+       nfs_fh3  object;
+};
+
+struct GETATTR3resok {
+        fattr3   obj_attributes;
+};
+
+union GETATTR3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               GETATTR3resok  resok;
+       default:
+               void;
+};
+
+
+
+enum time_how {
+       DONT_CHANGE        = 0,
+       SET_TO_SERVER_TIME = 1,
+       SET_TO_CLIENT_TIME = 2
+};
+
+union set_mode3 switch (bool set_it) {
+       case TRUE:
+               mode3    mode;
+       default:
+       void;
+};
+
+union set_uid3 switch (bool set_it) {
+       case TRUE:
+               uid3     uid;
+       default:
+               void;
+};
+
+union set_gid3 switch (bool set_it) {
+       case TRUE:
+               gid3     gid;
+       default:
+               void;
+};
+
+union set_size3 switch (bool set_it) {
+       case TRUE:
+               size3    size;
+       default:
+               void;
+};
+
+union set_atime switch (time_how set_it) {
+       case SET_TO_CLIENT_TIME:
+               nfstime3  atime;
+       default:
+               void;
+};
+
+union set_mtime switch (time_how set_it) {
+       case SET_TO_CLIENT_TIME:
+               nfstime3  mtime;
+       default:
+               void;
+};
+
+struct sattr3 {
+       set_mode3   mode;
+       set_uid3    uid;
+       set_gid3    gid;
+       set_size3   size;
+       set_atime   atime;
+       set_mtime   mtime;
+};
+
+enum createmode3 {
+       UNCHECKED = 0,
+       GUARDED   = 1,
+       EXCLUSIVE = 2
+};
+
+
+typedef opaque createverf3[NFS3_CREATEVERFSIZE];
+
+union createhow3 switch (createmode3 mode) {
+       case UNCHECKED:
+       case GUARDED:
+               sattr3       obj_attributes;
+       case EXCLUSIVE:
+               createverf3  verf;
+};
+
+struct CREATE3args {
+       diropargs3   where;
+       createhow3   how;
+};
+
+union post_op_fh3 switch (bool handle_follows) {
+       case TRUE:
+               nfs_fh3  handle;
+       case FALSE:
+               void;
+};
+
+struct CREATE3resok {
+       post_op_fh3   obj;
+       post_op_attr  obj_attributes;
+       wcc_data      dir_wcc;
+};
+
+struct CREATE3resfail {
+       wcc_data      dir_wcc;
+       };
+
+union CREATE3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               CREATE3resok    resok;
+       default:
+               CREATE3resfail  resfail;
+};
+
+struct REMOVE3args {
+       diropargs3  object;
+};
+
+struct REMOVE3resok {
+       wcc_data    dir_wcc;
+};
+
+struct REMOVE3resfail {
+       wcc_data    dir_wcc;
+};
+
+union REMOVE3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               REMOVE3resok   resok;
+       default:
+       REMOVE3resfail resfail;
+};
+
+struct READ3args {
+       nfs_fh3  file;
+       offset3  offset;
+       count3   count;
+};
+
+struct READ3resok {
+       post_op_attr   file_attributes;
+       count3         count;
+       bool           eof;
+       opaque         data<>;
+};
+
+struct READ3resfail {
+       post_op_attr   file_attributes;
+};
+
+union READ3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               READ3resok   resok;
+       default:
+               READ3resfail resfail;
+};
+
+
+const FSF3_LINK        = 0x0001;
+const FSF3_SYMLINK     = 0x0002;
+const FSF3_HOMOGENEOUS = 0x0008;
+const FSF3_CANSETTIME  = 0x0010;
+
+struct FSINFO3args {
+       nfs_fh3   fsroot;
+};
+
+struct FSINFO3resok {
+       post_op_attr obj_attributes;
+       uint32       rtmax;
+       uint32       rtpref;
+       uint32       rtmult;
+       uint32       wtmax;
+       uint32       wtpref;
+       uint32       wtmult;
+       uint32       dtpref;
+       size3        maxfilesize;
+       nfstime3     time_delta;
+       uint32       properties;
+};
+
+struct FSINFO3resfail {
+       post_op_attr obj_attributes;
+};
+
+union FSINFO3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               FSINFO3resok   resok;
+       default:
+               FSINFO3resfail resfail;
+};
+
+
+struct FSSTAT3args {
+       nfs_fh3   fsroot;
+};
+
+struct FSSTAT3resok {
+       post_op_attr obj_attributes;
+       size3        tbytes;
+       size3        fbytes;
+       size3        abytes;
+       size3        tfiles;
+       size3        ffiles;
+       size3        afiles;
+       uint32       invarsec;
+};
+
+struct FSSTAT3resfail {
+       post_op_attr obj_attributes;
+};
+
+union FSSTAT3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               FSSTAT3resok   resok;
+       default:
+               FSSTAT3resfail resfail;
+};
+
+struct PATHCONF3args {
+       nfs_fh3   object;
+};
+
+struct PATHCONF3resok {
+       post_op_attr obj_attributes;
+       uint32       linkmax;
+       uint32       name_max;
+       bool         no_trunc;
+       bool         chown_restricted;
+       bool         case_insensitive;
+       bool         case_preserving;
+};
+
+struct PATHCONF3resfail {
+       post_op_attr obj_attributes;
+};
+
+union PATHCONF3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               PATHCONF3resok   resok;
+       default:
+               PATHCONF3resfail resfail;
+};
+
+typedef string nfspath3<>;
+
+struct symlinkdata3 {
+       sattr3    symlink_attributes;
+       nfspath3  symlink_data;
+};
+
+struct SYMLINK3args {
+       diropargs3    where;
+       symlinkdata3  symlink;
+};
+
+struct SYMLINK3resok {
+       post_op_fh3   obj;
+       post_op_attr  obj_attributes;
+       wcc_data      dir_wcc;
+};
+
+struct SYMLINK3resfail {
+       wcc_data      dir_wcc;
+};
+
+union SYMLINK3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               SYMLINK3resok   resok;
+       default:
+               SYMLINK3resfail resfail;
+};
+
+
+struct READLINK3args {
+       nfs_fh3  symlink;
+};
+
+struct READLINK3resok {
+       post_op_attr   symlink_attributes;
+       nfspath3       data;
+};
+
+struct READLINK3resfail {
+       post_op_attr   symlink_attributes;
+};
+
+union READLINK3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               READLINK3resok   resok;
+       default:
+       READLINK3resfail resfail;
+};
+
+
+struct devicedata3 {
+       sattr3     dev_attributes;
+       specdata3  spec;
+};
+
+union mknoddata3 switch (ftype3 type) {
+       case NF3CHR:
+       case NF3BLK:
+               devicedata3  device;
+       case NF3SOCK:
+       case NF3FIFO:
+               sattr3       pipe_attributes;
+       default:
+               void;
+};
+
+struct MKNOD3args {
+       diropargs3   where;
+       mknoddata3   what;
+};
+
+struct MKNOD3resok {
+       post_op_fh3   obj;
+       post_op_attr  obj_attributes;
+       wcc_data      dir_wcc;
+};
+
+struct MKNOD3resfail {
+       wcc_data      dir_wcc;
+};
+
+union MKNOD3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               MKNOD3resok   resok;
+       default:
+               MKNOD3resfail resfail;
+};
+
+
+struct MKDIR3args {
+       diropargs3   where;
+       sattr3       attributes;
+};
+
+struct MKDIR3resok {
+       post_op_fh3   obj;
+       post_op_attr  obj_attributes;
+       wcc_data      dir_wcc;
+};
+
+struct MKDIR3resfail {
+       wcc_data      dir_wcc;
+};
+
+union MKDIR3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               MKDIR3resok   resok;
+       default:
+               MKDIR3resfail resfail;
+};
+
+struct RMDIR3args {
+       diropargs3  object;
+};
+
+struct RMDIR3resok {
+       wcc_data    dir_wcc;
+};
+
+struct RMDIR3resfail {
+       wcc_data    dir_wcc;
+};
+
+union RMDIR3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               RMDIR3resok   resok;
+       default:
+               RMDIR3resfail resfail;
+};
+
+struct RENAME3args {
+       diropargs3   from;
+       diropargs3   to;
+};
+
+struct RENAME3resok {
+       wcc_data     fromdir_wcc;
+       wcc_data     todir_wcc;
+};
+
+struct RENAME3resfail {
+       wcc_data     fromdir_wcc;
+       wcc_data     todir_wcc;
+};
+
+union RENAME3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               RENAME3resok   resok;
+       default:
+               RENAME3resfail resfail;
+};
+
+struct READDIRPLUS3args {
+       nfs_fh3      dir;
+       cookie3      cookie;
+       cookieverf3  cookieverf;
+       count3       dircount;
+       count3       maxcount;
+};
+
+struct entryplus3 {
+       fileid3      fileid;
+       filename3    name;
+       cookie3      cookie;
+       post_op_attr name_attributes;
+       post_op_fh3  name_handle;
+       entryplus3   *nextentry;
+};
+
+struct dirlistplus3 {
+       entryplus3   *entries;
+       bool         eof;
+};
+
+struct READDIRPLUS3resok {
+       post_op_attr dir_attributes;
+       cookieverf3  cookieverf;
+       dirlistplus3 reply;
+};
+
+
+struct READDIRPLUS3resfail {
+       post_op_attr dir_attributes;
+};
+
+union READDIRPLUS3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               READDIRPLUS3resok   resok;
+       default:
+               READDIRPLUS3resfail resfail;
+};
+
+struct READDIR3args {
+       nfs_fh3      dir;
+       cookie3      cookie;
+       cookieverf3  cookieverf;
+       count3       count;
+};
+
+
+struct entry3 {
+       fileid3      fileid;
+       filename3    name;
+       cookie3      cookie;
+       entry3       *nextentry;
+};
+
+struct dirlist3 {
+       entry3  *entries;
+       bool    eof;
+};
+
+struct READDIR3resok {
+       post_op_attr dir_attributes;
+       cookieverf3  cookieverf;
+       dirlist3     reply;
+};
+
+struct READDIR3resfail {
+       post_op_attr dir_attributes;
+};
+
+union READDIR3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               READDIR3resok   resok;
+       default:
+               READDIR3resfail resfail;
+};
+
+struct LINK3args {
+       nfs_fh3     file;
+       diropargs3  link;
+};
+
+struct LINK3resok {
+       post_op_attr   file_attributes;
+       wcc_data       linkdir_wcc;
+};
+
+struct LINK3resfail {
+       post_op_attr   file_attributes;
+       wcc_data       linkdir_wcc;
+};
+
+union LINK3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               LINK3resok    resok;
+       default:
+               LINK3resfail  resfail;
+};
+
+union sattrguard3 switch (bool check) {
+       case TRUE:
+               nfstime3  obj_ctime;
+       case FALSE:
+               void;
+};
+
+struct SETATTR3args {
+       nfs_fh3      object;
+       sattr3       new_attributes;
+       sattrguard3  guard;
+};
+
+struct SETATTR3resok {
+       wcc_data  obj_wcc;
+};
+
+struct SETATTR3resfail {
+       wcc_data  obj_wcc;
+};
+
+union SETATTR3res switch (nfsstat3 status) {
+       case NFS3_OK:
+               SETATTR3resok   resok;
+       default:
+               SETATTR3resfail resfail;
+};
+
+program NFS_PROGRAM {
+       version NFS_V3 {
+               void
+               NFS3_NULL(void)                    = 0;
+
+               GETATTR3res
+               NFS3_GETATTR(GETATTR3args)         = 1;
+
+               SETATTR3res
+               NFS3_SETATTR(SETATTR3args)         = 2;
+
+               LOOKUP3res
+               NFS3_LOOKUP(LOOKUP3args)           = 3;
+
+               ACCESS3res
+               NFS3_ACCESS(ACCESS3args)           = 4;
+
+               READLINK3res
+               NFS3_READLINK(READLINK3args)       = 5;
+
+               READ3res
+               NFS3_READ(READ3args)               = 6;
+
+               WRITE3res
+               NFS3_WRITE(WRITE3args)             = 7;
+
+               CREATE3res
+               NFS3_CREATE(CREATE3args)           = 8;
+
+               MKDIR3res
+               NFS3_MKDIR(MKDIR3args)             = 9;
+
+               SYMLINK3res
+               NFS3_SYMLINK(SYMLINK3args)         = 10;
+
+/*             MKNOD3res NFSPROC3_MKNOD(MKNOD3args)             = 11;*/
+
+               REMOVE3res
+               NFS3_REMOVE(REMOVE3args)           = 12;
+
+               RMDIR3res
+               NFS3_RMDIR(RMDIR3args)             = 13;
+
+               RENAME3res
+               NFS3_RENAME(RENAME3args)           = 14;
+
+               LINK3res
+               NFS3_LINK(LINK3args)               = 15;
+
+               READDIR3res
+               NFS3_READDIR(READDIR3args)         = 16;
+
+               READDIRPLUS3res
+               NFS3_READDIRPLUS(READDIRPLUS3args) = 17;
+
+               FSSTAT3res
+               NFS3_FSSTAT(FSSTAT3args)           = 18;
+
+               FSINFO3res
+               NFS3_FSINFO(FSINFO3args)           = 19;
+
+               PATHCONF3res
+               NFS3_PATHCONF(PATHCONF3args)       = 20;
+
+               COMMIT3res
+               NFS3_COMMIT(COMMIT3args)           = 21;
+       } = 3;
+} = 100003;
diff --git a/ccan/nfs/rpc/nfsacl.x b/ccan/nfs/rpc/nfsacl.x
new file mode 100644 (file)
index 0000000..68313c9
--- /dev/null
@@ -0,0 +1,8 @@
+/* deducted from wireshark traces */
+
+
+program NFSACL_PROGRAM {
+       version NFSACL_V3 {
+       void      NFSACL3_NULL(void)    = 0;
+       } = 3;
+} = 100227;
diff --git a/ccan/nfs/rpc/portmap.x b/ccan/nfs/rpc/portmap.x
new file mode 100644 (file)
index 0000000..8921b92
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * From RFC1833
+ */
+
+const PMAP_PORT = 111;      /* portmapper port number */
+
+struct mapping {
+       unsigned int prog;
+       unsigned int vers;
+       unsigned int prot;
+       unsigned int port;
+};
+
+struct call_args {
+       unsigned int prog;
+       unsigned int vers;
+       unsigned int proc;
+       opaque args<>;
+};
+
+
+program PMAP_PROGRAM {
+       version PMAP_V2 {
+               void
+               PMAP_NULL(void)         = 0;
+
+               bool
+               PMAP_SET(mapping)       = 1;
+
+               bool
+               PMAP_UNSET(mapping)     = 2;
+
+               unsigned int
+               PMAP_GETPORT(mapping)   = 3;
+       } = 2;
+} = 100000;
+
index b1d0f292bf9ee4443eee6feac809811f1b29912d..ccdd18df565eda924de92612fce4f9ef0c5a4d27 100644 (file)
@@ -25,7 +25,7 @@
 #include <rpc/xdr.h>
 #include <arpa/inet.h>
 #include <sys/ioctl.h>
 #include <rpc/xdr.h>
 #include <arpa/inet.h>
 #include <sys/ioctl.h>
-#include "libnfs.h"
+#include "nfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "dlinklist.h"
 #include "libnfs-raw.h"
 #include "libnfs-private.h"
 #include "dlinklist.h"
diff --git a/ccan/nfs/tools/nfsclient-async.c b/ccan/nfs/tools/nfsclient-async.c
new file mode 100644 (file)
index 0000000..feb4478
--- /dev/null
@@ -0,0 +1,233 @@
+/* 
+   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Example program using the highlevel async interface.
+ */
+
+#define SERVER "10.1.1.27"
+#define EXPORT "/VIRTUAL"
+#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
+#define NFSDIR "/BOOKS/Classics/"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <ccan/nfs/nfs.h>
+
+struct client {
+       char *server;
+       char *export;
+       uint32_t mount_port;
+       struct nfsfh *nfsfh;
+       int is_finished;
+};
+
+void nfs_opendir_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct nfsdir *nfsdir = data;
+       struct nfsdirent *nfsdirent;
+
+       if (status < 0) {
+               printf("opendir failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("opendir successful\n");
+       while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
+               printf("Inode:%d Name:%s\n", (int)nfsdirent->inode, nfsdirent->name);
+       }
+       nfs_closedir(nfs, nfsdir);
+
+       client->is_finished = 1;
+}
+
+void nfs_close_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status < 0) {
+               printf("close failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("close successful\n");
+       printf("call opendir(%s)\n", NFSDIR);
+       if (nfs_opendir_async(nfs, NFSDIR, nfs_opendir_cb, client) != 0) {
+               printf("Failed to start async nfs close\n");
+               exit(10);
+       }
+}
+
+void nfs_fstat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct stat *st;
+       if (status < 0) {
+               printf("fstat call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("Got reply from server for fstat(%s).\n", NFSFILE);
+       st = (struct stat *)data;
+       printf("Mode %04o\n", st->st_mode);
+       printf("Size %d\n", (int)st->st_size);
+       printf("Inode %04o\n", (int)st->st_ino);
+
+       printf("Close file\n");
+       if (nfs_close_async(nfs, client->nfsfh, nfs_close_cb, client) != 0) {
+               printf("Failed to start async nfs close\n");
+               exit(10);
+       }
+}
+
+void nfs_read_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       char *read_data;
+       int i;
+
+       if (status < 0) {
+               printf("read failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("read successful with %d bytes of data\n", status);
+       read_data = data;
+       for (i=0;i<16;i++) {
+               printf("%02x ", read_data[i]&0xff);
+       }
+       printf("\n");
+       printf("Fstat file :%s\n", NFSFILE);
+       if (nfs_fstat_async(nfs, client->nfsfh, nfs_fstat_cb, client) != 0) {
+               printf("Failed to start async nfs fstat\n");
+               exit(10);
+       }
+}
+
+void nfs_open_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct nfsfh *nfsfh;
+
+       if (status < 0) {
+               printf("open call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       nfsfh         = data;
+       client->nfsfh = nfsfh;
+       printf("Got reply from server for open(%s). Handle:%p\n", NFSFILE, data);
+       printf("Read first 16 bytes\n");
+       if (nfs_pread_async(nfs, nfsfh, 0, 16, nfs_read_cb, client) != 0) {
+               printf("Failed to start async nfs open\n");
+               exit(10);
+       }
+}
+
+void nfs_stat_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       struct stat *st;
+       if (status < 0) {
+               printf("stat call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("Got reply from server for stat(%s).\n", NFSFILE);
+       st = (struct stat *)data;
+       printf("Mode %04o\n", st->st_mode);
+       printf("Size %d\n", (int)st->st_size);
+       printf("Inode %04o\n", (int)st->st_ino);
+
+       printf("Open file for reading :%s\n", NFSFILE);
+       if (nfs_open_async(nfs, NFSFILE, O_RDONLY, nfs_open_cb, client) != 0) {
+               printf("Failed to start async nfs open\n");
+               exit(10);
+       }
+}
+
+void nfs_mount_cb(int status, struct nfs_context *nfs, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status < 0) {
+               printf("mount/mnt call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+
+       printf("Got reply from server for MOUNT/MNT procedure.\n");
+       printf("Stat file :%s\n", NFSFILE);
+       if (nfs_stat_async(nfs, NFSFILE, nfs_stat_cb, client) != 0) {
+               printf("Failed to start async nfs stat\n");
+               exit(10);
+       }
+}
+
+
+
+int main(int argc, char *argv[])
+{
+       struct nfs_context *nfs;
+       struct pollfd pfd;
+       int ret;
+       struct client client;
+
+       client.server = SERVER;
+       client.export = EXPORT;
+       client.is_finished = 0;
+
+       nfs = nfs_init_context();
+       if (nfs == NULL) {
+               printf("failed to init context\n");
+               exit(10);
+       }
+
+       ret = nfs_mount_async(nfs, client.server, client.export, nfs_mount_cb, &client);
+       if (ret != 0) {
+               printf("Failed to start async nfs mount\n");
+               exit(10);
+       }
+
+       for (;;) {
+               pfd.fd = nfs_get_fd(nfs);
+               pfd.events = nfs_which_events(nfs);
+
+               if (poll(&pfd, 1, -1) < 0) {
+                       printf("Poll failed");
+                       exit(10);
+               }
+               if (nfs_service(nfs, pfd.revents) < 0) {
+                       printf("nfs_service failed\n");
+                       break;
+               }
+               if (client.is_finished) {
+                       break;
+               }
+       }
+       
+       nfs_destroy_context(nfs);
+       printf("nfsclient finished\n");
+       return 0;
+}
diff --git a/ccan/nfs/tools/nfsclient-raw.c b/ccan/nfs/tools/nfsclient-raw.c
new file mode 100644 (file)
index 0000000..d9db373
--- /dev/null
@@ -0,0 +1,220 @@
+/* 
+   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Example program using the lowlevel raw interface.
+ * This allow accurate control of the exact commands that are being used.
+ */
+
+#define SERVER "10.1.1.27"
+#define EXPORT "/VIRTUAL"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <ccan/nfs/nfs.h>
+#include <ccan/nfs/libnfs-raw.h>
+#include <ccan/nfs/rpc/mount.h>
+
+struct client {
+       char *server;
+       char *export;
+       uint32_t mount_port;
+       int is_finished;
+};
+
+void mount_mnt_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       mountres3 *res;
+       struct client *client = private_data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("mount/mnt call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("mount/mnt call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       res = data;
+       if (res->fhs_status != MNT3_OK) {
+               printf("RPC error: Mount failed with error %s(%d) %s(%d)", mountstat3_to_str(res->fhs_status), res->fhs_status, strerror(-mountstat3_to_errno(res->fhs_status)), -mountstat3_to_errno(res->fhs_status));
+               exit(10);
+       }
+
+       printf("Got reply from server for MOUNT/MNT procedure.\n");
+       client->is_finished = 1;
+}
+
+
+void mount_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("mount null call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("mount null call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       printf("Got reply from server for MOUNT/NULL procedure.\n");
+       printf("Send MOUNT/MNT command for %s\n", client->export);
+       if (rpc_mount_mnt_async(rpc, mount_mnt_cb, client->export, client) != 0) {
+               printf("Failed to send mnt request\n");
+               exit(10);
+       }
+
+}
+
+void mount_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("connection to RPC.MOUNTD on server %s failed\n", client->server);
+               exit(10);
+       }
+
+       printf("Connected to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
+       printf("Send NULL request to check if RPC.MOUNTD is actually running\n");
+       if (rpc_mount_null_async(rpc, mount_null_cb, client) != 0) {
+               printf("Failed to send null request\n");
+               exit(10);
+       }
+}
+
+
+void pmap_getport_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+       uint32_t port;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("portmapper getport call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+               if (status != RPC_STATUS_SUCCESS) {
+               printf("portmapper getport call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       client->mount_port = *(uint32_t *)data;
+       printf("GETPORT returned Port:%d\n", client->mount_port);
+       if (client->mount_port == 0) {
+               printf("RPC.MOUNTD is not available on server : %s\n", client->server, client->mount_port);
+               exit(10);
+       }               
+
+       printf("Disconnect socket from portmap server\n");
+       if (rpc_disconnect(rpc, "normal disconnect") != 0) {
+               printf("Failed to disconnect socket to portmapper\n");
+               exit(10);
+       }
+
+       printf("Connect to RPC.MOUNTD on %s:%d\n", client->server, client->mount_port);
+       if (rpc_connect_async(rpc, client->server, client->mount_port, 1, mount_connect_cb, client) != 0) {
+               printf("Failed to start connection\n");
+               exit(10);
+       }
+}
+
+
+void pmap_null_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       if (status == RPC_STATUS_ERROR) {
+               printf("portmapper null call failed with \"%s\"\n", (char *)data);
+               exit(10);
+       }
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("portmapper null call to server %s failed, status:%d\n", client->server, status);
+               exit(10);
+       }
+
+       printf("Got reply from server for PORTMAP/NULL procedure.\n");
+       printf("Send getport request asking for MOUNT port\n");
+       if (rpc_pmap_getport_async(rpc, MOUNT_PROGRAM, MOUNT_V3, pmap_getport_cb, client) != 0) {
+               printf("Failed to send getport request\n");
+               exit(10);
+       }
+}
+
+void pmap_connect_cb(struct rpc_context *rpc, int status, void *data, void *private_data)
+{
+       struct client *client = private_data;
+
+       printf("pmap_connect_cb    status:%d.\n", status);
+       if (status != RPC_STATUS_SUCCESS) {
+               printf("connection to portmapper on server %s failed\n", client->server);
+               exit(10);
+       }
+
+       printf("Send NULL request to check if portmapper is actually running\n");
+       if (rpc_pmap_null_async(rpc, pmap_null_cb, client) != 0) {
+               printf("Failed to send null request\n");
+               exit(10);
+       }
+}
+
+
+int main(int argc, char *argv[])
+{
+       struct rpc_context *rpc;
+       struct pollfd pfd;
+       int ret;
+       struct client client;
+
+       rpc = rpc_init_context();
+       if (rpc == NULL) {
+               printf("failed to init context\n");
+               exit(10);
+       }
+
+       client.server = SERVER;
+       client.export = EXPORT;
+       client.is_finished = 0;
+       if (rpc_connect_async(rpc, client.server, 111, 0, pmap_connect_cb, &client) != 0) {
+               printf("Failed to start connection\n");
+               exit(10);
+       }
+
+       for (;;) {
+               pfd.fd = rpc_get_fd(rpc);
+               pfd.events = rpc_which_events(rpc);
+
+               if (poll(&pfd, 1, -1) < 0) {
+                       printf("Poll failed");
+                       exit(10);
+               }
+               if (rpc_service(rpc, pfd.revents) < 0) {
+                       printf("rpc_service failed\n");
+                       break;
+               }
+               if (client.is_finished) {
+                       break;
+               }
+       }
+       
+       rpc_destroy_context(rpc);
+       rpc=NULL;
+       printf("nfsclient finished\n");
+       return 0;
+}
diff --git a/ccan/nfs/tools/nfsclient-sync.c b/ccan/nfs/tools/nfsclient-sync.c
new file mode 100644 (file)
index 0000000..e762109
--- /dev/null
@@ -0,0 +1,202 @@
+/* 
+   Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+/* Example program using the highlevel sync interface
+ */
+
+#define SERVER "10.1.1.27"
+#define EXPORT "/VIRTUAL"
+#define NFSFILE "/BOOKS/Classics/Dracula.djvu"
+#define NFSFILER "/BOOKS/Classics/Dracula.djvu.renamed"
+#define NFSFILEW "/BOOKS/Classics/foo"
+#define NFSDIR "/BOOKS/Classics/"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ccan/nfs/nfs.h>
+#include <rpc/rpc.h>            /* for authunix_create() */
+
+struct client {
+       char *server;
+       char *export;
+       uint32_t mount_port;
+       int is_finished;
+};
+
+
+int main(int argc, char *argv[])
+{
+       struct nfs_context *nfs;
+       int i, ret;
+       struct client client;
+       struct stat st;
+       struct nfsfh  *nfsfh;
+       struct nfsdir *nfsdir;
+       struct nfsdirent *nfsdirent;
+       client.server = SERVER;
+       client.export = EXPORT;
+       client.is_finished = 0;
+       char buf[16];
+       off_t offset;
+       struct statvfs svfs;
+
+       nfs = nfs_init_context();
+       if (nfs == NULL) {
+               printf("failed to init context\n");
+               exit(10);
+       }
+
+       ret = nfs_mount_sync(nfs, client.server, client.export);
+       if (ret != 0) {
+               printf("Failed to mount nfs share : %s\n", nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("mounted share successfully\n");
+exit(10);
+
+       ret = nfs_stat_sync(nfs, NFSFILE, &st);
+       if (ret != 0) {
+               printf("Failed to stat(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("Mode %04o\n", st.st_mode);
+       printf("Size %d\n", (int)st.st_size);
+       printf("Inode %04o\n", (int)st.st_ino);
+
+       ret = nfs_open_sync(nfs, NFSFILE, O_RDONLY, &nfsfh);
+       if (ret != 0) {
+               printf("Failed to open(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+
+       ret = nfs_read_sync(nfs, nfsfh, 16, buf);
+       if (ret < 0) {
+               printf("Failed to pread(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("read %d bytes\n", ret);
+       for (i=0;i<16;i++) {
+               printf("%02x ", buf[i]&0xff);
+       }
+       printf("\n");
+       ret = nfs_read_sync(nfs, nfsfh, 16, buf);
+       if (ret < 0) {
+               printf("Failed to pread(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("read %d bytes\n", ret);
+       for (i=0;i<16;i++) {
+               printf("%02x ", buf[i]&0xff);
+       }
+       printf("\n");
+
+       ret = (int)nfs_lseek_sync(nfs, nfsfh, 0, SEEK_CUR, &offset);
+       if (ret < 0) {
+               printf("Failed to lseek(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("File position is %d\n", (int)offset);
+
+       printf("seek to end of file\n");
+       ret = (int)nfs_lseek_sync(nfs, nfsfh, 0, SEEK_END, &offset);
+       if (ret < 0) {
+               printf("Failed to lseek(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("File position is %d\n", (int)offset);
+
+       ret = nfs_fstat_sync(nfs, nfsfh, &st);
+       if (ret != 0) {
+               printf("Failed to stat(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("Mode %04o\n", st.st_mode);
+       printf("Size %d\n", (int)st.st_size);
+       printf("Inode %04o\n", (int)st.st_ino);
+
+
+       ret = nfs_close_sync(nfs, nfsfh);
+       if (ret < 0) {
+               printf("Failed to close(%s)\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+
+       ret = nfs_opendir_sync(nfs, NFSDIR, &nfsdir);
+       if (ret != 0) {
+               printf("Failed to open(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+               exit(10);
+       }
+       while((nfsdirent = nfs_readdir(nfs, nfsdir)) != NULL) {
+               printf("Inode:%d Name:%s\n", (int)nfsdirent->inode, nfsdirent->name);
+       }
+       nfs_closedir(nfs, nfsdir);
+
+
+       ret = nfs_open_sync(nfs, NFSFILEW, O_WRONLY, &nfsfh);
+       if (ret != 0) {
+               printf("Failed to open(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
+               exit(10);
+       }
+       ret = nfs_pwrite_sync(nfs, nfsfh, 0, 16, buf);
+       if (ret < 0) {
+               printf("Failed to pwrite(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
+               exit(10);
+       }
+       ret = nfs_fsync_sync(nfs, nfsfh);
+       if (ret < 0) {
+               printf("Failed to fsync(%s) %s\n", NFSFILEW, nfs_get_error(nfs));
+               exit(10);
+       }
+       ret = nfs_close_sync(nfs, nfsfh);
+       if (ret < 0) {
+               printf("Failed to close(%s)\n", NFSFILEW, nfs_get_error(nfs));
+               exit(10);
+       }
+
+
+       ret = nfs_statvfs_sync(nfs, NFSDIR, &svfs);
+       if (ret < 0) {
+               printf("Failed to statvfs(%s)\n", NFSDIR, nfs_get_error(nfs));
+               exit(10);
+       }
+       printf("files %d/%d/%d\n", (int)svfs.f_files, (int)svfs.f_ffree, (int)svfs.f_favail);
+
+
+       ret = nfs_access_sync(nfs, NFSFILE, R_OK);
+       if (ret != 0) {
+               printf("Failed to access(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+       }
+
+       /* become root */
+       nfs_set_auth(nfs, authunix_create("Ronnies-Laptop", 0, 0, 0, NULL));
+
+       ret = nfs_link_sync(nfs, NFSFILE, NFSFILER);
+       if (ret != 0) {
+               printf("Failed to link(%s) %s\n", NFSFILE, nfs_get_error(nfs));
+       }
+
+
+       nfs_destroy_context(nfs);
+       printf("nfsclient finished\n");
+       return 0;
+}