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.

61 lines
1.7 KiB

  1. /*
  2. Copyright (c) 2019, 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. #pragma once
  15. #include "fuse.h"
  16. #include "tofrom_string.hpp"
  17. #include "fuse_readdir_base.hpp"
  18. #include <memory>
  19. #include <mutex>
  20. #include <assert.h>
  21. // The initialization behavior is not pretty but for the moment
  22. // needed due to the daemonizing function of the libfuse library when
  23. // not using foreground mode. The threads need to be created after the
  24. // fork, not before.
  25. namespace FUSE
  26. {
  27. int readdir(fuse_file_info_t const *ffi,
  28. fuse_dirents_t *buf);
  29. class ReadDir : public ToFromString
  30. {
  31. public:
  32. ReadDir(std::string const s_);
  33. public:
  34. std::string to_string() const;
  35. int from_string(const std::string &);
  36. public:
  37. int operator()(fuse_file_info_t const *ffi,
  38. fuse_dirents_t *buf);
  39. public:
  40. void initialize();
  41. private:
  42. mutable std::mutex _mutex;
  43. private:
  44. bool _initialized;
  45. std::string _type;
  46. std::shared_ptr<FUSE::ReadDirBase> _readdir;
  47. };
  48. }