1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 11:27:34 +00:00

Kernel/SysFS: Prevent allocation for component name during construction

Instead, allocate before constructing the object and pass NonnullOwnPtr
of KString to the object if needed. Some classes can determine their
names as they have a known attribute to look for or have a static name.
This commit is contained in:
Liav A 2021-12-12 16:33:08 +02:00 committed by Andreas Kling
parent 4daf07e69f
commit 478f543899
17 changed files with 116 additions and 65 deletions

View file

@ -25,7 +25,7 @@ struct SysFSInodeData : public OpenFileDescriptionData {
class SysFSComponent : public RefCounted<SysFSComponent> {
public:
virtual StringView name() const { return m_name->view(); }
virtual StringView name() const = 0;
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
@ -42,10 +42,9 @@ public:
virtual ~SysFSComponent() = default;
protected:
explicit SysFSComponent(StringView name);
SysFSComponent();
private:
NonnullOwnPtr<KString> m_name;
InodeIndex m_component_index {};
};
@ -57,8 +56,8 @@ public:
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
protected:
explicit SysFSDirectory(StringView name);
SysFSDirectory(StringView name, SysFSDirectory const& parent_directory);
SysFSDirectory() = default;
explicit SysFSDirectory(SysFSDirectory const& parent_directory);
NonnullRefPtrVector<SysFSComponent> m_components;
RefPtr<SysFSDirectory> m_parent_directory;
};