diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-04-08 15:21:10 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-04-11 07:58:21 +0200 |
| commit | 2793770dc6eba30b73b4a4993618d2cbe184790e (patch) | |
| tree | b3e18a675aecf20a5356b36985628b0c59b0c52b /kernel/include | |
| parent | 9c0fb15aa67a4dda6beed3cbdfc4cc510674313f (diff) | |
| download | teachos-2793770dc6eba30b73b4a4993618d2cbe184790e.tar.xz teachos-2793770dc6eba30b73b4a4993618d2cbe184790e.zip | |
implement unmount, improve error codes
Diffstat (limited to 'kernel/include')
| -rw-r--r-- | kernel/include/kernel/filesystem/devfs/filesystem.hpp | 4 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/ext2/filesystem.hpp | 4 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/filesystem.hpp | 12 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/mount.hpp | 10 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/mount_table.hpp | 21 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/rootfs/filesystem.hpp | 4 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/vfs.hpp | 23 |
7 files changed, 66 insertions, 12 deletions
diff --git a/kernel/include/kernel/filesystem/devfs/filesystem.hpp b/kernel/include/kernel/filesystem/devfs/filesystem.hpp index 60c39cf..137eca3 100644 --- a/kernel/include/kernel/filesystem/devfs/filesystem.hpp +++ b/kernel/include/kernel/filesystem/devfs/filesystem.hpp @@ -24,9 +24,9 @@ namespace kernel::filesystem::devfs /** @brief Initializes the devfs instance and builds the device inode table. @param device Backing device passed by the generic filesystem interface (not required by devfs). - @return 0 on success, -1 on failure. + @return The result of the mount operation. */ - auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> int override; + auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> operation_result override; /** @brief Looks up an inode by @p name within a @p parent directory. diff --git a/kernel/include/kernel/filesystem/ext2/filesystem.hpp b/kernel/include/kernel/filesystem/ext2/filesystem.hpp index 32374dc..65324c8 100644 --- a/kernel/include/kernel/filesystem/ext2/filesystem.hpp +++ b/kernel/include/kernel/filesystem/ext2/filesystem.hpp @@ -27,9 +27,9 @@ namespace kernel::filesystem::ext2 /** @brief Initializes the ext2 filesystem with the given @p device. @param device The device to mount. - @return 0 on success, negative error code on failure. + @return The result of the mount operation. */ - auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> int override; + auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> operation_result override; /** @brief Looks up an inode by @p name within a @p parent directory. diff --git a/kernel/include/kernel/filesystem/filesystem.hpp b/kernel/include/kernel/filesystem/filesystem.hpp index f855380..ef6929a 100644 --- a/kernel/include/kernel/filesystem/filesystem.hpp +++ b/kernel/include/kernel/filesystem/filesystem.hpp @@ -18,6 +18,14 @@ namespace kernel::filesystem */ struct filesystem { + enum class operation_result : int + { + success = 0, + invalid_magic_number = -1, + invalid_root_inode = -2, + unmount_failed = -3 + }; + /** @brief Virtual destructor for the filesystem. */ @@ -37,9 +45,9 @@ namespace kernel::filesystem /** @brief Initializes the filesystem with the given @p device. @param device The device to mount. - @return 0 on success, or a negative error code on failure. + @return The result of the mount operation. */ - virtual auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> int; + virtual auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> operation_result; /** @brief Looks up a child inode within the given @p parent inode with the specified @p name. This method must be diff --git a/kernel/include/kernel/filesystem/mount.hpp b/kernel/include/kernel/filesystem/mount.hpp index 3e3c69f..0ac6b2f 100644 --- a/kernel/include/kernel/filesystem/mount.hpp +++ b/kernel/include/kernel/filesystem/mount.hpp @@ -24,9 +24,11 @@ namespace kernel::filesystem @param root_dentry The root dentry of the mounted filesystem. @param fs The filesystem instance being mounted. @param mount_path The path at which the filesystem is mounted. + @param parent_mount The parent mount that this mount is attached beneath. */ mount(kstd::shared_ptr<dentry> const & mount_dentry, kstd::shared_ptr<dentry> const & root_dentry, - kstd::shared_ptr<filesystem> const & fs, std::string_view mount_path); + kstd::shared_ptr<filesystem> const & fs, std::string_view mount_path, + kstd::shared_ptr<mount> const & parent_mount); /** @brief Get the dentry where the filesystem is mounted. @@ -48,11 +50,17 @@ namespace kernel::filesystem */ [[nodiscard]] auto get_mount_path() const -> std::string_view; + /** + @brief Get the parent mount that this mount was attached beneath. + */ + [[nodiscard]] auto get_parent_mount() const -> kstd::shared_ptr<mount> const &; + private: kstd::string m_mount_path; kstd::shared_ptr<dentry> m_mount_dentry; kstd::shared_ptr<dentry> m_root_dentry; kstd::shared_ptr<filesystem> m_filesystem{}; + kstd::shared_ptr<mount> m_parent_mount{}; }; } // namespace kernel::filesystem diff --git a/kernel/include/kernel/filesystem/mount_table.hpp b/kernel/include/kernel/filesystem/mount_table.hpp index a8ef59e..a5cdde6 100644 --- a/kernel/include/kernel/filesystem/mount_table.hpp +++ b/kernel/include/kernel/filesystem/mount_table.hpp @@ -16,10 +16,27 @@ namespace kernel::filesystem struct mount_table { /** + @brief Results for mount table operations. + */ + enum class operation_result : int + { + removed = 0, + has_child_mounts = -1, + mount_not_found = -2 + }; + + /** @brief Adds a mount to the table. @param mount The mount to add. */ - void add_mount(kstd::shared_ptr<mount> const & mount); + auto add_mount(kstd::shared_ptr<mount> const & mount) -> void; + + /** + @brief Removes the topmost mount at the given @p path. + @param path The mount path to remove. + @return The result of the removal operation. + */ + [[nodiscard]] auto remove_mount(std::string_view path) -> operation_result; /** @brief Finds the mount with the longest prefix matching the given @p path. This method is used to determine which @@ -30,6 +47,8 @@ namespace kernel::filesystem [[nodiscard]] auto find_longest_prefix_mount(std::string_view path) const -> kstd::shared_ptr<mount>; private: + [[nodiscard]] auto has_child_mounts(kstd::shared_ptr<mount> const & parent_mount) const -> bool; + kstd::vector<kstd::shared_ptr<mount>> m_mounts; }; } // namespace kernel::filesystem diff --git a/kernel/include/kernel/filesystem/rootfs/filesystem.hpp b/kernel/include/kernel/filesystem/rootfs/filesystem.hpp index b7e7c6f..0155c41 100644 --- a/kernel/include/kernel/filesystem/rootfs/filesystem.hpp +++ b/kernel/include/kernel/filesystem/rootfs/filesystem.hpp @@ -25,9 +25,9 @@ namespace kernel::filesystem::rootfs /** @brief Initializes the rootfs filesystem with the given @p device. @param device The device to mount (not required by rootfs). - @return 0 on success, negative error code on failure. + @return The result of the mount operation. */ - auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> int override; + auto mount(kstd::shared_ptr<kapi::devices::device> const & device) -> operation_result override; /** @brief Looks up an inode by @p name within a @p parent directory. diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp index 2d05765..4dd2a83 100644 --- a/kernel/include/kernel/filesystem/vfs.hpp +++ b/kernel/include/kernel/filesystem/vfs.hpp @@ -21,6 +21,18 @@ namespace kernel::filesystem struct vfs { /** + @brief Results for VFS operations. + */ + enum class operation_result : int + { + success = 0, + invalid_path = -1, + mount_point_not_found = -2, + filesystem_null = -3, + unmount_failed = -4 + }; + + /** @brief Initialize the virtual filesystem. @warning Panics if the VFS has already been initialized. */ @@ -49,9 +61,16 @@ namespace kernel::filesystem @brief Mount a @p filesystem at a specific @p path. @param path The path where the filesystem should be mounted. @param filesystem The filesystem to mount. - @return 0 on success, or a negative error code on failure. + @return The result of the mount operation. + */ + auto do_mount(std::string_view path, kstd::shared_ptr<filesystem> const & filesystem) -> operation_result; + + /** + @brief Unmount the filesystem mounted at the specified @p path. + @param path The path where the filesystem is mounted. + @return The result of the unmount operation. */ - auto do_mount(std::string_view path, kstd::shared_ptr<filesystem> const & filesystem) -> int; + auto unmount(std::string_view path) -> operation_result; private: vfs() = default; |
