Smbios (Linux): improve performance of small file reading

This commit is contained in:
Carter Li
2026-03-25 11:01:56 +08:00
parent 8fdaa987e3
commit 06ecd5a1ff
2 changed files with 15 additions and 2 deletions
+1
View File
@@ -230,6 +230,7 @@ static inline void ffStrbufInitMoveS(FFstrbuf* strbuf, char* heapStr)
ffStrbufInitMoveNS(strbuf, (uint32_t) strlen(heapStr), heapStr);
}
// Despite the name, this function resets strbuf to the initial/unallocated state
static inline void ffStrbufDestroy(FFstrbuf* strbuf)
{
if(strbuf->allocated > 0)
+14 -2
View File
@@ -161,15 +161,27 @@ static bool parseSmbiosTable(const uint8_t* data, uint32_t length)
#ifdef __linux__
bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
if (ffReadFileBuffer(devicesPath, buffer))
// /sys/class/dmi/id/* are all pseudo-files with very small content
// so reading the whole file at once is efficient
ffStrbufEnsureFixedLengthFree(buffer, 127);
ssize_t len = ffReadFileData(devicesPath, buffer->allocated - 1, buffer->chars);
if (len > 0)
{
assert(len < buffer->allocated);
buffer->chars[len] = '\0';
buffer->length = (uint32_t) len;
ffStrbufTrimRightSpace(buffer);
if(ffIsSmbiosValueSet(buffer))
return true;
}
if (ffReadFileBuffer(classPath, buffer))
len = ffReadFileData(classPath, buffer->allocated - 1, buffer->chars);
if (len > 0)
{
assert(len < buffer->allocated);
buffer->chars[len] = '\0';
buffer->length = (uint32_t) len;
ffStrbufTrimRightSpace(buffer);
if(ffIsSmbiosValueSet(buffer))
return true;