passthrough: implemented create()
authorNikolaus Rath <Nikolaus@rath.org>
Fri, 7 Apr 2017 23:36:52 +0000 (16:36 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Fri, 7 Apr 2017 23:40:15 +0000 (16:40 -0700)
This allows calls like open(file, O_CREAT|O_RDONLY, 0200) which would
otherwise fail because we cannot open the file after mknod() has
created it with 0200 permissions.

example/passthrough.c

index d5edc04dff0fcbbc0cdca971a979509f30a5a385..0c635ca62d2363fda0b9df4a555764ea983c3a03 100644 (file)
@@ -278,6 +278,19 @@ static int xmp_utimens(const char *path, const struct timespec ts[2],
 }
 #endif
 
+static int xmp_create(const char *path, mode_t mode,
+                     struct fuse_file_info *fi)
+{
+       int res;
+
+       res = open(path, fi->flags, mode);
+       if (res == -1)
+               return -errno;
+
+       fi->fh = res;
+       return 0;
+}
+
 static int xmp_open(const char *path, struct fuse_file_info *fi)
 {
        int res;
@@ -452,6 +465,7 @@ static struct fuse_operations xmp_oper = {
        .utimens        = xmp_utimens,
 #endif
        .open           = xmp_open,
+       .create         = xmp_create,
        .read           = xmp_read,
        .write          = xmp_write,
        .statfs         = xmp_statfs,