filearr.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include "dentry.hpp"
  3. #include "file.hpp"
  4. #include <memory>
  5. #include <types/path.hpp>
  6. #include <kernel/vfs.hpp>
  7. namespace fs {
  8. class filearray {
  9. private:
  10. struct impl;
  11. std::shared_ptr<impl> pimpl;
  12. filearray(std::shared_ptr<impl>);
  13. public:
  14. filearray(const fs_context* ctx);
  15. filearray(filearray&& other) = default;
  16. filearray copy() const;
  17. filearray share() const;
  18. // dup old_fd to some random fd
  19. int dup(int old_fd);
  20. // dup old_fd to new_fd, close new_fd if it is already open
  21. int dup(int old_fd, int new_fd, int flags);
  22. // dup old_fd to the first available fd starting from min_fd
  23. int dupfd(int fd, int min_fd, int flags);
  24. fs::file* operator[](int i) const;
  25. int set_flags(int fd, int flags);
  26. int pipe(int (&pipefd)[2]);
  27. int open(const dentry_pointer& cwd, types::string_view filepath, int flags,
  28. mode_t mode);
  29. int open(types::string_view filepath, int flags, mode_t mode);
  30. int close(int fd);
  31. // any call to member methods will be invalid after clear()
  32. void clear();
  33. void onexec();
  34. };
  35. } // namespace fs