mergerfs/src/mergerfs.cpp

203 lines
5.6 KiB
C++
Raw Normal View History

2014-05-12 12:41:46 -04:00
/*
The MIT License (MIT)
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <fuse.h>
#include <string.h>
#include <cstdlib>
#include <iostream>
#include "mergerfs.hpp"
#include "option_parser.hpp"
#include "resources.hpp"
#include "fs.hpp"
2015-01-27 18:25:20 -05:00
#include "clonepath.hpp"
2014-05-12 12:41:46 -04:00
#include "access.hpp"
#include "chmod.hpp"
#include "chown.hpp"
#include "create.hpp"
#include "destroy.hpp"
2014-05-12 12:41:46 -04:00
#include "fallocate.hpp"
2014-05-28 06:03:06 -04:00
#include "fgetattr.hpp"
2014-06-13 11:04:26 -04:00
#include "flush.hpp"
2014-05-12 12:41:46 -04:00
#include "fsync.hpp"
#include "ftruncate.hpp"
#include "getattr.hpp"
#include "getxattr.hpp"
#include "init.hpp"
2014-05-12 12:41:46 -04:00
#include "ioctl.hpp"
#include "link.hpp"
#include "listxattr.hpp"
#include "mkdir.hpp"
#include "mknod.hpp"
#include "open.hpp"
#include "opendir.hpp"
2014-05-12 12:41:46 -04:00
#include "read.hpp"
#include "read_buf.hpp"
2014-05-12 12:41:46 -04:00
#include "readdir.hpp"
#include "readlink.hpp"
#include "release.hpp"
#include "releasedir.hpp"
2014-05-12 12:41:46 -04:00
#include "removexattr.hpp"
#include "rename.hpp"
#include "rmdir.hpp"
#include "setxattr.hpp"
#include "statfs.hpp"
#include "symlink.hpp"
#include "truncate.hpp"
#include "unlink.hpp"
#include "utimens.hpp"
#include "write.hpp"
#include "write_buf.hpp"
2014-05-12 12:41:46 -04:00
2015-01-27 16:08:13 -05:00
namespace local
2014-05-12 12:41:46 -04:00
{
2015-01-27 18:25:20 -05:00
static
std::string
getappname(const int argc,
char * const *argv)
{
return fs::path::basename(argv[0]);
2015-01-27 18:25:20 -05:00
}
2015-01-27 16:08:13 -05:00
static
void
get_fuse_operations(struct fuse_operations &ops)
{
2014-11-04 13:42:20 -05:00
#if FLAG_NOPATH
2015-01-27 16:08:13 -05:00
ops.flag_nopath = false;
2014-11-04 13:42:20 -05:00
#endif
2015-01-27 16:08:13 -05:00
ops.flag_nullpath_ok = false;
ops.access = mergerfs::access::access;
ops.bmap = NULL;
ops.chmod = mergerfs::chmod::chmod;
ops.chown = mergerfs::chown::chown;
ops.create = mergerfs::create::create;
ops.destroy = mergerfs::destroy::destroy;
2014-11-04 13:42:20 -05:00
#if FALLOCATE
2015-01-27 16:08:13 -05:00
ops.fallocate = mergerfs::fallocate::fallocate;
2014-11-04 13:42:20 -05:00
#endif
2015-01-27 16:08:13 -05:00
ops.fgetattr = mergerfs::fgetattr::fgetattr;
2014-11-04 13:42:20 -05:00
#if FLOCK
2015-01-27 16:08:13 -05:00
ops.flock = NULL;
2014-11-04 13:42:20 -05:00
#endif
2015-01-27 16:08:13 -05:00
ops.flush = mergerfs::flush::flush;
ops.fsync = mergerfs::fsync::fsync;
ops.fsyncdir = NULL;
ops.ftruncate = mergerfs::ftruncate::ftruncate;
ops.getattr = mergerfs::getattr::getattr;
ops.getdir = NULL; /* deprecated; use readdir */
ops.getxattr = mergerfs::getxattr::getxattr;
ops.init = mergerfs::init::init;
ops.ioctl = mergerfs::ioctl::ioctl;
ops.link = mergerfs::link::link;
ops.listxattr = mergerfs::listxattr::listxattr;
ops.lock = NULL;
ops.mkdir = mergerfs::mkdir::mkdir;
ops.mknod = mergerfs::mknod::mknod;
ops.open = mergerfs::open::open;
ops.opendir = mergerfs::opendir::opendir;
ops.poll = NULL;
ops.read = mergerfs::read::read;
2014-11-04 13:42:20 -05:00
#if READ_BUF
2015-01-27 16:08:13 -05:00
ops.read_buf = mergerfs::read_buf::read_buf;
2014-11-04 13:42:20 -05:00
#endif
2015-01-27 16:08:13 -05:00
ops.readdir = mergerfs::readdir::readdir;
ops.readlink = mergerfs::readlink::readlink;
ops.release = mergerfs::release::release;
ops.releasedir = mergerfs::releasedir::releasedir;
ops.removexattr = mergerfs::removexattr::removexattr;
ops.rename = mergerfs::rename::rename;
ops.rmdir = mergerfs::rmdir::rmdir;
ops.setxattr = mergerfs::setxattr::setxattr;
ops.statfs = mergerfs::statfs::statfs;
ops.symlink = mergerfs::symlink::symlink;
ops.truncate = mergerfs::truncate::truncate;
ops.unlink = mergerfs::unlink::unlink;
ops.utime = NULL; /* deprecated; use utimens() */
ops.utimens = mergerfs::utimens::utimens;
ops.write = mergerfs::write::write;
2014-11-04 13:42:20 -05:00
#if WRITE_BUF
2015-01-27 16:08:13 -05:00
ops.write_buf = mergerfs::write_buf::write_buf;
2014-11-04 13:42:20 -05:00
#endif
2014-05-12 12:41:46 -04:00
2015-01-27 16:08:13 -05:00
return;
}
static
void
setup_resources(void)
{
const int prio = -10;
2015-01-27 16:08:13 -05:00
std::srand(time(NULL));
mergerfs::resources::reset_umask();
mergerfs::resources::maxout_rlimit_nofile();
mergerfs::resources::maxout_rlimit_fsize();
mergerfs::resources::setpriority(prio);
2015-01-27 16:08:13 -05:00
}
2014-05-12 12:41:46 -04:00
}
namespace mergerfs
{
int
2015-01-27 16:08:13 -05:00
main(const int argc,
char **argv)
2014-05-12 12:41:46 -04:00
{
2015-01-27 16:08:13 -05:00
struct fuse_args args;
struct fuse_operations ops = {0};
mergerfs::config::Config config;
2014-05-12 12:41:46 -04:00
2015-01-27 16:08:13 -05:00
args.argc = argc;
args.argv = argv;
args.allocated = 0;
2014-05-12 12:41:46 -04:00
2015-01-27 16:08:13 -05:00
mergerfs::options::parse(args,config);
local::setup_resources();
local::get_fuse_operations(ops);
2014-05-12 12:41:46 -04:00
return fuse_main(args.argc,
args.argv,
&ops,
&config);
}
}
int
2015-01-27 16:08:13 -05:00
main(int argc,
char **argv)
2014-05-12 12:41:46 -04:00
{
2015-01-27 18:25:20 -05:00
std::string appname;
2014-05-12 12:41:46 -04:00
2015-01-27 18:25:20 -05:00
appname = local::getappname(argc,argv);
if(appname == "clonepath")
return clonepath::main(argc,argv);
2014-05-12 12:41:46 -04:00
2015-01-27 18:25:20 -05:00
return mergerfs::main(argc,argv);
2014-05-12 12:41:46 -04:00
}