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.

117 lines
3.0 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. #include <fuse.h>
  21. #include <string>
  22. #include <vector>
  23. #include <sys/types.h>
  24. #include <errno.h>
  25. #include <string.h>
  26. #include "config.hpp"
  27. #include "category.hpp"
  28. #include "fs.hpp"
  29. #include "ugid.hpp"
  30. #include "assert.hpp"
  31. #include "xattr.hpp"
  32. using std::string;
  33. using std::vector;
  34. using namespace mergerfs;
  35. static
  36. int
  37. _listxattr_controlfile(char *list,
  38. const size_t size)
  39. {
  40. size_t xattrssize;
  41. string xattrs;
  42. for(int i = Category::Enum::BEGIN; i < Category::Enum::END; ++i)
  43. xattrs += "user.mergerfs." + (string)Category::categories[i] + '\0';
  44. xattrssize = xattrs.size();
  45. if(size == 0)
  46. return xattrssize;
  47. if(size < xattrssize)
  48. return -ERANGE;
  49. memcpy(list,xattrs.data(),xattrssize);
  50. return xattrssize;
  51. }
  52. static
  53. int
  54. _listxattr(const fs::SearchFunc searchFunc,
  55. const vector<string> &srcmounts,
  56. const string fusepath,
  57. char *list,
  58. const size_t size)
  59. {
  60. #ifndef WITHOUT_XATTR
  61. int rv;
  62. fs::PathVector paths;
  63. searchFunc(srcmounts,fusepath,paths);
  64. if(paths.empty())
  65. return -ENOENT;
  66. rv = ::llistxattr(paths[0].full.c_str(),list,size);
  67. return ((rv == -1) ? -errno : rv);
  68. #else
  69. return -ENOTSUP;
  70. #endif
  71. }
  72. namespace mergerfs
  73. {
  74. namespace listxattr
  75. {
  76. int
  77. listxattr(const char *fusepath,
  78. char *list,
  79. size_t size)
  80. {
  81. const struct fuse_context *fc = fuse_get_context();
  82. const config::Config &config = config::get();
  83. const ugid::SetResetGuard ugid(fc->uid,fc->gid);
  84. if(fusepath == config.controlfile)
  85. return _listxattr_controlfile(list,
  86. size);
  87. return _listxattr(*config.search,
  88. config.srcmounts,
  89. fusepath,
  90. list,
  91. size);
  92. }
  93. }
  94. }