From 162b99e6b86e64293e80da607ec8dc4278f2bbc3 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 11 Apr 2017 08:53:46 -0400 Subject: [PATCH] enable nopath and nullpath_ok --- src/config.hpp | 10 ++++++++ src/create.cpp | 2 +- src/dirinfo.hpp | 34 +++++++++++++++++++++++++++ src/fgetattr.cpp | 2 +- src/fileinfo.hpp | 9 ++++++-- src/flush.cpp | 2 +- src/fs_base_fsync.hpp | 4 ++++ src/fs_base_ioctl.hpp | 6 ++--- src/fsync.cpp | 7 +----- src/fsyncdir.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++ src/fsyncdir.hpp | 33 +++++++++++++++++++++++++++ src/ftruncate.cpp | 3 +-- src/ioctl.cpp | 38 +++++++++++++++++++------------ src/mergerfs.cpp | 7 +++--- src/open.cpp | 2 +- src/opendir.cpp | 4 +++- src/read.cpp | 4 ++-- src/readdir.cpp | 13 ++++++----- src/release.cpp | 5 ++-- src/releasedir.cpp | 15 +++++++++++- src/write.cpp | 10 +++----- 21 files changed, 208 insertions(+), 55 deletions(-) create mode 100644 src/dirinfo.hpp create mode 100644 src/fsyncdir.cpp create mode 100644 src/fsyncdir.hpp diff --git a/src/config.hpp b/src/config.hpp index fd20f44c..ac22dc3e 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -77,6 +77,16 @@ namespace mergerfs const std::string controlfile; public: + static + const + Config & + get(void) + { + const fuse_context *fc = fuse_get_context(); + + return get(fc); + } + static const Config & get(const fuse_context *fc) diff --git a/src/create.cpp b/src/create.cpp index 3b35bf45..5ea71e8f 100644 --- a/src/create.cpp +++ b/src/create.cpp @@ -75,7 +75,7 @@ _create_core(const string &existingpath, if(rv == -1) return -errno; - fh = reinterpret_cast(new FileInfo(rv)); + fh = reinterpret_cast(new FileInfo(rv,fusepath)); return 0; } diff --git a/src/dirinfo.hpp b/src/dirinfo.hpp new file mode 100644 index 00000000..007aa094 --- /dev/null +++ b/src/dirinfo.hpp @@ -0,0 +1,34 @@ +/* + Copyright (c) 2017, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef __DIRINFO_HPP__ +#define __DIRINFO_HPP__ + +#include + +class DirInfo +{ +public: + DirInfo(const char *fusepath_) + : fusepath(fusepath_) + { + } + +public: + std::string fusepath; +}; + +#endif diff --git a/src/fgetattr.cpp b/src/fgetattr.cpp index 82b7a70d..05186803 100644 --- a/src/fgetattr.cpp +++ b/src/fgetattr.cpp @@ -48,7 +48,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _fgetattr(fi->fd,*st); + return ::_fgetattr(fi->fd,*st); } } } diff --git a/src/fileinfo.hpp b/src/fileinfo.hpp index 1eb0b178..b42f1c4b 100644 --- a/src/fileinfo.hpp +++ b/src/fileinfo.hpp @@ -17,16 +17,21 @@ #ifndef __FILEINFO_HPP__ #define __FILEINFO_HPP__ +#include + class FileInfo { public: - FileInfo(int _fd) : - fd(_fd) + FileInfo(const int fd_, + const char *fusepath_) + : fd(fd_), + fusepath(fusepath_) { } public: int fd; + std::string fusepath; }; #endif diff --git a/src/flush.cpp b/src/flush.cpp index d04b7933..e2062d12 100644 --- a/src/flush.cpp +++ b/src/flush.cpp @@ -46,7 +46,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _flush(fi->fd); + return ::_flush(fi->fd); } } } diff --git a/src/fs_base_fsync.hpp b/src/fs_base_fsync.hpp index 46c2a27e..4a7800ee 100644 --- a/src/fs_base_fsync.hpp +++ b/src/fs_base_fsync.hpp @@ -19,6 +19,10 @@ #ifndef __FS_BASE_FSYNC_HPP__ #define __FS_BASE_FSYNC_HPP__ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include #include "errno.hpp" diff --git a/src/fs_base_ioctl.hpp b/src/fs_base_ioctl.hpp index 9de63983..980378b6 100644 --- a/src/fs_base_ioctl.hpp +++ b/src/fs_base_ioctl.hpp @@ -26,9 +26,9 @@ namespace fs static inline int - ioctl(const int fd, - const int request, - void *data) + ioctl(const int fd, + const unsigned long request, + void *data) { return ::ioctl(fd,request,data); } diff --git a/src/fsync.cpp b/src/fsync.cpp index 6d10ab4b..03d45b0b 100644 --- a/src/fsync.cpp +++ b/src/fsync.cpp @@ -14,10 +14,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - #include #include @@ -52,8 +48,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _fsync(fi->fd, - isdatasync); + return ::_fsync(fi->fd,isdatasync); } } } diff --git a/src/fsyncdir.cpp b/src/fsyncdir.cpp new file mode 100644 index 00000000..0f5b9248 --- /dev/null +++ b/src/fsyncdir.cpp @@ -0,0 +1,53 @@ +/* + Copyright (c) 2017, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include + +#include +#include + +#include "errno.hpp" +#include "dirinfo.hpp" +#include "fs_base_fsync.hpp" + +static +int +_fsyncdir(const DirInfo *di, + const int isdatasync) +{ + int rv; + + rv = -1; + errno = ENOSYS; + + return ((rv == -1) ? -errno : 0); +} + +namespace mergerfs +{ + namespace fuse + { + int + fsyncdir(const char *fusepath, + int isdatasync, + fuse_file_info *ffi) + { + DirInfo *di = reinterpret_cast(ffi->fh); + + return ::_fsyncdir(di,isdatasync); + } + } +} diff --git a/src/fsyncdir.hpp b/src/fsyncdir.hpp new file mode 100644 index 00000000..2a0794c2 --- /dev/null +++ b/src/fsyncdir.hpp @@ -0,0 +1,33 @@ +/* + Copyright (c) 2017, Antonio SJ Musumeci + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#ifndef __FSYNCDIR_HPP__ +#define __FSYNCDIR_HPP__ + +#include + +namespace mergerfs +{ + namespace fuse + { + int + fsyncdir(const char *fusepath, + int isdatasync, + fuse_file_info *ffi); + } +} + +#endif diff --git a/src/ftruncate.cpp b/src/ftruncate.cpp index 07c643df..920087a7 100644 --- a/src/ftruncate.cpp +++ b/src/ftruncate.cpp @@ -43,8 +43,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _ftruncate(fi->fd, - size); + return ::_ftruncate(fi->fd,size); } } } diff --git a/src/ioctl.cpp b/src/ioctl.cpp index c081bfc9..46a1fd80 100644 --- a/src/ioctl.cpp +++ b/src/ioctl.cpp @@ -22,6 +22,7 @@ #include #include "config.hpp" +#include "dirinfo.hpp" #include "errno.hpp" #include "fileinfo.hpp" #include "fs_base_close.hpp" @@ -37,9 +38,9 @@ using namespace mergerfs; static int -_ioctl(const int fd, - const int cmd, - void *data) +_ioctl(const int fd, + const unsigned long cmd, + void *data) { int rv; @@ -48,6 +49,17 @@ _ioctl(const int fd, return ((rv == -1) ? -errno : rv); } +static +int +_ioctl_file(fuse_file_info *ffi, + const unsigned long cmd, + void *data) +{ + FileInfo *fi = reinterpret_cast(ffi->fh); + + return _ioctl(fi->fd,cmd,data); +} + #ifdef FUSE_IOCTL_DIR #ifndef O_NOATIME @@ -60,7 +72,7 @@ _ioctl_dir_base(Policy::Func::Search searchFunc, const vector &srcmounts, const uint64_t minfreespace, const char *fusepath, - const int cmd, + const unsigned long cmd, void *data) { int fd; @@ -88,10 +100,11 @@ _ioctl_dir_base(Policy::Func::Search searchFunc, static int -_ioctl_dir(const char *fusepath, - const int cmd, - void *data) +_ioctl_dir(fuse_file_info *ffi, + const unsigned long cmd, + void *data) { + DirInfo *di = reinterpret_cast(ffi->fh); const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); @@ -100,7 +113,7 @@ _ioctl_dir(const char *fusepath, return _ioctl_dir_base(config.getattr, config.srcmounts, config.minfreespace, - fusepath, + di->fusepath.c_str(), cmd, data); } @@ -120,15 +133,10 @@ namespace mergerfs { #ifdef FUSE_IOCTL_DIR if(flags & FUSE_IOCTL_DIR) - return _ioctl_dir(fusepath, - cmd, - data); + return ::_ioctl_dir(ffi,cmd,data); #endif - FileInfo *fi = reinterpret_cast(ffi->fh); - return _ioctl(fi->fd, - cmd, - data); + return ::_ioctl_file(ffi,cmd,data); } } } diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index ddf9aa7f..bc552edf 100644 --- a/src/mergerfs.cpp +++ b/src/mergerfs.cpp @@ -35,6 +35,7 @@ #include "flock.hpp" #include "flush.hpp" #include "fsync.hpp" +#include "fsyncdir.hpp" #include "ftruncate.hpp" #include "getattr.hpp" #include "getxattr.hpp" @@ -71,9 +72,9 @@ namespace local get_fuse_operations(struct fuse_operations &ops, const bool direct_io) { - ops.flag_nullpath_ok = false; + ops.flag_nullpath_ok = true; #if FLAG_NOPATH - ops.flag_nopath = false; + ops.flag_nopath = true; #endif #if FLAG_UTIME ops.flag_utime_omit_ok = true; @@ -94,7 +95,7 @@ namespace local #endif ops.flush = mergerfs::fuse::flush; ops.fsync = mergerfs::fuse::fsync; - ops.fsyncdir = NULL; + ops.fsyncdir = mergerfs::fuse::fsyncdir; ops.ftruncate = mergerfs::fuse::ftruncate; ops.getattr = mergerfs::fuse::getattr; ops.getdir = NULL; /* deprecated; use readdir */ diff --git a/src/open.cpp b/src/open.cpp index d51a99d1..78218ba2 100644 --- a/src/open.cpp +++ b/src/open.cpp @@ -49,7 +49,7 @@ _open_core(const string *basepath, if(fd == -1) return -errno; - fh = reinterpret_cast(new FileInfo(fd)); + fh = reinterpret_cast(new FileInfo(fd,fusepath)); return 0; } diff --git a/src/opendir.cpp b/src/opendir.cpp index 819d356e..d97fcdf5 100644 --- a/src/opendir.cpp +++ b/src/opendir.cpp @@ -16,6 +16,8 @@ #include +#include "dirinfo.hpp" + namespace mergerfs { namespace fuse @@ -24,7 +26,7 @@ namespace mergerfs opendir(const char *fusepath, fuse_file_info *ffi) { - ffi->fh = 0; + ffi->fh = reinterpret_cast(new DirInfo(fusepath)); return 0; } diff --git a/src/read.cpp b/src/read.cpp index 80d08c09..a3e6489a 100644 --- a/src/read.cpp +++ b/src/read.cpp @@ -73,7 +73,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _read(fi->fd,buf,count,offset); + return ::_read(fi->fd,buf,count,offset); } int @@ -85,7 +85,7 @@ namespace mergerfs { FileInfo *fi = reinterpret_cast(ffi->fh); - return _read_direct_io(fi->fd,buf,count,offset); + return ::_read_direct_io(fi->fd,buf,count,offset); } } } diff --git a/src/readdir.cpp b/src/readdir.cpp index 56d8e054..48d984b5 100644 --- a/src/readdir.cpp +++ b/src/readdir.cpp @@ -23,6 +23,7 @@ #include #include "config.hpp" +#include "dirinfo.hpp" #include "errno.hpp" #include "fs_base_closedir.hpp" #include "fs_base_dirfd.hpp" @@ -39,7 +40,6 @@ using std::string; using std::vector; -using std::pair; #define NO_OFFSET 0 @@ -103,17 +103,18 @@ namespace mergerfs void *buf, fuse_fill_dir_t filler, off_t offset, - fuse_file_info *fi) + fuse_file_info *ffi) { + DirInfo *di = reinterpret_cast(ffi->fh); const fuse_context *fc = fuse_get_context(); const Config &config = Config::get(fc); const ugid::Set ugid(fc->uid,fc->gid); const rwlock::ReadGuard readlock(&config.srcmountslock); - return _readdir(config.srcmounts, - fusepath, - buf, - filler); + return ::_readdir(config.srcmounts, + di->fusepath.c_str(), + buf, + filler); } } } diff --git a/src/release.cpp b/src/release.cpp index 447e65ec..196bf645 100644 --- a/src/release.cpp +++ b/src/release.cpp @@ -52,9 +52,8 @@ namespace mergerfs release(const char *fusepath, fuse_file_info *ffi) { - const fuse_context *fc = fuse_get_context(); - const Config &config = Config::get(fc); - FileInfo *fi = reinterpret_cast(ffi->fh); + const Config &config = Config::get(); + FileInfo *fi = reinterpret_cast(ffi->fh); return _release(fi,config.dropcacheonclose); } diff --git a/src/releasedir.cpp b/src/releasedir.cpp index 8fde1d79..d95486c7 100644 --- a/src/releasedir.cpp +++ b/src/releasedir.cpp @@ -16,6 +16,17 @@ #include +#include "dirinfo.hpp" + +static +int +_releasedir(DirInfo *di) +{ + delete di; + + return 0; +} + namespace mergerfs { namespace fuse @@ -24,7 +35,9 @@ namespace mergerfs releasedir(const char *fusepath, fuse_file_info *ffi) { - return 0; + DirInfo *di = reinterpret_cast(ffi->fh); + + return ::_releasedir(di); } } } diff --git a/src/write.cpp b/src/write.cpp index 6d722b06..b7da6d64 100644 --- a/src/write.cpp +++ b/src/write.cpp @@ -72,9 +72,6 @@ _write_direct_io(const int fd, return rv; } - - - namespace mergerfs { namespace fuse @@ -83,7 +80,6 @@ namespace mergerfs inline int write(WriteFunc func, - const char *fusepath, const char *buf, const size_t count, const off_t offset, @@ -103,7 +99,7 @@ namespace mergerfs const ugid::Set ugid(0,0); const rwlock::ReadGuard readlock(&config.srcmountslock); - rv = fs::movefile(config.srcmounts,fusepath,count,fi->fd); + rv = fs::movefile(config.srcmounts,fi->fusepath,count,fi->fd); if(rv == -1) return -ENOSPC; @@ -121,7 +117,7 @@ namespace mergerfs off_t offset, fuse_file_info *ffi) { - return write(_write,fusepath,buf,count,offset,ffi); + return write(_write,buf,count,offset,ffi); } int @@ -131,7 +127,7 @@ namespace mergerfs off_t offset, fuse_file_info *ffi) { - return write(_write_direct_io,fusepath,buf,count,offset,ffi); + return write(_write_direct_io,buf,count,offset,ffi); } } }