From: Nikolaus Rath Date: Mon, 5 Jun 2017 10:57:36 +0000 (-0400) Subject: example/passthrough_ll: added write support X-Git-Tag: fuse-3.1.0~17 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=bb3770f38a01f4032a717b4a07087a166482d0fe;p=qemu-gpiodev%2Flibfuse.git example/passthrough_ll: added write support --- diff --git a/ChangeLog.rst b/ChangeLog.rst index 560ad98..ca166f9 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,6 +1,8 @@ Unreleased Changes ================== +* The `example/passthrough_ll` filesystem now supports writing + to files. * `fuse_main()` / `fuse_remove_signal_handlers()`: do not reset `SIGPIPE` handler to `SIG_DFL` it was not set by us. * Documented the `RENAME_EXCHANGE` and `RENAME_NOREPLACE` flags that diff --git a/example/passthrough_ll.c b/example/passthrough_ll.c index 772a822..dd3166a 100644 --- a/example/passthrough_ll.c +++ b/example/passthrough_ll.c @@ -453,7 +453,7 @@ static void lo_release(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi } static void lo_read(fuse_req_t req, fuse_ino_t ino, size_t size, - off_t offset, struct fuse_file_info *fi) + off_t offset, struct fuse_file_info *fi) { struct fuse_bufvec buf = FUSE_BUFVEC_INIT(size); @@ -466,6 +466,25 @@ static void lo_read(fuse_req_t req, fuse_ino_t ino, size_t size, fuse_reply_data(req, &buf, FUSE_BUF_SPLICE_MOVE); } +static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, + struct fuse_bufvec *in_buf, off_t off, + struct fuse_file_info *fi) +{ + (void) ino; + ssize_t res; + struct fuse_bufvec out_buf = FUSE_BUFVEC_INIT(fuse_buf_size(in_buf)); + + out_buf.buf[0].flags = FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK; + out_buf.buf[0].fd = fi->fh; + out_buf.buf[0].pos = off; + + res = fuse_buf_copy(&out_buf, in_buf, 0); + if(res < 0) + fuse_reply_err(req, -res); + else + fuse_reply_write(req, (size_t) res); +} + static struct fuse_lowlevel_ops lo_oper = { .init = lo_init, .lookup = lo_lookup, @@ -479,6 +498,7 @@ static struct fuse_lowlevel_ops lo_oper = { .open = lo_open, .release = lo_release, .read = lo_read, + .write_buf = lo_write_buf }; int main(int argc, char *argv[]) diff --git a/test/test_examples.py b/test/test_examples.py index 953eeec..401f074 100755 --- a/test/test_examples.py +++ b/test/test_examples.py @@ -86,11 +86,11 @@ def test_passthrough(tmpdir, name, debug, capfd): tst_statvfs(work_dir) tst_readdir(src_dir, work_dir) tst_open_read(src_dir, work_dir) + tst_open_write(src_dir, work_dir) if not is_ll: tst_mkdir(work_dir) tst_rmdir(src_dir, work_dir) tst_create(work_dir) - tst_open_write(src_dir, work_dir) tst_unlink(src_dir, work_dir) tst_symlink(work_dir) if os.getuid() == 0: