aboutsummaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-05-04 19:47:57 +0200
committerLukas Oesch <lukasoesch20@gmail.com>2026-05-05 14:38:52 +0200
commit7ff97f0fe861bb7382f41ecd4bab26cbb62b1f7d (patch)
treed0b37665a6dbdf9fac1ab3b3408c5cc58489bc2e /kernel/src
parent72d686961a26789b7659f17fb090511ee28604ec (diff)
downloadkernel-7ff97f0fe861bb7382f41ecd4bab26cbb62b1f7d.tar.xz
kernel-7ff97f0fe861bb7382f41ecd4bab26cbb62b1f7d.zip
Resolve TODOs concerning path validation
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/filesystem/vfs.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp
index ba4f404..8f48820 100644
--- a/kernel/src/filesystem/vfs.cpp
+++ b/kernel/src/filesystem/vfs.cpp
@@ -5,6 +5,7 @@
#include <kernel/filesystem/filesystem.hpp>
#include <kernel/filesystem/mount.hpp>
#include <kernel/filesystem/mount_table.hpp>
+#include <kernel/filesystem/path.hpp>
#include <kernel/filesystem/rootfs/filesystem.hpp>
#include <kapi/system.hpp>
@@ -89,12 +90,11 @@ namespace kernel::filesystem
auto vfs::do_mount(std::string_view source, std::string_view target) -> operation_result
{
- // TODO BA-FS26 better path validation
- if (target.empty() || target.front() != '/' || (target.size() > 1 && target.back() == '/'))
+ if (!kernel::filesystem::path::is_valid_path(source) || !kernel::filesystem::path::is_valid_path(target))
{
return operation_result::invalid_path;
}
- // TODO BA-FS26 check if target is directory?
+
if (auto mount_point_dentry = resolve_path(target))
{
if (auto source_dentry = resolve_path(source))
@@ -113,8 +113,7 @@ namespace kernel::filesystem
auto vfs::unmount(std::string_view path) -> operation_result
{
- // TODO BA-FS26 better path validation
- if (path.empty() || path.front() != '/' || (path.size() > 1 && path.back() == '/'))
+ if (!kernel::filesystem::path::is_valid_path(path))
{
return operation_result::invalid_path;
}
@@ -145,11 +144,12 @@ namespace kernel::filesystem
auto vfs::resolve_path(std::string_view path) -> kstd::shared_ptr<dentry>
{
- // TODO BA-FS26 better path validation
- // TODO BA-FS26 implement a path parser (maybe in libs?) and use it here and in do_mount
- if (path.empty() || path.front() != '/')
+ if (!kernel::filesystem::path::is_valid_absolute_path(path))
+ {
return nullptr;
+ }
+ // TODO BA-FS26 refactor (get mount by path, no more prefix matching)
auto current_mount = m_mount_table.find_longest_prefix_mount("/");
if (!current_mount)
{
@@ -157,10 +157,8 @@ namespace kernel::filesystem
}
auto current_dentry = current_mount->root_dentry();
- std::string_view remaining = path.substr(current_mount->get_mount_path().size());
- auto path_parts =
- std::views::split(remaining, '/') | std::views::filter([](auto const & part) { return !part.empty(); });
+ auto path_parts = kernel::filesystem::path::split(path);
for (auto it = path_parts.begin(); it != path_parts.end(); ++it)
{