aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMiklos Szeredi <miklos@szeredi.hu>2010-07-12 17:17:25 +0200
committerMiklos Szeredi <mszeredi@suse.cz>2010-07-12 17:17:25 +0200
commit2709f9a53d94a2c181511a66a33a6f0f80d1b281 (patch)
treeb349acd7f36f2cf77a0f15a327060b0c950c05f5 /include
parent5454e4fa74390b7c16cf37efb0ec11c0c9faad1c (diff)
downloadandroid_external_fuse-2709f9a53d94a2c181511a66a33a6f0f80d1b281.tar.gz
android_external_fuse-2709f9a53d94a2c181511a66a33a6f0f80d1b281.tar.bz2
android_external_fuse-2709f9a53d94a2c181511a66a33a6f0f80d1b281.zip
libfuse: add buffer interface
Add a generic buffer interface for use with I/O. Buffer vectors are supplied and each buffer in the vector may be a memory pointer or a file descriptor. The fuse_reply_fd() interface is converted to using buffers.
Diffstat (limited to 'include')
-rw-r--r--include/fuse_common.h164
-rw-r--r--include/fuse_lowlevel.h28
2 files changed, 173 insertions, 19 deletions
diff --git a/include/fuse_common.h b/include/fuse_common.h
index 70304c3..7c651ff 100644
--- a/include/fuse_common.h
+++ b/include/fuse_common.h
@@ -17,6 +17,7 @@
#include "fuse_opt.h"
#include <stdint.h>
+#include <sys/types.h>
/** Major version of FUSE library interface */
#define FUSE_MAJOR_VERSION 2
@@ -246,6 +247,169 @@ int fuse_version(void);
void fuse_pollhandle_destroy(struct fuse_pollhandle *ph);
/* ----------------------------------------------------------- *
+ * Data buffer *
+ * ----------------------------------------------------------- */
+
+/**
+ * Buffer flags
+ */
+enum fuse_buf_flags {
+ /**
+ * Buffer contains a file descriptor
+ *
+ * If this flag is set, the .fd field is valid, otherwise the
+ * .mem fields is valid.
+ */
+ FUSE_BUF_IS_FD = (1 << 1),
+
+ /**
+ * Seek on the file descriptor
+ *
+ * If this flag is set then the .pos field is valid and is
+ * used to seek to the given offset before performing
+ * operation on file descriptor.
+ */
+ FUSE_BUF_FD_SEEK = (1 << 2),
+
+ /**
+ * Retry operation on file descriptor
+ *
+ * If this flag is set then retry operation on file descriptor
+ * until .size bytes have been copied or an error or EOF is
+ * detetected.
+ */
+ FUSE_BUF_FD_RETRY = (1 << 3),
+};
+
+/**
+ * Buffer copy flags
+ */
+enum fuse_buf_copy_flags {
+ /**
+ * Don't use splice(2)
+ *
+ * Always fall back to using read and write instead of
+ * splice(2) to copy data from one file descriptor to another.
+ *
+ * If this flag is not set, then only fall back if splice is
+ * unavailable.
+ */
+ FUSE_BUF_NO_SPLICE = (1 << 1),
+
+ /**
+ * Force splice
+ *
+ * Always use splice(2) to copy data from one file descriptor
+ * to another. If splice is not available, return -EINVAL.
+ */
+ FUSE_BUF_FORCE_SPLICE = (1 << 2),
+
+ /**
+ * Try to move data with splice.
+ *
+ * If splice is used, try to move pages from the source to the
+ * destination instead of copying. See documentation of
+ * SPLICE_F_MOVE in splice(2) man page.
+ */
+ FUSE_BUF_SPLICE_MOVE = (1 << 2),
+
+ /**
+ * Don't block on the pipe when copying data with splice
+ *
+ * Makes the operations on the pipe non-blocking (if the pipe
+ * is full or empty). See SPLICE_F_NONBLOCK in the splice(2)
+ * man page.
+ */
+ FUSE_BUF_SPLICE_NONBLOCK= (1 << 3),
+};
+
+/**
+ * Single data buffer
+ *
+ * Generic data buffer for I/O, extended attributes, etc... Data may
+ * be supplied as a memory pointer or as a file descriptor
+ */
+struct fuse_buf {
+ /**
+ * Size of data in bytes
+ */
+ size_t size;
+
+ /**
+ * Buffer flags
+ */
+ enum fuse_buf_flags flags;
+
+ /**
+ * Memory pointer
+ *
+ * Used unless FUSE_BUF_IS_FD flag is set.
+ */
+ void *mem;
+
+ /**
+ * File descriptor
+ *
+ * Used if FUSE_BUF_IS_FD flag is set.
+ */
+ int fd;
+
+ /**
+ * File position
+ *
+ * Used if FUSE_BUF_FD_SEEK flag is set.
+ */
+ off_t pos;
+};
+
+/**
+ * Data buffer vector
+ *
+ * An array of data buffers, each containing a memory pointer or a
+ * file descriptor.
+ */
+struct fuse_bufvec {
+ /**
+ * Array of buffers
+ */
+ const struct fuse_buf *buf;
+
+ /**
+ * Number of buffers in the array
+ */
+ size_t count;
+
+ /**
+ * Index of current buffer within the array
+ */
+ size_t idx;
+
+ /**
+ * Current offset within the current buffer
+ */
+ size_t off;
+};
+
+/**
+ * Get total size of data in a fuse buffer vector
+ *
+ * @param bufv buffer vector
+ * @return size of data
+ */
+size_t fuse_buf_size(const struct fuse_bufvec *bufv);
+
+/**
+ * Copy data from one buffer vector to another
+ *
+ * @param dst destination buffer vector
+ * @param src source buffer vector
+ * @param flags flags controlling the copy
+ * @return actual number of bytes copied or -errno on error
+ */
+ssize_t fuse_buf_copy(struct fuse_bufvec *dst, struct fuse_bufvec *src,
+ enum fuse_buf_copy_flags flags);
+
+/* ----------------------------------------------------------- *
* Signal handling *
* ----------------------------------------------------------- */
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index ad17b07..5592544 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -124,14 +124,6 @@ struct fuse_ctx {
#define FUSE_SET_ATTR_ATIME_NOW (1 << 7)
#define FUSE_SET_ATTR_MTIME_NOW (1 << 8)
-/**
- * flags for fuse_reply_fd()
- *
- * FUSE_REPLY_FD_MOVE: attempt to move the data instead of copying
- * (see SPLICE_F_MOVE flag for splice(2)
- */
-#define FUSE_REPLY_FD_MOVE (1 << 0)
-
/* ----------------------------------------------------------- *
* Request methods and replies *
* ----------------------------------------------------------- */
@@ -420,7 +412,7 @@ struct fuse_lowlevel_ops {
* Valid replies:
* fuse_reply_buf
* fuse_reply_iov
- * fuse_reply_fd
+ * fuse_reply_data
* fuse_reply_err
*
* @param req request handle
@@ -570,7 +562,7 @@ struct fuse_lowlevel_ops {
*
* Valid replies:
* fuse_reply_buf
- * fuse_reply_fd
+ * fuse_reply_data
* fuse_reply_err
*
* @param req request handle
@@ -656,7 +648,7 @@ struct fuse_lowlevel_ops {
*
* Valid replies:
* fuse_reply_buf
- * fuse_reply_fd
+ * fuse_reply_data
* fuse_reply_xattr
* fuse_reply_err
*
@@ -683,7 +675,7 @@ struct fuse_lowlevel_ops {
*
* Valid replies:
* fuse_reply_buf
- * fuse_reply_fd
+ * fuse_reply_data
* fuse_reply_xattr
* fuse_reply_err
*
@@ -1008,20 +1000,18 @@ int fuse_reply_write(fuse_req_t req, size_t count);
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size);
/**
- * Reply with data copied/moved from a file descriptor
+ * Reply with data copied/moved from buffer(s)
*
* Possible requests:
* read, readdir, getxattr, listxattr
*
* @param req request handle
- * @param fd file descriptor
- * @param off offset pointer, may be NULL
- * @param len length of data in bytes
- * @param flags FUSE_REPLY_FD_* flags
+ * @param bufv buffer vector
+ * @param flags flags controlling the copy
* @return zero for success, -errno for failure to send reply
*/
-int fuse_reply_fd(fuse_req_t req, int fd, loff_t *off, size_t len,
- unsigned int flags);
+int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
+ enum fuse_buf_copy_flags flags);
/**
* Reply with data vector