From 604c2a843d95921e0429ebbdd5849174e47a9547 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 16 Jul 2026 17:30:17 +0200 Subject: kernel: begin block device re-architecture work --- kapi/kapi/devices.hpp | 1 + kapi/kapi/devices/block_device.hpp | 51 ++++++++++++++++++++++++++++++++++++++ kapi/kapi/devices/device.hpp | 6 ----- kapi/kapi/filesystem.hpp | 6 +++-- 4 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 kapi/kapi/devices/block_device.hpp (limited to 'kapi') diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp index 64820f7c..989ca0fa 100644 --- a/kapi/kapi/devices.hpp +++ b/kapi/kapi/devices.hpp @@ -1,6 +1,7 @@ #ifndef TEACHOS_KAPI_DEVICES_HPP #define TEACHOS_KAPI_DEVICES_HPP +#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export diff --git a/kapi/kapi/devices/block_device.hpp b/kapi/kapi/devices/block_device.hpp new file mode 100644 index 00000000..4b3eab61 --- /dev/null +++ b/kapi/kapi/devices/block_device.hpp @@ -0,0 +1,51 @@ +#ifndef TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP +#define TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP + +// IWYU pragma: private, include + +#include + +#include +#include + +#include + +namespace kapi::devices +{ + + struct block_device + { + constexpr auto static id = interface{"block"}; + + //! Virtual destructor to enable clean deletes through base pointers. + virtual ~block_device() = default; + + //! Read data from a block into a given buffer. + //! + //! If the selected block is smaller than the buffer, a partial read will occur. + //! + //! @param block_index The number of the block to read from. + //! @param buffer The buffer to read into. + //! @return The number of bytes read on success, an error otherwise. + [[nodiscard]] auto virtual read_block(size_t block_index, void * buffer) const + -> kstd::result = 0; + + //! Write data from a buffer into a block. + //! + //! If the buffer is larger than the selected block, a partial write will occur. + //! + //! @param block_index The number of the block to write to. + //! @param buffer The buffer to write from. + //! @return The number of bytes written on success, an error otherwise. + auto virtual write_block(std::size_t block_index, void const * buffer) -> kstd::result = 0; + + //! Get the block size in bytes. + [[nodiscard]] auto virtual block_size() const -> kstd::units::bytes = 0; + + //! Get the capacity of the associated device. + [[nodiscard]] auto virtual capacity() const -> kstd::units::bytes = 0; + }; + +} // namespace kapi::devices + +#endif \ No newline at end of file diff --git a/kapi/kapi/devices/device.hpp b/kapi/kapi/devices/device.hpp index e99dd5f8..bf91dfcf 100644 --- a/kapi/kapi/devices/device.hpp +++ b/kapi/kapi/devices/device.hpp @@ -76,12 +76,6 @@ namespace kapi::devices */ [[nodiscard]] auto name() const -> kstd::string const &; - /** - * @brief Check if the device is a block device. - * @return true if this device is a block device, false otherwise. - */ - [[nodiscard]] virtual auto is_block_device() const -> bool; - protected: auto virtual query_interface(interface interface) -> void *; diff --git a/kapi/kapi/filesystem.hpp b/kapi/kapi/filesystem.hpp index 0f092d29..f293692d 100644 --- a/kapi/kapi/filesystem.hpp +++ b/kapi/kapi/filesystem.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -50,14 +51,15 @@ namespace kapi::filesystem //! @param file_descriptor The file descriptor to read from. //! @param buffer The buffer to store the read data. //! @return The number of bytes read on success, an error code otherwise. - auto read(size_t file_descriptor, std::span buffer) -> std::expected; + auto read(size_t file_descriptor, std::span buffer) -> std::expected; //! Write bytes from a given buffer to a file descriptor. //! //! @param file_descriptor The file descriptor to write to. //! @param buffer The buffer containing the data to write. //! @return The number of bytes written on success, an error code otherwise. - auto write(size_t file_descriptor, std::span buffer) -> std::expected; + auto write(size_t file_descriptor, std::span buffer) + -> std::expected; //! Create a new directory at the specified path. //! -- cgit v1.2.3