summaryrefslogtreecommitdiff
path: root/include/hilbert/kernel/storage.hpp
diff options
context:
space:
mode:
authorBenji Dial <benji@benjidial.net>2024-01-15 15:44:20 -0500
committerBenji Dial <benji@benjidial.net>2024-01-15 15:44:20 -0500
commitc9a1266d219a83882735a3a8304f3824e0219cdb (patch)
treefea71a0b5b0de8f3a8962dc6ed417273f231e2a9 /include/hilbert/kernel/storage.hpp
parent7c6a18d77a81f232ad2e1d3a311bb21ea8f1f5b4 (diff)
downloadhilbert-os-c9a1266d219a83882735a3a8304f3824e0219cdb.tar.gz
redo application paging and system calls, rename mercury to hilbert
Diffstat (limited to 'include/hilbert/kernel/storage.hpp')
-rw-r--r--include/hilbert/kernel/storage.hpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/include/hilbert/kernel/storage.hpp b/include/hilbert/kernel/storage.hpp
new file mode 100644
index 0000000..ea40d86
--- /dev/null
+++ b/include/hilbert/kernel/storage.hpp
@@ -0,0 +1,104 @@
+#ifndef HILBERT_KERNEL_STORAGE_HPP
+#define HILBERT_KERNEL_STORAGE_HPP
+
+#include <hilbert/kernel/utility.hpp>
+#include <cstdint>
+
+namespace hilbert::kernel::storage {
+
+ typedef uint64_t node_id_t;
+ typedef uint64_t directory_iter_t;
+
+ enum class file_type {
+ regular_file,
+ directory,
+ symlink
+ };
+
+ enum class bd_result {
+ success,
+ out_of_bounds,
+ device_error
+ };
+
+ enum class fs_result {
+ success,
+ device_error,
+ fs_corrupt
+ };
+
+ struct dir_entry {
+ utility::string name;
+ node_id_t node;
+ file_type type;
+ //only used if type is regular_file.
+ uint64_t length;
+ //only used if type is symlink.
+ utility::string target;
+ };
+
+ class file_system_instance {
+
+ public:
+ virtual ~file_system_instance() {}
+
+ virtual fs_result get_root_node(node_id_t &out) = 0;
+
+ //it is assumed that this is a directory. sets iter_out
+ //to a value that can be passed to subsequent calls
+ //to get_next_child with the same argument for node.
+ virtual fs_result get_first_child(node_id_t node, std::optional<dir_entry> &out, directory_iter_t &iter_out) = 0;
+
+ //it is assumed that this is a directory. sets iter_out
+ //to a value that can be passed to subsequent calls
+ //to get_next_child with the same argument for node.
+ virtual fs_result get_next_child(node_id_t node, std::optional<dir_entry> &out, directory_iter_t &iter) = 0;
+
+ //it is assumed that this is a regular file and that
+ //the region requested is within the bounds of the file.
+ virtual fs_result read_bytes_from_file(node_id_t node, uint64_t start, uint64_t count, void *into) = 0;
+
+ };
+
+ class block_device {
+
+ private:
+ uint8_t *block_cache;
+ uint64_t block_cache_i;
+
+ //it is assumed that this block is within the bounds of the device.
+ bd_result load_cache_block(uint64_t i);
+
+ protected:
+ //implemented in driver. it is assumed that the
+ //blocks are within the bounds of the device.
+ virtual bd_result read_blocks_no_cache(uint64_t start, uint64_t count, void *into) = 0;
+
+ //it is assumed that this is only called once, by the driver, after
+ //block_size and block_count have been set, and before read_bytes or
+ //write_bytes can be called (e.g. in the derived class's constructor).
+ void allocate_block_cache();
+
+ public:
+ //set by storage component
+ file_system_instance *mounted_as;
+ //set by storage component
+ utility::uuid id;
+
+ //set by driver
+ uint64_t block_size;
+ //set by driver
+ uint64_t block_count;
+
+ virtual ~block_device() {
+ if (block_cache)
+ delete block_cache;
+ }
+
+ bd_result read_bytes(uint64_t start, uint64_t count, void *into);
+
+ };
+
+}
+
+#endif