aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-15 15:47:23 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-15 15:47:23 +0200
commit3130556cdab078de5db6fabdf6f2d57c05ced08a (patch)
tree90499c51c1082f294fbbd8afcf880d80e7fdff92 /kernel
parentda1fac36310716f45029f4f1f0bac4d54c9e0e54 (diff)
downloadkernel-3130556cdab078de5db6fabdf6f2d57c05ced08a.tar.xz
kernel-3130556cdab078de5db6fabdf6f2d57c05ced08a.zip
kernel: rework ramdisk numbering
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kapi/filesystem.tests.cpp10
-rw-r--r--kernel/kernel/devices/storage/ram_disk/controller.cpp4
-rw-r--r--kernel/kernel/devices/storage/ram_disk/device.cpp5
-rw-r--r--kernel/kernel/devices/storage/ram_disk/device.hpp2
-rw-r--r--kernel/kernel/devices/storage/ram_disk/device.tests.cpp6
-rw-r--r--kernel/kernel/filesystem/devfs/filesystem.tests.cpp4
-rw-r--r--kernel/kernel/filesystem/vfs.tests.cpp26
-rw-r--r--kernel/kernel/main.cpp16
8 files changed, 37 insertions, 36 deletions
diff --git a/kernel/kapi/filesystem.tests.cpp b/kernel/kapi/filesystem.tests.cpp
index afd43d97..ffd8d7f6 100644
--- a/kernel/kapi/filesystem.tests.cpp
+++ b/kernel/kapi/filesystem.tests.cpp
@@ -113,7 +113,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
THEN("a filesystem can be mounted, files can be opened, read and closed again and unmounted")
{
- REQUIRE(kapi::filesystem::mount("/dev/ram16", "/information"));
+ REQUIRE(kapi::filesystem::mount("/dev/ram1", "/information"));
auto fd = kapi::filesystem::open("/information/monkey_house/monkey_1.txt").value();
@@ -130,7 +130,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
THEN("a filesystem cannot be unmounted if files are still open and can be unmounted after files are closed")
{
- REQUIRE(kapi::filesystem::mount("/dev/ram16", "/information"));
+ REQUIRE(kapi::filesystem::mount("/dev/ram1", "/information"));
auto fd = kapi::filesystem::open("/information/monkey_house/monkey_1.txt").value();
@@ -153,13 +153,13 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
THEN("device can be opened as file and written to and read from again")
{
- auto read_fd = kapi::filesystem::open("/dev/ram16").value();
+ auto read_fd = kapi::filesystem::open("/dev/ram1").value();
auto buffer = std::vector<std::byte>(512, std::byte{0xAB});
auto bytes_written = kapi::filesystem::write(read_fd, buffer);
REQUIRE(bytes_written);
- auto write_fd = kapi::filesystem::open("/dev/ram16").value();
+ auto write_fd = kapi::filesystem::open("/dev/ram1").value();
auto read_buffer = std::vector<std::byte>(512);
auto bytes_read = kapi::filesystem::read(write_fd, read_buffer);
@@ -261,7 +261,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "Kap
THEN("a file can be created in a mounted filesystem, opened, and closed again")
{
- CHECK(kapi::filesystem::mount("/dev/ram16", "/information"));
+ CHECK(kapi::filesystem::mount("/dev/ram1", "/information"));
auto new_file_path = "/information/monkey_house/monkey_4.txt";
REQUIRE(!kapi::filesystem::open(new_file_path));
diff --git a/kernel/kernel/devices/storage/ram_disk/controller.cpp b/kernel/kernel/devices/storage/ram_disk/controller.cpp
index c1075733..c260e1cd 100644
--- a/kernel/kernel/devices/storage/ram_disk/controller.cpp
+++ b/kernel/kernel/devices/storage/ram_disk/controller.cpp
@@ -20,8 +20,8 @@ namespace kernel::devices::storage::ram_disk
size_t current_device_index = 0;
std::ranges::for_each(*m_boot_module_registry, [this, &current_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));
+ auto const minor = current_device_index++;
+ m_devices.push_back(kstd::make_shared<device>(module, m_major, minor, minor));
});
}
} // namespace kernel::devices::storage::ram_disk \ No newline at end of file
diff --git a/kernel/kernel/devices/storage/ram_disk/device.cpp b/kernel/kernel/devices/storage/ram_disk/device.cpp
index 1b53b0d3..2b1c02a2 100644
--- a/kernel/kernel/devices/storage/ram_disk/device.cpp
+++ b/kernel/kernel/devices/storage/ram_disk/device.cpp
@@ -6,6 +6,7 @@
#include <kapi/system.hpp>
#include <kstd/cstring.hpp>
+#include <kstd/format.hpp>
#include <kstd/string.hpp>
#include <cstddef>
@@ -17,8 +18,8 @@ namespace kernel::devices::storage::ram_disk
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)
+ device::device(kapi::boot_modules::boot_module const & module, size_t major, size_t minor, std::size_t device_index)
+ : block_device(major, minor, kstd::format("ram{}", device_index), ram_disk_block_size)
, m_boot_module(module)
{}
diff --git a/kernel/kernel/devices/storage/ram_disk/device.hpp b/kernel/kernel/devices/storage/ram_disk/device.hpp
index 89789ea9..cd62a1ec 100644
--- a/kernel/kernel/devices/storage/ram_disk/device.hpp
+++ b/kernel/kernel/devices/storage/ram_disk/device.hpp
@@ -20,7 +20,7 @@ namespace kernel::devices::storage::ram_disk
* @param major Device major number.
* @param minor Device minor number.
*/
- device(kapi::boot_modules::boot_module const & module, size_t major, size_t minor);
+ device(kapi::boot_modules::boot_module const & module, size_t major, size_t minor, std::size_t device_index);
/**
* @brief Initialize the RAM disk device.
diff --git a/kernel/kernel/devices/storage/ram_disk/device.tests.cpp b/kernel/kernel/devices/storage/ram_disk/device.tests.cpp
index d0fab76b..988c2d38 100644
--- a/kernel/kernel/devices/storage/ram_disk/device.tests.cpp
+++ b/kernel/kernel/devices/storage/ram_disk/device.tests.cpp
@@ -22,7 +22,7 @@ SCENARIO("RAM Disk Device Construction and Initialization", "[ram_disk_device]")
WHEN("constructing the device")
{
- kernel::devices::storage::ram_disk::device device{boot_module, 0, 0};
+ kernel::devices::storage::ram_disk::device device{boot_module, 0, 0, 0};
THEN("init return false")
{
@@ -39,7 +39,7 @@ SCENARIO("RAM Disk Device Construction and Initialization", "[ram_disk_device]")
WHEN("constructing the device")
{
- kernel::devices::storage::ram_disk::device device{boot_module, 0, 0};
+ kernel::devices::storage::ram_disk::device device{boot_module, 0, 0, 0};
THEN("init return true")
{
@@ -56,7 +56,7 @@ SCENARIO("RAM Disk Device Read and Write", "[ram_disk_device]")
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};
+ auto device = kernel::devices::storage::ram_disk::device{module, 0, 0, 0};
REQUIRE(device.init());
WHEN("reading a full block from the device")
diff --git a/kernel/kernel/filesystem/devfs/filesystem.tests.cpp b/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
index c1aad37c..1028b6ba 100644
--- a/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
+++ b/kernel/kernel/filesystem/devfs/filesystem.tests.cpp
@@ -72,8 +72,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_fixture,
THEN("lookup finds all generated RAM devices")
{
REQUIRE(fs.lookup(fs.root_inode(), "ram0"));
- REQUIRE(fs.lookup(fs.root_inode(), "ram16"));
- REQUIRE(fs.lookup(fs.root_inode(), "ram32"));
+ REQUIRE(fs.lookup(fs.root_inode(), "ram1"));
+ REQUIRE(fs.lookup(fs.root_inode(), "ram2"));
}
}
}
diff --git a/kernel/kernel/filesystem/vfs.tests.cpp b/kernel/kernel/filesystem/vfs.tests.cpp
index ace1bd1f..c70c13c8 100644
--- a/kernel/kernel/filesystem/vfs.tests.cpp
+++ b/kernel/kernel/filesystem/vfs.tests.cpp
@@ -104,7 +104,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("second image can be mounted, data retrieved and unmounted again")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
auto mounted_monkey_1 = vfs.open("/information/monkey_house/monkey_1.txt");
REQUIRE(mounted_monkey_1);
@@ -120,8 +120,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("third image can be mounted in a mounted file system, unmount only if no child mount exists")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
- REQUIRE(vfs.mount("/dev/ram32", "/information/monkey_house/infrastructure"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
+ REQUIRE(vfs.mount("/dev/ram2", "/information/monkey_house/infrastructure"));
auto mounted_monkey_1 = vfs.open("/information/monkey_house/monkey_1.txt");
auto mounted_fish1 = vfs.open("/information/monkey_house/infrastructure/enclosures/aquarium/tank_1/fish_1.txt");
@@ -139,7 +139,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("image can be mounted, unmount only if no files are open")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
auto mounted_monkey_1 = vfs.open("/information/monkey_house/monkey_1.txt");
REQUIRE(mounted_monkey_1);
@@ -168,8 +168,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("images can be stacked mounted and correct file system is unmounted again")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
- REQUIRE(vfs.mount("/dev/ram32", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
+ REQUIRE(vfs.mount("/dev/ram2", "/information"));
auto mounted_tickets = vfs.open("/information/entrance/tickets.txt");
REQUIRE(mounted_tickets);
@@ -189,7 +189,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
auto info_1 = vfs.open("/information/info_1.txt");
REQUIRE(info_1 != nullptr);
- REQUIRE(vfs.mount("/dev/ram16", "/"));
+ REQUIRE(vfs.mount("/dev/ram1", "/"));
info_1 = vfs.open("/information/info_1.txt");
REQUIRE(info_1.error() == kstd::errc::no_such_file_or_directory);
@@ -210,7 +210,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
auto info_1 = vfs.open("/information/info_1.txt");
REQUIRE(info_1 != nullptr);
- REQUIRE(vfs.mount("/dev/ram16", "/"));
+ REQUIRE(vfs.mount("/dev/ram1", "/"));
info_1 = vfs.open("/information/info_1.txt");
REQUIRE(info_1.error() == kstd::errc::no_such_file_or_directory);
@@ -302,7 +302,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("a file can be accessed over multiple mounts if path contains .. or . ")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
auto img = vfs.open("/information/monkey_house/caretaker/../../../../../../archiv/2024.img");
REQUIRE(img != nullptr);
@@ -316,7 +316,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("a file can be accessed over multiple mounts (device and file) if path contains .. ")
{
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
REQUIRE(vfs.mount("/archiv/2024.img", "/information/monkey_house/infrastructure"));
auto pig_1 = vfs.open("/information/monkey_house/infrastructure/stable/pig_1.txt");
@@ -463,7 +463,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("cannot unmount a filesystem if files are mounted")
{
- REQUIRE(vfs.mount("/dev/ram16", "/entrance"));
+ REQUIRE(vfs.mount("/dev/ram1", "/entrance"));
REQUIRE(vfs.mount("/entrance/archiv/2024.img", "/enclosures"));
REQUIRE(vfs.unmount("/entrance").error() == kstd::errc::device_or_resource_busy);
@@ -473,7 +473,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
THEN("can mount filesystem onto the directory that contains it")
{
- REQUIRE(vfs.mount("/dev/ram16", "/entrance"));
+ REQUIRE(vfs.mount("/dev/ram1", "/entrance"));
REQUIRE(vfs.mount("/entrance/archiv/2024.img", "/entrance"));
REQUIRE(vfs.unmount("/entrance"));
@@ -566,7 +566,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS
setup_modules_from_img_and_init_vfs({"test_img_module_1", "test_img_module_2"}, {image_path_1, image_path_2}));
auto & vfs = kernel::filesystem::vfs::get();
- REQUIRE(vfs.mount("/dev/ram16", "/information"));
+ REQUIRE(vfs.mount("/dev/ram1", "/information"));
THEN("file can be opened through symbolic link pointing to the parent filesystem and back into the mounted "
"filesystem again")
diff --git a/kernel/kernel/main.cpp b/kernel/kernel/main.cpp
index 6968782f..525e25c4 100644
--- a/kernel/kernel/main.cpp
+++ b/kernel/kernel/main.cpp
@@ -54,10 +54,10 @@ auto run_demo() -> void
}
// 4) mount a new filesystem on top of /entrance
- kstd::println("mount /dev/ram16 to /entrance");
- if (kapi::filesystem::mount("/dev/ram16", "/entrance"))
+ kstd::println("mount /dev/ram1 to /entrance");
+ if (kapi::filesystem::mount("/dev/ram1", "/entrance"))
{
- kstd::println("--> successfully mounted /dev/ram16 to /entrance");
+ kstd::println("--> successfully mounted /dev/ram1 to /entrance");
}
else
{
@@ -84,11 +84,11 @@ auto run_demo() -> void
kstd::println("--> read {} bytes from /entrance/information/info_1.txt: {} ", bytes_read, buffer_as_str);
// 7) open device as file
- kstd::println("attempting to open /dev/ram32 as a file");
- auto fd_3 = kapi::filesystem::open("/dev/ram32");
+ kstd::println("attempting to open /dev/ram2 as a file");
+ auto fd_3 = kapi::filesystem::open("/dev/ram2");
if (fd_3)
{
- kstd::println("--> successfully opened /dev/ram32 as a file with file descriptor {}", fd_3.value());
+ kstd::println("--> successfully opened /dev/ram2 as a file with file descriptor {}", fd_3.value());
}
else
{
@@ -98,13 +98,13 @@ auto run_demo() -> void
// 8) read from the device file
kstd::vector<std::byte> buffer_3{2};
bytes_read = *kapi::filesystem::read(fd_3.value(), buffer_3);
- kstd::println("--> read {} bytes from /dev/ram32: {::#04x} ", bytes_read, buffer_3);
+ kstd::println("--> read {} bytes from /dev/ram2: {::#04x} ", bytes_read, buffer_3);
// 9) write to the device file
auto const default_buffer_value = std::byte{0xAA};
kstd::vector<std::byte> write_buffer{default_buffer_value, default_buffer_value};
auto bytes_written = *kapi::filesystem::write(fd_3.value(), write_buffer);
- kstd::println("--> written {} bytes to /dev/ram32: {::#04x}", bytes_written, write_buffer);
+ kstd::println("--> written {} bytes to /dev/ram2: {::#04x}", bytes_written, write_buffer);
// 10) do memory dump to show that the write to the device file had an effect