mirror of
https://github.com/trapexit/mergerfs.git
synced 2024-11-23 03:43:43 +08:00
config get and struct naming cleanup
This commit is contained in:
parent
81dbafdc19
commit
f130d07fd8
|
@ -74,8 +74,8 @@ namespace mergerfs
|
|||
access(const char *fusepath,
|
||||
int mask)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace mergerfs
|
|||
chmod(const char *fusepath,
|
||||
mode_t mode)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
using std::string;
|
||||
using std::vector;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Config;
|
||||
|
||||
static
|
||||
int
|
||||
|
@ -77,8 +78,8 @@ namespace mergerfs
|
|||
uid_t uid,
|
||||
gid_t gid)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
149
src/config.cpp
149
src/config.cpp
|
@ -40,102 +40,81 @@ using std::vector;
|
|||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace config
|
||||
Config::Config()
|
||||
: destmount(),
|
||||
srcmounts(),
|
||||
srcmountslock(),
|
||||
minfreespace(UINT32_MAX),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
POLICYINIT(create),
|
||||
POLICYINIT(getattr),
|
||||
POLICYINIT(getxattr),
|
||||
POLICYINIT(link),
|
||||
POLICYINIT(listxattr),
|
||||
POLICYINIT(mkdir),
|
||||
POLICYINIT(mknod),
|
||||
POLICYINIT(open),
|
||||
POLICYINIT(readlink),
|
||||
POLICYINIT(removexattr),
|
||||
POLICYINIT(rename),
|
||||
POLICYINIT(rmdir),
|
||||
POLICYINIT(setxattr),
|
||||
POLICYINIT(symlink),
|
||||
POLICYINIT(truncate),
|
||||
POLICYINIT(unlink),
|
||||
POLICYINIT(utimens),
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
Config::Config()
|
||||
: destmount(),
|
||||
srcmounts(),
|
||||
srcmountslock(),
|
||||
minfreespace(UINT32_MAX),
|
||||
POLICYINIT(access),
|
||||
POLICYINIT(chmod),
|
||||
POLICYINIT(chown),
|
||||
POLICYINIT(create),
|
||||
POLICYINIT(getattr),
|
||||
POLICYINIT(getxattr),
|
||||
POLICYINIT(link),
|
||||
POLICYINIT(listxattr),
|
||||
POLICYINIT(mkdir),
|
||||
POLICYINIT(mknod),
|
||||
POLICYINIT(open),
|
||||
POLICYINIT(readlink),
|
||||
POLICYINIT(removexattr),
|
||||
POLICYINIT(rename),
|
||||
POLICYINIT(rmdir),
|
||||
POLICYINIT(setxattr),
|
||||
POLICYINIT(symlink),
|
||||
POLICYINIT(truncate),
|
||||
POLICYINIT(unlink),
|
||||
POLICYINIT(utimens),
|
||||
controlfile("/.mergerfs")
|
||||
{
|
||||
pthread_rwlock_init(&srcmountslock,NULL);
|
||||
pthread_rwlock_init(&srcmountslock,NULL);
|
||||
|
||||
set_category_policy("action","all");
|
||||
set_category_policy("create","epmfs");
|
||||
set_category_policy("search","ff");
|
||||
}
|
||||
set_category_policy("action","all");
|
||||
set_category_policy("create","epmfs");
|
||||
set_category_policy("search","ff");
|
||||
}
|
||||
|
||||
int
|
||||
Config::set_func_policy(const string &fusefunc_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const FuseFunc *fusefunc;
|
||||
int
|
||||
Config::set_func_policy(const string &fusefunc_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const FuseFunc *fusefunc;
|
||||
|
||||
fusefunc = FuseFunc::find(fusefunc_);
|
||||
if(fusefunc == FuseFunc::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
fusefunc = FuseFunc::find(fusefunc_);
|
||||
if(fusefunc == FuseFunc::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
|
||||
policies[(FuseFunc::Enum::Type)*fusefunc] = policy;
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Config::set_category_policy(const string &category_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const Category *category;
|
||||
int
|
||||
Config::set_category_policy(const string &category_,
|
||||
const string &policy_)
|
||||
{
|
||||
const Policy *policy;
|
||||
const Category *category;
|
||||
|
||||
category = Category::find(category_);
|
||||
if(category == Category::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
category = Category::find(category_);
|
||||
if(category == Category::invalid)
|
||||
return (errno=ENODATA,-1);
|
||||
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
policy = Policy::find(policy_);
|
||||
if(policy == Policy::invalid)
|
||||
return (errno=EINVAL,-1);
|
||||
|
||||
for(int i = 0; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(FuseFunc::fusefuncs[i] == (Category::Enum::Type)*category)
|
||||
policies[(FuseFunc::Enum::Type)FuseFunc::fusefuncs[i]] = policy;
|
||||
}
|
||||
for(int i = 0; i < FuseFunc::Enum::END; i++)
|
||||
{
|
||||
if(FuseFunc::fusefuncs[i] == (Category::Enum::Type)*category)
|
||||
policies[(FuseFunc::Enum::Type)FuseFunc::fusefuncs[i]] = policy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(const struct fuse_context *fc)
|
||||
{
|
||||
return *((Config*)fc->private_data);
|
||||
}
|
||||
|
||||
const Config&
|
||||
get(void)
|
||||
{
|
||||
return get(fuse_get_context());
|
||||
}
|
||||
|
||||
Config&
|
||||
get_writable(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
102
src/config.hpp
102
src/config.hpp
|
@ -38,56 +38,64 @@
|
|||
|
||||
namespace mergerfs
|
||||
{
|
||||
namespace config
|
||||
class Config
|
||||
{
|
||||
class Config
|
||||
public:
|
||||
Config();
|
||||
|
||||
public:
|
||||
int set_func_policy(const std::string &fusefunc_,
|
||||
const std::string &policy_);
|
||||
int set_category_policy(const std::string &category,
|
||||
const std::string &policy);
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
mutable pthread_rwlock_t srcmountslock;
|
||||
size_t minfreespace;
|
||||
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
const Policy *&access;
|
||||
const Policy *&chmod;
|
||||
const Policy *&chown;
|
||||
const Policy *&create;
|
||||
const Policy *&getattr;
|
||||
const Policy *&getxattr;
|
||||
const Policy *&link;
|
||||
const Policy *&listxattr;
|
||||
const Policy *&mkdir;
|
||||
const Policy *&mknod;
|
||||
const Policy *&open;
|
||||
const Policy *&readlink;
|
||||
const Policy *&removexattr;
|
||||
const Policy *&rename;
|
||||
const Policy *&rmdir;
|
||||
const Policy *&setxattr;
|
||||
const Policy *&symlink;
|
||||
const Policy *&truncate;
|
||||
const Policy *&unlink;
|
||||
const Policy *&utimens;
|
||||
|
||||
public:
|
||||
const std::string controlfile;
|
||||
|
||||
public:
|
||||
static
|
||||
const Config &
|
||||
get(const fuse_context *fc)
|
||||
{
|
||||
public:
|
||||
Config();
|
||||
return *((Config*)fc->private_data);
|
||||
}
|
||||
|
||||
public:
|
||||
int set_func_policy(const std::string &fusefunc_,
|
||||
const std::string &policy_);
|
||||
int set_category_policy(const std::string &category,
|
||||
const std::string &policy);
|
||||
|
||||
public:
|
||||
std::string destmount;
|
||||
std::vector<std::string> srcmounts;
|
||||
mutable pthread_rwlock_t srcmountslock;
|
||||
size_t minfreespace;
|
||||
|
||||
public:
|
||||
const Policy *policies[FuseFunc::Enum::END];
|
||||
const Policy *&access;
|
||||
const Policy *&chmod;
|
||||
const Policy *&chown;
|
||||
const Policy *&create;
|
||||
const Policy *&getattr;
|
||||
const Policy *&getxattr;
|
||||
const Policy *&link;
|
||||
const Policy *&listxattr;
|
||||
const Policy *&mkdir;
|
||||
const Policy *&mknod;
|
||||
const Policy *&open;
|
||||
const Policy *&readlink;
|
||||
const Policy *&removexattr;
|
||||
const Policy *&rename;
|
||||
const Policy *&rmdir;
|
||||
const Policy *&setxattr;
|
||||
const Policy *&symlink;
|
||||
const Policy *&truncate;
|
||||
const Policy *&unlink;
|
||||
const Policy *&utimens;
|
||||
|
||||
public:
|
||||
const std::string controlfile;
|
||||
};
|
||||
|
||||
const Config &get(const struct fuse_context *fc);
|
||||
const Config &get(void);
|
||||
Config &get_writable(void);
|
||||
}
|
||||
static
|
||||
Config &
|
||||
get_writable(void)
|
||||
{
|
||||
return (*((Config*)fuse_get_context()->private_data));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -89,12 +89,12 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
struct fuse_file_info *fileinfo)
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
fuse_file_info *fileinfo)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
struct fuse_file_info *fileinfo);
|
||||
create(const char *fusepath,
|
||||
mode_t mode,
|
||||
fuse_file_info *fileinfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,11 +67,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
struct fuse_file_info *ffi)
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _fallocate(ffi->fh,
|
||||
mode,
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
struct fuse_file_info *fi);
|
||||
fallocate(const char *fusepath,
|
||||
int mode,
|
||||
off_t offset,
|
||||
off_t len,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
struct fuse_file_info *ffi)
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _fgetattr(ffi->fh,
|
||||
*st);
|
||||
|
|
|
@ -31,8 +31,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
struct fuse_file_info *fileinfo);
|
||||
fgetattr(const char *fusepath,
|
||||
struct stat *st,
|
||||
fuse_file_info *fileinfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,8 +47,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
flush(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
flush(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _flush(ffi->fh);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
flush(const char *path,
|
||||
struct fuse_file_info *fi);
|
||||
flush(const char *path,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,9 +53,9 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
struct fuse_file_info *ffi)
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _fsync(ffi->fh,
|
||||
isdatasync);
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
struct fuse_file_info *fi);
|
||||
fsync(const char *fusepath,
|
||||
int isdatasync,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,9 +45,9 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
struct fuse_file_info *ffi)
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _ftruncate(ffi->fh,
|
||||
size);
|
||||
|
|
|
@ -32,8 +32,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
struct fuse_file_info *fi);
|
||||
ftruncate(const char *fusepath,
|
||||
off_t size,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,12 +94,12 @@ namespace mergerfs
|
|||
getattr(const char *fusepath,
|
||||
struct stat *st)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _getattr_controlfile(*st);
|
||||
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ using std::string;
|
|||
using std::vector;
|
||||
using std::set;
|
||||
using namespace mergerfs;
|
||||
using namespace mergerfs::config;
|
||||
|
||||
static
|
||||
void
|
||||
|
@ -246,7 +245,8 @@ namespace mergerfs
|
|||
char *buf,
|
||||
size_t count)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _getxattr_controlfile(config,
|
||||
|
@ -254,9 +254,8 @@ namespace mergerfs
|
|||
buf,
|
||||
count);
|
||||
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _getxattr(config.getxattr,
|
||||
config.srcmounts,
|
||||
|
|
|
@ -31,13 +31,13 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn)
|
||||
init(fuse_conn_info *conn)
|
||||
{
|
||||
#ifdef FUSE_CAP_IOCTL_DIR
|
||||
conn->want |= FUSE_CAP_IOCTL_DIR;
|
||||
#endif
|
||||
|
||||
return &config::get_writable();
|
||||
return &Config::get_writable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,6 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
void *
|
||||
init(struct fuse_conn_info *conn);
|
||||
init(fuse_conn_info *conn);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,8 +98,8 @@ _ioctl_dir(const string &fusepath,
|
|||
const int cmd,
|
||||
void *data)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get(fc);
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
@ -117,12 +117,12 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
struct fuse_file_info *ffi,
|
||||
unsigned int flags,
|
||||
void *data)
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
fuse_file_info *ffi,
|
||||
unsigned int flags,
|
||||
void *data)
|
||||
{
|
||||
#ifdef FUSE_IOCTL_DIR
|
||||
if(flags & FUSE_IOCTL_DIR)
|
||||
|
|
|
@ -27,11 +27,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
struct fuse_file_info *fi,
|
||||
unsigned int flags,
|
||||
void *data);
|
||||
ioctl(const char *fusepath,
|
||||
int cmd,
|
||||
void *arg,
|
||||
fuse_file_info *fi,
|
||||
unsigned int flags,
|
||||
void *data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,8 +110,8 @@ namespace mergerfs
|
|||
link(const char *from,
|
||||
const char *to)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -109,12 +109,12 @@ namespace mergerfs
|
|||
char *list,
|
||||
size_t size)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _listxattr_controlfile(list,size);
|
||||
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -168,9 +168,9 @@ namespace mergerfs
|
|||
main(const int argc,
|
||||
char **argv)
|
||||
{
|
||||
struct fuse_args args;
|
||||
struct fuse_operations ops = {0};
|
||||
mergerfs::config::Config config;
|
||||
fuse_args args;
|
||||
fuse_operations ops = {0};
|
||||
Config config;
|
||||
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
|
|
|
@ -94,8 +94,8 @@ namespace mergerfs
|
|||
mkdir(const char *fusepath,
|
||||
mode_t mode)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -97,8 +97,8 @@ namespace mergerfs
|
|||
mode_t mode,
|
||||
dev_t rdev)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -73,11 +73,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
open(const char *fusepath,
|
||||
struct fuse_file_info *fileinfo)
|
||||
open(const char *fusepath,
|
||||
fuse_file_info *fileinfo)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
open(const char *fusepath,
|
||||
struct fuse_file_info *fileinfo);
|
||||
open(const char *fusepath,
|
||||
fuse_file_info *fileinfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
opendir(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
ffi->fh = 0;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
opendir(const char *fusepath,
|
||||
struct fuse_file_info *ffi);
|
||||
opendir(const char *fusepath,
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ using namespace mergerfs;
|
|||
|
||||
static
|
||||
void
|
||||
set_option(struct fuse_args &args,
|
||||
set_option(fuse_args &args,
|
||||
const std::string &option_)
|
||||
{
|
||||
string option;
|
||||
|
@ -57,7 +57,7 @@ set_option(struct fuse_args &args,
|
|||
|
||||
static
|
||||
void
|
||||
set_kv_option(struct fuse_args &args,
|
||||
set_kv_option(fuse_args &args,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
|
@ -70,7 +70,7 @@ set_kv_option(struct fuse_args &args,
|
|||
|
||||
static
|
||||
void
|
||||
set_fsname(struct fuse_args &args,
|
||||
set_fsname(fuse_args &args,
|
||||
const vector<string> &srcmounts)
|
||||
{
|
||||
if(srcmounts.size() > 0)
|
||||
|
@ -85,14 +85,14 @@ set_fsname(struct fuse_args &args,
|
|||
|
||||
static
|
||||
void
|
||||
set_subtype(struct fuse_args &args)
|
||||
set_subtype(fuse_args &args)
|
||||
{
|
||||
set_kv_option(args,"subtype","mergerfs");
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
set_default_options(struct fuse_args &args)
|
||||
set_default_options(fuse_args &args)
|
||||
{
|
||||
set_option(args,"big_writes");
|
||||
set_option(args,"splice_read");
|
||||
|
@ -118,9 +118,9 @@ parse_and_process_minfreespace(const std::string &value,
|
|||
|
||||
static
|
||||
int
|
||||
parse_and_process_arg(config::Config &config,
|
||||
parse_and_process_arg(Config &config,
|
||||
const std::string &arg,
|
||||
struct fuse_args *outargs)
|
||||
fuse_args *outargs)
|
||||
{
|
||||
if(arg == "defaults")
|
||||
{
|
||||
|
@ -133,7 +133,7 @@ parse_and_process_arg(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
parse_and_process_kv_arg(config::Config &config,
|
||||
parse_and_process_kv_arg(Config &config,
|
||||
const std::string &key,
|
||||
const std::string &value)
|
||||
{
|
||||
|
@ -162,9 +162,9 @@ parse_and_process_kv_arg(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
process_opt(config::Config &config,
|
||||
process_opt(Config &config,
|
||||
const std::string &arg,
|
||||
struct fuse_args *outargs)
|
||||
fuse_args *outargs)
|
||||
{
|
||||
int rv;
|
||||
std::vector<std::string> argvalue;
|
||||
|
@ -191,8 +191,8 @@ process_opt(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
process_srcmounts(const char *arg,
|
||||
config::Config &config)
|
||||
process_srcmounts(const char *arg,
|
||||
Config &config)
|
||||
{
|
||||
vector<string> paths;
|
||||
|
||||
|
@ -205,8 +205,8 @@ process_srcmounts(const char *arg,
|
|||
|
||||
static
|
||||
int
|
||||
process_destmounts(const char *arg,
|
||||
config::Config &config)
|
||||
process_destmounts(const char *arg,
|
||||
Config &config)
|
||||
{
|
||||
config.destmount = arg;
|
||||
|
||||
|
@ -215,13 +215,13 @@ process_destmounts(const char *arg,
|
|||
|
||||
static
|
||||
int
|
||||
option_processor(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
struct fuse_args *outargs)
|
||||
option_processor(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
fuse_args *outargs)
|
||||
{
|
||||
int rv = 0;
|
||||
config::Config &config = *(config::Config*)data;
|
||||
int rv = 0;
|
||||
Config &config = *(Config*)data;
|
||||
|
||||
switch(key)
|
||||
{
|
||||
|
@ -247,8 +247,8 @@ namespace mergerfs
|
|||
namespace options
|
||||
{
|
||||
void
|
||||
parse(struct fuse_args &args,
|
||||
config::Config &config)
|
||||
parse(fuse_args &args,
|
||||
Config &config)
|
||||
{
|
||||
|
||||
fuse_opt_parse(&args,
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace mergerfs
|
|||
namespace options
|
||||
{
|
||||
void
|
||||
parse(struct fuse_args &args,
|
||||
mergerfs::config::Config &config);
|
||||
parse(fuse_args &args,
|
||||
Config &config);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,8 @@ _all(const vector<string> &basepaths,
|
|||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
const char *basepath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
|
@ -58,7 +57,23 @@ _all(const vector<string> &basepaths,
|
|||
paths.push_back(basepath);
|
||||
}
|
||||
|
||||
return paths.empty() ? (errno=ENOENT,-1) : 0;
|
||||
if(paths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_all_create(const vector<string> &basepaths,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(basepaths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths = basepaths;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
|
@ -70,6 +85,9 @@ namespace mergerfs
|
|||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _all_create(basepaths,paths);
|
||||
|
||||
return _all(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ using std::size_t;
|
|||
static
|
||||
inline
|
||||
void
|
||||
_calc_epmfs(const struct statvfs &fsstats,
|
||||
const char *basepath,
|
||||
fsblkcnt_t &epmfs,
|
||||
const char *&epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
_calc_epmfs(const struct statvfs &fsstats,
|
||||
const string &basepath,
|
||||
fsblkcnt_t &epmfs,
|
||||
string &epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
string &mfsbasepath)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
|
@ -66,10 +66,10 @@ _calc_epmfs(const struct statvfs &fsstats,
|
|||
static
|
||||
inline
|
||||
void
|
||||
_calc_mfs(const struct statvfs &fsstats,
|
||||
const char *basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
_calc_mfs(const struct statvfs &fsstats,
|
||||
const string &basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
string &mfsbasepath)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
||||
|
@ -84,12 +84,12 @@ _calc_mfs(const struct statvfs &fsstats,
|
|||
static
|
||||
inline
|
||||
int
|
||||
_try_statvfs(const char *basepath,
|
||||
const string &fullpath,
|
||||
fsblkcnt_t &epmfs,
|
||||
const char *&epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
_try_statvfs(const string &basepath,
|
||||
const string &fullpath,
|
||||
fsblkcnt_t &epmfs,
|
||||
string &epmfsbasepath,
|
||||
fsblkcnt_t &mfs,
|
||||
string &mfsbasepath)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
|
@ -104,14 +104,14 @@ _try_statvfs(const char *basepath,
|
|||
static
|
||||
inline
|
||||
int
|
||||
_try_statvfs(const char *basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
const char *&mfsbasepath)
|
||||
_try_statvfs(const string &basepath,
|
||||
fsblkcnt_t &mfs,
|
||||
string &mfsbasepath)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
_calc_mfs(fsstats,basepath,mfs,mfsbasepath);
|
||||
|
||||
|
@ -125,22 +125,19 @@ _epmfs_create(const vector<string> &basepaths,
|
|||
vector<string> &paths)
|
||||
|
||||
{
|
||||
fsblkcnt_t epmfs;
|
||||
fsblkcnt_t mfs;
|
||||
const char *basepath;
|
||||
const char *mfsbasepath;
|
||||
const char *epmfsbasepath;
|
||||
string fullpath;
|
||||
fsblkcnt_t epmfs;
|
||||
fsblkcnt_t mfs;
|
||||
string mfsbasepath;
|
||||
string epmfsbasepath;
|
||||
string fullpath;
|
||||
|
||||
mfs = 0;
|
||||
epmfs = 0;
|
||||
mfsbasepath = NULL;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = _try_statvfs(basepath,fusepath,epmfs,epmfsbasepath,mfs,mfsbasepath);
|
||||
|
@ -148,7 +145,7 @@ _epmfs_create(const vector<string> &basepaths,
|
|||
_try_statvfs(basepath,mfs,mfsbasepath);
|
||||
}
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
if(epmfsbasepath.empty())
|
||||
epmfsbasepath = mfsbasepath;
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
@ -163,19 +160,17 @@ _epmfs(const vector<string> &basepaths,
|
|||
vector<string> &paths)
|
||||
|
||||
{
|
||||
fsblkcnt_t epmfs;
|
||||
const char *basepath;
|
||||
const char *epmfsbasepath;
|
||||
string fullpath;
|
||||
fsblkcnt_t epmfs;
|
||||
string epmfsbasepath;
|
||||
string fullpath;
|
||||
|
||||
epmfs = 0;
|
||||
epmfsbasepath = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
|
@ -183,7 +178,7 @@ _epmfs(const vector<string> &basepaths,
|
|||
_calc_mfs(fsstats,basepath,epmfs,epmfsbasepath);
|
||||
}
|
||||
|
||||
if(epmfsbasepath == NULL)
|
||||
if(epmfsbasepath.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(epmfsbasepath);
|
||||
|
|
|
@ -45,12 +45,11 @@ _ff(const vector<string> &basepaths,
|
|||
{
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
|
@ -65,6 +64,20 @@ _ff(const vector<string> &basepaths,
|
|||
return (errno=ENOENT,-1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_ff_create(const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(basepaths.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(basepaths[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
|
@ -74,6 +87,9 @@ namespace mergerfs
|
|||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
if(type == Category::Enum::create)
|
||||
return _ff_create(basepaths,fusepath,paths);
|
||||
|
||||
return _ff(basepaths,fusepath,paths);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,15 @@ _ffwp(const vector<string> &basepaths,
|
|||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
const char *fallback;
|
||||
string fallback;
|
||||
|
||||
fallback = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
|
@ -67,7 +65,7 @@ _ffwp(const vector<string> &basepaths,
|
|||
}
|
||||
}
|
||||
|
||||
if(fallback == NULL)
|
||||
if(fallback.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(fallback);
|
||||
|
|
|
@ -47,11 +47,10 @@ _fwfs_create(const Category::Enum::Type type,
|
|||
for(size_t i = 0, size = basepaths.size(); i != size; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
@ -81,11 +80,11 @@ _fwfs(const Category::Enum::Type type,
|
|||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
|
|
|
@ -47,19 +47,17 @@ _lfs_create(const Category::Enum::Type type,
|
|||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
const char *lfsstr;
|
||||
fsblkcnt_t lfs;
|
||||
string lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
lfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
@ -74,7 +72,7 @@ _lfs_create(const Category::Enum::Type type,
|
|||
}
|
||||
}
|
||||
|
||||
if(lfsstr == NULL)
|
||||
if(lfsstr.empty())
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
@ -90,20 +88,19 @@ _lfs(const Category::Enum::Type type,
|
|||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t lfs;
|
||||
const char *lfsstr;
|
||||
fsblkcnt_t lfs;
|
||||
string lfsstr;
|
||||
|
||||
lfs = -1;
|
||||
lfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
|
@ -119,7 +116,7 @@ _lfs(const Category::Enum::Type type,
|
|||
}
|
||||
}
|
||||
|
||||
if(lfsstr == NULL)
|
||||
if(lfsstr.empty())
|
||||
return Policy::Func::mfs(type,basepaths,fusepath,minfreespace,paths);
|
||||
|
||||
paths.push_back(lfsstr);
|
||||
|
|
|
@ -40,19 +40,17 @@ _mfs_create(const vector<string> &basepaths,
|
|||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
const char *mfsstr;
|
||||
fsblkcnt_t mfs;
|
||||
string mfsstr;
|
||||
|
||||
mfs = 0;
|
||||
mfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
rv = ::statvfs(basepath,&fsstats);
|
||||
rv = ::statvfs(basepath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
fsblkcnt_t spaceavail;
|
||||
|
@ -66,7 +64,7 @@ _mfs_create(const vector<string> &basepaths,
|
|||
}
|
||||
}
|
||||
|
||||
if(mfsstr == NULL)
|
||||
if(mfsstr.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(mfsstr);
|
||||
|
@ -80,20 +78,19 @@ _mfs(const vector<string> &basepaths,
|
|||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
fsblkcnt_t mfs;
|
||||
const char *mfsstr;
|
||||
fsblkcnt_t mfs;
|
||||
string mfsstr;
|
||||
|
||||
mfs = 0;
|
||||
mfsstr = NULL;
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
string fullpath;
|
||||
const char *basepath;
|
||||
struct statvfs fsstats;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::statvfs(fullpath.c_str(),&fsstats);
|
||||
if(rv == 0)
|
||||
{
|
||||
|
@ -108,7 +105,7 @@ _mfs(const vector<string> &basepaths,
|
|||
}
|
||||
}
|
||||
|
||||
if(mfsstr == NULL)
|
||||
if(mfsstr.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(mfsstr);
|
||||
|
|
|
@ -43,17 +43,16 @@ _newest(const vector<string> &basepaths,
|
|||
const string &fusepath,
|
||||
vector<string> &paths)
|
||||
{
|
||||
time_t newest = std::numeric_limits<time_t>::min();
|
||||
const char *neweststr = NULL;
|
||||
time_t newest = std::numeric_limits<time_t>::min();
|
||||
string neweststr;
|
||||
|
||||
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
|
||||
{
|
||||
int rv;
|
||||
struct stat st;
|
||||
const char *basepath;
|
||||
string fullpath;
|
||||
int rv;
|
||||
struct stat st;
|
||||
string fullpath;
|
||||
const string &basepath = basepaths[i];
|
||||
|
||||
basepath = basepaths[i].c_str();
|
||||
fullpath = fs::path::make(basepath,fusepath);
|
||||
|
||||
rv = ::lstat(fullpath.c_str(),&st);
|
||||
|
@ -64,7 +63,7 @@ _newest(const vector<string> &basepaths,
|
|||
}
|
||||
}
|
||||
|
||||
if(neweststr == NULL)
|
||||
if(neweststr.empty())
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths.push_back(neweststr);
|
||||
|
|
10
src/read.cpp
10
src/read.cpp
|
@ -49,11 +49,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
read(const char *fusepath,
|
||||
char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
read(const char *fusepath,
|
||||
char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _read(ffi->fh,
|
||||
buf,
|
||||
|
|
10
src/read.hpp
10
src/read.hpp
|
@ -27,10 +27,10 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
read(const char *fusepath,
|
||||
char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
read(const char *fusepath,
|
||||
char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,14 +32,14 @@
|
|||
|
||||
static
|
||||
int
|
||||
_read_buf(const int fd,
|
||||
struct fuse_bufvec **bufp,
|
||||
const size_t size,
|
||||
const off_t offset)
|
||||
_read_buf(const int fd,
|
||||
fuse_bufvec **bufp,
|
||||
const size_t size,
|
||||
const off_t offset)
|
||||
{
|
||||
struct fuse_bufvec *src;
|
||||
fuse_bufvec *src;
|
||||
|
||||
src = (fuse_bufvec*)malloc(sizeof(struct fuse_bufvec));
|
||||
src = (fuse_bufvec*)malloc(sizeof(fuse_bufvec));
|
||||
if(src == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@ -59,11 +59,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
read_buf(const char *fusepath,
|
||||
struct fuse_bufvec **bufp,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
read_buf(const char *fusepath,
|
||||
fuse_bufvec **bufp,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _read_buf(ffi->fh,
|
||||
bufp,
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
read_buf(const char *fusepath,
|
||||
struct fuse_bufvec **buf,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
read_buf(const char *fusepath,
|
||||
fuse_bufvec **buf,
|
||||
size_t size,
|
||||
off_t offset,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,14 +90,14 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
readdir(const char *fusepath,
|
||||
void *buf,
|
||||
fuse_fill_dir_t filler,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
readdir(const char *fusepath,
|
||||
void *buf,
|
||||
fuse_fill_dir_t filler,
|
||||
off_t offset,
|
||||
fuse_file_info *fi)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -39,11 +39,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
readdir(const char *fusepath,
|
||||
void *buf,
|
||||
fuse_fill_dir_t filler,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
readdir(const char *fusepath,
|
||||
void *buf,
|
||||
fuse_fill_dir_t filler,
|
||||
off_t offset,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ namespace mergerfs
|
|||
char *buf,
|
||||
size_t size)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
release(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
release(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _release(ffi->fh);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
release(const char *fusepath,
|
||||
struct fuse_file_info *fi);
|
||||
release(const char *fusepath,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
releasedir(const char *fusepath,
|
||||
struct fuse_file_info *ffi)
|
||||
releasedir(const char *fusepath,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
releasedir(const char *fusepath,
|
||||
struct fuse_file_info *ffi);
|
||||
releasedir(const char *fusepath,
|
||||
fuse_file_info *ffi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,14 +81,14 @@ namespace mergerfs
|
|||
removexattr(const char *fusepath,
|
||||
const char *attrname)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return -ENOTSUP;
|
||||
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _removexattr(config.removexattr,
|
||||
config.srcmounts,
|
||||
|
|
|
@ -113,8 +113,8 @@ namespace mergerfs
|
|||
rename(const char *oldpath,
|
||||
const char *newpath)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -73,8 +73,8 @@ namespace mergerfs
|
|||
int
|
||||
rmdir(const char *fusepath)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readguard(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -168,9 +168,9 @@ _setxattr_srcmounts(vector<string> &srcmounts,
|
|||
|
||||
static
|
||||
int
|
||||
_setxattr_minfreespace(config::Config &config,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
_setxattr_minfreespace(Config &config,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
@ -186,10 +186,10 @@ _setxattr_minfreespace(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile_func_policy(config::Config &config,
|
||||
const char *funcname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
_setxattr_controlfile_func_policy(Config &config,
|
||||
const char *funcname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
@ -205,10 +205,10 @@ _setxattr_controlfile_func_policy(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile_category_policy(config::Config &config,
|
||||
const char *categoryname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
_setxattr_controlfile_category_policy(Config &config,
|
||||
const char *categoryname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
@ -224,10 +224,10 @@ _setxattr_controlfile_category_policy(config::Config &config,
|
|||
|
||||
static
|
||||
int
|
||||
_setxattr_controlfile(config::Config &config,
|
||||
const char *attrname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
_setxattr_controlfile(Config &config,
|
||||
const char *attrname,
|
||||
const string &attrval,
|
||||
const int flags)
|
||||
{
|
||||
const char *attrbasename = &attrname[sizeof("user.mergerfs.")-1];
|
||||
|
||||
|
@ -307,33 +307,31 @@ namespace mergerfs
|
|||
size_t attrvalsize,
|
||||
int flags)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
{
|
||||
if((fc->uid != ::getuid()) && (fc->gid != ::getgid()))
|
||||
return -EPERM;
|
||||
|
||||
return _setxattr_controlfile(config::get_writable(),
|
||||
return _setxattr_controlfile(Config::get_writable(),
|
||||
attrname,
|
||||
string(attrval,attrvalsize),
|
||||
flags);
|
||||
}
|
||||
|
||||
{
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
return _setxattr(config.setxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
attrval,
|
||||
attrvalsize,
|
||||
flags);
|
||||
}
|
||||
return _setxattr(config.setxattr,
|
||||
config.srcmounts,
|
||||
config.minfreespace,
|
||||
fusepath,
|
||||
attrname,
|
||||
attrval,
|
||||
attrvalsize,
|
||||
flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,8 +124,8 @@ namespace mergerfs
|
|||
statfs(const char *fusepath,
|
||||
struct statvfs *stat)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ namespace mergerfs
|
|||
symlink(const char *oldpath,
|
||||
const char *newpath)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -77,8 +77,8 @@ namespace mergerfs
|
|||
truncate(const char *fusepath,
|
||||
off_t size)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ namespace mergerfs
|
|||
int
|
||||
unlink(const char *fusepath)
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -42,11 +42,11 @@ using mergerfs::Policy;
|
|||
|
||||
static
|
||||
int
|
||||
_utimens(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const struct timespec ts[2])
|
||||
_utimens(Policy::Func::Action actionFunc,
|
||||
const vector<string> &srcmounts,
|
||||
const size_t minfreespace,
|
||||
const string &fusepath,
|
||||
const timespec ts[2])
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
|
@ -74,11 +74,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
utimens(const char *fusepath,
|
||||
const struct timespec ts[2])
|
||||
utimens(const char *fusepath,
|
||||
const timespec ts[2])
|
||||
{
|
||||
const struct fuse_context *fc = fuse_get_context();
|
||||
const config::Config &config = config::get();
|
||||
const fuse_context *fc = fuse_get_context();
|
||||
const Config &config = Config::get(fc);
|
||||
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
|
||||
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
utimens(const char *fusepath,
|
||||
const struct timespec ts[2]);
|
||||
utimens(const char *fusepath,
|
||||
const timespec ts[2]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,11 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
write(const char *fusepath,
|
||||
const char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
write(const char *fusepath,
|
||||
const char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _write(ffi->fh,
|
||||
buf,
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
write(const char *fusepath,
|
||||
const char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
write(const char *fusepath,
|
||||
const char *buf,
|
||||
size_t count,
|
||||
off_t offset,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,12 +32,12 @@
|
|||
|
||||
static
|
||||
int
|
||||
_write_buf(const int fd,
|
||||
struct fuse_bufvec &src,
|
||||
const off_t offset)
|
||||
_write_buf(const int fd,
|
||||
fuse_bufvec &src,
|
||||
const off_t offset)
|
||||
{
|
||||
size_t size = fuse_buf_size(&src);
|
||||
struct fuse_bufvec dst = FUSE_BUFVEC_INIT(size);
|
||||
size_t size = fuse_buf_size(&src);
|
||||
fuse_bufvec dst = FUSE_BUFVEC_INIT(size);
|
||||
const fuse_buf_copy_flags cpflags =
|
||||
(fuse_buf_copy_flags)(FUSE_BUF_SPLICE_MOVE|FUSE_BUF_SPLICE_NONBLOCK);
|
||||
|
||||
|
@ -53,10 +53,10 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
write_buf(const char *fusepath,
|
||||
struct fuse_bufvec *src,
|
||||
off_t offset,
|
||||
struct fuse_file_info *ffi)
|
||||
write_buf(const char *fusepath,
|
||||
fuse_bufvec *src,
|
||||
off_t offset,
|
||||
fuse_file_info *ffi)
|
||||
{
|
||||
return _write_buf(ffi->fh,
|
||||
*src,
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace mergerfs
|
|||
namespace fuse
|
||||
{
|
||||
int
|
||||
write_buf(const char *fusepath,
|
||||
struct fuse_bufvec *buf,
|
||||
off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
write_buf(const char *fusepath,
|
||||
fuse_bufvec *buf,
|
||||
off_t offset,
|
||||
fuse_file_info *fi);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user