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