Virtual File System #10

Merged
apio merged 7 commits from vfs into main 2022-10-10 18:25:43 +00:00
2 changed files with 59 additions and 0 deletions
Showing only changes of commit 63b2de4e3c - Show all commits

View File

@ -0,0 +1,35 @@
#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:
uint64_t m_offset;
VFS::Node* m_node;
bool m_can_read;
bool m_is_open;
}

View File

@ -0,0 +1,24 @@
#include "fs/FileDescriptor.h"
Descriptor::Descriptor() : m_is_open(false)
{
}
Descriptor::Descriptor(const Descriptor& other)
: m_is_open(other.is_open()), m_can_read(other.can_read()), m_node(other.m_node), m_offset(other.m_offset)
{
}
void Descriptor::open(VFS::Node* node, bool can_read)
{
m_can_read = can_read;
m_node = node;
m_offset = 0;
}
ssize_t Descriptor::read(size_t size, char* buffer)
{
ssize_t result = VFS::read(m_node, m_offset, size, buffer);
m_offset += result;
return result;
}