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.

77 lines
2.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 <string>
  15. #include <vector>
  16. #include <fcntl.h>
  17. #include <unistd.h>
  18. #include "config.hpp"
  19. #include "errno.hpp"
  20. #include "fs_path.hpp"
  21. #include "rwlock.hpp"
  22. #include "ugid.hpp"
  23. using std::string;
  24. using std::vector;
  25. using mergerfs::Policy;
  26. using mergerfs::Category;
  27. static
  28. int
  29. _access(Policy::Func::Search searchFunc,
  30. const vector<string> &srcmounts,
  31. const uint64_t minfreespace,
  32. const char *fusepath,
  33. const int mask)
  34. {
  35. int rv;
  36. string fullpath;
  37. vector<const string*> basepaths;
  38. rv = searchFunc(srcmounts,fusepath,minfreespace,basepaths);
  39. if(rv == -1)
  40. return -errno;
  41. fs::path::make(basepaths[0],fusepath,fullpath);
  42. rv = ::faccessat(AT_FDCWD,fullpath.c_str(),mask,AT_EACCESS);
  43. return ((rv == -1) ? -errno : 0);
  44. }
  45. namespace mergerfs
  46. {
  47. namespace fuse
  48. {
  49. int
  50. access(const char *fusepath,
  51. int mask)
  52. {
  53. const fuse_context *fc = fuse_get_context();
  54. const Config &config = Config::get(fc);
  55. const ugid::Set ugid(fc->uid,fc->gid);
  56. const rwlock::ReadGuard readlock(&config.srcmountslock);
  57. return _access(config.access,
  58. config.srcmounts,
  59. config.minfreespace,
  60. fusepath,
  61. mask);
  62. }
  63. }
  64. }