mirror of https://github.com/trapexit/mergerfs.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.0 KiB
118 lines
3.0 KiB
/*
|
|
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.h>
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "config.hpp"
|
|
#include "errno.hpp"
|
|
#include "fs_base_stat.hpp"
|
|
#include "fs_inode.hpp"
|
|
#include "fs_path.hpp"
|
|
#include "rwlock.hpp"
|
|
#include "symlinkify.hpp"
|
|
#include "ugid.hpp"
|
|
|
|
using std::string;
|
|
using std::vector;
|
|
using mergerfs::Policy;
|
|
|
|
static
|
|
int
|
|
_getattr_controlfile(struct stat &st)
|
|
{
|
|
static const uid_t uid = ::getuid();
|
|
static const gid_t gid = ::getgid();
|
|
static const time_t now = ::time(NULL);
|
|
|
|
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;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static
|
|
int
|
|
_getattr(Policy::Func::Search searchFunc,
|
|
const Branches &branches_,
|
|
const uint64_t minfreespace,
|
|
const char *fusepath,
|
|
struct stat &st,
|
|
const bool symlinkify,
|
|
const time_t symlinkify_timeout)
|
|
{
|
|
int rv;
|
|
string fullpath;
|
|
vector<const string*> basepaths;
|
|
|
|
rv = searchFunc(branches_,fusepath,minfreespace,basepaths);
|
|
if(rv == -1)
|
|
return -errno;
|
|
|
|
fs::path::make(basepaths[0],fusepath,fullpath);
|
|
|
|
rv = fs::lstat(fullpath,st);
|
|
if(rv == -1)
|
|
return -errno;
|
|
|
|
if(symlinkify && symlinkify::can_be_symlink(st,symlinkify_timeout))
|
|
st.st_mode = symlinkify::convert(st.st_mode);
|
|
|
|
fs::inode::recompute(st);
|
|
|
|
return 0;
|
|
}
|
|
|
|
namespace mergerfs
|
|
{
|
|
namespace fuse
|
|
{
|
|
int
|
|
getattr(const char *fusepath,
|
|
struct stat *st)
|
|
{
|
|
const fuse_context *fc = fuse_get_context();
|
|
const Config &config = Config::get(fc);
|
|
|
|
if(fusepath == config.controlfile)
|
|
return _getattr_controlfile(*st);
|
|
|
|
const ugid::Set ugid(fc->uid,fc->gid);
|
|
const rwlock::ReadGuard readlock(&config.branches_lock);
|
|
|
|
return _getattr(config.getattr,
|
|
config.branches,
|
|
config.minfreespace,
|
|
fusepath,
|
|
*st,
|
|
config.symlinkify,
|
|
config.symlinkify_timeout);
|
|
}
|
|
}
|
|
}
|