#pragma once #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(BAN::StringView absolute_path, int flags); 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 fstat(int fd, struct stat*) const; BAN::ErrorOr fstatat(int fd, BAN::StringView path, struct stat* buf, int flag); BAN::ErrorOr stat(BAN::StringView absolute_path, struct stat* buf, int flag); BAN::ErrorOr close(int); void close_all(); void close_cloexec(); BAN::ErrorOr read(int fd, void* buffer, size_t count); BAN::ErrorOr write(int fd, const void* buffer, size_t count); BAN::ErrorOr read_dir_entries(int fd, DirectoryEntryList* list, size_t list_size); BAN::ErrorOr path_of(int) const; BAN::ErrorOr> inode_of(int); BAN::ErrorOr flags_of(int) const; private: struct OpenFileDescription : public BAN::RefCounted { OpenFileDescription(BAN::RefPtr inode, BAN::String path, off_t offset, int flags) : inode(inode) , path(BAN::move(path)) , offset(offset) , flags(flags) { } BAN::RefPtr inode; BAN::String path; 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; }; }