summaryrefslogtreecommitdiff
path: root/Kernel/Firmware/PowerStateSwitch.cpp
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-09-17 11:52:51 +0300
committerAndreas Kling <kling@serenityos.org>2021-10-09 12:07:56 +0200
commitf8489da8ee7408d8a4a2dda163fb36867c16ad45 (patch)
tree399f0aa9a8fbd45a855994362ecf589a63ea2dd0 /Kernel/Firmware/PowerStateSwitch.cpp
parent7269ce15fce8acdf6711dc3a67e16d6f9c8ba67f (diff)
downloadserenity-f8489da8ee7408d8a4a2dda163fb36867c16ad45.zip
Kernel/SysFS: Provide a way to "truncate" and "set" mtime on inodes
Normally, trying to truncate a SysFSInode should result in EPERM error. However, as suggested by Ali (@alimpfard), we can allow the PowerState node to be "truncated" so one can open that file with O_TRUNC option. Likewise, we also need to provide a way to set modified time on SysFS inodes. For most inodes, we should return ENOTIMPL error, but for the power state switch, we ignore the modified time setting and just return KSuccess. These fixes allow to do "echo -n 1 > /sys/firmware/power_state" in Shell after gaining root permissions, to switch the power state.
Diffstat (limited to 'Kernel/Firmware/PowerStateSwitch.cpp')
-rw-r--r--Kernel/Firmware/PowerStateSwitch.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/Kernel/Firmware/PowerStateSwitch.cpp b/Kernel/Firmware/PowerStateSwitch.cpp
index 16f9e07101..e0f9b53dbe 100644
--- a/Kernel/Firmware/PowerStateSwitch.cpp
+++ b/Kernel/Firmware/PowerStateSwitch.cpp
@@ -30,6 +30,15 @@ UNMAP_AFTER_INIT PowerStateSwitchNode::PowerStateSwitchNode(FirmwareSysFSDirecto
{
}
+KResult PowerStateSwitchNode::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).
+ if (size != 0)
+ return EPERM;
+ return KSuccess;
+}
+
KResultOr<size_t> PowerStateSwitchNode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& data, OpenFileDescription*)
{
if (Checked<off_t>::addition_would_overflow(offset, count))