Kernel: Remove the /sys/kernel/constants directory

The name for this directory is a bit awkward. Also, the distinction of
constant information is not really valuable as I thought it would be, so
let's bring that information back into the /sys/kernel directory.
This commit is contained in:
Liav A 2023-08-12 14:06:35 +03:00 committed by Jelle Raaijmakers
parent 751aae77bc
commit aee5f4e4b2
Notes: sideshowbarker 2024-07-16 20:21:48 +09:00
8 changed files with 32 additions and 88 deletions

View File

@ -182,6 +182,7 @@ set(KERNEL_SOURCES
FileSystem/SysFS/Subsystems/Kernel/Interrupts.cpp
FileSystem/SysFS/Subsystems/Kernel/Processes.cpp
FileSystem/SysFS/Subsystems/Kernel/CPUInfo.cpp
FileSystem/SysFS/Subsystems/Kernel/ConstantInformation.cpp
FileSystem/SysFS/Subsystems/Kernel/Jails.cpp
FileSystem/SysFS/Subsystems/Kernel/Keymap.cpp
FileSystem/SysFS/Subsystems/Kernel/Profile.cpp
@ -200,8 +201,6 @@ set(KERNEL_SOURCES
FileSystem/SysFS/Subsystems/Kernel/Network/Route.cpp
FileSystem/SysFS/Subsystems/Kernel/Network/TCP.cpp
FileSystem/SysFS/Subsystems/Kernel/Network/UDP.cpp
FileSystem/SysFS/Subsystems/Kernel/Constants/ConstantInformation.cpp
FileSystem/SysFS/Subsystems/Kernel/Constants/Directory.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/BooleanVariable.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/CapsLockRemap.cpp
FileSystem/SysFS/Subsystems/Kernel/Configuration/CoredumpDirectory.cpp

View File

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/ConstantInformation.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/ConstantInformation.h>
#include <Kernel/Sections.h>
#include <Kernel/Tasks/Process.h>

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Error.h>
#include <AK/Try.h>
#include <Kernel/Boot/CommandLine.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/ConstantInformation.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/Directory.h>
#include <Kernel/Library/KBufferBuilder.h>
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<SysFSGlobalKernelConstantsDirectory> SysFSGlobalKernelConstantsDirectory::must_create(SysFSDirectory const& parent_directory)
{
auto global_constants_directory = adopt_ref_if_nonnull(new (nothrow) SysFSGlobalKernelConstantsDirectory(parent_directory)).release_nonnull();
MUST(global_constants_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.appendff("{}", kernel_load_base));
auto load_base_buffer = builder.build();
VERIFY(load_base_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_constants_directory, load_base_buffer.release_nonnull(), S_IRUSR, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::LoadBase));
}
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.append(kernel_command_line().string()));
MUST(builder.append('\n'));
auto command_line_buffer = builder.build();
VERIFY(command_line_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_constants_directory, command_line_buffer.release_nonnull(), S_IRUSR | S_IRGRP | S_IROTH, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::CommandLine));
}
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.append(kernel_command_line().system_mode()));
MUST(builder.append('\n'));
auto system_mode_buffer = builder.build();
VERIFY(system_mode_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_constants_directory, system_mode_buffer.release_nonnull(), S_IRUSR | S_IRGRP | S_IROTH, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::SystemMode));
}
return {};
}));
return global_constants_directory;
}
UNMAP_AFTER_INIT SysFSGlobalKernelConstantsDirectory::SysFSGlobalKernelConstantsDirectory(SysFSDirectory const& parent_directory)
: SysFSDirectory(parent_directory)
{
}
}

View File

