aboutsummaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-06-02 17:32:08 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-06-02 17:32:08 +0200
commit3274bb4377b9f04b7a70139a86283e0fae44b228 (patch)
treeface2b0b544578e5efd1c28c8d75b3307d6e4a8a /kernel/include
parente92df52c599f78f36a278508a2b6be5f3a15f3db (diff)
parent46d3f8978e9f4235064daf5f19de5bf3054e7c24 (diff)
downloadkernel-3274bb4377b9f04b7a70139a86283e0fae44b228.tar.xz
kernel-3274bb4377b9f04b7a70139a86283e0fae44b228.zip
Merge branch 'fmorgner/develop-BA-FS26/dynamic-fs' into 'develop-BA-FS26'
Add support infrastructure for automatic file system registration See merge request teachos/kernel!46
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/kernel/filesystem/type.hpp42
-rw-r--r--kernel/include/kernel/filesystem/type_registry.hpp53
-rw-r--r--kernel/include/kernel/filesystem/vfs.hpp7
3 files changed, 98 insertions, 4 deletions
diff --git a/kernel/include/kernel/filesystem/type.hpp b/kernel/include/kernel/filesystem/type.hpp
new file mode 100644
index 0000000..0948e54
--- /dev/null
+++ b/kernel/include/kernel/filesystem/type.hpp
@@ -0,0 +1,42 @@
+#ifndef TEACH_OS_KERNEL_FILESYSTEM_TYPE_HPP
+#define TEACH_OS_KERNEL_FILESYSTEM_TYPE_HPP
+
+#include <kernel/filesystem/filesystem.hpp>
+
+#include <kstd/memory>
+
+#include <string_view>
+
+namespace kernel::filesystem
+{
+
+ //! A type descriptor for a filesystem driver.
+ //!
+ //! Each filesystem must expose an instance of a class derived from this type in order to be registered with the vfs
+ //! filesystem registry.
+ struct type
+ {
+ virtual ~type() = default;
+
+ //! Get the name of the filesystem represented by this descriptor.
+ [[nodiscard]] virtual auto name() const noexcept -> std::string_view = 0;
+
+ //! Check if filesystems of this type require a device to back them.
+ [[nodiscard]] virtual auto requires_device() const noexcept -> bool = 0;
+
+ //! Create a new instance of the filesytem represented by this descriptor.
+ [[nodiscard]] virtual auto make_instance() const -> kstd::shared_ptr<filesystem> = 0;
+ };
+
+ template<typename Type>
+ struct type_registration
+ {
+ constexpr auto static instance = Type{};
+ [[using gnu: section("fs_types"), used, visibility("hidden")]] constexpr auto static pointer{
+ kstd::make_observer<type const>(&instance),
+ };
+ };
+
+} // namespace kernel::filesystem
+
+#endif
diff --git a/kernel/include/kernel/filesystem/type_registry.hpp b/kernel/include/kernel/filesystem/type_registry.hpp
new file mode 100644
index 0000000..3be7295
--- /dev/null
+++ b/kernel/include/kernel/filesystem/type_registry.hpp
@@ -0,0 +1,53 @@
+#ifndef TEACH_OS_KERNEL_TYPE_REGISRY_HPP
+#define TEACH_OS_KERNEL_TYPE_REGISRY_HPP
+
+#include <kernel/filesystem/type.hpp>
+
+#include <kstd/flat_map>
+#include <kstd/memory>
+#include <kstd/string>
+
+#include <cstddef>
+#include <span>
+#include <string_view>
+
+namespace kernel::filesystem
+{
+
+ struct type_registry
+ {
+ using value_type = type;
+ using pointer = kstd::observer_ptr<value_type const>;
+
+ auto static init() -> void;
+ auto static get() -> type_registry &;
+
+ constexpr type_registry() noexcept = default;
+
+ //! Add a type descriptor to this registry.
+ //!
+ //! This function will register the given descriptor with this registry, given that no descriptor for a filesystem
+ //! with the same name exists in this registry already.
+ //!
+ //! @param descriptor The filesystem type descriptor to add to the registry.
+ //! @return @p true iff. the descriptor was successfully added, @p false if not.
+ auto add(pointer descriptor) -> bool;
+
+ //! Get all currently registered type descriptors.
+ //!
+ //! @return A span containing all currently registered filesystem type descriptors.
+ [[nodiscard]] auto all() const noexcept -> std::span<pointer const>;
+
+ //! Get the number of registered filesystem types.
+ //!
+ //! @return The number of filesystem descriptors currently registered with this registry.
+ [[nodiscard]] auto size() const noexcept -> std::size_t;
+
+ private:
+ //! A map from filesystem names (identifiers) to filesystem type descriptors.
+ kstd::flat_map<std::string_view, pointer> m_descriptors{};
+ };
+
+} // namespace kernel::filesystem
+
+#endif
diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp
index e6f2327..ddc9a9b 100644
--- a/kernel/include/kernel/filesystem/vfs.hpp
+++ b/kernel/include/kernel/filesystem/vfs.hpp
@@ -35,6 +35,8 @@ namespace kernel::filesystem
invalid_filesystem = -5
};
+ vfs();
+
/**
@brief Initialize the virtual filesystem.
@warning Panics if the VFS has already been initialized.
@@ -83,9 +85,6 @@ namespace kernel::filesystem
auto unmount(std::string_view path) -> operation_result;
private:
- vfs() = default;
- auto init_internal() -> void;
-
/**
* Note: Resolving a dentry requires traversing mount points; since the
* associated 'mount' object is discovered as a byproduct of this
@@ -107,7 +106,7 @@ namespace kernel::filesystem
auto graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void;
- mount_table m_mount_table;
+ mount_table m_mount_table{};
};
} // namespace kernel::filesystem