2022-10-10 17:00:24 +00:00
|
|
|
#pragma once
|
|
|
|
#include "fs/VFS.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
struct Descriptor
|
|
|
|
{
|
|
|
|
bool is_open()
|
|
|
|
{
|
|
|
|
return m_is_open;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool can_read()
|
|
|
|
{
|
|
|
|
return m_can_read && m_is_open;
|
|
|
|
}
|
|
|
|
|
2022-10-11 19:03:30 +00:00
|
|
|
bool can_write()
|
|
|
|
{
|
|
|
|
return m_can_write && m_is_open;
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:00:24 +00:00
|
|
|
void close()
|
|
|
|
{
|
|
|
|
m_is_open = false;
|
|
|
|
}
|
|
|
|
|
2022-10-21 16:34:31 +00:00
|
|
|
VFS::Node* node()
|
|
|
|
{
|
|
|
|
return m_node;
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:00:24 +00:00
|
|
|
ssize_t read(size_t size, char* buffer);
|
2022-10-11 19:03:30 +00:00
|
|
|
ssize_t write(size_t size, const char* buffer);
|
2022-10-10 17:00:24 +00:00
|
|
|
|
2022-11-02 19:24:07 +00:00
|
|
|
uintptr_t mmap(uintptr_t addr, size_t size, int prot, off_t offset);
|
|
|
|
|
2022-11-02 19:59:42 +00:00
|
|
|
long ioctl(int cmd, uintptr_t arg);
|
|
|
|
|
2022-10-22 08:28:02 +00:00
|
|
|
void open(VFS::Node* node, bool can_read, bool can_write, bool able_to_block, bool close_on_exec);
|
2022-10-10 17:00:24 +00:00
|
|
|
|
2022-10-12 13:28:52 +00:00
|
|
|
int seek(long offset);
|
|
|
|
long offset()
|
|
|
|
{
|
|
|
|
return (long)m_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long length()
|
|
|
|
{
|
|
|
|
return m_node->length;
|
|
|
|
}
|
|
|
|
|
2022-10-21 19:51:03 +00:00
|
|
|
bool able_to_block()
|
|
|
|
{
|
|
|
|
return m_able_to_block;
|
|
|
|
}
|
|
|
|
|
2022-10-22 08:28:02 +00:00
|
|
|
bool close_on_exec()
|
|
|
|
{
|
|
|
|
return m_close_on_exec;
|
|
|
|
}
|
|
|
|
|
2022-10-27 15:17:24 +00:00
|
|
|
void set_close_on_exec(bool value)
|
|
|
|
{
|
|
|
|
m_close_on_exec = value;
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:00:24 +00:00
|
|
|
Descriptor(const Descriptor& other);
|
|
|
|
Descriptor();
|
|
|
|
|
2022-10-15 09:16:18 +00:00
|
|
|
const Descriptor& operator=(const Descriptor& other);
|
|
|
|
|
2022-10-10 17:00:24 +00:00
|
|
|
private:
|
|
|
|
bool m_is_open;
|
2022-10-10 18:21:39 +00:00
|
|
|
bool m_can_read;
|
2022-10-11 19:03:30 +00:00
|
|
|
bool m_can_write;
|
2022-10-21 19:51:03 +00:00
|
|
|
bool m_able_to_block;
|
2022-10-22 08:28:02 +00:00
|
|
|
bool m_close_on_exec;
|
2022-10-10 18:21:39 +00:00
|
|
|
VFS::Node* m_node;
|
|
|
|
uint64_t m_offset;
|
|
|
|
};
|