mirror of https://github.com/trapexit/mergerfs.git
Antonio SJ Musumeci
3 years ago
50 changed files with 40 additions and 2539 deletions
-
8config.toml
-
402src/config.cpp
-
205src/config.hpp
-
62src/config_cachefiles.cpp
-
33src/config_cachefiles.hpp
-
58src/config_follow_symlinks.cpp
-
30src/config_follow_symlinks.hpp
-
59src/config_inodecalc.cpp
-
35src/config_inodecalc.hpp
-
53src/config_log_metrics.cpp
-
31src/config_log_metrics.hpp
-
56src/config_moveonenospc.cpp
-
44src/config_moveonenospc.hpp
-
55src/config_nfsopenhack.cpp
-
31src/config_nfsopenhack.hpp
-
51src/config_readdir.cpp
-
30src/config_readdir.hpp
-
51src/config_statfs.cpp
-
30src/config_statfs.hpp
-
55src/config_statfsignore.cpp
-
30src/config_statfsignore.hpp
-
55src/config_xattr.cpp
-
32src/config_xattr.hpp
-
2src/fuse_access_policy_factory.cpp
-
2src/fuse_chmod_policy_factory.cpp
-
2src/fuse_chown_policy_factory.cpp
-
2src/fuse_create_policy_factory.cpp
-
2src/fuse_getattr_policy_factory.cpp
-
2src/fuse_getxattr_policy_factory.cpp
-
323src/fuse_ioctl.cpp
-
2src/fuse_ioctl_policy_factory.cpp
-
2src/fuse_link_policy_factory.cpp
-
2src/fuse_listxattr_policy_factory.cpp
-
2src/fuse_mkdir_policy_factory.cpp
-
2src/fuse_mknod_policy_factory.cpp
-
2src/fuse_open_policy_factory.cpp
-
2src/fuse_readlink_policy_factory.cpp
-
2src/fuse_removexattr_policy_factory.cpp
-
2src/fuse_rename_policy_factory.cpp
-
2src/fuse_rmdir_policy_factory.cpp
-
163src/fuse_setxattr.cpp
-
2src/fuse_setxattr_policy_factory.cpp
-
2src/fuse_symlink_policy_factory.cpp
-
2src/fuse_truncate_policy_factory.cpp
-
99src/fuse_unlink.cpp
-
2src/fuse_unlink_policy_factory.cpp
-
2src/fuse_utimens_policy_factory.cpp
-
9src/mergerfs.cpp
-
418src/option_parser.cpp
-
29src/option_parser.hpp
@ -1,402 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "fuse_access.hpp"
|
|
||||
#include "fuse_getattr.hpp"
|
|
||||
|
|
||||
#include "config.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
#include "from_string.hpp"
|
|
||||
#include "num.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
#include "str.hpp"
|
|
||||
#include "to_string.hpp"
|
|
||||
#include "version.hpp"
|
|
||||
#include "toml.hpp"
|
|
||||
#include "toml_verify.hpp"
|
|
||||
//#include "nonstd/span.hpp"
|
|
||||
|
|
||||
#include <algorithm>
|
|
||||
#include <cstdint>
|
|
||||
#include <fstream>
|
|
||||
#include <iostream>
|
|
||||
#include <string>
|
|
||||
|
|
||||
#include <pthread.h>
|
|
||||
#include <string.h>
|
|
||||
#include <sys/stat.h>
|
|
||||
#include <unistd.h>
|
|
||||
|
|
||||
#define MINFREESPACE_DEFAULT (4294967295ULL)
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
#define IFERT(S) if(S == s_) return true
|
|
||||
|
|
||||
|
|
||||
Config Config::_singleton; |
|
||||
|
|
||||
|
|
||||
namespace l |
|
||||
{ |
|
||||
static |
|
||||
bool |
|
||||
readonly(const std::string &s_) |
|
||||
{ |
|
||||
IFERT("async_read"); |
|
||||
IFERT("cache.symlinks"); |
|
||||
IFERT("cache.writeback"); |
|
||||
IFERT("fsname"); |
|
||||
IFERT("fuse_msg_size"); |
|
||||
IFERT("mount"); |
|
||||
IFERT("nullrw"); |
|
||||
IFERT("pid"); |
|
||||
IFERT("readdirplus"); |
|
||||
IFERT("threads"); |
|
||||
IFERT("version"); |
|
||||
|
|
||||
return false; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
Config::Config() |
|
||||
: async_read(true), |
|
||||
auto_cache(false), |
|
||||
minfreespace(MINFREESPACE_DEFAULT), |
|
||||
branches(minfreespace), |
|
||||
cache_attr(1), |
|
||||
cache_entry(1), |
|
||||
cache_files(CacheFiles::ENUM::LIBFUSE), |
|
||||
cache_negative_entry(0), |
|
||||
cache_readdir(false), |
|
||||
cache_statfs(0), |
|
||||
cache_symlinks(false), |
|
||||
category(func), |
|
||||
direct_io(false), |
|
||||
dropcacheonclose(false), |
|
||||
fsname(), |
|
||||
follow_symlinks(FollowSymlinks::ENUM::NEVER), |
|
||||
func(), |
|
||||
fuse_msg_size(FUSE_MAX_MAX_PAGES), |
|
||||
ignorepponrename(false), |
|
||||
inodecalc("hybrid-hash"), |
|
||||
link_cow(false), |
|
||||
log_metrics(false), |
|
||||
mount(), |
|
||||
moveonenospc(false), |
|
||||
nfsopenhack(NFSOpenHack::ENUM::OFF), |
|
||||
nullrw(false), |
|
||||
pid(::getpid()), |
|
||||
posix_acl(false), |
|
||||
readdir(ReadDir::ENUM::POSIX), |
|
||||
readdirplus(false), |
|
||||
security_capability(true), |
|
||||
srcmounts(branches), |
|
||||
statfs(StatFS::ENUM::BASE), |
|
||||
statfs_ignore(StatFSIgnore::ENUM::NONE), |
|
||||
symlinkify(false), |
|
||||
symlinkify_timeout(3600), |
|
||||
threads(0), |
|
||||
version(MERGERFS_VERSION), |
|
||||
writeback_cache(false), |
|
||||
xattr(XAttr::ENUM::PASSTHROUGH) |
|
||||
{ |
|
||||
_map["async_read"] = &async_read; |
|
||||
_map["auto_cache"] = &auto_cache; |
|
||||
_map["branches"] = &branches; |
|
||||
_map["cache.attr"] = &cache_attr; |
|
||||
_map["cache.entry"] = &cache_entry; |
|
||||
_map["cache.files"] = &cache_files; |
|
||||
_map["cache.negative_entry"] = &cache_negative_entry; |
|
||||
_map["cache.readdir"] = &cache_readdir; |
|
||||
_map["cache.statfs"] = &cache_statfs; |
|
||||
_map["cache.symlinks"] = &cache_symlinks; |
|
||||
_map["cache.writeback"] = &writeback_cache; |
|
||||
_map["category.action"] = &category.action; |
|
||||
_map["category.create"] = &category.create; |
|
||||
_map["category.search"] = &category.search; |
|
||||
_map["direct_io"] = &direct_io; |
|
||||
_map["dropcacheonclose"] = &dropcacheonclose; |
|
||||
_map["follow-symlinks"] = &follow_symlinks; |
|
||||
_map["fsname"] = &fsname; |
|
||||
_map["func.access"] = &func.access; |
|
||||
_map["func.chmod"] = &func.chmod; |
|
||||
_map["func.chown"] = &func.chown; |
|
||||
_map["func.create"] = &func.create; |
|
||||
_map["func.getattr"] = &func.getattr; |
|
||||
_map["func.getxattr"] = &func.getxattr; |
|
||||
_map["func.link"] = &func.link; |
|
||||
_map["func.listxattr"] = &func.listxattr; |
|
||||
_map["func.mkdir"] = &func.mkdir; |
|
||||
_map["func.mknod"] = &func.mknod; |
|
||||
_map["func.open"] = &func.open; |
|
||||
_map["func.readlink"] = &func.readlink; |
|
||||
_map["func.removexattr"] = &func.removexattr; |
|
||||
_map["func.rename"] = &func.rename; |
|
||||
_map["func.rmdir"] = &func.rmdir; |
|
||||
_map["func.setxattr"] = &func.setxattr; |
|
||||
_map["func.symlink"] = &func.symlink; |
|
||||
_map["func.truncate"] = &func.truncate; |
|
||||
_map["func.unlink"] = &func.unlink; |
|
||||
_map["func.utimens"] = &func.utimens; |
|
||||
_map["fuse_msg_size"] = &fuse_msg_size; |
|
||||
_map["ignorepponrename"] = &ignorepponrename; |
|
||||
_map["inodecalc"] = &inodecalc; |
|
||||
_map["kernel_cache"] = &kernel_cache; |
|
||||
_map["link_cow"] = &link_cow; |
|
||||
_map["log.metrics"] = &log_metrics; |
|
||||
_map["minfreespace"] = &minfreespace; |
|
||||
_map["mount"] = &mount; |
|
||||
_map["moveonenospc"] = &moveonenospc; |
|
||||
_map["nfsopenhack"] = &nfsopenhack; |
|
||||
_map["nullrw"] = &nullrw; |
|
||||
_map["pid"] = &pid; |
|
||||
_map["posix_acl"] = &posix_acl; |
|
||||
// _map["readdir"] = &readdir;
|
|
||||
_map["readdirplus"] = &readdirplus; |
|
||||
_map["security_capability"] = &security_capability; |
|
||||
_map["srcmounts"] = &srcmounts; |
|
||||
_map["statfs"] = &statfs; |
|
||||
_map["statfs_ignore"] = &statfs_ignore; |
|
||||
_map["symlinkify"] = &symlinkify; |
|
||||
_map["symlinkify_timeout"] = &symlinkify_timeout; |
|
||||
_map["threads"] = &threads; |
|
||||
_map["version"] = &version; |
|
||||
_map["xattr"] = &xattr; |
|
||||
} |
|
||||
|
|
||||
Config& |
|
||||
Config::operator=(const Config &cfg_) |
|
||||
{ |
|
||||
int rv; |
|
||||
std::string val; |
|
||||
|
|
||||
for(auto &kv : _map) |
|
||||
{ |
|
||||
rv = cfg_.get(kv.first,&val); |
|
||||
if(rv) |
|
||||
continue; |
|
||||
|
|
||||
kv.second->from_string(val); |
|
||||
} |
|
||||
|
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
bool |
|
||||
Config::has_key(const std::string &key_) const |
|
||||
{ |
|
||||
return _map.count(key_); |
|
||||
} |
|
||||
|
|
||||
void |
|
||||
Config::keys(std::string &s_) const |
|
||||
{ |
|
||||
Str2TFStrMap::const_iterator i; |
|
||||
Str2TFStrMap::const_iterator ei; |
|
||||
|
|
||||
s_.reserve(512); |
|
||||
|
|
||||
i = _map.begin(); |
|
||||
ei = _map.end(); |
|
||||
|
|
||||
for(; i != ei; ++i) |
|
||||
{ |
|
||||
s_ += i->first; |
|
||||
s_ += '\0'; |
|
||||
} |
|
||||
|
|
||||
s_.resize(s_.size() - 1); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
void |
|
||||
Config::keys_xattr(std::string &s_) const |
|
||||
{ |
|
||||
Str2TFStrMap::const_iterator i; |
|
||||
Str2TFStrMap::const_iterator ei; |
|
||||
|
|
||||
s_.reserve(1024); |
|
||||
for(i = _map.begin(), ei = _map.end(); i != ei; ++i) |
|
||||
{ |
|
||||
s_ += "user.mergerfs."; |
|
||||
s_ += i->first; |
|
||||
s_ += '\0'; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::get(const std::string &key_, |
|
||||
std::string *val_) const |
|
||||
{ |
|
||||
Str2TFStrMap::const_iterator i; |
|
||||
|
|
||||
i = _map.find(key_); |
|
||||
if(i == _map.end()) |
|
||||
return -ENOATTR; |
|
||||
|
|
||||
*val_ = i->second->to_string(); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::set_raw(const std::string &key_, |
|
||||
const std::string &value_) |
|
||||
{ |
|
||||
Str2TFStrMap::iterator i; |
|
||||
|
|
||||
i = _map.find(key_); |
|
||||
if(i == _map.end()) |
|
||||
return -ENOATTR; |
|
||||
|
|
||||
return i->second->from_string(value_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::set(const std::string &key_, |
|
||||
const std::string &value_) |
|
||||
{ |
|
||||
if(l::readonly(key_)) |
|
||||
return -EROFS; |
|
||||
|
|
||||
return set_raw(key_,value_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::set(const std::string &kv_) |
|
||||
{ |
|
||||
std::string key; |
|
||||
std::string val; |
|
||||
|
|
||||
str::splitkv(kv_,'=',&key,&val); |
|
||||
key = str::trim(key); |
|
||||
val = str::trim(val); |
|
||||
|
|
||||
return set(key,val); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::from_stream(std::istream &istrm_, |
|
||||
ErrVec *errs_) |
|
||||
{ |
|
||||
int rv; |
|
||||
std::string line; |
|
||||
std::string key; |
|
||||
std::string val; |
|
||||
Config newcfg; |
|
||||
|
|
||||
newcfg = *this; |
|
||||
|
|
||||
while(std::getline(istrm_,line,'\n')) |
|
||||
{ |
|
||||
line = str::trim(line); |
|
||||
if(!line.empty() && (line[0] == '#')) |
|
||||
continue; |
|
||||
|
|
||||
str::splitkv(line,'=',&key,&val); |
|
||||
key = str::trim(key); |
|
||||
val = str::trim(val); |
|
||||
|
|
||||
rv = newcfg.set(key,val); |
|
||||
if(rv < 0) |
|
||||
errs_->push_back({rv,key}); |
|
||||
} |
|
||||
|
|
||||
if(!errs_->empty()) |
|
||||
return -EINVAL; |
|
||||
|
|
||||
*this = newcfg; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Config::from_file(const std::string &filepath_, |
|
||||
ErrVec *errs_) |
|
||||
{ |
|
||||
int rv; |
|
||||
std::ifstream ifstrm; |
|
||||
|
|
||||
ifstrm.open(filepath_); |
|
||||
if(!ifstrm.good()) |
|
||||
{ |
|
||||
errs_->push_back({-errno,filepath_}); |
|
||||
return -errno; |
|
||||
} |
|
||||
|
|
||||
rv = from_stream(ifstrm,errs_); |
|
||||
|
|
||||
ifstrm.close(); |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
|
|
||||
std::ostream& |
|
||||
operator<<(std::ostream &os_, |
|
||||
const Config &c_) |
|
||||
{ |
|
||||
Str2TFStrMap::const_iterator i; |
|
||||
Str2TFStrMap::const_iterator ei; |
|
||||
|
|
||||
for(i = c_._map.begin(), ei = c_._map.end(); i != ei; ++i) |
|
||||
{ |
|
||||
os_ << i->first << '=' << i->second->to_string() << std::endl; |
|
||||
} |
|
||||
|
|
||||
return os_; |
|
||||
} |
|
||||
|
|
||||
|
|
||||
static |
|
||||
std::string |
|
||||
err2str(const int err_) |
|
||||
{ |
|
||||
switch(err_) |
|
||||
{ |
|
||||
case 0: |
|
||||
return std::string(); |
|
||||
case -EINVAL: |
|
||||
return "invalid value"; |
|
||||
case -ENOATTR: |
|
||||
return "unknown option"; |
|
||||
case -EROFS: |
|
||||
return "read-only option"; |
|
||||
default: |
|
||||
return strerror(-err_); |
|
||||
} |
|
||||
|
|
||||
return std::string(); |
|
||||
} |
|
||||
|
|
||||
std::ostream& |
|
||||
operator<<(std::ostream &os_, |
|
||||
const Config::ErrVec &ev_) |
|
||||
{ |
|
||||
std::string errstr; |
|
||||
|
|
||||
for(auto &err : ev_) |
|
||||
{ |
|
||||
os_ << "* ERROR: "; |
|
||||
errstr = err2str(err.err); |
|
||||
if(!errstr.empty()) |
|
||||
os_ << errstr << " - "; |
|
||||
os_ << err.str << std::endl; |
|
||||
} |
|
||||
|
|
||||
return os_; |
|
||||
} |
|
@ -1,205 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "branches.hpp"
|
|
||||
#include "category.hpp"
|
|
||||
#include "config_cachefiles.hpp"
|
|
||||
#include "config_follow_symlinks.hpp"
|
|
||||
#include "config_inodecalc.hpp"
|
|
||||
#include "config_log_metrics.hpp"
|
|
||||
#include "config_moveonenospc.hpp"
|
|
||||
#include "config_nfsopenhack.hpp"
|
|
||||
#include "config_readdir.hpp"
|
|
||||
#include "config_statfs.hpp"
|
|
||||
#include "config_statfsignore.hpp"
|
|
||||
#include "config_xattr.hpp"
|
|
||||
#include "enum.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
#include "funcs.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
#include "tofrom_wrapper.hpp"
|
|
||||
|
|
||||
#include "fuse.h"
|
|
||||
|
|
||||
#include "toml.hpp"
|
|
||||
|
|
||||
#include <cstdint>
|
|
||||
#include <map>
|
|
||||
#include <memory>
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include <sys/stat.h>
|
|
||||
|
|
||||
typedef ToFromWrapper<bool> ConfigBOOL; |
|
||||
typedef ToFromWrapper<uint64_t> ConfigUINT64; |
|
||||
typedef ToFromWrapper<int> ConfigINT; |
|
||||
typedef ToFromWrapper<std::string> ConfigSTR; |
|
||||
typedef std::map<std::string,ToFromString*> Str2TFStrMap; |
|
||||
|
|
||||
|
|
||||
class Config |
|
||||
{ |
|
||||
public: |
|
||||
struct Err |
|
||||
{ |
|
||||
int err; |
|
||||
std::string str; |
|
||||
}; |
|
||||
|
|
||||
typedef std::vector<Err> ErrVec; |
|
||||
|
|
||||
public: |
|
||||
class Read |
|
||||
{ |
|
||||
public: |
|
||||
Read(); |
|
||||
|
|
||||
public: |
|
||||
inline const Config* operator->() const; |
|
||||
|
|
||||
private: |
|
||||
const Config &_cfg; |
|
||||
}; |
|
||||
|
|
||||
public: |
|
||||
class Write |
|
||||
{ |
|
||||
public: |
|
||||
Write(); |
|
||||
|
|
||||
public: |
|
||||
Config* operator->(); |
|
||||
|
|
||||
private: |
|
||||
Config &_cfg; |
|
||||
}; |
|
||||
|
|
||||
public: |
|
||||
Config(); |
|
||||
|
|
||||
public: |
|
||||
Config& operator=(const Config&); |
|
||||
|
|
||||
public: |
|
||||
ConfigBOOL async_read; |
|
||||
ConfigBOOL auto_cache; |
|
||||
ConfigUINT64 minfreespace; |
|
||||
Branches branches; |
|
||||
ConfigUINT64 cache_attr; |
|
||||
ConfigUINT64 cache_entry; |
|
||||
CacheFiles cache_files; |
|
||||
ConfigUINT64 cache_negative_entry; |
|
||||
ConfigBOOL cache_readdir; |
|
||||
ConfigUINT64 cache_statfs; |
|
||||
ConfigBOOL cache_symlinks; |
|
||||
Categories category; |
|
||||
ConfigBOOL direct_io; |
|
||||
ConfigBOOL dropcacheonclose; |
|
||||
ConfigSTR fsname; |
|
||||
FollowSymlinks follow_symlinks; |
|
||||
Funcs func; |
|
||||
ConfigUINT64 fuse_msg_size; |
|
||||
ConfigBOOL ignorepponrename; |
|
||||
InodeCalc inodecalc; |
|
||||
ConfigBOOL kernel_cache; |
|
||||
ConfigBOOL link_cow; |
|
||||
LogMetrics log_metrics; |
|
||||
ConfigSTR mount; |
|
||||
MoveOnENOSPC moveonenospc; |
|
||||
NFSOpenHack nfsopenhack; |
|
||||
ConfigBOOL nullrw; |
|
||||
ConfigUINT64 pid; |
|
||||
ConfigBOOL posix_acl; |
|
||||
ReadDir readdir; |
|
||||
ConfigBOOL readdirplus; |
|
||||
ConfigBOOL security_capability; |
|
||||
SrcMounts srcmounts; |
|
||||
StatFS statfs; |
|
||||
StatFSIgnore statfs_ignore; |
|
||||
ConfigBOOL symlinkify; |
|
||||
ConfigUINT64 symlinkify_timeout; |
|
||||
ConfigINT threads; |
|
||||
ConfigSTR version; |
|
||||
ConfigBOOL writeback_cache; |
|
||||
XAttr xattr; |
|
||||
|
|
||||
public: |
|
||||
friend std::ostream& operator<<(std::ostream &s, |
|
||||
const Config &c); |
|
||||
|
|
||||
public: |
|
||||
bool has_key(const std::string &key) const; |
|
||||
void keys(std::string &s) const; |
|
||||
void keys_xattr(std::string &s) const; |
|
||||
|
|
||||
public: |
|
||||
int get(const std::string &key, std::string *val) const; |
|
||||
int set_raw(const std::string &key, const std::string &val); |
|
||||
int set(const std::string &key, const std::string &val); |
|
||||
int set(const std::string &kv); |
|
||||
|
|
||||
public: |
|
||||
int from_stream(std::istream &istrm, ErrVec *errs); |
|
||||
int from_file(const std::string &filepath, ErrVec *errs); |
|
||||
int from_toml(const toml::value &value, ErrVec *errs); |
|
||||
|
|
||||
private: |
|
||||
Str2TFStrMap _map; |
|
||||
|
|
||||
private: |
|
||||
static Config _singleton; |
|
||||
|
|
||||
public: |
|
||||
friend class Read; |
|
||||
friend class Write; |
|
||||
}; |
|
||||
|
|
||||
std::ostream& operator<<(std::ostream &s,const Config::ErrVec &ev); |
|
||||
|
|
||||
inline |
|
||||
Config::Read::Read() |
|
||||
: _cfg(Config::_singleton) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
inline |
|
||||
const |
|
||||
Config* |
|
||||
Config::Read::operator->() const |
|
||||
{ |
|
||||
return &_cfg; |
|
||||
} |
|
||||
|
|
||||
inline |
|
||||
Config::Write::Write() |
|
||||
: _cfg(Config::_singleton) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
inline |
|
||||
Config* |
|
||||
Config::Write::operator->() |
|
||||
{ |
|
||||
return &_cfg; |
|
||||
} |
|
||||
|
|
||||
int process_toml_config(const std::string &filepath_); |
|
@ -1,62 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_cachefiles.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
CacheFiles::to_string() const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case CacheFiles::ENUM::LIBFUSE: |
|
||||
return "libfuse"; |
|
||||
case CacheFiles::ENUM::OFF: |
|
||||
return "off"; |
|
||||
case CacheFiles::ENUM::PARTIAL: |
|
||||
return "partial"; |
|
||||
case CacheFiles::ENUM::FULL: |
|
||||
return "full"; |
|
||||
case CacheFiles::ENUM::AUTO_FULL: |
|
||||
return "auto-full"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
CacheFiles::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "libfuse") |
|
||||
_data = CacheFiles::ENUM::LIBFUSE; |
|
||||
ef(s_ == "off") |
|
||||
_data = CacheFiles::ENUM::OFF; |
|
||||
ef(s_ == "partial") |
|
||||
_data = CacheFiles::ENUM::PARTIAL; |
|
||||
ef(s_ == "full") |
|
||||
_data = CacheFiles::ENUM::FULL; |
|
||||
ef(s_ == "auto-full") |
|
||||
_data = CacheFiles::ENUM::AUTO_FULL; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,33 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
|
|
||||
enum class CacheFilesEnum |
|
||||
{ |
|
||||
LIBFUSE, |
|
||||
OFF, |
|
||||
PARTIAL, |
|
||||
FULL, |
|
||||
AUTO_FULL |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<CacheFilesEnum> CacheFiles; |
|
@ -1,58 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_follow_symlinks.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
FollowSymlinks::to_string(void) const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case FollowSymlinks::ENUM::NEVER: |
|
||||
return "never"; |
|
||||
case FollowSymlinks::ENUM::DIRECTORY: |
|
||||
return "directory"; |
|
||||
case FollowSymlinks::ENUM::REGULAR: |
|
||||
return "regular"; |
|
||||
case FollowSymlinks::ENUM::ALL: |
|
||||
return "all"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
FollowSymlinks::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "never") |
|
||||
_data = FollowSymlinks::ENUM::NEVER; |
|
||||
ef(s_ == "directory") |
|
||||
_data = FollowSymlinks::ENUM::DIRECTORY; |
|
||||
ef(s_ == "regular") |
|
||||
_data = FollowSymlinks::ENUM::REGULAR; |
|
||||
ef(s_ == "all") |
|
||||
_data = FollowSymlinks::ENUM::ALL; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,30 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
enum class FollowSymlinksEnum |
|
||||
{ |
|
||||
NEVER, |
|
||||
DIRECTORY, |
|
||||
REGULAR, |
|
||||
ALL |
|
||||
}; |
|
||||
typedef Enum<FollowSymlinksEnum> FollowSymlinks; |
|
@ -1,59 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_inodecalc.hpp"
|
|
||||
#include "fs_inode.hpp"
|
|
||||
#include "toml.hpp"
|
|
||||
|
|
||||
InodeCalc::InodeCalc(const std::string &s_) |
|
||||
{ |
|
||||
fs::inode::set_algo(s_); |
|
||||
} |
|
||||
|
|
||||
std::string |
|
||||
InodeCalc::to_string(void) const |
|
||||
{ |
|
||||
return fs::inode::get_algo(); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
InodeCalc::from_string(const std::string &s_) |
|
||||
{ |
|
||||
return fs::inode::set_algo(s_); |
|
||||
} |
|
||||
|
|
||||
void |
|
||||
InodeCalc::from_toml(const toml::value &v_) |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = fs::inode::set_algo(v_.as_string()); |
|
||||
if(rv < 0) |
|
||||
throw toml::type_error("must be: " |
|
||||
"passthrough|" |
|
||||
"path-hash|" |
|
||||
"path-hash32|" |
|
||||
"devino-hash|" |
|
||||
"devino-hash32|" |
|
||||
"hybrid-hash|" |
|
||||
"hybrid-hash32" |
|
||||
, |
|
||||
v_.location()); |
|
||||
|
|
||||
return; |
|
||||
} |
|
@ -1,35 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "tofrom_string.hpp"
|
|
||||
#include "toml.hpp"
|
|
||||
|
|
||||
class InodeCalc : public ToFromString |
|
||||
{ |
|
||||
public: |
|
||||
InodeCalc(const std::string &); |
|
||||
|
|
||||
public: |
|
||||
void from_toml(const toml::value &); |
|
||||
|
|
||||
public: |
|
||||
std::string to_string(void) const final; |
|
||||
int from_string(const std::string &) final; |
|
||||
}; |
|
@ -1,53 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2021, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_log_metrics.hpp"
|
|
||||
#include "from_string.hpp"
|
|
||||
#include "to_string.hpp"
|
|
||||
|
|
||||
#include "fuse.h"
|
|
||||
|
|
||||
LogMetrics::LogMetrics(const bool val_) |
|
||||
{ |
|
||||
fuse_log_metrics_set(val_); |
|
||||
} |
|
||||
|
|
||||
std::string |
|
||||
LogMetrics::to_string(void) const |
|
||||
{ |
|
||||
bool val; |
|
||||
|
|
||||
val = fuse_log_metrics_get(); |
|
||||
|
|
||||
return str::to(val); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
LogMetrics::from_string(const std::string &s_) |
|
||||
{ |
|
||||
int rv; |
|
||||
bool val; |
|
||||
|
|
||||
rv = str::from(s_,&val); |
|
||||
if(rv < 0) |
|
||||
return rv; |
|
||||
|
|
||||
fuse_log_metrics_set(val); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,31 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2021, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "tofrom_string.hpp"
|
|
||||
|
|
||||
class LogMetrics : public ToFromString |
|
||||
{ |
|
||||
public: |
|
||||
LogMetrics(const bool); |
|
||||
|
|
||||
public: |
|
||||
std::string to_string(void) const final; |
|
||||
int from_string(const std::string &) final; |
|
||||
}; |
|
@ -1,56 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_moveonenospc.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
#include "from_string.hpp"
|
|
||||
|
|
||||
|
|
||||
int |
|
||||
MoveOnENOSPC::from_string(const std::string &s_) |
|
||||
{ |
|
||||
int rv; |
|
||||
std::string s; |
|
||||
Policy::CreateImpl *tmp; |
|
||||
|
|
||||
rv = str::from(s_,&enabled); |
|
||||
if((rv == 0) && (enabled == true)) |
|
||||
s = "mfs"; |
|
||||
ef(rv != 0) |
|
||||
s = s_; |
|
||||
else |
|
||||
return 0; |
|
||||
|
|
||||
tmp = Policies::Create::find(s); |
|
||||
if(tmp == NULL) |
|
||||
return -EINVAL; |
|
||||
|
|
||||
policy = tmp; |
|
||||
enabled = true; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
std::string |
|
||||
MoveOnENOSPC::to_string(void) const |
|
||||
{ |
|
||||
if(enabled) |
|
||||
return policy.name(); |
|
||||
return "false"; |
|
||||
} |
|
@ -1,44 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "tofrom_string.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
|
|
||||
class MoveOnENOSPC : public ToFromString |
|
||||
{ |
|
||||
public: |
|
||||
MoveOnENOSPC(const bool enabled_) |
|
||||
: enabled(enabled_), |
|
||||
policy(&Policies::Create::mfs) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int from_string(const std::string &s) final; |
|
||||
std::string to_string() const final; |
|
||||
|
|
||||
public: |
|
||||
bool enabled; |
|
||||
Policy::Create policy; |
|
||||
}; |
|
@ -1,55 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_nfsopenhack.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
NFSOpenHack::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "off") |
|
||||
_data = NFSOpenHack::ENUM::OFF; |
|
||||
ef(s_ == "git") |
|
||||
_data = NFSOpenHack::ENUM::GIT; |
|
||||
ef(s_ == "all") |
|
||||
_data = NFSOpenHack::ENUM::ALL; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
NFSOpenHack::to_string(void) const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case NFSOpenHack::ENUM::OFF: |
|
||||
return "off"; |
|
||||
case NFSOpenHack::ENUM::GIT: |
|
||||
return "git"; |
|
||||
case NFSOpenHack::ENUM::ALL: |
|
||||
return "all"; |
|
||||
} |
|
||||
|
|
||||
return std::string(); |
|
||||
} |
|
@ -1,31 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
|
|
||||
enum class NFSOpenHackEnum |
|
||||
{ |
|
||||
OFF, |
|
||||
GIT, |
|
||||
ALL |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<NFSOpenHackEnum> NFSOpenHack; |
|
@ -1,51 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_readdir.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
ReadDir::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "posix") |
|
||||
_data = ReadDir::ENUM::POSIX; |
|
||||
ef(s_ == "linux") |
|
||||
_data = ReadDir::ENUM::LINUX; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
ReadDir::to_string(void) const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case ReadDir::ENUM::POSIX: |
|
||||
return "posix"; |
|
||||
case ReadDir::ENUM::LINUX: |
|
||||
return "linux"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
@ -1,30 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
|
|
||||
enum class ReadDirEnum |
|
||||
{ |
|
||||
POSIX, |
|
||||
LINUX |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<ReadDirEnum> ReadDir; |
|
@ -1,51 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_statfs.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
StatFS::to_string() const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case StatFS::ENUM::BASE: |
|
||||
return "base"; |
|
||||
case StatFS::ENUM::FULL: |
|
||||
return "full"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
StatFS::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "base") |
|
||||
_data = StatFS::ENUM::BASE; |
|
||||
ef(s_ == "full") |
|
||||
_data = StatFS::ENUM::FULL; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,30 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
|
|
||||
enum class StatFSEnum |
|
||||
{ |
|
||||
BASE, |
|
||||
FULL |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<StatFSEnum> StatFS; |
|
@ -1,55 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_statfsignore.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
StatFSIgnore::to_string() const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case StatFSIgnore::ENUM::NONE: |
|
||||
return "none"; |
|
||||
case StatFSIgnore::ENUM::RO: |
|
||||
return "ro"; |
|
||||
case StatFSIgnore::ENUM::NC: |
|
||||
return "nc"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
StatFSIgnore::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "none") |
|
||||
_data = StatFSIgnore::ENUM::NONE; |
|
||||
ef(s_ == "ro") |
|
||||
_data = StatFSIgnore::ENUM::RO; |
|
||||
ef(s_ == "nc") |
|
||||
_data = StatFSIgnore::ENUM::NC; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,30 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
|
|
||||
enum class StatFSIgnoreEnum |
|
||||
{ |
|
||||
NONE, |
|
||||
RO, |
|
||||
NC |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<StatFSIgnoreEnum> StatFSIgnore; |
|
@ -1,55 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config_xattr.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
template<> |
|
||||
std::string |
|
||||
XAttr::to_string() const |
|
||||
{ |
|
||||
switch(_data) |
|
||||
{ |
|
||||
case XAttr::ENUM::PASSTHROUGH: |
|
||||
return "passthrough"; |
|
||||
case XAttr::ENUM::NOSYS: |
|
||||
return "nosys"; |
|
||||
case XAttr::ENUM::NOATTR: |
|
||||
return "noattr"; |
|
||||
} |
|
||||
|
|
||||
return "invalid"; |
|
||||
} |
|
||||
|
|
||||
template<> |
|
||||
int |
|
||||
XAttr::from_string(const std::string &s_) |
|
||||
{ |
|
||||
if(s_ == "passthrough") |
|
||||
_data = XAttr::ENUM::PASSTHROUGH; |
|
||||
ef(s_ == "nosys") |
|
||||
_data = XAttr::ENUM::NOSYS; |
|
||||
ef(s_ == "noattr") |
|
||||
_data = XAttr::ENUM::NOATTR; |
|
||||
else |
|
||||
return -EINVAL; |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,32 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "enum.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
|
|
||||
|
|
||||
enum class XAttrEnum |
|
||||
{ |
|
||||
PASSTHROUGH = 0, |
|
||||
NOSYS = ENOSYS, |
|
||||
NOATTR = ENOATTR |
|
||||
}; |
|
||||
|
|
||||
typedef Enum<XAttrEnum> XAttr; |
|
@ -1,418 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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 "config.hpp"
|
|
||||
#include "ef.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_glob.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "hw_cpu.hpp"
|
|
||||
#include "num.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "str.hpp"
|
|
||||
#include "version.hpp"
|
|
||||
|
|
||||
#include "fuse.h"
|
|
||||
|
|
||||
#include <fstream>
|
|
||||
#include <iomanip>
|
|
||||
#include <iostream>
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
#include <stddef.h>
|
|
||||
#include <stdio.h>
|
|
||||
#include <stdlib.h>
|
|
||||
#include <string.h>
|
|
||||
#include <unistd.h>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
enum |
|
||||
{ |
|
||||
MERGERFS_OPT_HELP, |
|
||||
MERGERFS_OPT_VERSION |
|
||||
}; |
|
||||
|
|
||||
|
|
||||
namespace l |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
calculate_thread_count(int threads_) |
|
||||
{ |
|
||||
int tc; |
|
||||
|
|
||||
if(threads_ > 0) |
|
||||
return threads_; |
|
||||
|
|
||||
tc = hw::cpu::logical_core_count(); |
|
||||
if(threads_ < 0) |
|
||||
tc /= -threads_; |
|
||||
if(tc == 0) |
|
||||
tc = 1; |
|
||||
|
|
||||
return tc; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_option(const std::string &option_, |
|
||||
fuse_args *args_) |
|
||||
{ |
|
||||
|
|
||||
fuse_opt_add_arg(args_,"-o"); |
|
||||
fuse_opt_add_arg(args_,option_.c_str()); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_kv_option(const std::string &key_, |
|
||||
const std::string &val_, |
|
||||
fuse_args *args_) |
|
||||
{ |
|
||||
std::string option; |
|
||||
|
|
||||
option = key_ + '=' + val_; |
|
||||
|
|
||||
set_option(option,args_); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_threads(Config::Write &cfg_, |
|
||||
fuse_args *args_) |
|
||||
{ |
|
||||
int threads; |
|
||||
|
|
||||
threads = l::calculate_thread_count(cfg_->threads); |
|
||||
|
|
||||
cfg_->threads = threads; |
|
||||
|
|
||||
set_kv_option("threads",cfg_->threads.to_string(),args_); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_fsname(Config::Write &cfg_, |
|
||||
fuse_args *args_) |
|
||||
{ |
|
||||
if(cfg_->fsname->empty()) |
|
||||
{ |
|
||||
vector<string> paths; |
|
||||
|
|
||||
cfg_->branches->to_paths(paths); |
|
||||
|
|
||||
if(paths.size() > 0) |
|
||||
cfg_->fsname = str::remove_common_prefix_and_join(paths,':'); |
|
||||
} |
|
||||
|
|
||||
set_kv_option("fsname",cfg_->fsname,args_); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_subtype(fuse_args *args_) |
|
||||
{ |
|
||||
set_kv_option("subtype","mergerfs",args_); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
set_default_options(fuse_args *args_) |
|
||||
{ |
|
||||
set_option("default_permissions",args_); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
parse_and_process_kv_arg(Config::Write &cfg_, |
|
||||
Config::ErrVec *errs_, |
|
||||
const std::string &key_, |
|
||||
const std::string &val_) |
|
||||
{ |
|
||||
int rv; |
|
||||
std::string key(key_); |
|
||||
std::string val(val_); |
|
||||
|
|
||||
rv = 0; |
|
||||
if(key == "config") |
|
||||
return ((cfg_->from_file(val_,errs_) < 0) ? 1 : 0); |
|
||||
ef(key == "attr_timeout") |
|
||||
key = "cache.attr"; |
|
||||
ef(key == "entry_timeout") |
|
||||
key = "cache.entry"; |
|
||||
ef(key == "negative_entry") |
|
||||
key = "cache.negative_entry"; |
|
||||
ef(key == "direct_io" && val.empty()) |
|
||||
val = "true"; |
|
||||
ef(key == "kernel_cache" && val.empty()) |
|
||||
val = "true"; |
|
||||
ef(key == "auto_cache" && val.empty()) |
|
||||
val = "true"; |
|
||||
ef(key == "async_read" && val.empty()) |
|
||||
val = "true"; |
|
||||
ef(key == "sync_read" && val.empty()) |
|
||||
{key = "async_read", val = "false";} |
|
||||
ef(key == "defaults") |
|
||||
return 0; |
|
||||
ef(key == "hard_remove") |
|
||||
return 0; |
|
||||
ef(key == "atomic_o_trunc") |
|
||||
return 0; |
|
||||
ef(key == "big_writes") |
|
||||
return 0; |
|
||||
ef(key == "cache.open") |
|
||||
return 0; |
|
||||
|
|
||||
if(cfg_->has_key(key) == false) |
|
||||
return 1; |
|
||||
|
|
||||
rv = cfg_->set_raw(key,val); |
|
||||
if(rv) |
|
||||
errs_->push_back({rv,key+'='+val}); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
process_opt(Config::Write &cfg_, |
|
||||
Config::ErrVec *errs_, |
|
||||
const std::string &arg_) |
|
||||
{ |
|
||||
std::string key; |
|
||||
std::string val; |
|
||||
|
|
||||
str::splitkv(arg_,'=',&key,&val); |
|
||||
key = str::trim(key); |
|
||||
val = str::trim(val); |
|
||||
|
|
||||
return parse_and_process_kv_arg(cfg_,errs_,key,val); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
process_branches(Config::Write &cfg_, |
|
||||
Config::ErrVec *errs_, |
|
||||
const char *arg_) |
|
||||
{ |
|
||||
int rv; |
|
||||
string arg; |
|
||||
|
|
||||
arg = arg_; |
|
||||
rv = cfg_->set_raw("branches",arg); |
|
||||
if(rv) |
|
||||
errs_->push_back({rv,"branches="+arg}); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
process_mount(Config::Write &cfg_, |
|
||||
Config::ErrVec *errs_, |
|
||||
const char *arg_) |
|
||||
{ |
|
||||
int rv; |
|
||||
string arg; |
|
||||
|
|
||||
arg = arg_; |
|
||||
rv = cfg_->set_raw("mount",arg); |
|
||||
if(rv) |
|
||||
errs_->push_back({rv,"mount="+arg}); |
|
||||
|
|
||||
return 1; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
void |
|
||||
usage(void) |
|
||||
{ |
|
||||
std::cout << |
|
||||
"Usage: mergerfs [options] <branches> <destpath>\n" |
|
||||
"\n" |
|
||||
" -o [opt,...] mount options\n" |
|
||||
" -h --help print help\n" |
|
||||
" -v --version print version\n" |
|
||||
"\n" |
|
||||
"mergerfs options:\n" |
|
||||
" <branches> ':' delimited list of directories. Supports\n" |
|
||||
" shell globbing (must be escaped in shell)\n" |
|
||||
" -o config=FILE Read options from file in key=val format\n" |
|
||||
" -o func.FUNC=POLICY Set function FUNC to policy POLICY\n" |
|
||||
" -o category.CAT=POLICY Set functions in category CAT to POLICY\n" |
|
||||
" -o fsname=STR Sets the name of the filesystem.\n" |
|
||||
" -o cache.open=INT 'open' policy cache timeout in seconds.\n" |
|
||||
" default = 0 (disabled)\n" |
|
||||
" -o cache.statfs=INT 'statfs' cache timeout in seconds. Used by\n" |
|
||||
" policies. default = 0 (disabled)\n" |
|
||||
" -o cache.files=libfuse|off|partial|full|auto-full\n" |
|
||||
" * libfuse: Use direct_io, kernel_cache, auto_cache\n" |
|
||||
" values directly\n" |
|
||||
" * off: Disable page caching\n" |
|
||||
" * partial: Clear page cache on file open\n" |
|
||||
" * full: Keep cache on file open\n" |
|
||||
" * auto-full: Keep cache if mtime & size not changed\n" |
|
||||
" default = libfuse\n" |
|
||||
" -o cache.writeback=BOOL\n" |
|
||||
" Enable kernel writeback caching (if supported)\n" |
|
||||
" cache.files must be enabled as well.\n" |
|
||||
" default = false\n" |
|
||||
" -o cache.symlinks=BOOL\n" |
|
||||
" Enable kernel caching of symlinks (if supported)\n" |
|
||||
" default = false\n" |
|
||||
" -o cache.readdir=BOOL\n" |
|
||||
" Enable kernel caching readdir (if supported)\n" |
|
||||
" default = false\n" |
|
||||
" -o cache.attr=INT File attribute cache timeout in seconds.\n" |
|
||||
" default = 1\n" |
|
||||
" -o cache.entry=INT File name lookup cache timeout in seconds.\n" |
|
||||
" default = 1\n" |
|
||||
" -o cache.negative_entry=INT\n" |
|
||||
" Negative file name lookup cache timeout in\n" |
|
||||
" seconds. default = 0\n" |
|
||||
" -o use_ino Have mergerfs generate inode values rather than\n" |
|
||||
" autogenerated by libfuse. Suggested.\n" |
|
||||
" -o inodecalc=passthrough|path-hash|devino-hash|hybrid-hash\n" |
|
||||
" Selects the inode calculation algorithm.\n" |
|
||||
" default = hybrid-hash\n" |
|
||||
" -o minfreespace=INT Minimum free space needed for certain policies.\n" |
|
||||
" default = 4G\n" |
|
||||
" -o moveonenospc=BOOL Try to move file to another drive when ENOSPC\n" |
|
||||
" on write. default = false\n" |
|
||||
" -o dropcacheonclose=BOOL\n" |
|
||||
" When a file is closed suggest to OS it drop\n" |
|
||||
" the file's cache. This is useful when using\n" |
|
||||
" 'cache.files'. default = false\n" |
|
||||
" -o symlinkify=BOOL Read-only files, after a timeout, will be turned\n" |
|
||||
" into symlinks. Read docs for limitations and\n" |
|
||||
" possible issues. default = false\n" |
|
||||
" -o symlinkify_timeout=INT\n" |
|
||||
" Timeout in seconds before files turn to symlinks.\n" |
|
||||
" default = 3600\n" |
|
||||
" -o nullrw=BOOL Disables reads and writes. For benchmarking.\n" |
|
||||
" default = false\n" |
|
||||
" -o ignorepponrename=BOOL\n" |
|
||||
" Ignore path preserving when performing renames\n" |
|
||||
" and links. default = false\n" |
|
||||
" -o link_cow=BOOL Delink/clone file on open to simulate CoW.\n" |
|
||||
" default = false\n" |
|
||||
" -o nfsopenhack=off|git|all\n" |
|
||||
" A workaround for exporting mergerfs over NFS\n" |
|
||||
" where there are issues with creating files for\n" |
|
||||
" write while setting the mode to read-only.\n" |
|
||||
" default = off\n" |
|
||||
" -o security_capability=BOOL\n" |
|
||||
" When disabled return ENOATTR when the xattr\n" |
|
||||
" security.capability is queried. default = true\n" |
|
||||
" -o xattr=passthrough|noattr|nosys\n" |
|
||||
" Runtime control of xattrs. By default xattr\n" |
|
||||
" requests will pass through to the underlying\n" |
|
||||
" filesystems. notattr will short circuit as if\n" |
|
||||
" nothing exists. nosys will respond as if not\n" |
|
||||
" supported or disabled. default = passthrough\n" |
|
||||
" -o statfs=base|full When set to 'base' statfs will use all branches\n" |
|
||||
" when performing statfs calculations. 'full' will\n" |
|
||||
" only include branches on which that path is\n" |
|
||||
" available. default = base\n" |
|
||||
" -o statfs_ignore=none|ro|nc\n" |
|
||||
" 'ro' will cause statfs calculations to ignore\n" |
|
||||
" available space for branches mounted or tagged\n" |
|
||||
" as 'read only' or 'no create'. 'nc' will ignore\n" |
|
||||
" available space for branches tagged as\n" |
|
||||
" 'no create'. default = none\n" |
|
||||
" -o posix_acl=BOOL Enable POSIX ACL support. default = false\n" |
|
||||
" -o async_read=BOOL If disabled or unavailable the kernel will\n" |
|
||||
" ensure there is at most one pending read \n" |
|
||||
" request per file and will attempt to order\n" |
|
||||
" requests by offset. default = true\n" |
|
||||
<< std::endl; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
option_processor(void *data_, |
|
||||
const char *arg_, |
|
||||
int key_, |
|
||||
fuse_args *outargs_) |
|
||||
{ |
|
||||
Config::Write cfg; |
|
||||
Config::ErrVec *errs = (Config::ErrVec*)data_; |
|
||||
|
|
||||
switch(key_) |
|
||||
{ |
|
||||
case FUSE_OPT_KEY_OPT: |
|
||||
return process_opt(cfg,errs,arg_); |
|
||||
|
|
||||
case FUSE_OPT_KEY_NONOPT: |
|
||||
if(cfg->branches->empty()) |
|
||||
return process_branches(cfg,errs,arg_); |
|
||||
else |
|
||||
return process_mount(cfg,errs,arg_); |
|
||||
|
|
||||
case MERGERFS_OPT_HELP: |
|
||||
usage(); |
|
||||
exit(0); |
|
||||
|
|
||||
case MERGERFS_OPT_VERSION: |
|
||||
std::cout << "mergerfs version: " |
|
||||
<< (MERGERFS_VERSION[0] ? MERGERFS_VERSION : "unknown") |
|
||||
<< std::endl; |
|
||||
exit(0); |
|
||||
|
|
||||
default: |
|
||||
break; |
|
||||
} |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
namespace options |
|
||||
{ |
|
||||
void |
|
||||
parse(fuse_args *args_, |
|
||||
Config::ErrVec *errs_) |
|
||||
{ |
|
||||
Config::Write cfg; |
|
||||
const struct fuse_opt opts[] = |
|
||||
{ |
|
||||
FUSE_OPT_KEY("-h",MERGERFS_OPT_HELP), |
|
||||
FUSE_OPT_KEY("--help",MERGERFS_OPT_HELP), |
|
||||
FUSE_OPT_KEY("-v",MERGERFS_OPT_VERSION), |
|
||||
FUSE_OPT_KEY("-V",MERGERFS_OPT_VERSION), |
|
||||
FUSE_OPT_KEY("--version",MERGERFS_OPT_VERSION), |
|
||||
{NULL,-1U,0} |
|
||||
}; |
|
||||
|
|
||||
fuse_opt_parse(args_, |
|
||||
errs_, |
|
||||
opts, |
|
||||
::option_processor); |
|
||||
|
|
||||
if(cfg->branches->empty()) |
|
||||
errs_->push_back({0,"branches not set"}); |
|
||||
if(cfg->mount->empty()) |
|
||||
errs_->push_back({0,"mountpoint not set"}); |
|
||||
|
|
||||
set_default_options(args_); |
|
||||
set_fsname(cfg,args_); |
|
||||
set_subtype(args_); |
|
||||
set_threads(cfg,args_); |
|
||||
} |
|
||||
} |
|
@ -1,29 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
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. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "config.hpp"
|
|
||||
|
|
||||
#include "fuse.h"
|
|
||||
|
|
||||
|
|
||||
namespace options |
|
||||
{ |
|
||||
void |
|
||||
parse(fuse_args *args, |
|
||||
Config::ErrVec *errs); |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue