mergerfs/src/mergerfs.cpp

185 lines
5 KiB
C++
Raw Normal View History

2014-05-12 12:41:46 -04: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-12 12:41:46 -04:00
#include <fuse.h>
#include <string.h>
#include <cstdlib>
#include <iostream>
2016-12-22 09:27:30 -05:00
#include "fs_path.hpp"
2014-05-12 12:41:46 -04:00
#include "mergerfs.hpp"
#include "option_parser.hpp"
#include "resources.hpp"
2015-01-27 18:25:20 -05:00
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"
2016-10-19 11:58:44 -04:00
#include "flock.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 16:08:13 -05:00
static
void
get_fuse_operations(struct fuse_operations &ops,
const bool direct_io)
2015-01-27 16:08:13 -05:00
{
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::fuse::access;
2015-01-27 16:08:13 -05:00
ops.bmap = NULL;
ops.chmod = mergerfs::fuse::chmod;
ops.chown = mergerfs::fuse::chown;
ops.create = mergerfs::fuse::create;
ops.destroy = mergerfs::fuse::destroy;
2014-11-04 13:42:20 -05:00
#if FALLOCATE
ops.fallocate = mergerfs::fuse::fallocate;
2014-11-04 13:42:20 -05:00
#endif
ops.fgetattr = mergerfs::fuse::fgetattr;
2014-11-04 13:42:20 -05:00
#if FLOCK
2016-10-19 11:58:44 -04:00
ops.flock = mergerfs::fuse::flock;
2014-11-04 13:42:20 -05:00
#endif
ops.flush = mergerfs::fuse::flush;
ops.fsync = mergerfs::fuse::fsync;
2015-01-27 16:08:13 -05:00
ops.fsyncdir = NULL;
ops.ftruncate = mergerfs::fuse::ftruncate;
ops.getattr = mergerfs::fuse::getattr;
2015-01-27 16:08:13 -05:00
ops.getdir = NULL; /* deprecated; use readdir */
ops.getxattr = mergerfs::fuse::getxattr;
ops.init = mergerfs::fuse::init;
ops.ioctl = mergerfs::fuse::ioctl;
ops.link = mergerfs::fuse::link;
ops.listxattr = mergerfs::fuse::listxattr;
2015-01-27 16:08:13 -05:00
ops.lock = NULL;
ops.mkdir = mergerfs::fuse::mkdir;
ops.mknod = mergerfs::fuse::mknod;
ops.open = mergerfs::fuse::open;
ops.opendir = mergerfs::fuse::opendir;
2015-01-27 16:08:13 -05:00
ops.poll = NULL;
ops.read = direct_io ?
mergerfs::fuse::read_direct_io :
mergerfs::fuse::read;
2014-11-04 13:42:20 -05:00
#if READ_BUF
ops.read_buf = mergerfs::fuse::read_buf;
2014-11-04 13:42:20 -05:00
#endif
ops.readdir = mergerfs::fuse::readdir;
ops.readlink = mergerfs::fuse::readlink;
ops.release = mergerfs::fuse::release;
ops.releasedir = mergerfs::fuse::releasedir;
ops.removexattr = mergerfs::fuse::removexattr;
ops.rename = mergerfs::fuse::rename;
ops.rmdir = mergerfs::fuse::rmdir;
ops.setxattr = mergerfs::fuse::setxattr;
ops.statfs = mergerfs::fuse::statfs;
ops.symlink = mergerfs::fuse::symlink;
ops.truncate = mergerfs::fuse::truncate;
ops.unlink = mergerfs::fuse::unlink;
2015-01-27 16:08:13 -05:00
ops.utime = NULL; /* deprecated; use utimens() */
ops.utimens = mergerfs::fuse::utimens;
ops.write = direct_io ?
mergerfs::fuse::write_direct_io :
mergerfs::fuse::write;
2014-11-04 13:42:20 -05:00
#if WRITE_BUF
ops.write_buf = mergerfs::fuse::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-07-21 14:19:17 -04:00
fuse_args args;
fuse_operations ops = {0};
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,config.direct_io);
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
return mergerfs::main(argc,argv);
2014-05-12 12:41:46 -04:00
}