diff options
Diffstat (limited to 'kernel/kernel/filesystem/filesystem.hpp')
| -rw-r--r-- | kernel/kernel/filesystem/filesystem.hpp | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/kernel/kernel/filesystem/filesystem.hpp b/kernel/kernel/filesystem/filesystem.hpp index 1a66c11c..f9fb2859 100644 --- a/kernel/kernel/filesystem/filesystem.hpp +++ b/kernel/kernel/filesystem/filesystem.hpp @@ -10,8 +10,10 @@ #include <kstd/system_error.hpp> #include <kstd/vector.hpp> +#include <cstdint> #include <optional> #include <string_view> +#include <utility> namespace kernel::filesystem { @@ -21,17 +23,19 @@ namespace kernel::filesystem //! Filesystem implementations must derive from this class. struct filesystem { + using filesystem_ptr = kstd::shared_ptr<filesystem>; + using driver_data_ptr = kstd::shared_ptr<void>; + using inode_ptr = kstd::shared_ptr<inode>; + using mount_result = std::pair<inode_ptr, driver_data_ptr>; + //! Virtual destructor enabling polymorphic destruction. virtual ~filesystem() = default; - //! Probes the given inode to determine if it contains a recognizable filesystem, and if so, mount it. - //! - //! @warning This function panics if @p backing_inode is null. + //! Check if the data represented by the given inode is recognized as this filesystem. //! - //! @param backing_inode The inode to probe and mount. - //! @return A pointer to the mounted filesystem instance on success, an error otherwise. - auto static probe_and_mount(kstd::shared_ptr<inode> const & backing_inode) - -> kstd::result<kstd::shared_ptr<filesystem>>; + //! @param inode The inode to probe, if any. + //! @return the priority (higher is better) of the match on success, an error otherwise. + [[nodiscard]] virtual auto probe(inode_ptr const & inode) const -> kstd::result<std::uint32_t> = 0; //! Initializes the filesystem with the given inode. //! @@ -39,8 +43,8 @@ namespace kernel::filesystem //! filesystem data (e.g. a file on an already mounted filesystem). //! //! @param backing_inode The inode to use as the backing inode for the filesystem. - //! @return Nothing on success, and error otherwise. - virtual auto mount(kstd::shared_ptr<inode> const & backing_inode) -> kstd::result<void>; + //! @return The root inode of the mounted filesystem on success, and error otherwise. + virtual auto mount(inode_ptr const & backing_inode) -> kstd::result<mount_result> = 0; //! Find a child inode below the given parent inode with the specified name. //! @@ -49,35 +53,23 @@ namespace kernel::filesystem //! //! @param parent The parent inode. //! @param name The name of the child inode to look up. + //! @param driver_data The per-mount data used by the driver. //! @return A pointer to the requested child inode on success, an error otherwise. - [[nodiscard]] virtual auto lookup(kstd::shared_ptr<inode> const & parent, std::string_view name) const - -> kstd::result<kstd::shared_ptr<inode>> = 0; + [[nodiscard]] virtual auto lookup(inode_ptr const & parent, std::string_view name, + driver_data_ptr driver_data) const -> kstd::result<inode_ptr> = 0; //! Create a new inode with the given name below a given parent inode. //! //! @param parent The parent inode. //! @param name The name of the inode to create. //! @param type The file type of inode to be created. + //! @param driver_data The per-mount data used by the driver. //! @param raw_device The device number the new inode should represent, if any. //! @return A pointer to the created inode on success, an error otherwise. - [[nodiscard]] virtual auto create_inode(kstd::shared_ptr<inode> const & parent, std::string_view name, - kapi::filesystem::file_type type, + [[nodiscard]] virtual auto create_inode(inode_ptr const & parent, std::string_view name, + kapi::filesystem::file_type type, driver_data_ptr driver_data, std::optional<kapi::filesystem::device_number> raw_device = std::nullopt) -> kstd::result<kstd::shared_ptr<inode>> = 0; - - //! Get the root inode of the file system. - //! - //! @return A reference to the root inode. - [[nodiscard]] auto root_inode() const -> kstd::shared_ptr<inode> const &; - - //! Get the backing inode of the file system. - //! - //! @return A reference to the backing inode. - [[nodiscard]] auto backing_inode() const -> kstd::shared_ptr<inode> const &; - - protected: - kstd::shared_ptr<inode> m_root_inode{}; - kstd::shared_ptr<inode> m_backing_inode{}; }; } // namespace kernel::filesystem |
