2014-05-13 00:41:46 +08:00
|
|
|
/*
|
2016-01-15 05:50:22 +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.
|
2014-05-13 00:41:46 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-18 07:12:09 +08:00
|
|
|
#include <fuse.h>
|
|
|
|
|
2014-05-13 00:41:46 +08:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <errno.h>
|
2014-05-20 11:33:59 +08:00
|
|
|
#include <string.h>
|
2014-05-13 00:41:46 +08:00
|
|
|
|
2015-09-16 06:49:18 +08:00
|
|
|
#include "buildvector.hpp"
|
2014-05-28 09:21:45 +08:00
|
|
|
#include "category.hpp"
|
2015-09-16 06:49:18 +08:00
|
|
|
#include "config.hpp"
|
|
|
|
#include "fs_path.hpp"
|
2014-08-04 03:50:28 +08:00
|
|
|
#include "rwlock.hpp"
|
2015-09-16 06:49:18 +08:00
|
|
|
#include "ugid.hpp"
|
2014-05-19 21:34:31 +08:00
|
|
|
#include "xattr.hpp"
|
2014-05-13 00:41:46 +08:00
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
2014-05-20 11:33:59 +08:00
|
|
|
using namespace mergerfs;
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
_listxattr_controlfile(char *list,
|
|
|
|
const size_t size)
|
|
|
|
{
|
2015-02-19 22:09:24 +08:00
|
|
|
string xattrs;
|
2015-07-03 23:56:01 +08:00
|
|
|
const vector<string> strs =
|
|
|
|
buildvector<string>
|
|
|
|
("user.mergerfs.srcmounts")
|
2015-09-06 07:49:08 +08:00
|
|
|
("user.mergerfs.minfreespace")
|
2015-09-16 06:49:18 +08:00
|
|
|
("user.mergerfs.moveonenospc")
|
2015-09-06 09:48:15 +08:00
|
|
|
("user.mergerfs.policies")
|
2015-12-08 05:36:24 +08:00
|
|
|
("user.mergerfs.version")
|
|
|
|
("user.mergerfs.pid");
|
2015-02-19 22:09:24 +08:00
|
|
|
|
2015-09-15 10:11:52 +08:00
|
|
|
xattrs.reserve(1024);
|
2015-07-03 23:56:01 +08:00
|
|
|
for(size_t i = 0; i < strs.size(); i++)
|
|
|
|
xattrs += (strs[i] + '\0');
|
|
|
|
for(size_t i = Category::Enum::BEGIN; i < Category::Enum::END; i++)
|
2015-02-19 22:09:24 +08:00
|
|
|
xattrs += ("user.mergerfs.category." + (std::string)*Category::categories[i] + '\0');
|
2015-07-03 23:56:01 +08:00
|
|
|
for(size_t i = FuseFunc::Enum::BEGIN; i < FuseFunc::Enum::END; i++)
|
2015-02-19 22:09:24 +08:00
|
|
|
xattrs += ("user.mergerfs.func." + (std::string)*FuseFunc::fusefuncs[i] + '\0');
|
2014-05-20 11:33:59 +08:00
|
|
|
|
|
|
|
if(size == 0)
|
2015-02-19 22:09:24 +08:00
|
|
|
return xattrs.size();
|
2014-05-20 11:33:59 +08:00
|
|
|
|
2015-02-19 22:09:24 +08:00
|
|
|
if(size < xattrs.size())
|
2014-05-20 11:33:59 +08:00
|
|
|
return -ERANGE;
|
|
|
|
|
2015-02-19 22:09:24 +08:00
|
|
|
memcpy(list,xattrs.c_str(),xattrs.size());
|
2014-05-20 11:33:59 +08:00
|
|
|
|
2015-02-19 22:09:24 +08:00
|
|
|
return xattrs.size();
|
2014-05-20 11:33:59 +08:00
|
|
|
}
|
2014-05-13 00:41:46 +08:00
|
|
|
|
2016-01-30 05:54:39 +08:00
|
|
|
#ifndef WITHOUT_XATTR
|
2014-05-13 00:41:46 +08:00
|
|
|
static
|
|
|
|
int
|
2015-06-26 05:55:16 +08:00
|
|
|
_listxattr(Policy::Func::Search searchFunc,
|
|
|
|
const vector<string> &srcmounts,
|
|
|
|
const size_t minfreespace,
|
2016-01-30 05:54:39 +08:00
|
|
|
const char *fusepath,
|
2015-06-26 05:55:16 +08:00
|
|
|
char *list,
|
|
|
|
const size_t size)
|
2014-05-13 00:41:46 +08:00
|
|
|
{
|
|
|
|
int rv;
|
2016-01-30 05:54:39 +08:00
|
|
|
string fullpath;
|
|
|
|
vector<const string*> basepaths;
|
2014-05-13 00:41:46 +08:00
|
|
|
|
2016-01-30 05:54:39 +08:00
|
|
|
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
2014-08-17 01:59:55 +08:00
|
|
|
if(rv == -1)
|
|
|
|
return -errno;
|
2014-05-13 00:41:46 +08:00
|
|
|
|
2016-01-30 05:54:39 +08:00
|
|
|
fs::path::make(basepaths[0],fusepath,fullpath);
|
2015-07-01 19:47:40 +08:00
|
|
|
|
2016-01-30 05:54:39 +08:00
|
|
|
rv = ::llistxattr(fullpath.c_str(),list,size);
|
2014-05-13 00:41:46 +08:00
|
|
|
|
|
|
|
return ((rv == -1) ? -errno : rv);
|
|
|
|
}
|
2016-01-30 05:54:39 +08:00
|
|
|
#endif
|
2014-05-13 00:41:46 +08:00
|
|
|
|
|
|
|
namespace mergerfs
|
|
|
|
{
|
2015-07-15 22:04:57 +08:00
|
|
|
namespace fuse
|
2014-05-13 00:41:46 +08:00
|
|
|
{
|
|
|
|
int
|
|
|
|
listxattr(const char *fusepath,
|
|
|
|
char *list,
|
|
|
|
size_t size)
|
|
|
|
{
|
2015-07-22 02:19:17 +08:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
const Config &config = Config::get(fc);
|
2014-05-13 00:41:46 +08:00
|
|
|
|
|
|
|
if(fusepath == config.controlfile)
|
2015-06-17 10:12:55 +08:00
|
|
|
return _listxattr_controlfile(list,size);
|
2014-05-13 00:41:46 +08:00
|
|
|
|
2016-01-30 05:54:39 +08:00
|
|
|
#ifndef WITHOUT_XATTR
|
2015-09-09 03:56:02 +08:00
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
|
|
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
2014-08-04 03:50:28 +08:00
|
|
|
|
2015-06-26 05:55:16 +08:00
|
|
|
return _listxattr(config.listxattr,
|
2014-05-13 00:41:46 +08:00
|
|
|
config.srcmounts,
|
2015-06-17 10:12:55 +08:00
|
|
|
config.minfreespace,
|
2014-05-13 00:41:46 +08:00
|
|
|
fusepath,
|
|
|
|
list,
|
|
|
|
size);
|
2016-01-30 05:54:39 +08:00
|
|
|
#else
|
|
|
|
return -ENOTSUP;
|
|
|
|
#endif
|
2014-05-13 00:41:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|