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.

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