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.

194 lines
5.1 KiB

  1. /*
  2. Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include <fuse.h>
  15. #include <string.h>
  16. #include <cstdlib>
  17. #include <iostream>
  18. #include "mergerfs.hpp"
  19. #include "option_parser.hpp"
  20. #include "resources.hpp"
  21. #include "fs_path.hpp"
  22. #include "clone.hpp"
  23. #include "access.hpp"
  24. #include "chmod.hpp"
  25. #include "chown.hpp"
  26. #include "create.hpp"
  27. #include "destroy.hpp"
  28. #include "fallocate.hpp"
  29. #include "fgetattr.hpp"
  30. #include "flush.hpp"
  31. #include "fsync.hpp"
  32. #include "ftruncate.hpp"
  33. #include "getattr.hpp"
  34. #include "getxattr.hpp"
  35. #include "init.hpp"
  36. #include "ioctl.hpp"
  37. #include "link.hpp"
  38. #include "listxattr.hpp"
  39. #include "mkdir.hpp"
  40. #include "mknod.hpp"
  41. #include "open.hpp"
  42. #include "opendir.hpp"
  43. #include "read.hpp"
  44. #include "read_buf.hpp"
  45. #include "readdir.hpp"
  46. #include "readlink.hpp"
  47. #include "release.hpp"
  48. #include "releasedir.hpp"
  49. #include "removexattr.hpp"
  50. #include "rename.hpp"
  51. #include "rmdir.hpp"
  52. #include "setxattr.hpp"
  53. #include "statfs.hpp"
  54. #include "symlink.hpp"
  55. #include "truncate.hpp"
  56. #include "unlink.hpp"
  57. #include "utimens.hpp"
  58. #include "write.hpp"
  59. #include "write_buf.hpp"
  60. namespace local
  61. {
  62. static
  63. std::string
  64. getappname(const int argc,
  65. char * const *argv)
  66. {
  67. return fs::path::basename(argv[0]);
  68. }
  69. static
  70. void
  71. get_fuse_operations(struct fuse_operations &ops)
  72. {
  73. #if FLAG_NOPATH
  74. ops.flag_nopath = false;
  75. #endif
  76. ops.flag_nullpath_ok = false;
  77. ops.access = mergerfs::fuse::access;
  78. ops.bmap = NULL;
  79. ops.chmod = mergerfs::fuse::chmod;
  80. ops.chown = mergerfs::fuse::chown;
  81. ops.create = mergerfs::fuse::create;
  82. ops.destroy = mergerfs::fuse::destroy;
  83. #if FALLOCATE
  84. ops.fallocate = mergerfs::fuse::fallocate;
  85. #endif
  86. ops.fgetattr = mergerfs::fuse::fgetattr;
  87. #if FLOCK
  88. ops.flock = NULL;
  89. #endif
  90. ops.flush = mergerfs::fuse::flush;
  91. ops.fsync = mergerfs::fuse::fsync;
  92. ops.fsyncdir = NULL;
  93. ops.ftruncate = mergerfs::fuse::ftruncate;
  94. ops.getattr = mergerfs::fuse::getattr;
  95. ops.getdir = NULL; /* deprecated; use readdir */
  96. ops.getxattr = mergerfs::fuse::getxattr;
  97. ops.init = mergerfs::fuse::init;
  98. ops.ioctl = mergerfs::fuse::ioctl;
  99. ops.link = mergerfs::fuse::link;
  100. ops.listxattr = mergerfs::fuse::listxattr;
  101. ops.lock = NULL;
  102. ops.mkdir = mergerfs::fuse::mkdir;
  103. ops.mknod = mergerfs::fuse::mknod;
  104. ops.open = mergerfs::fuse::open;
  105. ops.opendir = mergerfs::fuse::opendir;
  106. ops.poll = NULL;
  107. ops.read = mergerfs::fuse::read;
  108. #if READ_BUF
  109. ops.read_buf = mergerfs::fuse::read_buf;
  110. #endif
  111. ops.readdir = mergerfs::fuse::readdir;
  112. ops.readlink = mergerfs::fuse::readlink;
  113. ops.release = mergerfs::fuse::release;
  114. ops.releasedir = mergerfs::fuse::releasedir;
  115. ops.removexattr = mergerfs::fuse::removexattr;
  116. ops.rename = mergerfs::fuse::rename;
  117. ops.rmdir = mergerfs::fuse::rmdir;
  118. ops.setxattr = mergerfs::fuse::setxattr;
  119. ops.statfs = mergerfs::fuse::statfs;
  120. ops.symlink = mergerfs::fuse::symlink;
  121. ops.truncate = mergerfs::fuse::truncate;
  122. ops.unlink = mergerfs::fuse::unlink;
  123. ops.utime = NULL; /* deprecated; use utimens() */
  124. ops.utimens = mergerfs::fuse::utimens;
  125. ops.write = mergerfs::fuse::write;
  126. #if WRITE_BUF
  127. ops.write_buf = mergerfs::fuse::write_buf;
  128. #endif
  129. return;
  130. }
  131. static
  132. void
  133. setup_resources(void)
  134. {
  135. const int prio = -10;
  136. std::srand(time(NULL));
  137. mergerfs::resources::reset_umask();
  138. mergerfs::resources::maxout_rlimit_nofile();
  139. mergerfs::resources::maxout_rlimit_fsize();
  140. mergerfs::resources::setpriority(prio);
  141. }
  142. }
  143. namespace mergerfs
  144. {
  145. int
  146. main(const int argc,
  147. char **argv)
  148. {
  149. fuse_args args;
  150. fuse_operations ops = {0};
  151. Config config;
  152. args.argc = argc;
  153. args.argv = argv;
  154. args.allocated = 0;
  155. mergerfs::options::parse(args,config);
  156. local::setup_resources();
  157. local::get_fuse_operations(ops);
  158. return fuse_main(args.argc,
  159. args.argv,
  160. &ops,
  161. &config);
  162. }
  163. }
  164. int
  165. main(int argc,
  166. char **argv)
  167. {
  168. std::string appname;
  169. appname = local::getappname(argc,argv);
  170. if(appname == "clone")
  171. return clonetool::main(argc,argv);
  172. return mergerfs::main(argc,argv);
  173. }