diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-03 09:32:30 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-03 09:32:30 +0200 |
| commit | 3012fa5dfe5dfed5e83baf9b40934ed8e8317627 (patch) | |
| tree | 00d1c60a3d5d1cdfa55e0ff1691cd3362b6064ee /kernel/src/devices/storage/ram_disk | |
| parent | 5d8a58d538515ffc57ddf82ba40ba763990a8696 (diff) | |
| download | kernel-3012fa5dfe5dfed5e83baf9b40934ed8e8317627.tar.xz kernel-3012fa5dfe5dfed5e83baf9b40934ed8e8317627.zip | |
kernel: rearrange sources according to p1204
Diffstat (limited to 'kernel/src/devices/storage/ram_disk')
| -rw-r--r-- | kernel/src/devices/storage/ram_disk/controller.cpp | 27 | ||||
| -rw-r--r-- | kernel/src/devices/storage/ram_disk/device.cpp | 71 | ||||
| -rw-r--r-- | kernel/src/devices/storage/ram_disk/device.tests.cpp | 116 |
3 files changed, 0 insertions, 214 deletions
diff --git a/kernel/src/devices/storage/ram_disk/controller.cpp b/kernel/src/devices/storage/ram_disk/controller.cpp deleted file mode 100644 index 30441fa5..00000000 --- a/kernel/src/devices/storage/ram_disk/controller.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include <kernel/devices/storage/ram_disk/controller.hpp> - -#include <kernel/devices/storage/ram_disk/device.hpp> - -#include <kapi/boot_module/boot_module_registry.hpp> - -#include <kstd/memory> - -#include <algorithm> -#include <cstddef> - -namespace kernel::devices::storage::ram_disk -{ - controller::controller(kapi::boot_modules::boot_module_registry const * registry) - : m_boot_module_registry(registry) - {} - - auto controller::probe() -> void - { - size_t current_device_index = 0; - - std::ranges::for_each(*m_boot_module_registry, [this, ¤t_device_index](auto const & module) { - auto const minor = current_device_index++ * m_minors_per_device; - m_devices.push_back(kstd::make_shared<device>(module, m_major, minor)); - }); - } -} // namespace kernel::devices::storage::ram_disk
\ No newline at end of file diff --git a/kernel/src/devices/storage/ram_disk/device.cpp b/kernel/src/devices/storage/ram_disk/device.cpp deleted file mode 100644 index 1557204b..00000000 --- a/kernel/src/devices/storage/ram_disk/device.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include <kernel/devices/storage/ram_disk/device.hpp> - -#include <kernel/devices/block_device.hpp> - -#include <kapi/boot_module/boot_module.hpp> -#include <kapi/system.hpp> - -#include <kstd/cstring> -#include <kstd/string> - -#include <cstddef> - -namespace kernel::devices::storage::ram_disk -{ - namespace - { - constexpr size_t ram_disk_block_size = 512uz; - } // namespace - - device::device(kapi::boot_modules::boot_module const & module, size_t major, size_t minor) - : block_device(major, minor, "ram" + kstd::to_string(minor), ram_disk_block_size) - , m_boot_module(module) - {} - - auto device::init() -> bool - { - return m_boot_module.start_address.raw() != 0 && m_boot_module.size > 0; - } - - auto device::read_block(size_t block_index, void * buffer) const -> void - { - if (buffer == nullptr) - { - kapi::system::panic("[RAM DISK DEVICE] read_block called with null buffer."); - } - - auto const info = calculate_transfer(block_index); - - if (info.to_transfer > 0) - { - auto const src = static_cast<std::byte const *>(m_boot_module.start_address) + info.offset; - kstd::libc::memcpy(buffer, src, info.to_transfer); - } - - if (info.remainder > 0) - { - kstd::libc::memset(static_cast<std::byte *>(buffer) + info.to_transfer, 0, info.remainder); - } - } - - auto device::write_block(size_t block_index, void const * buffer) -> void - { - if (buffer == nullptr) - { - kapi::system::panic("[RAM DISK DEVICE] write_block called with null buffer."); - } - - auto const info = calculate_transfer(block_index); - - if (info.to_transfer > 0) - { - auto const dest = static_cast<std::byte *>(m_boot_module.start_address) + info.offset; - kstd::libc::memcpy(dest, buffer, info.to_transfer); - } - } - - auto device::size() const -> size_t - { - return m_boot_module.size; - } -} // namespace kernel::devices::storage::ram_disk
\ No newline at end of file diff --git a/kernel/src/devices/storage/ram_disk/device.tests.cpp b/kernel/src/devices/storage/ram_disk/device.tests.cpp deleted file mode 100644 index d0fab76b..00000000 --- a/kernel/src/devices/storage/ram_disk/device.tests.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include <kernel/devices/storage/ram_disk/device.hpp> - -#include <kapi/boot_module/boot_module.hpp> -#include <kapi/memory.hpp> - -#include <catch2/catch_test_macros.hpp> -#include <catch2/matchers/catch_matchers.hpp> -#include <catch2/matchers/catch_matchers_range_equals.hpp> - -#include <cstddef> -#include <ranges> -#include <stdexcept> -#include <vector> - -SCENARIO("RAM Disk Device Construction and Initialization", "[ram_disk_device]") -{ - GIVEN("an empty boot module") - { - kapi::boot_modules::boot_module boot_module{}; - boot_module.start_address = kapi::memory::linear_address{nullptr}; - boot_module.size = 0; - - WHEN("constructing the device") - { - kernel::devices::storage::ram_disk::device device{boot_module, 0, 0}; - - THEN("init return false") - { - REQUIRE_FALSE(device.init()); - } - } - } - - GIVEN("a boot module with a valid start address and size") - { - kapi::boot_modules::boot_module boot_module{}; - boot_module.start_address = kapi::memory::linear_address{reinterpret_cast<std::byte *>(0x1000)}; - boot_module.size = 512; - - WHEN("constructing the device") - { - kernel::devices::storage::ram_disk::device device{boot_module, 0, 0}; - - THEN("init return true") - { - REQUIRE(device.init()); - } - } - } -} - -SCENARIO("RAM Disk Device Read and Write", "[ram_disk_device]") -{ - GIVEN("a device initialized with a valid boot module") - { - auto storage = std::vector{4096, std::byte{0xff}}; - auto module = - kapi::boot_modules::boot_module{"test_module", kapi::memory::linear_address{storage.data()}, storage.size()}; - auto device = kernel::devices::storage::ram_disk::device{module, 0, 0}; - REQUIRE(device.init()); - - WHEN("reading a full block from the device") - { - auto buffer = std::vector<std::byte>(device.block_size()); - device.read_block(0, buffer.data()); - - THEN("the buffer is filled with the module data") - { - REQUIRE_THAT(buffer, Catch::Matchers::RangeEquals(std::views::take(storage, device.block_size()))); - } - } - - WHEN("reading from a block index beyond the module size") - { - auto buffer = std::vector<std::byte>(device.block_size()); - device.read_block(10, buffer.data()); - - THEN("the buffer is filled with zeros") - { - REQUIRE_THAT(buffer, Catch::Matchers::RangeEquals(std::vector<std::byte>(device.block_size(), std::byte{0}))); - } - } - - WHEN("reading into a null buffer") - { - REQUIRE_THROWS_AS(device.read_block(0, nullptr), std::runtime_error); - } - - WHEN("writing to a full block") - { - auto buffer = std::vector<std::byte>(device.block_size(), std::byte{0x01}); - device.write_block(0, buffer.data()); - - THEN("the module data is updated") - { - REQUIRE_THAT(std::views::take(storage, device.block_size()), Catch::Matchers::RangeEquals(buffer)); - } - } - - WHEN("writing to a block index beyond the module size") - { - auto buffer = std::vector<std::byte>(device.block_size(), std::byte{0x01}); - device.write_block(10, buffer.data()); - - THEN("the module data is not updated") - { - REQUIRE_THAT(storage, Catch::Matchers::RangeEquals(std::vector{4096, std::byte{0xff}})); - } - } - - WHEN("writing from a null buffer") - { - REQUIRE_THROWS_AS(device.write_block(0, nullptr), std::runtime_error); - } - } -}
\ No newline at end of file |
