2014-05-12 12:41:46 -04:00
|
|
|
/*
|
2016-01-14 16:50:22 -05:00
|
|
|
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-14 16:50:22 -05:00
|
|
|
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.
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-14 16:50:22 -05:00
|
|
|
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-12 12:41:46 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <fuse.h>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "config.hpp"
|
2016-09-14 08:36:06 -04:00
|
|
|
#include "errno.hpp"
|
2016-10-19 09:28:06 -04:00
|
|
|
#include "fs_base_stat.hpp"
|
2016-12-11 18:27:52 -05:00
|
|
|
#include "fs_inode.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "fs_path.hpp"
|
2014-08-03 15:50:28 -04:00
|
|
|
#include "rwlock.hpp"
|
2015-09-15 18:49:18 -04:00
|
|
|
#include "ugid.hpp"
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::vector;
|
2015-06-22 23:35:46 -04:00
|
|
|
using mergerfs::Policy;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2014-06-25 15:17:26 -04:00
|
|
|
static
|
|
|
|
|
int
|
2016-12-11 18:27:52 -05:00
|
|
|
_getattr_controlfile(struct stat &st)
|
2014-06-25 15:17:26 -04:00
|
|
|
{
|
2015-09-14 22:11:52 -04:00
|
|
|
static const uid_t uid = ::getuid();
|
|
|
|
|
static const gid_t gid = ::getgid();
|
|
|
|
|
static const time_t now = ::time(NULL);
|
2014-07-29 00:00:42 -04:00
|
|
|
|
2016-12-11 18:27:52 -05:00
|
|
|
st.st_dev = 0;
|
|
|
|
|
st.st_ino = fs::inode::MAGIC;
|
|
|
|
|
st.st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
|
|
|
|
|
st.st_nlink = 1;
|
|
|
|
|
st.st_uid = uid;
|
|
|
|
|
st.st_gid = gid;
|
|
|
|
|
st.st_rdev = 0;
|
|
|
|
|
st.st_size = 0;
|
|
|
|
|
st.st_blksize = 512;
|
|
|
|
|
st.st_blocks = 0;
|
|
|
|
|
st.st_atime = now;
|
|
|
|
|
st.st_mtime = now;
|
|
|
|
|
st.st_ctime = now;
|
2014-06-25 15:17:26 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-12 12:41:46 -04:00
|
|
|
static
|
|
|
|
|
int
|
2015-06-25 17:55:16 -04:00
|
|
|
_getattr(Policy::Func::Search searchFunc,
|
|
|
|
|
const vector<string> &srcmounts,
|
2016-07-10 12:44:29 -04:00
|
|
|
const uint64_t minfreespace,
|
2016-01-29 16:54:39 -05:00
|
|
|
const char *fusepath,
|
2016-12-11 18:27:52 -05:00
|
|
|
struct stat &st)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
|
int rv;
|
2016-01-29 16:54:39 -05:00
|
|
|
string fullpath;
|
|
|
|
|
vector<const string*> basepaths;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-29 16:54:39 -05:00
|
|
|
rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
|
2014-08-16 13:59:55 -04:00
|
|
|
if(rv == -1)
|
|
|
|
|
return -errno;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-01-29 16:54:39 -05:00
|
|
|
fs::path::make(basepaths[0],fusepath,fullpath);
|
2015-07-01 07:47:40 -04:00
|
|
|
|
2016-12-11 18:27:52 -05:00
|
|
|
rv = fs::lstat(fullpath,st);
|
|
|
|
|
if(rv == -1)
|
|
|
|
|
return -errno;
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2016-12-11 18:27:52 -05:00
|
|
|
fs::inode::recompute(st);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace mergerfs
|
|
|
|
|
{
|
2015-07-15 10:04:57 -04:00
|
|
|
namespace fuse
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
|
|
|
|
int
|
|
|
|
|
getattr(const char *fusepath,
|
2014-06-25 15:17:26 -04:00
|
|
|
struct stat *st)
|
2014-05-12 12:41:46 -04:00
|
|
|
{
|
2015-07-21 14:19:17 -04:00
|
|
|
const fuse_context *fc = fuse_get_context();
|
|
|
|
|
const Config &config = Config::get(fc);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
|
|
|
|
if(fusepath == config.controlfile)
|
2014-07-29 00:00:42 -04:00
|
|
|
return _getattr_controlfile(*st);
|
2014-05-12 12:41:46 -04:00
|
|
|
|
2015-09-08 15:56:02 -04:00
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
|
|
|
const rwlock::ReadGuard readlock(&config.srcmountslock);
|
2014-08-03 15:50:28 -04:00
|
|
|
|
2015-06-25 17:55:16 -04:00
|
|
|
return _getattr(config.getattr,
|
2014-05-12 12:41:46 -04:00
|
|
|
config.srcmounts,
|
2015-06-16 22:12:55 -04:00
|
|
|
config.minfreespace,
|
2014-05-12 12:41:46 -04:00
|
|
|
fusepath,
|
2014-06-25 15:17:26 -04:00
|
|
|
*st);
|
2014-05-12 12:41:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|