|
|
@ -14,11 +14,6 @@ |
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "config.hpp"
|
|
|
|
#include "errno.hpp"
|
|
|
|
#include "fileinfo.hpp"
|
|
|
@ -29,71 +24,78 @@ |
|
|
|
#include "rwlock.hpp"
|
|
|
|
#include "ugid.hpp"
|
|
|
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
using std::vector; |
|
|
|
using namespace mergerfs; |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
_create_core(const string &fullpath, |
|
|
|
mode_t mode, |
|
|
|
const mode_t umask, |
|
|
|
const int flags) |
|
|
|
namespace local |
|
|
|
{ |
|
|
|
if(!fs::acl::dir_has_defaults(fullpath)) |
|
|
|
mode &= ~umask; |
|
|
|
static |
|
|
|
int |
|
|
|
create_core(const string &fullpath_, |
|
|
|
mode_t mode_, |
|
|
|
const mode_t umask_, |
|
|
|
const int flags_) |
|
|
|
{ |
|
|
|
if(!fs::acl::dir_has_defaults(fullpath_)) |
|
|
|
mode_ &= ~umask_; |
|
|
|
|
|
|
|
return fs::open(fullpath,flags,mode); |
|
|
|
} |
|
|
|
return fs::open(fullpath_,flags_,mode_); |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
_create_core(const string &createpath, |
|
|
|
const char *fusepath, |
|
|
|
const mode_t mode, |
|
|
|
const mode_t umask, |
|
|
|
const int flags, |
|
|
|
uint64_t &fh) |
|
|
|
{ |
|
|
|
static |
|
|
|
int |
|
|
|
create_core(const string &createpath_, |
|
|
|
const char *fusepath_, |
|
|
|
const mode_t mode_, |
|
|
|
const mode_t umask_, |
|
|
|
const int flags_, |
|
|
|
uint64_t *fh_) |
|
|
|
{ |
|
|
|
int rv; |
|
|
|
string fullpath; |
|
|
|
|
|
|
|
fs::path::make(&createpath,fusepath,fullpath); |
|
|
|
fs::path::make(&createpath_,fusepath_,fullpath); |
|
|
|
|
|
|
|
rv = _create_core(fullpath,mode,umask,flags); |
|
|
|
rv = local::create_core(fullpath,mode_,umask_,flags_); |
|
|
|
if(rv == -1) |
|
|
|
return -errno; |
|
|
|
|
|
|
|
fh = reinterpret_cast<uint64_t>(new FileInfo(rv,fusepath)); |
|
|
|
*fh_ = reinterpret_cast<uint64_t>(new FileInfo(rv,fusepath_)); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static |
|
|
|
int |
|
|
|
_create(Policy::Func::Search searchFunc, |
|
|
|
Policy::Func::Create createFunc, |
|
|
|
static |
|
|
|
int |
|
|
|
create(Policy::Func::Search searchFunc_, |
|
|
|
Policy::Func::Create createFunc_, |
|
|
|
const Branches &branches_, |
|
|
|
const uint64_t minfreespace, |
|
|
|
const char *fusepath, |
|
|
|
const mode_t mode, |
|
|
|
const mode_t umask, |
|
|
|
const int flags, |
|
|
|
uint64_t &fh) |
|
|
|
{ |
|
|
|
const uint64_t minfreespace_, |
|
|
|
const char *fusepath_, |
|
|
|
const mode_t mode_, |
|
|
|
const mode_t umask_, |
|
|
|
const int flags_, |
|
|
|
uint64_t *fh_) |
|
|
|
{ |
|
|
|
int rv; |
|
|
|
string fullpath; |
|
|
|
string fusedirpath; |
|
|
|
vector<const string*> createpaths; |
|
|
|
vector<const string*> existingpaths; |
|
|
|
|
|
|
|
fusedirpath = fs::path::dirname(fusepath); |
|
|
|
fusedirpath = fs::path::dirname(fusepath_); |
|
|
|
|
|
|
|
rv = searchFunc(branches_,fusedirpath,minfreespace,existingpaths); |
|
|
|
rv = searchFunc_(branches_,fusedirpath,minfreespace_,existingpaths); |
|
|
|
if(rv == -1) |
|
|
|
return -errno; |
|
|
|
|
|
|
|
rv = createFunc(branches_,fusedirpath,minfreespace,createpaths); |
|
|
|
rv = createFunc_(branches_,fusedirpath,minfreespace_,createpaths); |
|
|
|
if(rv == -1) |
|
|
|
return -errno; |
|
|
|
|
|
|
@ -101,9 +103,13 @@ _create(Policy::Func::Search searchFunc, |
|
|
|
if(rv == -1) |
|
|
|
return -errno; |
|
|
|
|
|
|
|
return _create_core(*createpaths[0], |
|
|
|
fusepath, |
|
|
|
mode,umask,flags,fh); |
|
|
|
return local::create_core(*createpaths[0], |
|
|
|
fusepath_, |
|
|
|
mode_, |
|
|
|
umask_, |
|
|
|
flags_, |
|
|
|
fh_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
namespace mergerfs |
|
|
@ -111,24 +117,25 @@ namespace mergerfs |
|
|
|
namespace fuse |
|
|
|
{ |
|
|
|
int |
|
|
|
create(const char *fusepath, |
|
|
|
mode_t mode, |
|
|
|
fuse_file_info *ffi) |
|
|
|
create(const char *fusepath_, |
|
|
|
mode_t mode_, |
|
|
|
fuse_file_info *ffi_) |
|
|
|
{ |
|
|
|
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.branches_lock); |
|
|
|
|
|
|
|
return _create(config.getattr, |
|
|
|
ffi_->direct_io = config.direct_io; |
|
|
|
return local::create(config.getattr, |
|
|
|
config.create, |
|
|
|
config.branches, |
|
|
|
config.minfreespace, |
|
|
|
fusepath, |
|
|
|
mode, |
|
|
|
fusepath_, |
|
|
|
mode_, |
|
|
|
fc->umask, |
|
|
|
ffi->flags, |
|
|
|
ffi->fh); |
|
|
|
ffi_->flags, |
|
|
|
&ffi_->fh); |
|
|
|
} |
|
|
|
} |
|
|
|
} |