From: Miklos Szeredi Date: Wed, 10 Nov 2010 10:45:50 +0000 (+0100) Subject: fusexmp_fh: add read_buf and write_buf implementations X-Git-Tag: fuse_2_9_0~83 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=e099bda0d0bbdbd7874176cae3ab80fc6ef6cc8f;p=qemu-gpiodev%2Flibfuse.git fusexmp_fh: add read_buf and write_buf implementations 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. --- diff --git a/ChangeLog b/ChangeLog index 36bda9e..2cf7052 100644 --- 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 * Fix check for read-only fs in mtab update diff --git a/example/fusexmp_fh.c b/example/fusexmp_fh.c index b86d3f6..8f8b1a9 100644 --- a/example/fusexmp_fh.c +++ b/example/fusexmp_fh.c @@ -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,