diff options
author | Miklos Szeredi <miklos@szeredi.hu> | 2010-11-10 11:45:50 +0100 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2010-11-10 11:45:50 +0100 |
commit | e099bda0d0bbdbd7874176cae3ab80fc6ef6cc8f (patch) | |
tree | 6a6fe593680c3c235417fc4131908ca1a27494c3 /example | |
parent | 63322038855660cc106c8f87a2ae42bcac37a4af (diff) |
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.
Diffstat (limited to 'example')
-rw-r--r-- | example/fusexmp_fh.c | 38 |
1 files changed, 38 insertions, 0 deletions
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, |