Virtual File System #10
35
kernel/include/fs/FileDescriptor.h
Normal file
35
kernel/include/fs/FileDescriptor.h
Normal 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;
|
||||
}
|
24
kernel/src/fs/FileDescriptor.cpp
Normal file
24
kernel/src/fs/FileDescriptor.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user