1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:35:08 +00:00

Kernel/SysFS: Ensure data stability when reading from Inodes

Like with the ProcFS, description data can change at anytime, so it's
wise to ensure that when the userland reads from an Inode, data is
consistent unless the userland indicated it wants to refresh the data
(by seeking to offset 0, or re-attaching the Inode).
Otherwise, if the data changes in the middle of the reading, it can
cause silent corruption in output which can lead to random crashes.
This commit is contained in:
Liav A 2021-09-04 16:23:45 +03:00 committed by Andreas Kling
parent a595345e7c
commit e490c17bde
5 changed files with 79 additions and 7 deletions

View file

@ -96,6 +96,22 @@ SysFSInode::SysFSInode(SysFS const& fs, SysFSComponent const& component)
{
}
void SysFSInode::did_seek(FileDescription& description, off_t new_offset)
{
if (new_offset != 0)
return;
auto result = m_associated_component->refresh_data(description);
if (result.is_error()) {
// Subsequent calls to read will return EIO!
dbgln("SysFS: Could not refresh contents: {}", result.error());
}
}
KResult SysFSInode::attach(FileDescription& description)
{
return m_associated_component->refresh_data(description);
}
KResultOr<size_t> SysFSInode::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription* fd) const
{
return m_associated_component->read_bytes(offset, count, buffer, fd);