This makes it closer to compiling under ccanlint.
CC=gcc
-CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))" -D_FILE_OFFSET_BITS=64
+CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))"
LIBS=
LIBNFS_OBJ = libnfs-raw-mount.o libnfs-raw-portmap.o libnfs-raw-nfs.o libnfs-raw-nfsacl.o mount.o nfs.o nfsacl.o portmap.o pdu.o init.o socket.o libnfs.o libnfs-sync.o
--- /dev/null
+#include <string.h>
+#include <stdio.h>
+
+/**
+ * nfs - nfs client library
+ *
+ * This code offers a POSIX-like interface directly to an NFS server.
+ *
+ * Note: various files are generated from the XDR descriptions in the rpc/
+ * directory using rpcgen.
+ *
+ * Example:
+ * #include <ccan/nfs/nfs.h>
+ * #include <err.h>
+ * #include <stdio.h>
+ * #include <sys/types.h>
+ * #include <sys/stat.h>
+ * #include <unistd.h>
+ *
+ * int main(int argc, char *argv[])
+ * {
+ * struct nfs_context *nfs;
+ * struct stat st;
+ *
+ * if (argc != 4)
+ * errx(1, "Usage: %s <serveraddr> <export> <filename>", argv[0]);
+ * nfs = nfs_init_context();
+ * if (!nfs)
+ * err(1, "Initializing nfs context");
+ *
+ * if (nfs_mount_sync(nfs, argv[1], argv[2]) != 0)
+ * errx(1, "Failed to mount nfs share: %s", nfs_get_error(nfs));
+ *
+ * if (nfs_stat_sync(nfs, argv[3], &st) != 0)
+ * errx(1, "Failed to stat(%s): %s", argv[3], nfs_get_error(nfs));
+ *
+ * printf("Mode %04o\n", st.st_mode);
+ * printf("Size %u\n", (int)st.st_size);
+ * printf("Inode %u\n", (int)st.st_ino);
+ *
+ * nfs_destroy_context(nfs);
+ * printf("nfsclient finished\n");
+ * return 0;
+ *}
+ */
+int main(int argc, char *argv[])
+{
+ /* Expect exactly one argument */
+ if (argc != 2)
+ return 1;
+
+ if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/compiler\n");
+ return 0;
+ }
+
+ return 1;
+}
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
-int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data);
+int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, nfs_off_t offset, size_t count, void *private_data);
/*
* Call NFS/WRITE
* RPC_STATUS_CANCEL : The connection attempt was aborted before it could complete.
* data is NULL.
*/
-int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data);
+int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, nfs_off_t offset, size_t count, int stable_how, void *private_data);
/*
* Call NFS/COMMIT
struct sync_cb_data {
int is_finished;
int status;
- off_t offset;
+ nfs_off_t offset;
void *return_data;
int return_int;
};
memcpy(buffer, (char *)data, status);
}
-int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buffer)
+int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buffer)
{
struct sync_cb_data cb_data;
}
}
-int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf)
+int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf)
{
struct sync_cb_data cb_data;
}
}
-int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length)
+int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length)
{
struct sync_cb_data cb_data;
}
}
-int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length)
+int nfs_truncate_sync(struct nfs_context *nfs, const char *path, nfs_off_t length)
{
struct sync_cb_data cb_data;
}
if (cb_data->return_data != NULL) {
- memcpy(cb_data->return_data, data, sizeof(off_t));
+ memcpy(cb_data->return_data, data, sizeof(nfs_off_t));
}
}
-int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset)
+int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_off_t *current_offset)
{
struct sync_cb_data cb_data;
struct nfsfh {
struct nfs_fh3 fh;
int is_sync;
- off_t offset;
+ nfs_off_t offset;
};
struct nfsdir {
free_nfs_cb_data(data);
}
-int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data)
+int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, nfs_cb cb, void *private_data)
{
struct nfs_cb_data *data;
free_nfs_cb_data(data);
}
-int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data)
+int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data)
{
struct nfs_cb_data *data;
free_nfs_cb_data(data);
}
-int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data)
+int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length, nfs_cb cb, void *private_data)
{
struct nfs_cb_data *data;
SETATTR3args args;
*/
static int nfs_truncate_continue_internal(struct nfs_context *nfs, struct nfs_cb_data *data)
{
- off_t offset = data->continue_int;
+ nfs_off_t offset = data->continue_int;
struct nfsfh nfsfh;
nfsfh.fh.data.data_val = data->fh.data.data_val;
return 0;
}
-int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data)
+int nfs_truncate_async(struct nfs_context *nfs, const char *path, nfs_off_t length, nfs_cb cb, void *private_data)
{
- off_t offset;
+ nfs_off_t offset;
offset = length;
struct lseek_cb_data {
struct nfs_context *nfs;
struct nfsfh *nfsfh;
- off_t offset;
+ nfs_off_t offset;
nfs_cb cb;
void *private_data;
};
free(data);
}
-int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data)
+int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_cb cb, void *private_data)
{
struct lseek_cb_data *data;
//qqq replace later with lseek()
-off_t nfs_get_current_offset(struct nfsfh *nfsfh)
+nfs_off_t nfs_get_current_offset(struct nfsfh *nfsfh)
{
return nfsfh->offset;
}
-int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, off_t offset, size_t count, void *private_data)
+int rpc_nfs_read_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, nfs_off_t offset, size_t count, void *private_data)
{
struct rpc_pdu *pdu;
READ3args args;
}
-int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, off_t offset, size_t count, int stable_how, void *private_data)
+int rpc_nfs_write_async(struct rpc_context *rpc, rpc_cb cb, struct nfs_fh3 *fh, char *buf, nfs_off_t offset, size_t count, int stable_how, void *private_data)
{
struct rpc_pdu *pdu;
WRITE3args args;
/*
* This is the highlevel interface to access NFS resources using a posix-like interface
*/
+#include <sys/types.h>
#include <stdint.h>
+typedef uint64_t nfs_off_t;
+
struct nfs_context;
/*
* -errno : An error occured.
* data is the error string.
*/
-int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, nfs_cb cb, void *private_data);
+int nfs_pread_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, nfs_cb cb, void *private_data);
/*
* Sync pread()
* Function returns
* >=0 : numer of bytes read.
* -errno : An error occured.
*/
-int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf);
+int nfs_pread_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf);
* -errno : An error occured.
* data is the error string.
*/
-int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data);
+int nfs_pwrite_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf, nfs_cb cb, void *private_data);
/*
* Sync pwrite()
* Function returns
* >=0 : numer of bytes written.
* -errno : An error occured.
*/
-int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, size_t count, char *buf);
+int nfs_pwrite_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, size_t count, char *buf);
/*
*
* When the callback is invoked, status indicates the result:
* >=0 : Success.
- * data is off_t * for the current position.
+ * data is nfs_off_t * for the current position.
* -errno : An error occured.
* data is the error string.
*/
-int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, nfs_cb cb, void *private_data);
+int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_cb cb, void *private_data);
/*
* Sync lseek()
* Function returns
* >=0 : numer of bytes read.
* -errno : An error occured.
*/
-int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t offset, int whence, off_t *current_offset);
+int nfs_lseek_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t offset, int whence, nfs_off_t *current_offset);
/*
* -errno : An error occured.
* data is the error string.
*/
-int nfs_truncate_async(struct nfs_context *nfs, const char *path, off_t length, nfs_cb cb, void *private_data);
+int nfs_truncate_async(struct nfs_context *nfs, const char *path, nfs_off_t length, nfs_cb cb, void *private_data);
/*
* Sync truncate()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
-int nfs_truncate_sync(struct nfs_context *nfs, const char *path, off_t length);
+int nfs_truncate_sync(struct nfs_context *nfs, const char *path, nfs_off_t length);
* -errno : An error occured.
* data is the error string.
*/
-int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length, nfs_cb cb, void *private_data);
+int nfs_ftruncate_async(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length, nfs_cb cb, void *private_data);
/*
* Sync ftruncate()
* Function returns
* 0 : Success
* -errno : An error occured.
*/
-int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, off_t length);
+int nfs_ftruncate_sync(struct nfs_context *nfs, struct nfsfh *nfsfh, nfs_off_t length);
//qqq replace later with lseek(cur, 0)
-off_t nfs_get_current_offset(struct nfsfh *nfsfh);
+nfs_off_t nfs_get_current_offset(struct nfsfh *nfsfh);
client.export = EXPORT;
client.is_finished = 0;
char buf[16];
- off_t offset;
+ nfs_off_t offset;
struct statvfs svfs;
nfs = nfs_init_context();