From fd1280bc4ba342b4f93182b243237dba0630421c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=9Alusarz?= Date: Wed, 1 Nov 2017 23:23:03 +0100 Subject: [PATCH] fuse: fix reads from files created using O_CREAT|O_RDWR "create" hook doesn't have sys_creat semantics. When user passed O_CREAT | O_RDWR as flags to open, we created write-only file handle... --- src/pmemfile-fuse/main.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pmemfile-fuse/main.c b/src/pmemfile-fuse/main.c index 5485e6831..e63dbb472 100644 --- a/src/pmemfile-fuse/main.c +++ b/src/pmemfile-fuse/main.c @@ -255,6 +255,17 @@ pmemfile_fuse_chown(const char *path, uid_t uid, gid_t gid) return 0; } +static PMEMfile * +pmemfile_open_wrapper(PMEMfilepool *pfp, const char *path, int flags, + pmemfile_mode_t mode) +{ + /* + * &~0x8000, because fuse passes flag pmemfile doesn't understand + * (O_LARGEFILE, which userspace on x86_64 defines as 0) + */ + return pmemfile_open(pfp, path, flags & ~0x8000, mode); +} + static int pmemfile_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) { @@ -266,9 +277,9 @@ pmemfile_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) if ((ret = update_ctx(pfp)) < 0) return ret; - PMEMfile *f = pmemfile_create(pfp, path, mode); + PMEMfile *f = pmemfile_open_wrapper(pfp, path, fi->flags, mode); if (!f) { - log("pmemfile_create %s failed: %d\n", path, errno); + log("pmemfile_open %s failed: %d\n", path, errno); return -errno; } fi->fh = (uintptr_t)f; @@ -306,11 +317,7 @@ pmemfile_fuse_open(const char *path, struct fuse_file_info *fi) if ((ret = update_ctx(pfp)) < 0) return ret; - /* - * &~0x8000, because fuse passes flag pmemfile doesn't understand - * (O_LARGEFILE, which userspace on x86_64 defines as 0) - */ - PMEMfile *f = pmemfile_open(pfp, path, fi->flags & ~0x8000); + PMEMfile *f = pmemfile_open_wrapper(pfp, path, fi->flags, 0); if (f == NULL) { log("pmemfile_open %s failed: %d\n", path, errno); return -errno;