filearr.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <memory>
  3. #include <types/path.hpp>
  4. #include <kernel/vfs.hpp>
  5. #include "dentry.hpp"
  6. #include "file.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(dentry* cwd, types::path_iterator filepath, int flags, mode_t mode);
  28. int open(types::path_iterator filepath, int flags, mode_t mode);
  29. int close(int fd);
  30. // any call to member methods will be invalid after clear()
  31. void clear();
  32. void onexec();
  33. };
  34. } // namespace fs