#pragma once #include #include #include #include #include namespace Kernel { class OpenFileDescriptorSet { BAN_NON_COPYABLE(OpenFileDescriptorSet); public: OpenFileDescriptorSet(const Credentials&); ~OpenFileDescriptorSet(); OpenFileDescriptorSet& operator=(OpenFileDescriptorSet&&); BAN::ErrorOr clone_from(const OpenFileDescriptorSet&); BAN::ErrorOr open(VirtualFileSystem::File&&, int flags); BAN::ErrorOr open(BAN::StringView absolute_path, int flags); BAN::ErrorOr socket(int domain, int type, int protocol); BAN::ErrorOr pipe(int fds[2]); BAN::ErrorOr dup(int); BAN::ErrorOr dup2(int, int); BAN::ErrorOr fcntl(int fd, int cmd, int extra); BAN::ErrorOr seek(int fd, off_t offset, int whence); BAN::ErrorOr tell(int) const; BAN::ErrorOr truncate(int fd, off_t length); BAN::ErrorOr close(int); void close_all(); void close_cloexec(); BAN::ErrorOr read(int fd, BAN::ByteSpan); BAN::ErrorOr write(int fd, BAN::ConstByteSpan); BAN::ErrorOr read_dir_entries(int fd, struct dirent* list, size_t list_len); BAN::ErrorOr file_of(int) const; BAN::ErrorOr path_of(int) const; BAN::ErrorOr> inode_of(int); BAN::ErrorOr flags_of(int) const; private: struct OpenFileDescription : public BAN::RefCounted { OpenFileDescription(VirtualFileSystem::File file, off_t offset, int flags) : file(BAN::move(file)) , offset(offset) , flags(flags) { } BAN::RefPtr inode() const { return file.inode; } BAN::StringView path() const { return file.canonical_path.sv(); } VirtualFileSystem::File file; off_t offset { 0 }; int flags { 0 }; friend class BAN::RefPtr; }; BAN::ErrorOr validate_fd(int) const; BAN::ErrorOr get_free_fd() const; BAN::ErrorOr get_free_fd_pair(int fds[2]) const; private: const Credentials& m_credentials; BAN::Array, OPEN_MAX> m_open_files; }; }