1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +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

@ -12,12 +12,17 @@
#include <AK/StringView.h>
#include <AK/Types.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/Forward.h>
#include <Kernel/KResult.h>
namespace Kernel {
struct SysFSInodeData : public FileDescriptionData {
OwnPtr<KBuffer> buffer;
};
class SysFSComponent : public RefCounted<SysFSComponent> {
public:
virtual StringView name() const { return m_name->view(); }
@ -25,6 +30,7 @@ public:
virtual KResult traverse_as_directory(unsigned, Function<bool(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
virtual KResultOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, FileDescription*) { return EROFS; }
virtual KResult refresh_data(FileDescription&) const { return KSuccess; }
virtual NonnullRefPtr<SysFSInode> to_inode(SysFS const&) const;