fusexmp_fh: add read_buf and write_buf implementations
authorMiklos Szeredi <miklos@szeredi.hu>
Wed, 10 Nov 2010 10:45:50 +0000 (11:45 +0100)
committerMiklos Szeredi <mszeredi@suse.cz>
Wed, 10 Nov 2010 10:45:50 +0000 (11:45 +0100)
In fusexmp_fh implement the ->read_buf() and ->write_buf() methods.
Leave the ->read() and ->write() implementations for reference, even
though they are not necessary.

ChangeLog
example/fusexmp_fh.c

index 36bda9e403e1d831d06428ea45a13101a4b50dc3..2cf7052c39cf17ee48444f38c6aa218a0e7469f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,10 @@
        returning a generic buffer from the read method, which in turn
        allows zero copy reads.
 
+       * In fusexmp_fh implement the ->read_buf() and ->write_buf()
+       methods.  Leave the ->read() and ->write() implementations for
+       reference, even though they are not necessary.
+
 2010-11-08  Miklos Szeredi <miklos@szeredi.hu>
 
        * Fix check for read-only fs in mtab update
index b86d3f6f8a9d9a21d3bb8571ab68917e1be30abb..8f8b1a983e415a14db128858737369d595ab75d0 100644 (file)
@@ -334,6 +334,28 @@ static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
        return res;
 }
 
+static int xmp_read_buf(const char *path, struct fuse_bufvec **bufp,
+                       size_t size, off_t offset, struct fuse_file_info *fi)
+{
+       struct fuse_bufvec *src;
+
+       (void) path;
+
+       src = malloc(sizeof(struct fuse_bufvec));
+       if (src == NULL)
+               return -ENOMEM;
+
+       *src = FUSE_BUFVEC_INIT(size);
+
+       src->buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK;
+       src->buf[0].fd = fi->fh;
+       src->buf[0].pos = offset;
+
+       *bufp = src;
+
+       return 0;
+}
+
 static int xmp_write(const char *path, const char *buf, size_t size,
                     off_t offset, struct fuse_file_info *fi)
 {
@@ -347,6 +369,20 @@ static int xmp_write(const char *path, const char *buf, size_t size,
        return res;
 }
 
+static int xmp_write_buf(const char *path, struct fuse_bufvec *buf,
+                    off_t offset, struct fuse_file_info *fi)
+{
+       struct fuse_bufvec dst = FUSE_BUFVEC_INIT(fuse_buf_size(buf));
+
+       (void) path;
+
+       dst.buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK;
+       dst.buf[0].fd = fi->fh;
+       dst.buf[0].pos = offset;
+
+       return fuse_buf_copy(&dst, buf, FUSE_BUF_SPLICE_NONBLOCK);
+}
+
 static int xmp_statfs(const char *path, struct statvfs *stbuf)
 {
        int res;
@@ -472,7 +508,9 @@ static struct fuse_operations xmp_oper = {
        .create         = xmp_create,
        .open           = xmp_open,
        .read           = xmp_read,
+       .read_buf       = xmp_read_buf,
        .write          = xmp_write,
+       .write_buf      = xmp_write_buf,
        .statfs         = xmp_statfs,
        .flush          = xmp_flush,
        .release        = xmp_release,