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.

187 lines
5.5 KiB

8 years ago
8 years ago
  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 "fs_path.hpp"
  19. #include "mergerfs.hpp"
  20. #include "option_parser.hpp"
  21. #include "resources.hpp"
  22. #include "access.hpp"
  23. #include "chmod.hpp"
  24. #include "chown.hpp"
  25. #include "create.hpp"
  26. #include "destroy.hpp"
  27. #include "fallocate.hpp"
  28. #include "fgetattr.hpp"
  29. #include "flock.hpp"
  30. #include "flush.hpp"
  31. #include "fsync.hpp"
  32. #include "fsyncdir.hpp"
  33. #include "ftruncate.hpp"
  34. #include "getattr.hpp"
  35. #include "getxattr.hpp"
  36. #include "init.hpp"
  37. #include "ioctl.hpp"
  38. #include "link.hpp"
  39. #include "listxattr.hpp"
  40. #include "mkdir.hpp"
  41. #include "mknod.hpp"
  42. #include "open.hpp"
  43. #include "opendir.hpp"
  44. #include "read.hpp"
  45. #include "read_buf.hpp"
  46. #include "readdir.hpp"
  47. #include "readlink.hpp"
  48. #include "release.hpp"
  49. #include "releasedir.hpp"
  50. #include "removexattr.hpp"
  51. #include "rename.hpp"
  52. #include "rmdir.hpp"
  53. #include "setxattr.hpp"
  54. #include "statfs.hpp"
  55. #include "symlink.hpp"
  56. #include "truncate.hpp"
  57. #include "unlink.hpp"
  58. #include "utimens.hpp"
  59. #include "write.hpp"
  60. #include "write_buf.hpp"
  61. namespace local
  62. {
  63. static
  64. void
  65. get_fuse_operations(struct fuse_operations &ops,
  66. const bool direct_io,
  67. const bool nullrw)
  68. {
  69. ops.flag_nullpath_ok = true;
  70. ops.flag_nopath = true;
  71. ops.flag_utime_omit_ok = true;
  72. ops.access = mergerfs::fuse::access;
  73. ops.bmap = NULL;
  74. ops.chmod = mergerfs::fuse::chmod;
  75. ops.chown = mergerfs::fuse::chown;
  76. ops.create = mergerfs::fuse::create;
  77. ops.destroy = mergerfs::fuse::destroy;
  78. ops.fallocate = mergerfs::fuse::fallocate;
  79. ops.fgetattr = mergerfs::fuse::fgetattr;
  80. ops.flock = mergerfs::fuse::flock;
  81. ops.flush = mergerfs::fuse::flush;
  82. ops.fsync = mergerfs::fuse::fsync;
  83. ops.fsyncdir = mergerfs::fuse::fsyncdir;
  84. ops.ftruncate = mergerfs::fuse::ftruncate;
  85. ops.getattr = mergerfs::fuse::getattr;
  86. ops.getdir = NULL; /* deprecated; use readdir */
  87. ops.getxattr = mergerfs::fuse::getxattr;
  88. ops.init = mergerfs::fuse::init;
  89. ops.ioctl = mergerfs::fuse::ioctl;
  90. ops.link = mergerfs::fuse::link;
  91. ops.listxattr = mergerfs::fuse::listxattr;
  92. ops.lock = NULL;
  93. ops.mkdir = mergerfs::fuse::mkdir;
  94. ops.mknod = mergerfs::fuse::mknod;
  95. ops.open = mergerfs::fuse::open;
  96. ops.opendir = mergerfs::fuse::opendir;
  97. ops.poll = NULL;
  98. ops.read = (nullrw ?
  99. mergerfs::fuse::read_null :
  100. (direct_io ?
  101. mergerfs::fuse::read_direct_io :
  102. mergerfs::fuse::read));
  103. ops.read_buf = (nullrw ?
  104. NULL :
  105. mergerfs::fuse::read_buf);
  106. ops.readdir = mergerfs::fuse::readdir;
  107. ops.readlink = mergerfs::fuse::readlink;
  108. ops.release = mergerfs::fuse::release;
  109. ops.releasedir = mergerfs::fuse::releasedir;
  110. ops.removexattr = mergerfs::fuse::removexattr;
  111. ops.rename = mergerfs::fuse::rename;
  112. ops.rmdir = mergerfs::fuse::rmdir;
  113. ops.setxattr = mergerfs::fuse::setxattr;
  114. ops.statfs = mergerfs::fuse::statfs;
  115. ops.symlink = mergerfs::fuse::symlink;
  116. ops.truncate = mergerfs::fuse::truncate;
  117. ops.unlink = mergerfs::fuse::unlink;
  118. ops.utime = NULL; /* deprecated; use utimens() */
  119. ops.utimens = mergerfs::fuse::utimens;
  120. ops.write = (nullrw ?
  121. mergerfs::fuse::write_null :
  122. (direct_io ?
  123. mergerfs::fuse::write_direct_io :
  124. mergerfs::fuse::write));
  125. ops.write_buf = (nullrw ?
  126. mergerfs::fuse::write_buf_null :
  127. mergerfs::fuse::write_buf);
  128. return;
  129. }
  130. static
  131. void
  132. setup_resources(void)
  133. {
  134. const int prio = -10;
  135. std::srand(time(NULL));
  136. mergerfs::resources::reset_umask();
  137. mergerfs::resources::maxout_rlimit_nofile();
  138. mergerfs::resources::maxout_rlimit_fsize();
  139. mergerfs::resources::setpriority(prio);
  140. }
  141. }
  142. namespace mergerfs
  143. {
  144. int
  145. main(const int argc,
  146. char **argv)
  147. {
  148. fuse_args args;
  149. fuse_operations ops = {0};
  150. Config config;
  151. args.argc = argc;
  152. args.argv = argv;
  153. args.allocated = 0;
  154. mergerfs::options::parse(args,config);
  155. local::setup_resources();
  156. local::get_fuse_operations(ops,
  157. config.direct_io,
  158. config.nullrw);
  159. return fuse_main(args.argc,
  160. args.argv,
  161. &ops,
  162. &config);
  163. }
  164. }
  165. int
  166. main(int argc,
  167. char **argv)
  168. {
  169. return mergerfs::main(argc,argv);
  170. }