diff options
Diffstat (limited to 'kernel/kernel/filesystem/vfs.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/vfs.hpp | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/kernel/kernel/filesystem/vfs.hpp b/kernel/kernel/filesystem/vfs.hpp index ddc9a9bc..9dfd3637 100644 --- a/kernel/kernel/filesystem/vfs.hpp +++ b/kernel/kernel/filesystem/vfs.hpp @@ -7,7 +7,9 @@ #include <kernel/filesystem/mount.hpp> #include <kernel/filesystem/mount_table.hpp> -#include <kstd/memory> +#include <kstd/memory.hpp> +#include <kstd/result.hpp> +#include <kstd/system_error.hpp> #include <string_view> #include <utility> @@ -17,23 +19,14 @@ namespace kernel::filesystem /** @brief The virtual filesystem (VFS) is responsible for managing mounted filesystems and providing a unified interface for file operations across different filesystem types. The VFS maintains a mount table to keep track of mounted - filesystems and their associated mount points. It provides methods for opening files by path, which involvesresolving + filesystems and their associated mount points. It provides methods for opening files by path, which involves resolving the path to the appropriate mounted filesystem and delegating the file operation to that filesystem's implementation. */ struct vfs { - /** - @brief Results for VFS operations. - */ - enum class operation_result : int - { - success = 0, - invalid_path = -1, - non_existent_path = -2, - mount_point_not_found = -3, - unmount_failed = -4, - invalid_filesystem = -5 - }; + using dentry_ptr = kstd::shared_ptr<dentry>; + using mount_ptr = kstd::shared_ptr<struct mount>; + using fs_ptr = kstd::shared_ptr<filesystem>; vfs(); @@ -58,31 +51,31 @@ namespace kernel::filesystem /** @brief Open a file by its @p path. This method resolves the path and returns the corresponding dentry. @param path The path to the file to open. - @return A shared pointer to the dentry or a null pointer if the file could not be opened. + @return A shared pointer to the dentry on success or an error code on failure. */ - auto open(std::string_view path) -> kstd::shared_ptr<dentry>; + auto open(std::string_view path) -> kstd::result<dentry_ptr>; /** @brief Close a file by its associated @p path. @param path The path to the file to close. - @return The result of the close operation. + @return Nothing on success or an error code on failure. */ - auto close(std::string_view path) -> operation_result; + auto close(std::string_view path) -> kstd::result<void>; /** @brief Mount a @p source path to a specific @p target path. @param source The source of the filesystem to mount. @param target The path where the filesystem should be mounted. - @return The result of the mount operation. + @return Nothing on success or an error code on failure. */ - auto do_mount(std::string_view source, std::string_view target) -> operation_result; + auto mount(std::string_view source, std::string_view target) -> kstd::result<void>; /** @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. + @return Nothing on success or an error code on failure. */ - auto unmount(std::string_view path) -> operation_result; + auto unmount(std::string_view path) -> kstd::result<void>; private: /** @@ -96,13 +89,14 @@ namespace kernel::filesystem * - find_mount() for the mount context only. */ [[nodiscard]] auto resolve_path_internal(std::string_view path) const - -> std::pair<kstd::shared_ptr<dentry>, kstd::shared_ptr<mount>>; - [[nodiscard]] auto resolve_path(std::string_view path) const -> kstd::shared_ptr<dentry>; - [[nodiscard]] auto find_mount(std::string_view path) const -> kstd::shared_ptr<mount>; + -> kstd::result<std::pair<dentry_ptr, mount_ptr>>; + + [[nodiscard]] auto resolve_path(std::string_view path) const -> kstd::result<dentry_ptr>; + + [[nodiscard]] auto find_mount(std::string_view path) const -> kstd::result<mount_ptr>; - auto do_mount_internal(kstd::shared_ptr<dentry> const & mount_point_dentry, - kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs, - kstd::shared_ptr<mount> const & source_mount = nullptr) -> void; + auto do_mount_internal(dentry_ptr const & mount_point_dentry, mount_ptr const & parent_mount, fs_ptr const & fs, + mount_ptr const & source_mount = nullptr) -> void; auto graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void; |
