Files
ladybird/Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/ConstantInformation.h
Liav A 61f4914d6e Kernel+Userland: Add constants subdirectory at /sys/kernel directory
This subdirectory is meant to hold all constant data related to the
kernel. This means that this data is never meant to updated and is
relevant from system boot to system shutdown.
Move the inodes of "load_base", "cmdline" and "system_mode" to that
directory. All nodes under this new subdirectory are generated during
boot, and therefore don't require calling kmalloc each time we need to
read them. Locking is also not necessary, because these nodes and their
data are completely static once being generated.
2023-02-19 13:47:11 +01:00

55 lines
1.8 KiB
C++

/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.h>
#include <AK/Error.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/UserOrKernelBuffer.h>
namespace Kernel {
class SysFSSystemConstantInformation final : public SysFSComponent {
public:
enum class NodeName {
LoadBase,
CommandLine,
SystemMode,
};
enum class ReadableByJailedProcesses {
Yes,
No,
};
virtual StringView name() const override;
static NonnullLockRefPtr<SysFSSystemConstantInformation> must_create(SysFSDirectory const& parent_directory, NonnullOwnPtr<KBuffer> constant_data_buffer, mode_t mode, ReadableByJailedProcesses readable_by_jailed_processes, NodeName name);
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const override;
private:
SysFSSystemConstantInformation(SysFSDirectory const& parent_directory, NonnullOwnPtr<KBuffer> constant_data_buffer, mode_t mode, ReadableByJailedProcesses readable_by_jailed_processes, NodeName name)
: SysFSComponent(parent_directory)
, m_constant_data_buffer(move(constant_data_buffer))
, m_permissions(mode)
, m_readable_by_jailed_processes(readable_by_jailed_processes)
, m_node_name(name)
{
}
virtual size_t size() const override { return m_constant_data_buffer->size(); }
virtual mode_t permissions() const override { return m_permissions; }
NonnullOwnPtr<KBuffer> m_constant_data_buffer;
mode_t const m_permissions { 0644 };
ReadableByJailedProcesses const m_readable_by_jailed_processes { ReadableByJailedProcesses::No };
NodeName const m_node_name { NodeName::LoadBase };
};
}