aboutsummaryrefslogtreecommitdiff
path: root/kernel/src
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-05-04 20:51:49 +0200
committerLukas Oesch <lukasoesch20@gmail.com>2026-05-05 14:38:52 +0200
commitbddee0f0cb77eb247eceea18005dc575b433bb69 (patch)
tree778006e5d5cebc56f6fa4107f2b5132f61f9abe0 /kernel/src
parentd1e64340abb960c579651635d580660c12f94e6e (diff)
downloadkernel-bddee0f0cb77eb247eceea18005dc575b433bb69.tar.xz
kernel-bddee0f0cb77eb247eceea18005dc575b433bb69.zip
Implement symlink non-recursive
Diffstat (limited to 'kernel/src')
-rw-r--r--kernel/src/filesystem/vfs.cpp41
1 files changed, 15 insertions, 26 deletions
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp
index c9939fa..06d36ce 100644
--- a/kernel/src/filesystem/vfs.cpp
+++ b/kernel/src/filesystem/vfs.cpp
@@ -15,6 +15,7 @@
#include <kstd/vector>
#include <algorithm>
+#include <cstdint>
#include <optional>
#include <ranges>
#include <string_view>
@@ -229,33 +230,21 @@ namespace kernel::filesystem
if (next_dentry->get_inode()->is_symbolic_link())
{
- // TODO BA-FS26 this for loop is ugly --> fix
- kstd::string symlink_path = "halo";
- if (symlink_path.size() > 0 && symlink_path.front() == '/')
- {
- for (auto it2 = std::next(it); it2 != path_parts.end(); ++it2)
- {
- symlink_path += "/";
- symlink_path.append(std::string_view{*it2});
- }
- return resolve_path(symlink_path.view());
- }
- else
+ // TODO BA-FS26 max symbolic link depth to prevent infinite loops
+ kstd::vector<uint8_t> buffer(4096); // TODO BA-FS26 max symlink size?
+ auto const bytes_read = next_dentry->get_inode()->read(buffer.data(), 0, buffer.size());
+ auto const symbolic_link_path = std::string_view{reinterpret_cast<char const *>(buffer.data()), bytes_read};
+
+ auto symbolic_link_parts = kernel::filesystem::path::split(symbolic_link_path);
+ kstd::vector symbolic_link_parts_vector(symbolic_link_parts.begin(), symbolic_link_parts.end());
+ std::ranges::reverse(symbolic_link_parts_vector);
+
+ path_parts_vector.insert_range(path_parts_vector.end(), symbolic_link_parts_vector);
+
+ if (kernel::filesystem::path::is_valid_absolute_path(symbolic_link_path))
{
- kstd::string combined;
- for (auto it3 = path_parts.begin(); it3 != it; ++it3)
- {
- combined += "/";
- combined.append(std::string_view{*it3});
- }
- combined += "/";
- combined += symlink_path;
- for (auto it4 = std::next(it); it4 != path_parts.end(); ++it4)
- {
- combined += "/";
- combined.append(std::string_view{*it4});
- }
- return resolve_path(combined.view());
+ current_mount = m_mount_table.find_longest_prefix_mount("/");
+ next_dentry = current_mount->root_dentry();
}
}