aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-03-20 22:13:36 +0100
committerLukas Oesch <lukasoesch20@gmail.com>2026-03-26 21:17:28 +0100
commita396b71827a24f9d6c8010fd85b9afd9d86b6e2a (patch)
treef6ebaf2fa7b2e977eb95ec01a9c123ea665b55f5 /kernel/src/filesystem
parentb02b90f21de5954aef34eb37a17775f194b8de39 (diff)
downloadteachos-a396b71827a24f9d6c8010fd85b9afd9d86b6e2a.tar.xz
teachos-a396b71827a24f9d6c8010fd85b9afd9d86b6e2a.zip
implement first draft of a do_mount function
Diffstat (limited to 'kernel/src/filesystem')
-rw-r--r--kernel/src/filesystem/vfs.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp
index 1bc9ae6..febb844 100644
--- a/kernel/src/filesystem/vfs.cpp
+++ b/kernel/src/filesystem/vfs.cpp
@@ -36,13 +36,12 @@ namespace filesystem
if (auto boot_device = storage_mgmt.determine_boot_device())
{
active_vfs->m_root_fs = kstd::make_shared<ext2::ext2_filesystem>();
- if (active_vfs->m_root_fs->mount(boot_device) != 0)
+ if (active_vfs->do_mount("/", active_vfs->m_root_fs) != 0)
{
kapi::system::panic("[FILESYSTEM] Failed to mount root filesystem.");
}
- active_vfs->m_root_mount = mount{"/", active_vfs->m_root_fs};
-
+ // TODO BA-FS26 use do_mount when tempdevfs is implemented -> just call /dev/ with all devices in devtempfs
std::ranges::for_each(storage_mgmt.all_controllers(), [&](auto controller) {
std::ranges::for_each(controller->all_devices(), [&](auto device) { active_vfs->make_device_node(device); });
});
@@ -69,8 +68,9 @@ namespace filesystem
{
auto node = custody->get_inode();
- if (auto current_inode_file = node->open_file();)
+ if (auto current_inode_file = node->open_file())
{
+ // TODO BA-FS26 return shared_ptr?
return open_file_description{current_inode_file};
}
@@ -80,6 +80,45 @@ namespace filesystem
return std::nullopt;
}
+ auto vfs::do_mount(std::string_view path, kstd::shared_ptr<filesystem> const & filesystem) -> int
+ {
+ if (!filesystem)
+ {
+ return -1; // TODO BA-FS26 panic or errorcode?
+ }
+
+ if (path.empty() || path.front() != '/')
+ {
+ return -1; // TODO BA-FS26 panic or errorcode?
+ }
+
+ // TODO BA-FS26 better path validation
+ if ((path.size() > 1 && path.back() == '/') || path.find("//") != std::string_view::npos)
+ {
+ return -1; // TODO BA-FS26 panic or errorcode?
+ }
+
+ if (path == "/")
+ {
+ m_root_fs = filesystem;
+ m_root_mount = mount{"/", filesystem};
+ return 0;
+ }
+
+ auto existing_mount =
+ std::ranges::find_if(m_mounts, [&](auto const & existing) { return existing.path() == path; });
+ if (existing_mount != m_mounts.end())
+ {
+ *existing_mount = mount{path, filesystem};
+ }
+ else
+ {
+ m_mounts.push_back(mount{path, filesystem});
+ }
+
+ return 0;
+ }
+
auto vfs::make_device_node(kstd::shared_ptr<devices::device> const & device) -> void
{
if (!device)
@@ -94,6 +133,8 @@ namespace filesystem
{
// TODO BA-FS26 implement real path resolution with mounts and directories etc.
// For now, just support device nodes at /dev/<device_name>.
+ // TODO BA-FS26 better path validation
+ // TODO BA-FS26 implement a path parser (maybe in libs?) and use it here and in do_mount
constexpr auto device_prefix = std::string_view{"/dev/"};
if (path.starts_with(device_prefix))