@ -1,24 +0,0 @@
/*
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/RootDirectory.h>
namespace Kernel {
class SysFSGlobalKernelConstantsDirectory : public SysFSDirectory {
public:
static NonnullRefPtr<SysFSGlobalKernelConstantsDirectory> must_create(SysFSDirectory const&);
virtual StringView name() const override { return "constants"sv; }
private:
explicit SysFSGlobalKernelConstantsDirectory(SysFSDirectory const&);
};
}

View File

@ -6,10 +6,11 @@
#include <AK/Error.h>
#include <AK/Try.h>
#include <Kernel/Boot/CommandLine.h>
#include <Kernel/FileSystem/SysFS/Component.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/CPUInfo.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Configuration/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Constants/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/ConstantInformation.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/DiskUsage.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/GlobalInformation.h>
@ -30,9 +31,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<SysFSGlobalKernelStatsDirectory> SysFSGlobalKernelStatsDirectory::must_create(SysFSRootDirectory const& root_directory)
{
auto global_kernel_stats_directory = adopt_ref_if_nonnull(new (nothrow) SysFSGlobalKernelStatsDirectory(root_directory)).release_nonnull();
auto global_constants_directory = SysFSGlobalKernelConstantsDirectory::must_create(*global_kernel_stats_directory);
MUST(global_kernel_stats_directory->m_child_components.with([&](auto& list) -> ErrorOr<void> {
list.append(global_constants_directory);
list.append(SysFSDiskUsage::must_create(*global_kernel_stats_directory));
list.append(SysFSMemoryStatus::must_create(*global_kernel_stats_directory));
list.append(SysFSSystemStatistics::must_create(*global_kernel_stats_directory));
@ -48,6 +47,32 @@ UNMAP_AFTER_INIT NonnullRefPtr<SysFSGlobalKernelStatsDirectory> SysFSGlobalKerne
list.append(SysFSGlobalNetworkStatsDirectory::must_create(*global_kernel_stats_directory));
list.append(SysFSKernelConfigurationDirectory::must_create(*global_kernel_stats_directory));
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.appendff("{}", kernel_load_base));
auto load_base_buffer = builder.build();
VERIFY(load_base_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_kernel_stats_directory, load_base_buffer.release_nonnull(), S_IRUSR, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::LoadBase));
}
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.append(kernel_command_line().string()));
MUST(builder.append('\n'));
auto command_line_buffer = builder.build();
VERIFY(command_line_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_kernel_stats_directory, command_line_buffer.release_nonnull(), S_IRUSR | S_IRGRP | S_IROTH, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::CommandLine));
}
{
auto builder = TRY(KBufferBuilder::try_create());
MUST(builder.append(kernel_command_line().system_mode()));
MUST(builder.append('\n'));
auto system_mode_buffer = builder.build();
VERIFY(system_mode_buffer);
list.append(SysFSSystemConstantInformation::must_create(*global_kernel_stats_directory, system_mode_buffer.release_nonnull(), S_IRUSR | S_IRGRP | S_IROTH, SysFSSystemConstantInformation::ReadableByJailedProcesses::No, SysFSSystemConstantInformation::NodeName::SystemMode));
}
return {};
}));
return global_kernel_stats_directory;

View File

@ -38,7 +38,7 @@ static KernelBaseState s_kernel_base_state = KernelBaseState::Uninitialized;
Optional<FlatPtr> kernel_base()
{
if (s_kernel_base_state == KernelBaseState::Uninitialized) {
auto file = Core::File::open("/sys/kernel/constants/load_base"sv, Core::File::OpenMode::Read);
auto file = Core::File::open("/sys/kernel/load_base"sv, Core::File::OpenMode::Read);
if (file.is_error()) {
s_kernel_base_state = KernelBaseState::Invalid;
return {};

View File

@ -72,7 +72,7 @@ static ErrorOr<void> determine_system_mode()
g_system_mode = "text";
});
auto file_or_error = Core::File::open("/sys/kernel/constants/system_mode"sv, Core::File::OpenMode::Read);
auto file_or_error = Core::File::open("/sys/kernel/system_mode"sv, Core::File::OpenMode::Read);
if (file_or_error.is_error()) {
dbgln("Failed to read system_mode: {}", file_or_error.error());
// Continue and assume "text" mode.