mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
Kernel+Userland: Move /sys/firmware/power_state to /sys/kernel directory
Let's put the power_state global node into the /sys/kernel directory, because that directory represents all global nodes and variables being related to the Kernel. It's also a mutable node, that is more acceptable being in the mentioned directory due to the fact that all other files in the /sys/firmware directory are just firmware blobs and are not mutable at all.
This commit is contained in:
parent
8c21d974b2
commit
75f01692b4
9 changed files with 21 additions and 21 deletions
|
@ -14,5 +14,5 @@ $ reboot
|
|||
|
||||
## Notes
|
||||
|
||||
The `reboot` utility opens the `/sys/firmware/power_state` node and writes the magic value "1"
|
||||
The `reboot` utility opens the `/sys/kernel/power_state` node and writes the magic value "1"
|
||||
to instruct the kernel to reboot the machine.
|
||||
|
|
|
@ -14,5 +14,5 @@ $ shutdown
|
|||
|
||||
## Notes
|
||||
|
||||
The `shutdown` utility opens the `/sys/firmware/power_state` node and writes the magic value "2"
|
||||
The `shutdown` utility opens the `/sys/kernel/power_state` node and writes the magic value "2"
|
||||
to instruct the kernel to power off the machine.
|
||||
|
|
|
@ -149,7 +149,6 @@ set(KERNEL_SOURCES
|
|||
FileSystem/SysFS/Subsystems/Firmware/BIOS/Component.cpp
|
||||
FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.cpp
|
||||
FileSystem/SysFS/Subsystems/Firmware/Directory.cpp
|
||||
FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/CommandLine.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/Interrupts.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/Processes.cpp
|
||||
|
@ -164,6 +163,7 @@ set(KERNEL_SOURCES
|
|||
FileSystem/SysFS/Subsystems/Kernel/SystemStatistics.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/GlobalInformation.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/MemoryStatus.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/Uptime.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/Network/Adapters.cpp
|
||||
FileSystem/SysFS/Subsystems/Kernel/Network/ARP.cpp
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include <Kernel/FileSystem/SysFS/Registry.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h>
|
||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
|
@ -26,7 +25,6 @@ void FirmwareSysFSDirectory::create_components()
|
|||
list.append(BIOSSysFSDirectory::must_create(*this));
|
||||
if (ACPI::is_enabled())
|
||||
list.append(ACPI::ACPISysFSDirectory::must_create(*this));
|
||||
list.append(PowerStateSwitchNode::must_create(*this));
|
||||
return {};
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Log.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/MemoryStatus.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Network/Directory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Processes.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Profile.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/SystemMode.h>
|
||||
|
@ -44,6 +45,7 @@ UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSGlobalKernelStatsDirectory> SysFSGlobalK
|
|||
list.append(SysFSSystemMode::must_create(*global_kernel_stats_directory));
|
||||
list.append(SysFSProfile::must_create(*global_kernel_stats_directory));
|
||||
list.append(SysFSKernelLoadBase::must_create(*global_kernel_stats_directory));
|
||||
list.append(SysFSPowerStateSwitchNode::must_create(*global_kernel_stats_directory));
|
||||
|
||||
list.append(SysFSGlobalNetworkStatsDirectory::must_create(*global_kernel_stats_directory));
|
||||
list.append(SysFSGlobalKernelVariablesDirectory::must_create(*global_kernel_stats_directory));
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
# include <Kernel/Arch/x86/common/Shutdown.h>
|
||||
#endif
|
||||
#include <Kernel/FileSystem/FileSystem.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/PowerStateSwitch.h>
|
||||
#include <Kernel/Firmware/ACPI/Parser.h>
|
||||
#include <Kernel/Process.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
@ -19,22 +19,22 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
mode_t PowerStateSwitchNode::permissions() const
|
||||
mode_t SysFSPowerStateSwitchNode::permissions() const
|
||||
{
|
||||
return S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<PowerStateSwitchNode> PowerStateSwitchNode::must_create(FirmwareSysFSDirectory& firmware_directory)
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSPowerStateSwitchNode> SysFSPowerStateSwitchNode::must_create(SysFSDirectory const& parent_directory)
|
||||
{
|
||||
return adopt_lock_ref_if_nonnull(new (nothrow) PowerStateSwitchNode(firmware_directory)).release_nonnull();
|
||||
return adopt_lock_ref_if_nonnull(new (nothrow) SysFSPowerStateSwitchNode(parent_directory)).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT PowerStateSwitchNode::PowerStateSwitchNode(FirmwareSysFSDirectory&)
|
||||
: SysFSComponent()
|
||||
UNMAP_AFTER_INIT SysFSPowerStateSwitchNode::SysFSPowerStateSwitchNode(SysFSDirectory const& parent_directory)
|
||||
: SysFSComponent(parent_directory)
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<void> PowerStateSwitchNode::truncate(u64 size)
|
||||
ErrorOr<void> SysFSPowerStateSwitchNode::truncate(u64 size)
|
||||
{
|
||||
// Note: This node doesn't store any useful data anyway, so we can safely
|
||||
// truncate this to zero (essentially ignoring the request without failing).
|
||||
|
@ -43,7 +43,7 @@ ErrorOr<void> PowerStateSwitchNode::truncate(u64 size)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<size_t> PowerStateSwitchNode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& data, OpenFileDescription*)
|
||||
ErrorOr<size_t> SysFSPowerStateSwitchNode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& data, OpenFileDescription*)
|
||||
{
|
||||
if (Checked<off_t>::addition_would_overflow(offset, count))
|
||||
return EOVERFLOW;
|
||||
|
@ -69,7 +69,7 @@ ErrorOr<size_t> PowerStateSwitchNode::write_bytes(off_t offset, size_t count, Us
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
void PowerStateSwitchNode::reboot()
|
||||
void SysFSPowerStateSwitchNode::reboot()
|
||||
{
|
||||
MutexLocker locker(Process::current().big_lock());
|
||||
|
||||
|
@ -88,7 +88,7 @@ void PowerStateSwitchNode::reboot()
|
|||
Processor::halt();
|
||||
}
|
||||
|
||||
void PowerStateSwitchNode::poweroff()
|
||||
void SysFSPowerStateSwitchNode::poweroff()
|
||||
{
|
||||
MutexLocker locker(Process::current().big_lock());
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/FileSystem/SysFS.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
|
||||
#include <Kernel/FileSystem/SysFS/Subsystems/Kernel/Directory.h>
|
||||
#include <Kernel/KBuffer.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Memory/MappedROM.h>
|
||||
|
@ -20,16 +20,16 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
class PowerStateSwitchNode final : public SysFSComponent {
|
||||
class SysFSPowerStateSwitchNode final : public SysFSComponent {
|
||||
public:
|
||||
virtual StringView name() const override { return "power_state"sv; }
|
||||
static NonnullLockRefPtr<PowerStateSwitchNode> must_create(FirmwareSysFSDirectory&);
|
||||
static NonnullLockRefPtr<SysFSPowerStateSwitchNode> must_create(SysFSDirectory const&);
|
||||
virtual mode_t permissions() const override;
|
||||
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
|
||||
virtual ErrorOr<void> truncate(u64) override;
|
||||
|
||||
private:
|
||||
PowerStateSwitchNode(FirmwareSysFSDirectory&);
|
||||
explicit SysFSPowerStateSwitchNode(SysFSDirectory const&);
|
||||
|
||||
void reboot();
|
||||
void poweroff();
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open("/sys/firmware/power_state"sv, Core::Stream::OpenMode::Write));
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/power_state"sv, Core::Stream::OpenMode::Write));
|
||||
|
||||
const String file_contents = "1";
|
||||
TRY(file->write(file_contents.bytes()));
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
ErrorOr<int> serenity_main(Main::Arguments)
|
||||
{
|
||||
auto file = TRY(Core::Stream::File::open("/sys/firmware/power_state"sv, Core::Stream::OpenMode::Write));
|
||||
auto file = TRY(Core::Stream::File::open("/sys/kernel/power_state"sv, Core::Stream::OpenMode::Write));
|
||||
|
||||
const String file_contents = "2";
|
||||
TRY(file->write(file_contents.bytes()));
|
||||
|
|
Loading…
Add table
Reference in a new issue