Kernel: Rework filesystem reading

We now read from a filesystem to user provided buffer.

Read sizes are determined by read call.

You should now get file descriptors and do reading through Process::current()
This commit is contained in:
Bananymous
2023-03-17 21:16:22 +02:00
parent ceb53533be
commit 1a26a318a4
11 changed files with 359 additions and 113 deletions

View File

@@ -131,12 +131,13 @@ namespace Kernel
virtual BAN::StringView name() const override { return m_name; }
virtual BAN::ErrorOr<BAN::Vector<uint8_t>> read_all() override;
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
virtual BAN::ErrorOr<BAN::Vector<BAN::RefPtr<Inode>>> directory_inodes() override;
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find(BAN::StringView) override;
private:
BAN::ErrorOr<void> for_each_block(BAN::Function<BAN::ErrorOr<bool>(const BAN::Vector<uint8_t>&)>&);
using block_callback_t = BAN::ErrorOr<bool>(*)(const BAN::Vector<uint8_t>&, void*);
BAN::ErrorOr<void> for_each_block(block_callback_t, void*);
private:
Ext2Inode() {}

View File

@@ -36,6 +36,8 @@ namespace Kernel
};
public:
virtual ~Inode() {}
bool ifdir() const { return mode().IFDIR; }
bool ifreg() const { return mode().IFREG; }
@@ -47,7 +49,7 @@ namespace Kernel
virtual BAN::StringView name() const = 0;
virtual BAN::ErrorOr<BAN::Vector<uint8_t>> read_all() = 0;
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) = 0;
virtual BAN::ErrorOr<BAN::Vector<BAN::RefPtr<Inode>>> directory_inodes() = 0;
virtual BAN::ErrorOr<BAN::RefPtr<Inode>> directory_find(BAN::StringView) = 0;
};

View File

@@ -15,19 +15,22 @@ namespace Kernel
static VirtualFileSystem& get();
virtual ~VirtualFileSystem() {};
virtual const BAN::RefPtr<Inode> root_inode() const override;
virtual const BAN::RefPtr<Inode> root_inode() const override { return m_root_inode; }
void close_inode(BAN::StringView);
BAN::ErrorOr<BAN::RefPtr<Inode>> from_absolute_path(BAN::StringView);
struct File
{
BAN::RefPtr<Inode> inode;
BAN::String canonical_path;
};
BAN::ErrorOr<File> file_from_absolute_path(BAN::StringView);
private:
VirtualFileSystem() = default;
BAN::ErrorOr<void> initialize_impl();
private:
BAN::HashMap<BAN::String, BAN::RefPtr<Inode>> m_open_inodes;
BAN::Vector<StorageController*> m_storage_controllers;
BAN::RefPtr<Inode> m_root_inode;
BAN::Vector<StorageController*> m_storage_controllers;
};
}

View File

@@ -1,7 +1,9 @@
#pragma once
#include <BAN/String.h>
#include <BAN/StringView.h>
#include <BAN/Vector.h>
#include <kernel/FS/Inode.h>
#include <kernel/Thread.h>
namespace Kernel
@@ -24,12 +26,39 @@ namespace Kernel
pid_t pid() const { return m_pid; }
BAN::ErrorOr<int> open(BAN::StringView, int);
BAN::ErrorOr<void> close(int);
BAN::ErrorOr<size_t> read(int, void*, size_t);
BAN::StringView working_directory() const { return m_working_directory; }
BAN::ErrorOr<void> set_working_directory(BAN::StringView);
Inode& inode_for_fd(int);
static BAN::RefPtr<Process> current() { return Thread::current()->process(); }
private:
Process(pid_t pid) : m_pid(pid) {}
BAN::ErrorOr<BAN::String> absolute_path_of(BAN::StringView) const;
private:
struct OpenFileDescription
{
BAN::RefPtr<Inode> inode;
BAN::String path;
size_t offset = 0;
uint8_t flags = 0;
BAN::ErrorOr<size_t> read(void*, size_t);
};
BAN::ErrorOr<void> validate_fd(int);
OpenFileDescription& open_file_description(int);
BAN::ErrorOr<int> get_free_fd();
BAN::Vector<OpenFileDescription> m_open_files;
pid_t m_pid = 0;
BAN::String m_working_directory;
BAN::Vector<BAN::RefPtr<Thread>> m_threads;

View File

@@ -13,7 +13,7 @@ namespace Kernel
public:
Shell(TTY*);
Shell(const Shell&) = delete;
void set_prompt(BAN::StringView);
BAN::ErrorOr<void> set_prompt(BAN::StringView);
void run();
private:
@@ -21,11 +21,13 @@ namespace Kernel
BAN::Vector<BAN::String> parse_arguments(BAN::StringView) const;
BAN::ErrorOr<void> process_command(const BAN::Vector<BAN::String>&);
void key_event_callback(Input::KeyEvent);
BAN::ErrorOr<void> update_prompt();
private:
TTY* m_tty;
BAN::Vector<BAN::String> m_old_buffer;
BAN::Vector<BAN::String> m_buffer;
BAN::String m_prompt_string;
BAN::String m_prompt;
uint32_t m_prompt_length = 0;