/* * Copyright (c) 2021, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Kernel { class SysFS final : public FileSystem { friend class SysFSInode; friend class SysFSDirectoryInode; public: virtual ~SysFS() override; static ErrorOr> try_create(); virtual ErrorOr initialize() override; virtual StringView class_name() const override { return "SysFS"sv; } virtual Inode& root_inode() override; private: SysFS(); RefPtr m_root_inode; }; class SysFSInode : public Inode { friend class SysFS; friend class SysFSDirectoryInode; public: static ErrorOr> try_create(SysFS const&, SysFSComponent const&); StringView name() const { return m_associated_component->name(); } protected: SysFSInode(SysFS const&, SysFSComponent const&); virtual ErrorOr read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual ErrorOr traverse_as_directory(Function(FileSystem::DirectoryEntryView const&)>) const override; virtual ErrorOr> lookup(StringView name) override; virtual ErrorOr flush_metadata() override; virtual InodeMetadata metadata() const override; virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override; virtual ErrorOr> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual ErrorOr add_child(Inode&, StringView name, mode_t) override; virtual ErrorOr remove_child(StringView name) override; virtual ErrorOr chmod(mode_t) override; virtual ErrorOr chown(UserID, GroupID) override; virtual ErrorOr truncate(u64) override; virtual ErrorOr set_mtime(time_t) override; virtual ErrorOr attach(OpenFileDescription& description) override final; virtual void did_seek(OpenFileDescription&, off_t) override final; NonnullRefPtr m_associated_component; }; class SysFSLinkInode : public SysFSInode { friend class SysFS; public: static ErrorOr> try_create(SysFS const&, SysFSComponent const&); virtual ~SysFSLinkInode() override; protected: SysFSLinkInode(SysFS const&, SysFSComponent const&); // ^Inode virtual InodeMetadata metadata() const override; }; class SysFSDirectoryInode : public SysFSInode { friend class SysFS; public: static ErrorOr> try_create(SysFS const&, SysFSComponent const&); virtual ~SysFSDirectoryInode() override; SysFS& fs() { return static_cast(Inode::fs()); } SysFS const& fs() const { return static_cast(Inode::fs()); } protected: SysFSDirectoryInode(SysFS const&, SysFSComponent const&); // ^Inode virtual InodeMetadata metadata() const override; virtual ErrorOr traverse_as_directory(Function(FileSystem::DirectoryEntryView const&)>) const override; virtual ErrorOr> lookup(StringView name) override; }; }