aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-16 17:30:17 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-16 17:30:17 +0200
commit604c2a843d95921e0429ebbdd5849174e47a9547 (patch)
tree79adbeeb843926c2a60bbc8b645cf073c8a3f1f1 /kapi
parenta6166befa7421be233ece97e184139870bbc0af7 (diff)
downloadkernel-604c2a843d95921e0429ebbdd5849174e47a9547.tar.xz
kernel-604c2a843d95921e0429ebbdd5849174e47a9547.zip
kernel: begin block device re-architecture work
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/devices.hpp1
-rw-r--r--kapi/kapi/devices/block_device.hpp51
-rw-r--r--kapi/kapi/devices/device.hpp6
-rw-r--r--kapi/kapi/filesystem.hpp6
4 files changed, 56 insertions, 8 deletions
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 <kapi/devices/block_device.hpp> // IWYU pragma: export
#include <kapi/devices/bus.hpp> // IWYU pragma: export
#include <kapi/devices/cpu.hpp> // IWYU pragma: export
#include <kapi/devices/device.hpp> // 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 <kapi/devices.hpp>
+
+#include <kapi/devices/interface.hpp>
+
+#include <kstd/result.hpp>
+#include <kstd/units.hpp>
+
+#include <cstddef>
+
+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<kstd::units::bytes> = 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<kstd::units::bytes> = 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 <kstd/result.hpp>
#include <kstd/system_error.hpp>
+#include <kstd/units.hpp>
#include <cstddef>
#include <expected>
@@ -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<std::byte> buffer) -> std::expected<std::size_t, kstd::error_code>;
+ auto read(size_t file_descriptor, std::span<std::byte> buffer) -> std::expected<kstd::units::bytes, kstd::error_code>;
//! 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<std::byte const> buffer) -> std::expected<std::size_t, kstd::error_code>;
+ auto write(size_t file_descriptor, std::span<std::byte const> buffer)
+ -> std::expected<kstd::units::bytes, kstd::error_code>;
//! Create a new directory at the specified path.
//!