/* * Copyright (c) 2021, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Kernel { struct SysFSInodeData : public OpenFileDescriptionData { OwnPtr buffer; }; class SysFSComponent : public RefCounted { public: virtual StringView name() const { return m_name->view(); } virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } virtual KResult traverse_as_directory(unsigned, Function) const { VERIFY_NOT_REACHED(); } virtual RefPtr lookup(StringView) { VERIFY_NOT_REACHED(); }; virtual mode_t permissions() const; virtual KResultOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } virtual KResult refresh_data(OpenFileDescription&) const { return KSuccess; } virtual KResultOr> to_inode(SysFS const&) const; InodeIndex component_index() const { return m_component_index; }; virtual ~SysFSComponent() = default; protected: explicit SysFSComponent(StringView name); private: NonnullOwnPtr m_name; InodeIndex m_component_index {}; }; class SysFSDirectory : public SysFSComponent { public: virtual KResult traverse_as_directory(unsigned, Function) const override; virtual RefPtr lookup(StringView name) override; virtual KResultOr> to_inode(SysFS const& sysfs_instance) const override final; protected: explicit SysFSDirectory(StringView name); SysFSDirectory(StringView name, SysFSDirectory const& parent_directory); NonnullRefPtrVector m_components; RefPtr m_parent_directory; }; }