Kernel: Allow SysFS components to have non-zero size

This is important for dmidecode because it does an fstat on the DMI
blobs, trying to figure out their size. Because we already know the size
of the blobs when creating the SysFS components, there's no performance
penalty whatsoever, and this allows dmidecode to not use the /dev/mem
device as a fallback.
This commit is contained in:
Liav A 2022-04-01 11:18:38 +03:00 committed by Andreas Kling
parent 66ff60db07
commit ae2ec45e78
3 changed files with 7 additions and 1 deletions

View file

@ -137,7 +137,7 @@ InodeMetadata SysFSInode::metadata() const
metadata.mode = S_IFREG | m_associated_component->permissions();
metadata.uid = 0;
metadata.gid = 0;
metadata.size = 0;
metadata.size = m_associated_component->size();
metadata.mtime = mepoch;
return metadata;
}

View file

@ -31,6 +31,7 @@ public:
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
virtual mode_t permissions() const;
virtual ErrorOr<void> truncate(u64) { return EPERM; }
virtual size_t size() const { return 0; }
virtual ErrorOr<void> set_mtime(time_t) { return ENOTIMPL; }
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; }
virtual ErrorOr<void> refresh_data(OpenFileDescription&) const { return {}; }

View file

@ -77,6 +77,9 @@ public:
private:
DMIEntryPointExposedBlob(PhysicalAddress dmi_entry_point, size_t blob_size);
virtual ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const override;
virtual size_t size() const override { return m_dmi_entry_point_length; }
PhysicalAddress m_dmi_entry_point;
size_t const m_dmi_entry_point_length { 0 };
};
@ -90,6 +93,8 @@ private:
SMBIOSExposedTable(PhysicalAddress dmi_entry_point, size_t blob_size);
virtual ErrorOr<NonnullOwnPtr<KBuffer>> try_to_generate_buffer() const override;
virtual size_t size() const override { return m_smbios_structure_table_length; }
PhysicalAddress m_smbios_structure_table;
size_t const m_smbios_structure_table_length { 0 };
};