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.

87 lines
2.4 KiB

  1. /*
  2. The MIT License (MIT)
  3. Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #ifndef _GNU_SOURCE
  21. #define _GNU_SOURCE
  22. #endif
  23. #include <fuse.h>
  24. #include <string>
  25. #include <vector>
  26. #include <unistd.h>
  27. #include <errno.h>
  28. #include "ugid.hpp"
  29. #include "fs.hpp"
  30. #include "config.hpp"
  31. #include "rwlock.hpp"
  32. using std::string;
  33. using std::vector;
  34. using mergerfs::Policy;
  35. using mergerfs::Category;
  36. static
  37. int
  38. _access(Policy::Func::Search searchFunc,
  39. const vector<string> &srcmounts,
  40. const size_t minfreespace,
  41. const string &fusepath,
  42. const int mask)
  43. {
  44. int rv;
  45. Paths paths;
  46. rv = searchFunc(srcmounts,fusepath,minfreespace,paths);
  47. if(rv == -1)
  48. return -errno;
  49. rv = ::eaccess(paths[0].full.c_str(),mask);
  50. return ((rv == -1) ? -errno : 0);
  51. }
  52. namespace mergerfs
  53. {
  54. namespace access
  55. {
  56. int
  57. access(const char *fusepath,
  58. int mask)
  59. {
  60. const struct fuse_context *fc = fuse_get_context();
  61. const config::Config &config = config::get();
  62. const ugid::SetResetGuard ugid(fc->uid,fc->gid);
  63. const rwlock::ReadGuard readlock(&config.srcmountslock);
  64. return _access(config.access,
  65. config.srcmounts,
  66. config.minfreespace,
  67. fusepath,
  68. mask);
  69. }
  70. }
  71. }