/* * Copyright (c) 2021, Liav A. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace Kernel { class SysFS; class SystemExposedComponent : public RefCounted { public: virtual KResultOr entries_count() const { VERIFY_NOT_REACHED(); }; virtual StringView name() const { return m_name->view(); } virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const { VERIFY_NOT_REACHED(); } virtual KResult traverse_as_directory(unsigned, Function) const { VERIFY_NOT_REACHED(); } virtual RefPtr lookup(StringView) { VERIFY_NOT_REACHED(); }; virtual KResultOr write_bytes(off_t, size_t, const UserOrKernelBuffer&, FileDescription*) { return -EROFS; } virtual size_t size() const { return 0; } virtual NonnullRefPtr to_inode(const SysFS& sysfs_instance) const; InodeIndex component_index() const { return m_component_index; }; virtual ~SystemExposedComponent() = default; protected: explicit SystemExposedComponent(StringView name); private: NonnullOwnPtr m_name; InodeIndex m_component_index {}; }; class SystemExposedFolder : public SystemExposedComponent { public: virtual KResultOr entries_count() const override { return m_components.size(); }; virtual KResult traverse_as_directory(unsigned, Function) const override; virtual RefPtr lookup(StringView name) override; void add_component(const SystemExposedComponent&); virtual NonnullRefPtr to_inode(const SysFS& sysfs_instance) const override final; protected: explicit SystemExposedFolder(String name); SystemExposedFolder(String name, const SystemExposedFolder& parent_folder); NonnullRefPtrVector m_components; RefPtr m_parent_folder; }; }