2019-01-25 20:03:46 +08:00
|
|
|
/*
|
|
|
|
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 "errno.hpp"
|
|
|
|
#include "fs_base_removexattr.hpp"
|
|
|
|
#include "fs_path.hpp"
|
|
|
|
#include "rv.hpp"
|
|
|
|
#include "ugid.hpp"
|
|
|
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace l
|
|
|
|
{
|
|
|
|
static
|
|
|
|
int
|
2019-09-24 22:27:46 +08:00
|
|
|
removexattr_loop_core(const string &basepath_,
|
2019-01-25 20:03:46 +08:00
|
|
|
const char *fusepath_,
|
|
|
|
const char *attrname_,
|
|
|
|
const int error_)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
string fullpath;
|
|
|
|
|
|
|
|
fullpath = fs::path::make(basepath_,fusepath_);
|
|
|
|
|
|
|
|
rv = fs::lremovexattr(fullpath,attrname_);
|
|
|
|
|
|
|
|
return error::calc(rv,error_,errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
2019-09-24 22:27:46 +08:00
|
|
|
removexattr_loop(const vector<string> &basepaths_,
|
|
|
|
const char *fusepath_,
|
|
|
|
const char *attrname_)
|
2019-01-25 20:03:46 +08:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = -1;
|
|
|
|
|
|
|
|
for(size_t i = 0, ei = basepaths_.size(); i != ei; i++)
|
|
|
|
{
|
|
|
|
error = l::removexattr_loop_core(basepaths_[i],fusepath_,attrname_,error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
removexattr(Policy::Func::Action actionFunc_,
|
|
|
|
const Branches &branches_,
|
|
|
|
const uint64_t minfreespace_,
|
|
|
|
const char *fusepath_,
|
|
|
|
const char *attrname_)
|
|
|
|
{
|
|
|
|
int rv;
|
2019-09-24 22:27:46 +08:00
|
|
|
vector<string> basepaths;
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2019-09-24 22:27:46 +08:00
|
|
|
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
|
2019-01-25 20:03:46 +08:00
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
|
|
|
|
|
|
|
return l::removexattr_loop(basepaths,fusepath_,attrname_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace FUSE
|
|
|
|
{
|
|
|
|
int
|
|
|
|
removexattr(const char *fusepath_,
|
|
|
|
const char *attrname_)
|
|
|
|
{
|
2019-09-24 22:27:46 +08:00
|
|
|
const Config &config = Config::ro();
|
2019-01-25 20:03:46 +08:00
|
|
|
|
|
|
|
if(fusepath_ == config.controlfile)
|
|
|
|
return -ENOATTR;
|
2019-09-24 22:27:46 +08:00
|
|
|
if(config.xattr.to_int())
|
|
|
|
return -config.xattr.to_int();
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2019-09-24 22:27:46 +08:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2019-09-24 22:27:46 +08:00
|
|
|
return l::removexattr(config.func.removexattr.policy,
|
2019-01-25 20:03:46 +08:00
|
|
|
config.branches,
|
|
|
|
config.minfreespace,
|
|
|
|
fusepath_,
|
|
|
|
attrname_);
|
|
|
|
}
|
|
|
|
}
|