Smbios (NetBSD): add support

This commit is contained in:
Carter Li
2025-02-15 14:45:09 +08:00
parent 437006f5f1
commit 532b3cd457
2 changed files with 17 additions and 6 deletions
+15 -4
View File
@@ -50,7 +50,7 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
return (const FFSmbiosHeader*) (p + 1);
}
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__HAIKU__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun) || defined(__HAIKU__)
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -63,6 +63,9 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
#define loff_t off_t // FreeBSD doesn't have loff_t
#elif defined(__sun)
#define loff_t off_t
#elif defined(__NetBSD__)
#include "common/sysctl.h"
#define loff_t off_t
#endif
bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
@@ -140,7 +143,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
if (!ffAppendFileBuffer("/sys/firmware/dmi/tables/DMI", &buffer))
#endif
{
#ifndef __sun
#if !defined(__sun) && !defined(__NetBSD__)
FF_STRBUF_AUTO_DESTROY strEntryAddress = ffStrbufCreate();
#ifdef __FreeBSD__
if (!ffSettingsGetFreeBSDKenv("hint.smbios.0.mem", &strEntryAddress))
@@ -177,7 +180,13 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
if (fd < 0) return NULL;
FFSmbiosEntryPoint entryPoint;
if (!ffReadFDData(fd, sizeof(entryPoint), &entryPoint)) return NULL;
#ifdef __NetBSD__
off_t addr = (off_t) ffSysctlGetInt64("machdep.smbios", 0);
if (addr == 0) return NULL;
if (pread(fd, &entryPoint, sizeof(entryPoint), addr) < 1) return NULL;
#else
if (ffReadFDData(fd, sizeof(entryPoint), &entryPoint) < 1) return NULL;
#endif
#endif
uint32_t tableLength = 0;
@@ -196,9 +205,11 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
tableLength = entryPoint.Smbios30.StructureTableMaximumSize;
tableAddress = (loff_t) entryPoint.Smbios30.StructureTableAddress;
}
else
return NULL;
ffStrbufEnsureFixedLengthFree(&buffer, tableLength);
if (pread(fd, buffer.chars, tableLength, tableAddress) == tableLength)
if (pread(fd, buffer.chars, tableLength, tableAddress) == (ssize_t) tableLength)
{
buffer.length = tableLength;
buffer.chars[buffer.length] = '\0';