1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:27:43 +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

@ -8,6 +8,8 @@
#include <Kernel/Bus/USB/USBDevice.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/KBufferBuilder.h>
#include <Kernel/Locking/Mutex.h>
namespace Kernel::USB {
@ -29,6 +31,11 @@ protected:
IntrusiveListNode<SysFSUSBDeviceInformation, RefPtr<SysFSUSBDeviceInformation>> m_list_node;
NonnullRefPtr<USB::Device> m_device;
private:
bool output(KBufferBuilder& builder);
virtual KResult refresh_data(FileDescription& description) const override;
mutable Mutex m_lock { "SysFSUSBDeviceInformation" };
};
class SysFSUSBBusDirectory final : public SysFSDirectory {