mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
only allow manipulation of runtime settings via xattrs. closes #22
This commit is contained in:
parent
45cec2d301
commit
7b0d703f00
35 changed files with 50 additions and 419 deletions
|
|
@ -27,80 +27,8 @@
|
|||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include "config.hpp"
|
||||
#include "policy.hpp"
|
||||
#include "category.hpp"
|
||||
#include "ugid.hpp"
|
||||
#include "fileinfo.hpp"
|
||||
|
||||
using mergerfs::config::Config;
|
||||
using mergerfs::Policy;
|
||||
using mergerfs::Category;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::stringstream;
|
||||
|
||||
static
|
||||
int
|
||||
_process_kv(Config &config,
|
||||
const string key,
|
||||
const string value)
|
||||
{
|
||||
const Category *cat;
|
||||
const Policy *policy;
|
||||
|
||||
cat = Category::find(key);
|
||||
if(cat == Category::invalid)
|
||||
return -EINVAL;
|
||||
|
||||
policy = Policy::find(value);
|
||||
if(policy == Policy::invalid)
|
||||
return -EINVAL;
|
||||
|
||||
config.policies[*cat] = policy;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_write_controlfile(Config &config,
|
||||
string &existing,
|
||||
const string buf,
|
||||
const off_t _offset)
|
||||
{
|
||||
size_t bufsize = buf.size();
|
||||
size_t existingsize = existing.size();
|
||||
|
||||
if((existingsize + buf.size()) > 1024)
|
||||
return (existing.clear(),-EINVAL);
|
||||
|
||||
existing += buf;
|
||||
|
||||
size_t nlpos = existing.find_first_of('\n',existingsize);
|
||||
if(nlpos == string::npos)
|
||||
return 0;
|
||||
|
||||
string line = existing.substr(0,nlpos);
|
||||
existing = existing.substr(nlpos+1);
|
||||
|
||||
size_t equalsoffset = line.find_first_of('=');
|
||||
if(equalsoffset == string::npos)
|
||||
return -EINVAL;
|
||||
|
||||
int rv;
|
||||
string key = line.substr(0,equalsoffset);
|
||||
string value = line.substr(equalsoffset+1);
|
||||
|
||||
rv = _process_kv(config,key,value);
|
||||
|
||||
return ((rv < 0) ? rv : bufsize);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_write(const int fd,
|
||||
|
|
@ -126,14 +54,6 @@ namespace mergerfs
|
|||
off_t offset,
|
||||
struct fuse_file_info *fi)
|
||||
{
|
||||
const config::Config &config = config::get();
|
||||
|
||||
if(fusepath == config.controlfile)
|
||||
return _write_controlfile(config::get_writable(),
|
||||
*(string*)fi->fh,
|
||||
string(buf,count),
|
||||
offset);
|
||||
|
||||
return _write(((FileInfo*)fi->fh)->fd,
|
||||
buf,
|
||||
count,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue