diff options
Diffstat (limited to 'kernel/filesystem/include')
10 files changed, 48 insertions, 32 deletions
diff --git a/kernel/filesystem/include/filesystem/custody.hpp b/kernel/filesystem/include/filesystem/custody.hpp index 9ee984d..b6eae22 100644 --- a/kernel/filesystem/include/filesystem/custody.hpp +++ b/kernel/filesystem/include/filesystem/custody.hpp @@ -3,18 +3,20 @@ #include "filesystem/inode.hpp" +#include <kstd/memory> + namespace filesystem { struct custody { - custody(custody * parent, inode * node); + custody(kstd::shared_ptr<custody> parent, kstd::shared_ptr<inode> node); - [[nodiscard]] auto get_inode() const -> inode *; - [[nodiscard]] auto get_parent() const -> custody *; + [[nodiscard]] auto get_inode() const -> kstd::shared_ptr<inode>; + [[nodiscard]] auto get_parent() const -> kstd::shared_ptr<custody>; private: - custody * m_parent; - inode * m_inode; + kstd::shared_ptr<custody> m_parent; + kstd::shared_ptr<inode> m_inode; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/device_file.hpp b/kernel/filesystem/include/filesystem/device_file.hpp index 033317b..4dce37f 100644 --- a/kernel/filesystem/include/filesystem/device_file.hpp +++ b/kernel/filesystem/include/filesystem/device_file.hpp @@ -5,13 +5,15 @@ #include "devices/device.hpp" #include "filesystem/file.hpp" +#include <kstd/memory> + #include <cstddef> namespace filesystem { struct device_file : file { - explicit device_file(devices::device * device); + explicit device_file(kstd::shared_ptr<devices::device> device); auto open() -> void override; @@ -23,7 +25,7 @@ namespace filesystem std::byte * scratch, void * buffer); auto process_blocks(size_t offset, size_t size, void * buffer, block_op op) const -> size_t; - devices::device * m_device; + kstd::shared_ptr<devices::device> m_device; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/ext2/ext2_filesystem.hpp b/kernel/filesystem/include/filesystem/ext2/ext2_filesystem.hpp index cba2192..dd52e72 100644 --- a/kernel/filesystem/include/filesystem/ext2/ext2_filesystem.hpp +++ b/kernel/filesystem/include/filesystem/ext2/ext2_filesystem.hpp @@ -5,17 +5,19 @@ #include "filesystem/filesystem.hpp" #include "filesystem/inode.hpp" +#include <kstd/memory> + #include <string_view> namespace filesystem::ext2 { struct ext2_filesystem : filesystem { - auto mount(devices::device * device) -> int override; + auto mount(kstd::shared_ptr<devices::device> device) -> int override; auto lookup(inode const & parent, std::string_view name) -> inode * override; private: - devices::device * m_device{}; + kstd::shared_ptr<devices::device> m_device{}; }; } // namespace filesystem::ext2 diff --git a/kernel/filesystem/include/filesystem/file_descriptor_table.hpp b/kernel/filesystem/include/filesystem/file_descriptor_table.hpp index 3ac03d1..6d78532 100644 --- a/kernel/filesystem/include/filesystem/file_descriptor_table.hpp +++ b/kernel/filesystem/include/filesystem/file_descriptor_table.hpp @@ -3,7 +3,8 @@ #include "open_file_description.hpp" -#include <array> +#include <kstd/vector> + #include <optional> namespace filesystem @@ -23,8 +24,7 @@ namespace filesystem file_descriptor_table() = default; // TODO BA-FS26 use kstd::shared_ptr when available - // TODO BA-FS26 use kstd::vector when available - std::array<std::optional<open_file_description>, 32> m_open_files{}; + kstd::vector<std::optional<open_file_description>> m_open_files{}; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/filesystem.hpp b/kernel/filesystem/include/filesystem/filesystem.hpp index 8deb336..eabefc0 100644 --- a/kernel/filesystem/include/filesystem/filesystem.hpp +++ b/kernel/filesystem/include/filesystem/filesystem.hpp @@ -4,6 +4,8 @@ #include "devices/device.hpp" #include "filesystem/inode.hpp" +#include <kstd/memory> + #include <string_view> namespace filesystem @@ -12,11 +14,10 @@ namespace filesystem { virtual ~filesystem() = default; - virtual auto mount(devices::device * device) -> int = 0; + virtual auto mount(kstd::shared_ptr<devices::device> device) -> int = 0; virtual auto lookup(inode const & parent, std::string_view name) -> inode * = 0; - [[nodiscard]] auto root_inode() -> inode *; - [[nodiscard]] auto root_inode() const -> inode const *; + [[nodiscard]] auto root_inode() const -> inode const &; protected: inode m_root_inode{}; // TODO BA-FS26 set during mount? diff --git a/kernel/filesystem/include/filesystem/inode.hpp b/kernel/filesystem/include/filesystem/inode.hpp index bceabb6..2b5ee6c 100644 --- a/kernel/filesystem/include/filesystem/inode.hpp +++ b/kernel/filesystem/include/filesystem/inode.hpp @@ -4,6 +4,8 @@ #include "devices/device.hpp" #include "filesystem/inode_metadata.hpp" +#include <kstd/memory> + #include <cstddef> namespace filesystem @@ -12,7 +14,7 @@ namespace filesystem { inode() = default; explicit inode(inode_kind kind); - explicit inode(devices::device * device); + explicit inode(kstd::shared_ptr<devices::device> device); [[nodiscard]] auto metadata() const -> inode_metadata; @@ -22,14 +24,14 @@ namespace filesystem [[nodiscard]] auto is_block_device() const -> bool; [[nodiscard]] auto major_device() const -> size_t; [[nodiscard]] auto minor_device() const -> size_t; - [[nodiscard]] auto backing_device() const -> devices::device *; + [[nodiscard]] auto backing_device() const -> kstd::shared_ptr<devices::device>; auto read(void * buffer, size_t offset, size_t size) const -> size_t; auto write(void const * buffer, size_t offset, size_t size) -> size_t; private: inode_kind m_kind{inode_kind::regular}; - devices::device * m_device{}; + kstd::shared_ptr<devices::device> m_device{}; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/inode_file.hpp b/kernel/filesystem/include/filesystem/inode_file.hpp index c091280..512f51d 100644 --- a/kernel/filesystem/include/filesystem/inode_file.hpp +++ b/kernel/filesystem/include/filesystem/inode_file.hpp @@ -4,13 +4,15 @@ #include "filesystem/file.hpp" #include "filesystem/inode.hpp" +#include <kstd/memory> + #include <cstddef> namespace filesystem { struct inode_file : file { - explicit inode_file(inode * inode); + explicit inode_file(kstd::shared_ptr<inode> inode); auto open() -> void override; @@ -18,7 +20,7 @@ namespace filesystem auto write(void const * buffer, size_t offset, size_t size) -> size_t override; private: - inode * m_inode; + kstd::shared_ptr<inode> m_inode; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/mount.hpp b/kernel/filesystem/include/filesystem/mount.hpp index fe5d9cc..f28de74 100644 --- a/kernel/filesystem/include/filesystem/mount.hpp +++ b/kernel/filesystem/include/filesystem/mount.hpp @@ -3,21 +3,22 @@ #include "filesystem/filesystem.hpp" +#include <kstd/memory> + #include <string_view> namespace filesystem { struct mount { - mount() = default; // TODO BA-FS26 remove again when kstd::vector is available and used in vfs - mount(std::string_view const & path, filesystem * fs); + mount(std::string_view const & path, kstd::shared_ptr<filesystem> fs); [[nodiscard]] auto path() const -> std::string_view; - [[nodiscard]] auto get_filesystem() const -> filesystem *; + [[nodiscard]] auto get_filesystem() const -> kstd::shared_ptr<filesystem>; private: std::string_view m_path; - filesystem * m_filesystem{}; + kstd::shared_ptr<filesystem> m_filesystem{}; }; } // namespace filesystem diff --git a/kernel/filesystem/include/filesystem/open_file_description.hpp b/kernel/filesystem/include/filesystem/open_file_description.hpp index 1589196..035b0ee 100644 --- a/kernel/filesystem/include/filesystem/open_file_description.hpp +++ b/kernel/filesystem/include/filesystem/open_file_description.hpp @@ -2,6 +2,7 @@ #define TEACH_OS_KERNEL_FILESYSTEM_OPEN_FILE_DESCRIPTION_HPP #include "file.hpp" +#include <kstd/memory> #include <cstddef> @@ -9,7 +10,7 @@ namespace filesystem { struct open_file_description { - open_file_description(file * file); + open_file_description(kstd::shared_ptr<file> file); ~open_file_description() = default; @@ -17,7 +18,7 @@ namespace filesystem auto write(void const * buffer, size_t size) -> size_t; private: - file * m_file; + kstd::shared_ptr<file> m_file; size_t m_offset; }; diff --git a/kernel/filesystem/include/filesystem/vfs.hpp b/kernel/filesystem/include/filesystem/vfs.hpp index 1d95d4a..9c89044 100644 --- a/kernel/filesystem/include/filesystem/vfs.hpp +++ b/kernel/filesystem/include/filesystem/vfs.hpp @@ -3,11 +3,14 @@ #include "devices/device.hpp" #include "filesystem/custody.hpp" +#include "filesystem/ext2/ext2_filesystem.hpp" #include "filesystem/inode.hpp" #include "filesystem/mount.hpp" #include "filesystem/open_file_description.hpp" -#include <array> +#include <kstd/memory> +#include <kstd/vector> + #include <optional> #include <string_view> @@ -26,17 +29,17 @@ namespace filesystem struct device_node_entry { std::string_view name; - inode node; + kstd::shared_ptr<inode> node; }; vfs() = default; - auto make_device_node(devices::device * device) -> void; + auto make_device_node(kstd::shared_ptr<devices::device> device) -> void; [[nodiscard]] auto resolve_path(std::string_view path) -> std::optional<custody>; + kstd::shared_ptr<ext2::ext2_filesystem> m_root_fs; std::optional<mount> m_root_mount; - std::array<mount, 10> m_mounts; // TODO BA-FS26 remove when kstd::vector is available and used - std::array<std::optional<device_node_entry>, 10> - m_device_nodes; // TODO BA-FS26 use kstd::vector // TODO BA-FS26 remove again, use + // kstd::vector<mount> m_mounts; // TODO BA-FS26 really needed? + kstd::vector<std::optional<device_node_entry>> m_device_nodes; // TODO BA-FS26 remove again, use devtempfs }; } // namespace filesystem |
