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.

139 lines
4.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. #ifndef __FUSEFUNC_HPP__
  21. #define __FUSEFUNC_HPP__
  22. #include <string>
  23. #include <vector>
  24. #include "category.hpp"
  25. namespace mergerfs
  26. {
  27. class FuseFunc
  28. {
  29. public:
  30. struct Enum
  31. {
  32. enum Type
  33. {
  34. invalid = -1,
  35. BEGIN = 0,
  36. access = BEGIN,
  37. chmod,
  38. chown,
  39. create,
  40. getattr,
  41. getxattr,
  42. link,
  43. listxattr,
  44. mkdir,
  45. mknod,
  46. open,
  47. readlink,
  48. removexattr,
  49. rename,
  50. rmdir,
  51. setxattr,
  52. symlink,
  53. truncate,
  54. unlink,
  55. utimens,
  56. END
  57. };
  58. };
  59. private:
  60. Enum::Type _enum;
  61. std::string _str;
  62. Category::Enum::Type _category;
  63. public:
  64. FuseFunc()
  65. : _enum(invalid),
  66. _str(invalid),
  67. _category(Category::Enum::invalid)
  68. {
  69. }
  70. FuseFunc(const Enum::Type enum_,
  71. const std::string &str_,
  72. const Category::Enum::Type category_)
  73. : _enum(enum_),
  74. _str(str_),
  75. _category(category_)
  76. {
  77. }
  78. public:
  79. operator const Enum::Type() const { return _enum; }
  80. operator const std::string&() const { return _str; }
  81. operator const Category::Enum::Type() const { return _category; }
  82. operator const FuseFunc*() const { return this; }
  83. bool operator==(const std::string &str_) const
  84. { return _str == str_; }
  85. bool operator==(const Enum::Type enum_) const
  86. { return _enum == enum_; }
  87. bool operator!=(const FuseFunc &r) const
  88. { return _enum != r._enum; }
  89. bool operator<(const FuseFunc &r) const
  90. { return _enum < r._enum; }
  91. public:
  92. static const FuseFunc &find(const std::string&);
  93. static const FuseFunc &find(const Enum::Type);
  94. public:
  95. static const std::vector<FuseFunc> _fusefuncs_;
  96. static const FuseFunc * const fusefuncs;
  97. static const FuseFunc &invalid;
  98. static const FuseFunc &access;
  99. static const FuseFunc &chmod;
  100. static const FuseFunc &chown;
  101. static const FuseFunc &create;
  102. static const FuseFunc &getattr;
  103. static const FuseFunc &getxattr;
  104. static const FuseFunc &link;
  105. static const FuseFunc &listxattr;
  106. static const FuseFunc &mkdir;
  107. static const FuseFunc &mknod;
  108. static const FuseFunc &open;
  109. static const FuseFunc &readlink;
  110. static const FuseFunc &removexattr;
  111. static const FuseFunc &rename;
  112. static const FuseFunc &rmdir;
  113. static const FuseFunc &setxattr;
  114. static const FuseFunc &symlink;
  115. static const FuseFunc &truncate;
  116. static const FuseFunc &unlink;
  117. static const FuseFunc &utimens;
  118. };
  119. }
  120. #endif