apio
da2ede3450
Kernel: Implement a descriptor struct which stores the opened node and read offset, and give each task 8 of those. Implement three syscalls: sys_read, sys_open and sys_close (sys_write still writes to the console instead of using a fd, for now) Implement three new errors: ENOENT, EBADF and EMFILE. libc: Implement the new errors, and the new syscalls in syscall(). Also fix _RETURN_WITH_ERRNO() to set errno correctly, which was making strerror() return null, thus crashing perror(). userspace: make init demonstrate the new file API.
34 lines
516 B
C++
34 lines
516 B
C++
#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;
|
|
}
|
|
|
|
void close()
|
|
{
|
|
m_is_open = false;
|
|
}
|
|
|
|
ssize_t read(size_t size, char* buffer);
|
|
|
|
void open(VFS::Node* node, bool can_read);
|
|
|
|
Descriptor(const Descriptor& other);
|
|
Descriptor();
|
|
|
|
private:
|
|
bool m_is_open;
|
|
bool m_can_read;
|
|
VFS::Node* m_node;
|
|
uint64_t m_offset;
|
|
}; |