examples/passthrough_ll: added support for create()
authorNikolaus Rath <Nikolaus@rath.org>
Mon, 5 Jun 2017 11:00:56 +0000 (07:00 -0400)
committerNikolaus Rath <Nikolaus@rath.org>
Mon, 5 Jun 2017 11:01:30 +0000 (07:01 -0400)
ChangeLog.rst
example/passthrough_ll.c
test/test_examples.py

index ca166f95bc66006afd8d9262b3b328c68aedd08d..285ef5af21374d775a9b2cae813a6dc3f02db771 100644 (file)
@@ -1,8 +1,8 @@
 Unreleased Changes
 ==================
 
-* The `example/passthrough_ll` filesystem now supports writing
-  to files.
+* The `example/passthrough_ll` filesystem now supports creating
+  and 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
index dd3166a24bedb1a807b1117b154dc8d20a73e067..84dd847f75cd86cd46bc63f5f85efc58509a00ee 100644 (file)
@@ -429,8 +429,29 @@ static void lo_releasedir(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info
        fuse_reply_err(req, 0);
 }
 
+static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,
+                     mode_t mode, struct fuse_file_info *fi)
+{
+       int fd;
+       struct fuse_entry_param e;
+       int err;
+
+       fd = openat(lo_fd(req, parent), name,
+                   (fi->flags | O_CREAT) & ~O_NOFOLLOW, mode);
+       if (fd == -1)
+               return (void) fuse_reply_err(req, errno);
+
+       fi->fh = fd;
+
+       err = lo_do_lookup(req, parent, name, &e);
+       if (err)
+               fuse_reply_err(req, err);
+       else
+               fuse_reply_create(req, &e, fi);
+}
+
 static void lo_open(fuse_req_t req, fuse_ino_t ino,
-                         struct fuse_file_info *fi)
+                   struct fuse_file_info *fi)
 {
        int fd;
        char buf[64];
@@ -495,6 +516,7 @@ static struct fuse_lowlevel_ops lo_oper = {
        .readdir        = lo_readdir,
        .readdirplus    = lo_readdirplus,
        .releasedir     = lo_releasedir,
+       .create         = lo_create,
        .open           = lo_open,
        .release        = lo_release,
        .read           = lo_read,
index 401f074cd5b0b64b2ea50bc8fa9af37751845fb2..794b31cc9f95b129c0a792b288ef2b98bc04bd34 100755 (executable)
@@ -87,10 +87,11 @@ def test_passthrough(tmpdir, name, debug, capfd):
         tst_readdir(src_dir, work_dir)
         tst_open_read(src_dir, work_dir)
         tst_open_write(src_dir, work_dir)
+        tst_create(work_dir)
+        tst_passthrough(src_dir, work_dir)
         if not is_ll:
             tst_mkdir(work_dir)
             tst_rmdir(src_dir, work_dir)
-            tst_create(work_dir)
             tst_unlink(src_dir, work_dir)
             tst_symlink(work_dir)
             if os.getuid() == 0:
@@ -103,7 +104,6 @@ def test_passthrough(tmpdir, name, debug, capfd):
             tst_truncate_path(work_dir)
             tst_truncate_fd(work_dir)
             tst_open_unlink(work_dir)
-            tst_passthrough(src_dir, work_dir)
 
             subprocess.check_call([ os.path.join(basename, 'test', 'test_syscalls'),
                                     work_dir, ':' + src_dir ])