From f4e210b1e6169df99db621ca624555027047bc50 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Wed, 8 Apr 2026 21:08:08 +0200 Subject: add mount_table tests --- kernel/src/filesystem/mount_table.tests.cpp | 164 ++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 kernel/src/filesystem/mount_table.tests.cpp (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp new file mode 100644 index 0000000..9f390c6 --- /dev/null +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -0,0 +1,164 @@ +#include "kernel/filesystem/mount_table.hpp" + +#include "kernel/filesystem/dentry.hpp" +#include "kernel/filesystem/mount.hpp" +#include "kernel/test_support/cpu.hpp" +#include "kernel/test_support/filesystem/filesystem.hpp" +#include "kernel/test_support/filesystem/inode.hpp" + +#include +#include +#include + +#include + +#include + +SCENARIO("Mount table construction", "[filesystem][mount_table]") +{ + GIVEN("an empty mount table") + { + kernel::filesystem::mount_table table; + + THEN("finding any mount returns null") + { + REQUIRE(table.find_longest_prefix_mount("/") == nullptr); + REQUIRE(table.find_longest_prefix_mount("/any/path") == nullptr); + } + + THEN("removing any mount returns mount_not_found") + { + REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::mount_not_found); + REQUIRE(table.remove_mount("/any/path") == kernel::filesystem::mount_table::operation_result::mount_not_found); + } + } +} + +SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem][mount_table]") +{ + GIVEN("a mount table and some mounts") + { + kernel::filesystem::mount_table table; + + auto fs1 = kstd::make_shared(); + auto root_inode1 = kstd::make_shared(); + auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); + auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + + auto fs2 = kstd::make_shared(); + auto root_inode2 = kstd::make_shared(); + auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); + auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/mnt", nullptr); + + table.add_mount(mount1); + table.add_mount(mount2); + + THEN("dentry flags are set correctly for mounted dentries") + { + REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + } + + THEN("finding mounts by path returns the correct mount") + { + REQUIRE(table.find_longest_prefix_mount("/") == mount1); + REQUIRE(table.find_longest_prefix_mount("/file") == mount1); + REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); + REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); + REQUIRE(table.find_longest_prefix_mount("/other") == mount1); + } + + THEN("removing a mount that has no child mounts succeeds") + { + REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(table.find_longest_prefix_mount("/mnt") == nullptr); + } + + THEN("removing a mount that does not exist returns mount_not_found") + { + REQUIRE(table.remove_mount("/nonexistent") == kernel::filesystem::mount_table::operation_result::mount_not_found); + } + } + + GIVEN("multiple mounts with the same path") + { + kernel::filesystem::mount_table table; + + auto fs1 = kstd::make_shared(); + auto root_inode1 = kstd::make_shared(); + auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); + auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + + auto fs2 = kstd::make_shared(); + auto root_inode2 = kstd::make_shared(); + auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); + auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/", mount1); + + table.add_mount(mount1); + table.add_mount(mount2); + + THEN("finding mounts by path returns the correct mount based on longest prefix") + { + REQUIRE(table.find_longest_prefix_mount("/") == mount2); + REQUIRE(table.find_longest_prefix_mount("/file") == mount2); + REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); + REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); + REQUIRE(table.find_longest_prefix_mount("/other") == mount2); + } + + THEN("removing the topmost mount with the same path succeeds") + { + REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(table.find_longest_prefix_mount("/") == mount1); + } + } + + GIVEN("a mount with child mounts") + { + kernel::filesystem::mount_table table; + + auto fs1 = kstd::make_shared(); + auto root_inode1 = kstd::make_shared(); + auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); + auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + + auto fs2 = kstd::make_shared(); + auto root_inode2 = kstd::make_shared(); + auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); + auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/mnt", mount1); + + auto fs3 = kstd::make_shared(); + auto root_inode3 = kstd::make_shared(); + auto root_dentry3 = kstd::make_shared(nullptr, root_inode3, "/"); + auto mount3 = kstd::make_shared(root_dentry2, root_dentry3, fs3, "/mnt/submnt", mount2); + + table.add_mount(mount1); + table.add_mount(mount2); + table.add_mount(mount3); + + THEN("finding mounts by path returns the correct mount based on longest prefix") + { + REQUIRE(table.find_longest_prefix_mount("/") == mount1); + REQUIRE(table.find_longest_prefix_mount("/file") == mount1); + REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); + REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); + REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount3); + REQUIRE(table.find_longest_prefix_mount("/other") == mount1); + } + + THEN("removing a mount with child mounts returns has_child_mounts") + { + REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::has_child_mounts); + REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::has_child_mounts); + } + + THEN("removing a leaf mount succeeds") + { + REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); + REQUIRE(!root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == nullptr); + } + } +} -- cgit v1.2.3 From 7a7c0106257665358e68bbbc99b41acc0c87c0ba Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Wed, 8 Apr 2026 21:16:14 +0200 Subject: fix mount table tests --- kernel/src/filesystem/mount_table.tests.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 9f390c6..439fe97 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -2,7 +2,6 @@ #include "kernel/filesystem/dentry.hpp" #include "kernel/filesystem/mount.hpp" -#include "kernel/test_support/cpu.hpp" #include "kernel/test_support/filesystem/filesystem.hpp" #include "kernel/test_support/filesystem/inode.hpp" @@ -56,7 +55,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("dentry flags are set correctly for mounted dentries") { REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); - REQUIRE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); } THEN("finding mounts by path returns the correct mount") @@ -72,7 +71,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt") == nullptr); + REQUIRE(table.find_longest_prefix_mount("/mnt") == mount1); } THEN("removing a mount that does not exist returns mount_not_found") @@ -158,7 +157,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE(!root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == nullptr); + REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount2); } } } -- cgit v1.2.3 From f6f10575f75ac23d06e1d94f7861611503daa7af Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 23 Apr 2026 14:03:28 +0200 Subject: chore: banish relative includes --- kernel/src/filesystem/mount_table.tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 439fe97..747ffdf 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -1,9 +1,9 @@ -#include "kernel/filesystem/mount_table.hpp" +#include -#include "kernel/filesystem/dentry.hpp" -#include "kernel/filesystem/mount.hpp" -#include "kernel/test_support/filesystem/filesystem.hpp" -#include "kernel/test_support/filesystem/inode.hpp" +#include +#include +#include +#include #include #include -- cgit v1.2.3 From a096d84920aa078b5775149a95e5d3f010ae995e Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sat, 2 May 2026 14:14:55 +0200 Subject: fix bht build --- kernel/src/filesystem/mount_table.tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 747ffdf..60b1755 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -54,8 +54,8 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("dentry flags are set correctly for mounted dentries") { - REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } THEN("finding mounts by path returns the correct mount") @@ -70,7 +70,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a mount that has no child mounts succeeds") { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/mnt") == mount1); } @@ -109,7 +109,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing the topmost mount with the same path succeeds") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/") == mount1); } } @@ -156,7 +156,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a leaf mount succeeds") { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::dcache_mounted)); + REQUIRE(!root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount2); } } -- cgit v1.2.3 From 40fbefab704695b905e3de3e80668447cc64b20e Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sat, 2 May 2026 15:36:19 +0200 Subject: refactoring and extend tests --- kernel/src/filesystem/mount_table.tests.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 60b1755..e028ac8 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -55,7 +55,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("dentry flags are set correctly for mounted dentries") { REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } THEN("finding mounts by path returns the correct mount") @@ -70,7 +70,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a mount that has no child mounts succeeds") { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/mnt") == mount1); } @@ -109,7 +109,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing the topmost mount with the same path succeeds") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/") == mount1); } } @@ -156,7 +156,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a leaf mount succeeds") { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE(!root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount2); } } -- cgit v1.2.3 From 870039d48d28f479eea88c7548b8d2b2a28c09bc Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Tue, 5 May 2026 21:18:48 +0200 Subject: add mount table find_exact_mount tests, remove todo --- kernel/src/filesystem/mount_table.tests.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index e028ac8..efacdfe 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -58,7 +58,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } - THEN("finding mounts by path returns the correct mount") + THEN("finding mounts by longest prefix returns the correct mount") { REQUIRE(table.find_longest_prefix_mount("/") == mount1); REQUIRE(table.find_longest_prefix_mount("/file") == mount1); @@ -67,6 +67,18 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] REQUIRE(table.find_longest_prefix_mount("/other") == mount1); } + THEN("finding mounts by exact valid path returns the correct mount") + { + REQUIRE(table.find_exact_mount("/") == mount1); + REQUIRE(table.find_exact_mount("/mnt") == mount2); + } + + THEN("finding mounts by exact invalid path returns null") + { + REQUIRE(table.find_exact_mount("/nonexistent") == nullptr); + REQUIRE(table.find_exact_mount("/mnt/file") == nullptr); + } + THEN("removing a mount that has no child mounts succeeds") { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); @@ -97,7 +109,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] table.add_mount(mount1); table.add_mount(mount2); - THEN("finding mounts by path returns the correct mount based on longest prefix") + THEN("finding mounts by longest prefix returns the correct mount") { REQUIRE(table.find_longest_prefix_mount("/") == mount2); REQUIRE(table.find_longest_prefix_mount("/file") == mount2); @@ -106,6 +118,11 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] REQUIRE(table.find_longest_prefix_mount("/other") == mount2); } + THEN("finding mounts by exact valid path returns the correct mount") + { + REQUIRE(table.find_exact_mount("/") == mount2); + } + THEN("removing the topmost mount with the same path succeeds") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); -- cgit v1.2.3 From 00aa2c8695b81944798010d81d600038e1f1ef3d Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sun, 10 May 2026 19:08:07 +0200 Subject: remove mount_path from mount struct (retrieve path from m_mount_dentry) --- kernel/src/filesystem/mount_table.tests.cpp | 60 ++++++++++++++++++----------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index efacdfe..732d32f 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -40,22 +40,26 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] kernel::filesystem::mount_table table; auto fs1 = kstd::make_shared(); - auto root_inode1 = kstd::make_shared(); - auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); - auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + auto root_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); auto fs2 = kstd::make_shared(); - auto root_inode2 = kstd::make_shared(); - auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); - auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/mnt", nullptr); + auto root_dentry2 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry2 = kstd::make_shared( + nullptr, kstd::make_shared(), "/mnt"); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr); table.add_mount(mount1); table.add_mount(mount2); THEN("dentry flags are set correctly for mounted dentries") { - REQUIRE(root_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE(mount_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE(mount_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } THEN("finding mounts by longest prefix returns the correct mount") @@ -97,14 +101,18 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] kernel::filesystem::mount_table table; auto fs1 = kstd::make_shared(); - auto root_inode1 = kstd::make_shared(); - auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); - auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + auto root_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); auto fs2 = kstd::make_shared(); - auto root_inode2 = kstd::make_shared(); - auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); - auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/", mount1); + auto root_dentry2 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry2 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr); table.add_mount(mount1); table.add_mount(mount2); @@ -136,19 +144,25 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] kernel::filesystem::mount_table table; auto fs1 = kstd::make_shared(); - auto root_inode1 = kstd::make_shared(); - auto root_dentry1 = kstd::make_shared(nullptr, root_inode1, "/"); - auto mount1 = kstd::make_shared(root_dentry1, root_dentry1, fs1, "/", nullptr); + auto root_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry1 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); auto fs2 = kstd::make_shared(); - auto root_inode2 = kstd::make_shared(); - auto root_dentry2 = kstd::make_shared(nullptr, root_inode2, "/"); - auto mount2 = kstd::make_shared(root_dentry1, root_dentry2, fs2, "/mnt", mount1); + auto root_dentry2 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry2 = kstd::make_shared( + mount_dentry1, kstd::make_shared(), "mnt"); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, mount1); auto fs3 = kstd::make_shared(); - auto root_inode3 = kstd::make_shared(); - auto root_dentry3 = kstd::make_shared(nullptr, root_inode3, "/"); - auto mount3 = kstd::make_shared(root_dentry2, root_dentry3, fs3, "/mnt/submnt", mount2); + auto root_dentry3 = kstd::make_shared( + nullptr, kstd::make_shared(), "/"); + auto mount_dentry3 = kstd::make_shared( + mount_dentry2, kstd::make_shared(), "submnt"); + auto mount3 = kstd::make_shared(mount_dentry3, root_dentry3, fs3, mount2); table.add_mount(mount1); table.add_mount(mount2); -- cgit v1.2.3 From 763227e31adf924a5dfe3139db158e26162294a0 Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Sun, 10 May 2026 21:58:54 +0200 Subject: Remove find_longest_prefix_mount --- kernel/src/filesystem/mount_table.tests.cpp | 37 ----------------------------- 1 file changed, 37 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 732d32f..80772ca 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -19,12 +19,6 @@ SCENARIO("Mount table construction", "[filesystem][mount_table]") { kernel::filesystem::mount_table table; - THEN("finding any mount returns null") - { - REQUIRE(table.find_longest_prefix_mount("/") == nullptr); - REQUIRE(table.find_longest_prefix_mount("/any/path") == nullptr); - } - THEN("removing any mount returns mount_not_found") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::mount_not_found); @@ -62,15 +56,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] REQUIRE(mount_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } - THEN("finding mounts by longest prefix returns the correct mount") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount1); - REQUIRE(table.find_longest_prefix_mount("/file") == mount1); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/other") == mount1); - } - THEN("finding mounts by exact valid path returns the correct mount") { REQUIRE(table.find_exact_mount("/") == mount1); @@ -87,7 +72,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount1); } THEN("removing a mount that does not exist returns mount_not_found") @@ -117,15 +101,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] table.add_mount(mount1); table.add_mount(mount2); - THEN("finding mounts by longest prefix returns the correct mount") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount2); - REQUIRE(table.find_longest_prefix_mount("/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/other") == mount2); - } - THEN("finding mounts by exact valid path returns the correct mount") { REQUIRE(table.find_exact_mount("/") == mount2); @@ -135,7 +110,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/") == mount1); } } @@ -168,16 +142,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] table.add_mount(mount2); table.add_mount(mount3); - THEN("finding mounts by path returns the correct mount based on longest prefix") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount1); - REQUIRE(table.find_longest_prefix_mount("/file") == mount1); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount3); - REQUIRE(table.find_longest_prefix_mount("/other") == mount1); - } - THEN("removing a mount with child mounts returns has_child_mounts") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::has_child_mounts); @@ -188,7 +152,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount2); } } } -- cgit v1.2.3 From 5d72c256d4e2b8a9d2fd70e5a27e883a0f733e50 Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Mon, 11 May 2026 20:48:03 +0200 Subject: Add is_mount_root flag to dentry and use in find_mount_root_dentry --- kernel/src/filesystem/mount_table.tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 80772ca..4ae8711 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -52,8 +52,8 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("dentry flags are set correctly for mounted dentries") { - REQUIRE(mount_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(mount_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE(mount_dentry1->has_flag(kernel::filesystem::dentry::dentry_flags::is_mount_point)); + REQUIRE(mount_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::is_mount_point)); } THEN("finding mounts by exact valid path returns the correct mount") @@ -71,7 +71,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a mount that has no child mounts succeeds") { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::is_mount_point)); } THEN("removing a mount that does not exist returns mount_not_found") @@ -109,7 +109,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing the topmost mount with the same path succeeds") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::is_mount_point)); } } @@ -151,7 +151,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("removing a leaf mount succeeds") { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); - REQUIRE_FALSE(root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); + REQUIRE_FALSE(root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::is_mount_point)); } } } -- cgit v1.2.3 From 963c926c68aac4606d80743aca8e7b052eee7efe Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Fri, 15 May 2026 11:42:33 +0200 Subject: Rename mount_table method from find_exact_mount to find_mount --- kernel/src/filesystem/mount_table.tests.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 4ae8711..f22b25e 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -58,14 +58,14 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("finding mounts by exact valid path returns the correct mount") { - REQUIRE(table.find_exact_mount("/") == mount1); - REQUIRE(table.find_exact_mount("/mnt") == mount2); + REQUIRE(table.find_mount("/") == mount1); + REQUIRE(table.find_mount("/mnt") == mount2); } THEN("finding mounts by exact invalid path returns null") { - REQUIRE(table.find_exact_mount("/nonexistent") == nullptr); - REQUIRE(table.find_exact_mount("/mnt/file") == nullptr); + REQUIRE(table.find_mount("/nonexistent") == nullptr); + REQUIRE(table.find_mount("/mnt/file") == nullptr); } THEN("removing a mount that has no child mounts succeeds") @@ -103,7 +103,7 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] THEN("finding mounts by exact valid path returns the correct mount") { - REQUIRE(table.find_exact_mount("/") == mount2); + REQUIRE(table.find_mount("/") == mount2); } THEN("removing the topmost mount with the same path succeeds") -- cgit v1.2.3 From 61d29a288334960cd9f43df91e4fd632a7f6ad66 Mon Sep 17 00:00:00 2001 From: Marcel Braun Date: Mon, 25 May 2026 11:13:18 +0200 Subject: Increase reference count of source_mount when one of its files is mounted somewhere --- kernel/src/filesystem/mount_table.tests.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index f22b25e..8118e19 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -38,14 +38,14 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] nullptr, kstd::make_shared(), "/"); auto mount_dentry1 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); - auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr, nullptr); auto fs2 = kstd::make_shared(); auto root_dentry2 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); auto mount_dentry2 = kstd::make_shared( nullptr, kstd::make_shared(), "/mnt"); - auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr, nullptr); table.add_mount(mount1); table.add_mount(mount2); @@ -89,14 +89,14 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] nullptr, kstd::make_shared(), "/"); auto mount_dentry1 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); - auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr, nullptr); auto fs2 = kstd::make_shared(); auto root_dentry2 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); auto mount_dentry2 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); - auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, nullptr, nullptr); table.add_mount(mount1); table.add_mount(mount2); @@ -122,21 +122,21 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] nullptr, kstd::make_shared(), "/"); auto mount_dentry1 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); - auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr); + auto mount1 = kstd::make_shared(mount_dentry1, root_dentry1, fs1, nullptr, nullptr); auto fs2 = kstd::make_shared(); auto root_dentry2 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); auto mount_dentry2 = kstd::make_shared( mount_dentry1, kstd::make_shared(), "mnt"); - auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, mount1); + auto mount2 = kstd::make_shared(mount_dentry2, root_dentry2, fs2, mount1, nullptr); auto fs3 = kstd::make_shared(); auto root_dentry3 = kstd::make_shared( nullptr, kstd::make_shared(), "/"); auto mount_dentry3 = kstd::make_shared( mount_dentry2, kstd::make_shared(), "submnt"); - auto mount3 = kstd::make_shared(mount_dentry3, root_dentry3, fs3, mount2); + auto mount3 = kstd::make_shared(mount_dentry3, root_dentry3, fs3, mount2, nullptr); table.add_mount(mount1); table.add_mount(mount2); -- cgit v1.2.3 From 756854104db95f247ad9bed5eb59fb90a9a1cb69 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Mon, 25 May 2026 13:04:36 +0200 Subject: add mount table and mount tests --- kernel/src/filesystem/mount_table.tests.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'kernel/src/filesystem/mount_table.tests.cpp') diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 8118e19..19b47b2 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -155,3 +155,30 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] } } } + +SCENARIO("Mount reference counting", "[filesystem][mount_table]") +{ + kernel::filesystem::mount_table table; + + GIVEN("a filesystem and a root dentry") + { + auto fs = kstd::make_shared(); + auto root_inode = kstd::make_shared(); + auto root_dentry = kstd::make_shared(nullptr, root_inode, "/"); + + auto source_mount = kstd::make_shared(root_dentry, root_dentry, fs, nullptr, nullptr); + auto mount = kstd::make_shared(root_dentry, root_dentry, fs, nullptr, source_mount); + + THEN("reference count of source mount is incremented when a mount is added to the mount table and decremented when " + "the mount is removed") + { + REQUIRE(source_mount->ref_count() == 0); + + table.add_mount(mount); + REQUIRE(source_mount->ref_count() == 1); + + REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); + REQUIRE(source_mount->ref_count() == 0); + } + } +} -- cgit v1.2.3