diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-11 01:14:53 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-11 01:14:53 +0200 |
commit | d40ea1a0a84d5056924d17efaea000a4b2214109 (patch) | |
tree | 8306e3668f6e295176fd2c14e6268b5c1cfccf7f /Kernel/FileSystem/SysFSComponent.h | |
parent | 807aadbe6edabdd14d00aff2a00feb5dc718b11a (diff) | |
download | serenity-d40ea1a0a84d5056924d17efaea000a4b2214109.zip |
Kernel: Move SystemExposed.* => FileSystem/SysFSComponent.*
Diffstat (limited to 'Kernel/FileSystem/SysFSComponent.h')
-rw-r--r-- | Kernel/FileSystem/SysFSComponent.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Kernel/FileSystem/SysFSComponent.h b/Kernel/FileSystem/SysFSComponent.h new file mode 100644 index 0000000000..7ed8d4d1bc --- /dev/null +++ b/Kernel/FileSystem/SysFSComponent.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Function.h> +#include <AK/RefCounted.h> +#include <AK/RefPtr.h> +#include <AK/StringView.h> +#include <AK/Types.h> +#include <Kernel/FileSystem/File.h> +#include <Kernel/FileSystem/FileSystem.h> +#include <Kernel/FileSystem/Forward.h> +#include <Kernel/KResult.h> + +namespace Kernel { + +class SysFSComponent : public RefCounted<SysFSComponent> { +public: + virtual KResultOr<size_t> entries_count() const { VERIFY_NOT_REACHED(); }; + virtual StringView name() const { return m_name->view(); } + virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const { VERIFY_NOT_REACHED(); } + virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); } + virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); }; + virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) { return -EROFS; } + virtual size_t size() const { return 0; } + + virtual NonnullRefPtr<Inode> to_inode(SysFS const&) const; + + InodeIndex component_index() const { return m_component_index; }; + + virtual ~SysFSComponent() = default; + +protected: + explicit SysFSComponent(StringView name); + +private: + NonnullOwnPtr<KString> m_name; + InodeIndex m_component_index {}; +}; + +class SysFSDirectory : public SysFSComponent { +public: + virtual KResultOr<size_t> entries_count() const override { return m_components.size(); }; + virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override; + virtual RefPtr<SysFSComponent> lookup(StringView name) override; + + virtual NonnullRefPtr<Inode> to_inode(SysFS const& sysfs_instance) const override final; + +protected: + explicit SysFSDirectory(StringView name); + SysFSDirectory(StringView name, SysFSDirectory const& parent_folder); + NonnullRefPtrVector<SysFSComponent> m_components; + RefPtr<SysFSDirectory> m_parent_folder; +}; + +} |