aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/main.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-04-12 19:15:38 +0200
committerMarcel Braun <marcel.braun@ost.ch>2026-04-12 19:15:38 +0200
commit4d2a1d028f8ba28b655026b93124e71a12562619 (patch)
treef49deef4dd3e8728fd1000b04c0908966f37663f /kernel/src/main.cpp
parent21fd1281cf19572e202d583689b99c33ec68da50 (diff)
parentcb7edbe6d4454ee5b217b522f62f4a7b92475a32 (diff)
downloadteachos-develop-BA-FS26.tar.xz
teachos-develop-BA-FS26.zip
Merge branch 'ext2' into 'develop-BA-FS26'HEADdevelop-BA-FS26
ext2 and tests See merge request teachos/kernel!22
Diffstat (limited to 'kernel/src/main.cpp')
-rw-r--r--kernel/src/main.cpp79
1 files changed, 51 insertions, 28 deletions
diff --git a/kernel/src/main.cpp b/kernel/src/main.cpp
index b920674..79ed703 100644
--- a/kernel/src/main.cpp
+++ b/kernel/src/main.cpp
@@ -8,8 +8,8 @@
#include "kernel/devices/storage/management.hpp"
#include "kernel/filesystem/device_inode.hpp"
-#include "kernel/filesystem/ext2/filesystem.hpp"
#include "kernel/filesystem/file_descriptor_table.hpp"
+#include "kernel/filesystem/filesystem.hpp"
#include "kernel/filesystem/open_file_description.hpp"
#include "kernel/filesystem/vfs.hpp"
#include "kernel/memory.hpp"
@@ -23,6 +23,7 @@
#include <algorithm>
#include <cstddef>
+#include <string_view>
using namespace kstd::units_literals;
@@ -87,8 +88,6 @@ auto test_file_description_manually() -> void
auto test_device_with_vfs() -> void
{
- // TODO BA-FS26
-
auto vfs = kernel::filesystem::vfs::get();
auto ofd = vfs.open("/dev/ram0");
if (!ofd)
@@ -112,40 +111,64 @@ auto test_device_with_vfs() -> void
auto test_file_lookup() -> void
{
- // TODO BA-FS26 implement a more complete test with multiple files and directories and mounts etc.
-
auto vfs = kernel::filesystem::vfs::get();
+ auto read_and_write_file = [&vfs](std::string_view path) {
+ kstd::println("[TEST] Reading and writing file at path: {}", path);
+ auto ofd = vfs.open(path);
+ if (!ofd)
+ {
+ kstd::os::panic("test code failed");
+ }
+
+ kstd::vector<std::byte> buffer{32};
+ auto number_of_read_bytes = ofd->read(buffer.data(), buffer.size());
+ kstd::println("read bytes: {}", number_of_read_bytes);
+ kstd::println("buffer: {::#04x}", buffer);
+
+ std::string_view buffer_as_str{reinterpret_cast<char *>(buffer.data()), number_of_read_bytes};
+ kstd::println("buffer_as_str: {}", buffer_as_str);
+ };
+
+ read_and_write_file("/info.txt");
+ read_and_write_file("/enclosures/info.txt");
+ read_and_write_file("/enclosures/aquarium/tank_1/fish_4.txt");
+ read_and_write_file("/enclosures/elephant_house/elephant_1.txt");
+ read_and_write_file(
+ "/enclosures/aquarium/tank_2/"
+ "this_is_a_very_very_long_fish_filename_that_keeps_going_and_going_until_it_almost_breaks_linux_filesystem_"
+ "limits_for_testing_purposes_and_we_add_more_characters_to_make_it_even_longer_30.txt");
+
auto storage_mgmt = kernel::devices::storage::management::get();
+ auto device_1 = storage_mgmt.device_by_major_minor(1, 16);
+ auto fs_1 = kernel::filesystem::filesystem::probe_and_mount(device_1);
- auto ofd1 = vfs.open("/a/b/c");
- auto ofd2 = vfs.open("/dev/ram0");
- auto ofd3 = vfs.open("/a/d/e");
- if (!ofd1 || !ofd2 || !ofd3)
- {
- kstd::os::panic("test code failed");
- }
+ vfs.do_mount("/enclosures/aquarium", fs_1);
+ read_and_write_file("/enclosures/aquarium/closed.txt");
+ read_and_write_file("/enclosures/aquarium/information/info_2.txt");
- if (auto ofd4 = vfs.open("/dev/xxx"))
- {
- kstd::os::panic("test code failed");
- }
+ vfs.unmount("/enclosures/aquarium");
+ read_and_write_file("/enclosures/aquarium/tank_1/fish_4.txt");
- auto new_filesystem = kstd::make_shared<kernel::filesystem::ext2::filesystem>();
- auto device = storage_mgmt.device_by_major_minor(1, 16);
- new_filesystem->mount(device);
- if (vfs.do_mount("/a/b", new_filesystem) != 0)
- {
- kstd::os::panic("test code failed");
- }
- auto ofd5 = vfs.open("/a/b/c");
- if (!ofd5)
+ auto device_2 = storage_mgmt.device_by_major_minor(1, 32);
+ auto fs_2 = kernel::filesystem::filesystem::probe_and_mount(device_2);
+
+ vfs.do_mount("/enclosures/elephant_house", fs_2);
+ read_and_write_file("/enclosures/elephant_house/monkey_house/infrastructure/info.txt");
+
+ vfs.do_mount("/enclosures/elephant_house/monkey_house", fs_1);
+ read_and_write_file("/enclosures/elephant_house/monkey_house/information/info_2.txt");
+
+ auto result = vfs.unmount("/enclosures/elephant_house");
+ if (result == kernel::filesystem::vfs::operation_result::unmount_failed)
{
- kstd::os::panic("test code failed");
+ kstd::println("[TEST] Unmount failed as expected due to active child mount.");
}
- if (auto ofd6 = vfs.open("x/y/z"))
+ vfs.unmount("/enclosures/elephant_house/monkey_house");
+ result = vfs.unmount("/enclosures/elephant_house");
+ if (result == kernel::filesystem::vfs::operation_result::success)
{
- kstd::os::panic("test code failed");
+ kstd::println("[TEST] Unmount succeeded after unmounting child mount.");
}
}