diff options
| -rw-r--r-- | kernel/kapi/filesystem.cpp | 2 | ||||
| -rw-r--r-- | kernel/kernel/filesystem/vfs.cpp | 15 | ||||
| -rw-r--r-- | kernel/kernel/filesystem/vfs.hpp | 10 | ||||
| -rw-r--r-- | kernel/kernel/filesystem/vfs.tests.cpp | 54 |
4 files changed, 41 insertions, 40 deletions
diff --git a/kernel/kapi/filesystem.cpp b/kernel/kapi/filesystem.cpp index f84949da..a7c8e403 100644 --- a/kernel/kapi/filesystem.cpp +++ b/kernel/kapi/filesystem.cpp @@ -15,7 +15,7 @@ namespace kapi::filesystem { auto mount(std::string_view source, std::string_view target) -> std::expected<void, kstd::error_code> { - return kernel::filesystem::vfs::get().do_mount(source, target); + return kernel::filesystem::vfs::get().mount(source, target); } auto umount(std::string_view target) -> std::expected<void, kstd::error_code> diff --git a/kernel/kernel/filesystem/vfs.cpp b/kernel/kernel/filesystem/vfs.cpp index 31b9e4d0..c38e19d7 100644 --- a/kernel/kernel/filesystem/vfs.cpp +++ b/kernel/kernel/filesystem/vfs.cpp @@ -51,7 +51,7 @@ namespace kernel::filesystem } auto root_fs_root_dentry = kstd::make_shared<dentry>(nullptr, root_fs->root_inode(), "/"); - auto root_mount = kstd::make_shared<mount>(nullptr, root_fs_root_dentry, root_fs, nullptr, nullptr); + auto root_mount = kstd::make_shared<struct mount>(nullptr, root_fs_root_dentry, root_fs, nullptr, nullptr); m_mount_table.add_mount(root_mount); // mount devfs at /dev (inside rootfs, temporary, will be shadowed) @@ -111,7 +111,7 @@ namespace kernel::filesystem return std::unexpected{vfs_errc::invalid_path}; } - auto vfs::do_mount(std::string_view source, std::string_view target) -> std::expected<void, kstd::error_code> + auto vfs::mount(std::string_view source, std::string_view target) -> std::expected<void, kstd::error_code> { if (!path::is_valid_path(source) || !path::is_valid_path(target)) { @@ -171,12 +171,13 @@ namespace kernel::filesystem } auto vfs::do_mount_internal(kstd::shared_ptr<dentry> const & mount_point_dentry, - kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs, - kstd::shared_ptr<mount> const & source_mount) -> void + kstd::shared_ptr<struct mount> const & parent_mount, + kstd::shared_ptr<filesystem> const & fs, + kstd::shared_ptr<struct mount> const & source_mount) -> void { auto new_fs_root = kstd::make_shared<dentry>(mount_point_dentry->parent(), fs->root_inode(), mount_point_dentry->name()); - auto new_mount = kstd::make_shared<mount>(mount_point_dentry, new_fs_root, fs, parent_mount, source_mount); + auto new_mount = kstd::make_shared<struct mount>(mount_point_dentry, new_fs_root, fs, parent_mount, source_mount); m_mount_table.add_mount(new_mount); } @@ -197,7 +198,7 @@ namespace kernel::filesystem } auto vfs::resolve_path_internal(std::string_view path) const - -> std::expected<std::pair<kstd::shared_ptr<dentry>, kstd::shared_ptr<mount>>, kstd::error_code> + -> std::expected<std::pair<kstd::shared_ptr<dentry>, kstd::shared_ptr<struct mount>>, kstd::error_code> { if (!path::is_valid_absolute_path(path)) { @@ -314,7 +315,7 @@ namespace kernel::filesystem return resolve_path_internal(path).transform([](auto result) { return result.first; }); } - auto vfs::find_mount(std::string_view path) const -> std::expected<kstd::shared_ptr<mount>, kstd::error_code> + auto vfs::find_mount(std::string_view path) const -> std::expected<kstd::shared_ptr<struct mount>, kstd::error_code> { return resolve_path_internal(path).transform([](auto result) { return result.second; }); } diff --git a/kernel/kernel/filesystem/vfs.hpp b/kernel/kernel/filesystem/vfs.hpp index 3e86eae5..f3f94e81 100644 --- a/kernel/kernel/filesystem/vfs.hpp +++ b/kernel/kernel/filesystem/vfs.hpp @@ -64,7 +64,7 @@ namespace kernel::filesystem @param target The path where the filesystem should be mounted. @return Nothing on success or an error code on failure. */ - auto do_mount(std::string_view source, std::string_view target) -> std::expected<void, kstd::error_code>; + auto mount(std::string_view source, std::string_view target) -> std::expected<void, kstd::error_code>; /** @brief Unmount the filesystem mounted at the specified @p path. @@ -85,17 +85,17 @@ namespace kernel::filesystem * - find_mount() for the mount context only. */ [[nodiscard]] auto resolve_path_internal(std::string_view path) const - -> std::expected<std::pair<kstd::shared_ptr<dentry>, kstd::shared_ptr<mount>>, kstd::error_code>; + -> std::expected<std::pair<kstd::shared_ptr<dentry>, kstd::shared_ptr<struct mount>>, kstd::error_code>; [[nodiscard]] auto resolve_path(std::string_view path) const -> std::expected<kstd::shared_ptr<dentry>, kstd::error_code>; [[nodiscard]] auto find_mount(std::string_view path) const - -> std::expected<kstd::shared_ptr<mount>, kstd::error_code>; + -> std::expected<kstd::shared_ptr<struct mount>, kstd::error_code>; auto do_mount_internal(kstd::shared_ptr<dentry> const & mount_point_dentry, - kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs, - kstd::shared_ptr<mount> const & source_mount = nullptr) -> void; + kstd::shared_ptr<struct mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs, + kstd::shared_ptr<struct mount> const & source_mount = nullptr) -> void; auto graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void; diff --git a/kernel/kernel/filesystem/vfs.tests.cpp b/kernel/kernel/filesystem/vfs.tests.cpp index 7ec70d9c..8ef24a15 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.do_mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram16", "/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.do_mount("/dev/ram16", "/information")); - REQUIRE(vfs.do_mount("/dev/ram32", "/information/monkey_house/infrastructure")); + REQUIRE(vfs.mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram32", "/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.do_mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram16", "/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.do_mount("/dev/ram16", "/information")); - REQUIRE(vfs.do_mount("/dev/ram32", "/information")); + REQUIRE(vfs.mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram32", "/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.do_mount("/dev/ram16", "/")); + REQUIRE(vfs.mount("/dev/ram16", "/")); 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.do_mount("/dev/ram16", "/")); + REQUIRE(vfs.mount("/dev/ram16", "/")); info_1 = vfs.open("/information/info_1.txt"); REQUIRE(info_1.error() == kstd::errc::no_such_file_or_directory); @@ -223,7 +223,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS auto dev_ram_16 = vfs.open("/dev/ram16"); REQUIRE(dev_ram_16.error() == kstd::errc::no_such_file_or_directory); - REQUIRE(vfs.do_mount("/dev/ram32", "/").error() == kstd::errc::no_such_file_or_directory); + REQUIRE(vfs.mount("/dev/ram32", "/").error() == kstd::errc::no_such_file_or_directory); REQUIRE(vfs.unmount("/")); @@ -244,7 +244,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS info_1 = vfs.open("/information/info_1.txt"); REQUIRE(info_1.error() == kstd::errc::no_such_file_or_directory); - REQUIRE(vfs.do_mount("/dev/ram0", "/")); + REQUIRE(vfs.mount("/dev/ram0", "/")); info_1 = vfs.open("/information/info_1.txt"); REQUIRE(info_1 != nullptr); @@ -255,23 +255,23 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS THEN("mount with null file system fails") { - REQUIRE(vfs.do_mount("/closed.txt", "/information").error() == kstd::errc::not_supported); + REQUIRE(vfs.mount("/closed.txt", "/information").error() == kstd::errc::not_supported); } THEN("mount with invalid path fails") { - REQUIRE(vfs.do_mount("/dev/ram16", "").error() == kstd::errc::invalid_argument); - REQUIRE(vfs.do_mount("/dev/ram16", "information").error() == kstd::errc::invalid_argument); + REQUIRE(vfs.mount("/dev/ram16", "").error() == kstd::errc::invalid_argument); + REQUIRE(vfs.mount("/dev/ram16", "information").error() == kstd::errc::invalid_argument); } THEN("mount with non-existent source path fails") { - REQUIRE(vfs.do_mount("/dev/nonexistent", "/information").error() == kstd::errc::no_such_file_or_directory); + REQUIRE(vfs.mount("/dev/nonexistent", "/information").error() == kstd::errc::no_such_file_or_directory); } THEN("mount with non-existent mount point fails") { - REQUIRE(vfs.do_mount("/dev/ram16", "/information/nonexistent").error() == kstd::errc::no_such_file_or_directory); + REQUIRE(vfs.mount("/dev/ram16", "/information/nonexistent").error() == kstd::errc::no_such_file_or_directory); } THEN("unmount with invalid path fails") @@ -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.do_mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram16", "/information")); auto img = vfs.open("/information/monkey_house/caretaker/../../../../../../archiv/2024.img"); REQUIRE(img != nullptr); @@ -316,8 +316,8 @@ 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.do_mount("/dev/ram16", "/information")); - REQUIRE(vfs.do_mount("/archiv/2024.img", "/information/monkey_house/infrastructure")); + REQUIRE(vfs.mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/archiv/2024.img", "/information/monkey_house/infrastructure")); auto pig_1 = vfs.open("/information/monkey_house/infrastructure/stable/pig_1.txt"); REQUIRE(pig_1 != nullptr); @@ -339,7 +339,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS THEN("the file-filesystem in the image can be mounted, files can be read and unmounted again") { auto & vfs = kernel::filesystem::vfs::get(); - REQUIRE(vfs.do_mount("/archiv/2024.img", "/information")); + REQUIRE(vfs.mount("/archiv/2024.img", "/information")); auto info_1 = vfs.open("/information/info_1.txt"); REQUIRE(info_1.error() == kstd::errc::no_such_file_or_directory); @@ -364,8 +364,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS "mounted, files can be read and unmounted again") { auto & vfs = kernel::filesystem::vfs::get(); - REQUIRE(vfs.do_mount("/archiv/2024.img", "/information")); - REQUIRE(vfs.do_mount("/archiv/2025.img", "/information/stable")); + REQUIRE(vfs.mount("/archiv/2024.img", "/information")); + REQUIRE(vfs.mount("/archiv/2025.img", "/information/stable")); auto sheep_1 = vfs.open("/information/sheep_1.txt"); auto goat_1 = vfs.open("/information/stable/petting_zoo/goat_1.txt"); @@ -416,8 +416,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS THEN("cannot unmount a filesystem if files are mounted") { - REQUIRE(vfs.do_mount("/dev/ram16", "/entrance")); - REQUIRE(vfs.do_mount("/entrance/archiv/2024.img", "/enclosures")); + REQUIRE(vfs.mount("/dev/ram16", "/entrance")); + REQUIRE(vfs.mount("/entrance/archiv/2024.img", "/enclosures")); REQUIRE(vfs.unmount("/entrance").error() == kstd::errc::device_or_resource_busy); REQUIRE(vfs.unmount("/enclosures")); @@ -426,8 +426,8 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS THEN("can mount filesystem onto the directory that contains it") { - REQUIRE(vfs.do_mount("/dev/ram16", "/entrance")); - REQUIRE(vfs.do_mount("/entrance/archiv/2024.img", "/entrance")); + REQUIRE(vfs.mount("/dev/ram16", "/entrance")); + REQUIRE(vfs.mount("/entrance/archiv/2024.img", "/entrance")); REQUIRE(vfs.unmount("/entrance")); REQUIRE(vfs.unmount("/entrance")); @@ -502,7 +502,7 @@ SCENARIO_METHOD(kernel::tests::filesystem::storage_boot_module_vfs_fixture, "VFS REQUIRE_NOTHROW(setup_modules_from_img_and_init_vfs({"test_img_module_1"}, {image_path_1})); auto & vfs = kernel::filesystem::vfs::get(); - REQUIRE(vfs.do_mount("/archiv/2024.img", "/information")); + REQUIRE(vfs.mount("/archiv/2024.img", "/information")); THEN("file can be opened through symbolic link pointing to the parent filesystem") { @@ -519,7 +519,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.do_mount("/dev/ram16", "/information")); + REQUIRE(vfs.mount("/dev/ram16", "/information")); THEN("file can be opened through symbolic link pointing to the parent filesystem and back into the mounted " "filesystem again") |
