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.
This commit is contained in:
Liav A 2021-09-17 11:52:51 +03:00 committed by Andreas Kling
commit f8489da8ee
Notes: sideshowbarker 2024-07-18 02:53:52 +09:00
5 changed files with 21 additions and 2 deletions

View file

@ -182,9 +182,14 @@ KResult SysFSInode::chown(UserID, GroupID)
return EPERM;
}
KResult SysFSInode::truncate(u64)
KResult SysFSInode::set_mtime(time_t time)
{
return EPERM;
return m_associated_component->set_mtime(time);
}
KResult SysFSInode::truncate(u64 size)
{
return m_associated_component->truncate(size);
}
KResultOr<NonnullRefPtr<SysFSDirectoryInode>> SysFSDirectoryInode::try_create(SysFS const& sysfs, SysFSComponent const& component)