/* * 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 = 0; virtual ErrorOr read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); } virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); } virtual RefPtr lookup(StringView) { VERIFY_NOT_REACHED(); }; virtual mode_t permissions() const; virtual ErrorOr truncate(u64) { return EPERM; } virtual ErrorOr set_mtime(time_t) { return ENOTIMPL; } virtual ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } virtual ErrorOr refresh_data(OpenFileDescription&) const { return {}; } virtual ErrorOr> to_inode(SysFS const&) const; InodeIndex component_index() const { return m_component_index; }; virtual ~SysFSComponent() = default; protected: SysFSComponent(); private: InodeIndex m_component_index {}; }; class SysFSDirectory : public SysFSComponent { public: virtual ErrorOr traverse_as_directory(FileSystemID, Function(FileSystem::DirectoryEntryView const&)>) const override; virtual RefPtr lookup(StringView name) override; virtual ErrorOr> to_inode(SysFS const& sysfs_instance) const override final; protected: SysFSDirectory() = default; explicit SysFSDirectory(SysFSDirectory const& parent_directory); NonnullRefPtrVector m_components; RefPtr m_parent_directory; }; }