libnfs.c: add nfs_create
[deb_libnfs.git] / include / nfsc / libnfs.h
index 7a9accde932b6b1e5941f305afe416614357063f..ff0d4e4ad4b4bcdfae7f38a9c502e0389faa7e3a 100644 (file)
 /*
  * This is the highlevel interface to access NFS resources using a posix-like interface
  */
+
+#ifndef _LIBNFS_H_
+#define _LIBNFS_H_
+
 #include <stdint.h>
 #if defined(ANDROID)
 #include <sys/time.h>
 #if defined(AROS)
 #include <sys/time.h>
 #endif
+#if defined(__APPLE__) && defined(__MACH__)
+#include <sys/time.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define LIBNFS_FEATURE_READAHEAD
+#define NFS_BLKSIZE 4096
 
 struct nfs_context;
 struct rpc_context;
@@ -37,7 +51,7 @@ struct nfs_url {
 #if defined(WIN32)
 #define EXTERN __declspec( dllexport )
 #else
-#define EXTERN 
+#define EXTERN
 #endif
 
 #if defined(WIN32)
@@ -50,7 +64,7 @@ struct statvfs {
        uint32_t        f_files;
        uint32_t        f_ffree;
        uint32_t        f_favail;
-       uint32_t        f_fsid; 
+       uint32_t        f_fsid;
        uint32_t        f_flag;
        uint32_t        f_namemax;
 };
@@ -113,7 +127,7 @@ EXTERN void nfs_destroy_context(struct nfs_context *nfs);
 
 /*
  * URL parsing functions.
- * These functions all parse a URL of the form 
+ * These functions all parse a URL of the form
  * nfs://server/path/file?argv=val[&arg=val]*
  * and returns a nfs_url.
  *
@@ -167,12 +181,13 @@ EXTERN uint64_t nfs_get_readmax(struct nfs_context *nfs);
 EXTERN uint64_t nfs_get_writemax(struct nfs_context *nfs);
 
 /*
- *  MODIFY CONNECT PARAMTERS 
+ *  MODIFY CONNECT PARAMTERS
  */
 
 EXTERN void nfs_set_tcp_syncnt(struct nfs_context *nfs, int v);
 EXTERN void nfs_set_uid(struct nfs_context *nfs, int uid);
 EXTERN void nfs_set_gid(struct nfs_context *nfs, int gid);
+EXTERN void nfs_set_readahead(struct nfs_context *nfs, uint32_t v);
 
 /*
  * MOUNT THE EXPORT
@@ -216,6 +231,7 @@ EXTERN int nfs_mount(struct nfs_context *nfs, const char *server, const char *ex
  * -errno : An error occured.
  *          data is the error string.
  */
+/* This function is deprecated. Use nfs_stat64_async() instead */
 struct stat;
 EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
 /*
@@ -224,12 +240,59 @@ EXTERN int nfs_stat_async(struct nfs_context *nfs, const char *path, nfs_cb cb,
  *      0 : The operation was successfull.
  * -errno : The command failed.
  */
+/* This function is deprecated. Use nfs_stat64() instead */
 #ifdef WIN32
 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct __stat64 *st);
 #else
 EXTERN int nfs_stat(struct nfs_context *nfs, const char *path, struct stat *st);
 #endif
 
+
+/* nfs_stat64
+ * 64 bit version if stat. All fields are always 64bit.
+ * Use these functions instead of nfs_stat[_async](), especially if you
+ * have weird stat structures.
+ */
+/*
+ * STAT()
+ */
+struct nfs_stat_64 {
+       uint64_t nfs_dev;
+       uint64_t nfs_ino;
+       uint64_t nfs_mode;
+       uint64_t nfs_nlink;
+       uint64_t nfs_uid;
+       uint64_t nfs_gid;
+       uint64_t nfs_rdev;
+       uint64_t nfs_size;
+       uint64_t nfs_blksize;
+       uint64_t nfs_blocks;
+       uint64_t nfs_atime;
+       uint64_t nfs_mtime;
+       uint64_t nfs_ctime;
+};
+
+/*
+ * 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 nfs_stat_64 *
+ * -errno : An error occured.
+ *          data is the error string.
+ */
+EXTERN int nfs_stat64_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.
+ */
+EXTERN int nfs_stat64(struct nfs_context *nfs, const char *path, struct nfs_stat_64 *st);
+
 /*
  * FSTAT()
  */
@@ -266,12 +329,20 @@ EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *
 /*
  * Async open(<filename>)
  *
- * mode is a combination of the flags : O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC
+ * mode is a combination of the flags :
+ * O_RDOLNY, O_WRONLY, O_RDWR , O_SYNC, O_APPEND
  *
  * 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.
  *
+ * Supported flags are
+ * O_APPEND
+ * O_RDONLY
+ * O_WRONLY
+ * O_RDWR
+ * O_TRUNC (Only valid with O_RDWR or O_WRONLY. Ignored otherwise.)
+ *
  * When the callback is invoked, status indicates the result:
  *      0 : Success.
  *          data is a struct *nfsfh;
@@ -279,14 +350,14 @@ EXTERN int nfs_fstat(struct nfs_context *nfs, struct nfsfh *nfsfh, struct stat *
  * -errno : An error occured.
  *          data is the error string.
  */
-EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb cb, void *private_data);
+EXTERN int nfs_open_async(struct nfs_context *nfs, const char *path, int flags, nfs_cb cb, void *private_data);
 /*
- * Sync stat(<filename>)
+ * Sync open(<filename>)
  * Function returns
  *      0 : The operation was successfull. *nfsfh is filled in.
  * -errno : The command failed.
  */
-EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
+EXTERN int nfs_open(struct nfs_context *nfs, const char *path, int flags, struct nfsfh **nfsfh);
 
 
 
@@ -442,14 +513,14 @@ EXTERN int nfs_write(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t coun
  * -errno : An error occured.
  *          data is the error string.
  */
-EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, nfs_cb cb, void *private_data);
+EXTERN int nfs_lseek_async(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, nfs_cb cb, void *private_data);
 /*
  * Sync lseek()
  * Function returns
  *    >=0 : numer of bytes read.
  * -errno : An error occured.
  */
-EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, uint64_t offset, int whence, uint64_t *current_offset);
+EXTERN int nfs_lseek(struct nfs_context *nfs, struct nfsfh *nfsfh, int64_t offset, int whence, uint64_t *current_offset);
 
 
 /*
@@ -611,6 +682,33 @@ EXTERN int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode,
  */
 EXTERN int nfs_creat(struct nfs_context *nfs, const char *path, int mode, struct nfsfh **nfsfh);
 
+/*
+ * Async create()
+ *
+ * Same as nfs_creat_async but allows passing flags:
+ * O_APPEND
+ * O_SYNC
+ * O_EXCL
+ *
+ * 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.
+ */
+EXTERN int nfs_create_async(struct nfs_context *nfs, const char *path, int flags, int mode, nfs_cb cb, void *private_data);
+/*
+ * Sync create()
+ * Function returns
+ *      0 : Success
+ * -errno : An error occured.
+ */
+EXTERN int nfs_create(struct nfs_context *nfs, const char *path, int flags, int mode, struct nfsfh **nfsfh);
+
 
 /*
  * MKNOD()
@@ -714,6 +812,7 @@ struct nfsdirent  {
        struct timeval ctime;
        uint32_t uid;
        uint32_t gid;
+       uint32_t nlink;
 };
 /*
  * nfs_readdir() never blocks, so no special sync/async versions are available
@@ -723,7 +822,7 @@ EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfs
 
 
 /*
- * READDIR()
+ * CLOSEDIR()
  */
 /*
  * nfs_closedir() never blocks, so no special sync/async versions are available
@@ -731,6 +830,49 @@ EXTERN struct nfsdirent *nfs_readdir(struct nfs_context *nfs, struct nfsdir *nfs
 EXTERN void nfs_closedir(struct nfs_context *nfs, struct nfsdir *nfsdir);
 
 
+/*
+ * CHDIR()
+ */
+/*
+ * Async chdir(<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.
+ */
+EXTERN int nfs_chdir_async(struct nfs_context *nfs, const char *path, nfs_cb cb, void *private_data);
+/*
+ * Sync chdir(<path>)
+ * Function returns
+ *      0 : The operation was successfull.
+ * -errno : The command failed.
+ */
+EXTERN int nfs_chdir(struct nfs_context *nfs, const char *path);
+
+/*
+ * GETCWD()
+ */
+/*
+ * nfs_getcwd() never blocks, so no special sync/async versions are available
+ */
+/*
+ * Sync getcwd()
+ * This function returns a pointer to the current working directory.
+ * This pointer is only stable until the next [f]chdir or when the
+ * context is destroyed.
+ *
+ * Function returns
+ *      0 : The operation was successfull and *cwd is filled in.
+ * -errno : The command failed.
+ */
+EXTERN void nfs_getcwd(struct nfs_context *nfs, const char **cwd);
+
 
 /*
  * STATVFS()
@@ -1074,7 +1216,7 @@ EXTERN int mount_getexports_async(struct rpc_context *rpc, const char *server, r
  * Function returns
  *            NULL : something failed
  *  exports export : a linked list of exported directories
- * 
+ *
  * returned data must be freed by calling mount_free_export_list(exportnode);
  */
 EXTERN struct exportnode *mount_getexports(const char *server);
@@ -1103,8 +1245,14 @@ struct nfs_server_list {
  * NULL : something failed
  *
  * struct nfs_server_list : a linked list of all discovered servers
- * 
+ *
  * returned data must be freed by nfs_free_srvr_list(srv);
  */
 struct nfs_server_list *nfs_find_local_servers(void);
 void free_nfs_srvr_list(struct nfs_server_list *srv);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !_LIBNFS_H_ */