mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 13:55:08 +00:00

Like with the ProcFS, description data can change at anytime, so it's wise to ensure that when the userland reads from an Inode, data is consistent unless the userland indicated it wants to refresh the data (by seeking to offset 0, or re-attaching the Inode). Otherwise, if the data changes in the middle of the reading, it can cause silent corruption in output which can lead to random crashes.
63 lines
2.1 KiB
C++
63 lines
2.1 KiB
C++
/*
|
|
* 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/FileDescription.h>
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
#include <Kernel/Forward.h>
|
|
#include <Kernel/KResult.h>
|
|
|
|
namespace Kernel {
|
|
|
|
struct SysFSInodeData : public FileDescriptionData {
|
|
OwnPtr<KBuffer> buffer;
|
|
};
|
|
|
|
class SysFSComponent : public RefCounted<SysFSComponent> {
|
|
public:
|
|
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 KResult refresh_data(FileDescription&) const { return KSuccess; }
|
|
|
|
virtual NonnullRefPtr<SysFSInode> 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 KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
|
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
|
|
|
virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const& sysfs_instance) const override final;
|
|
|
|
protected:
|
|
explicit SysFSDirectory(StringView name);
|
|
SysFSDirectory(StringView name, SysFSDirectory const& parent_directory);
|
|
NonnullRefPtrVector<SysFSComponent> m_components;
|
|
RefPtr<SysFSDirectory> m_parent_directory;
|
|
};
|
|
|
|
}
|