#pragma once #include "fs/VFS.h" #include struct Descriptor { bool is_open() { return m_is_open; } bool can_read() { return m_can_read && m_is_open; } bool can_write() { return m_can_write && m_is_open; } void close() { m_is_open = false; } VFS::Node* node() { return m_node; } ssize_t read(size_t size, char* buffer); ssize_t write(size_t size, const char* buffer); ssize_t user_read(size_t size, char* buffer); ssize_t user_write(size_t size, const char* buffer); uintptr_t mmap(uintptr_t addr, size_t size, int prot, off_t offset); long ioctl(int cmd, uintptr_t arg); void open(VFS::Node* node, bool can_read, bool can_write, bool able_to_block, bool close_on_exec); int seek(long offset); long offset() { return (long)m_offset; } unsigned long length() { return m_node->length; } bool able_to_block() { return m_able_to_block; } bool close_on_exec() { return m_close_on_exec; } void set_close_on_exec(bool value) { m_close_on_exec = value; } Descriptor(const Descriptor& other); Descriptor(); const Descriptor& operator=(const Descriptor& other); private: bool m_is_open; bool m_can_read; bool m_can_write; bool m_able_to_block; bool m_close_on_exec; VFS::Node* m_node; uint64_t m_offset; };