aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/filesystem/include/filesystem/vfs.hpp2
-rw-r--r--kernel/filesystem/src/vfs.cpp31
2 files changed, 32 insertions, 1 deletions
diff --git a/kernel/filesystem/include/filesystem/vfs.hpp b/kernel/filesystem/include/filesystem/vfs.hpp
index 5998137..67fd5df 100644
--- a/kernel/filesystem/include/filesystem/vfs.hpp
+++ b/kernel/filesystem/include/filesystem/vfs.hpp
@@ -1,6 +1,7 @@
#ifndef TEACH_OS_KERNEL_FILESYSTEM_VFS_HPP
#define TEACH_OS_KERNEL_FILESYSTEM_VFS_HPP
+#include "devices/device.hpp"
#include "filesystem/mount.hpp"
#include <array>
@@ -17,6 +18,7 @@ namespace filesystem
~vfs() = default;
// auto do_mount(std::string_view const & path) ->
+ auto make_device_node(devices::device * device) -> void;
private:
vfs() = default;
diff --git a/kernel/filesystem/src/vfs.cpp b/kernel/filesystem/src/vfs.cpp
index 3f2576f..573994a 100644
--- a/kernel/filesystem/src/vfs.cpp
+++ b/kernel/filesystem/src/vfs.cpp
@@ -2,11 +2,17 @@
#include "kapi/system.hpp"
+#include "devices/device.hpp"
#include "devices/storage/storage_management.hpp"
#include "filesystem/ext2/ext2_filesystem.hpp"
#include "filesystem/mount.hpp"
+#include <kstd/cstring>
+
+#include <algorithm>
+#include <array>
#include <optional>
+#include <string_view>
namespace filesystem
{
@@ -17,6 +23,12 @@ namespace filesystem
// TODO BA-FS26 @Felix better solution? while dynamic memory not available?
// TODO BA-FS26 remove when dynamic memory available;
constinit auto static root_fs = std::optional<ext2::ext2_filesystem>{};
+ // TODO BA-FS26 use kstd::vector when available
+ constinit auto static filesystems = std::array<std::optional<ext2::ext2_filesystem>, 1>{};
+
+ // TODO BA-FS26 @Felix
+ // TODO BA-FS26 depends on the length of ram_disk_device name
+ constinit std::array<char, 10> device_mount_path = {'/', 'd', 'e', 'v', '/', 'x', 'x', 'x', 'x', '\0'};
} // namespace
auto vfs::init() -> void
@@ -39,7 +51,9 @@ namespace filesystem
active_vfs->m_root_mount = mount{"/", &*root_fs};
- // TODO BA-FS26 mount all the other devices to "/dev/ramxy"
+ 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); });
+ });
}
else
{
@@ -57,4 +71,19 @@ namespace filesystem
return *active_vfs;
}
+ auto vfs::make_device_node(devices::device * device) -> void
+ {
+ auto device_name = device->name();
+ kstd::libc::memcpy(&device_mount_path[5], device_name.data(), device_name.size());
+
+ // TODO BA-FS26 use kstd::vector and push_back when available
+ filesystems[0].emplace(ext2::ext2_filesystem{});
+ if (filesystems[0]->mount(device) != 0)
+ {
+ kapi::system::panic("[FILESYSTEM] Failed to mount device filesystem.");
+ }
+
+ m_mounts[0] = mount{std::string_view{device_mount_path.data()}, &*filesystems[0]};
+ }
+
} // namespace filesystem \ No newline at end of file