ohmu
·
2026-10-15
1#pragma once
2
3#include "fastfetch.h"
4
5// Not `pure`: it trims the trailing spaces of `value` before reporting whether it is set
6[[gnu::nonnull(1), nodiscard]] bool ffIsSmbiosValueSet(FFstrbuf* value);
7[[gnu::nonnull(1)]] static inline void ffCleanUpSmbiosValue(FFstrbuf* value) {
8 if (!ffIsSmbiosValueSet(value)) {
9 ffStrbufClear(value);
10 }
11}
12
13// https://github.com/KunYi/DumpSMBIOS
14// https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
15
16typedef enum FFSmbiosType : uint8_t {
17 FF_SMBIOS_TYPE_BIOS = 0,
18 FF_SMBIOS_TYPE_SYSTEM_INFO = 1,
19 FF_SMBIOS_TYPE_BASEBOARD_INFO = 2,
20 FF_SMBIOS_TYPE_SYSTEM_ENCLOSURE = 3,
21 FF_SMBIOS_TYPE_PROCESSOR_INFO = 4,
22 FF_SMBIOS_TYPE_MEMORY_CONTROLLER_INFO = 5, // obsolete
23 FF_SMBIOS_TYPE_MEMORY_MODULE_INFO = 6, // obsolete
24 FF_SMBIOS_TYPE_CACHE_INFO = 7,
25 FF_SMBIOS_TYPE_PORT_CONNECTOR_INFO = 8,
26 FF_SMBIOS_TYPE_SYSTEM_SLOTS = 9,
27 FF_SMBIOS_TYPE_ON_BOARD_DEVICES_INFO = 10, // obsolete
28 FF_SMBIOS_TYPE_OEM_STRING = 11,
29 FF_SMBIOS_TYPE_SYSTEM_CONFIGURATION_OPTIONS = 12,
30 FF_SMBIOS_TYPE_BIOS_LANGUAGE_INFO = 13,
31 FF_SMBIOS_TYPE_GROUP_ASSOCIATIONS = 14,
32 FF_SMBIOS_TYPE_SYSTEM_EVENT_LOG = 15,
33 FF_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY = 16,
34 FF_SMBIOS_TYPE_MEMORY_DEVICE = 17,
35 FF_SMBIOS_TYPE_32BIT_MEMORY_ERROR_INFO = 18,
36 FF_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS = 19,
37 FF_SMBIOS_TYPE_MEMORY_DEVICE_MAPPED_ADDRESS = 20,
38 FF_SMBIOS_TYPE_BUILTIN_POINTING_DEVICE = 21,
39 FF_SMBIOS_TYPE_PORTABLE_BATTERY = 22,
40 FF_SMBIOS_TYPE_SYSTEM_RESET = 23,
41 FF_SMBIOS_TYPE_HARDWARE_SECURITY = 24,
42 FF_SMBIOS_TYPE_SYSTEM_POWER_CONTROLS = 25,
43 FF_SMBIOS_TYPE_VOLTAGE_PROBE = 26,
44 FF_SMBIOS_TYPE_COOLING_DEVICE = 27,
45 FF_SMBIOS_TYPE_TEMPERATURE_PROBE = 28,
46 FF_SMBIOS_TYPE_ELECTRICAL_CURRENT_PROBE = 29,
47 FF_SMBIOS_TYPE_OUT_OF_BAND_REMOTE_ACCESS = 30,
48 FF_SMBIOS_TYPE_BOOT_INTEGRITY_SERVICES_ENTRY_POINT = 31, // reserved
49 FF_SMBIOS_TYPE_SYSTEM_BOOT_INFO = 32,
50 FF_SMBIOS_TYPE_64BIT_MEMORY_ERROR_INFO = 33,
51 FF_SMBIOS_TYPE_MANAGEMENT_DEVICE = 34,
52 FF_SMBIOS_TYPE_MANAGEMENT_DEVICE_COMPONENT = 35,
53 FF_SMBIOS_TYPE_MANAGEMENT_DEVICE_THRESHOLD_DATA = 36,
54 FF_SMBIOS_TYPE_MEMORY_CHANNEL = 37,
55 FF_SMBIOS_TYPE_IPMI_DEVICE_INFO = 38,
56 FF_SMBIOS_TYPE_SYSTEM_POWER_SUPPLY = 39,
57 FF_SMBIOS_TYPE_ADDITIONAL_INFO = 40,
58 FF_SMBIOS_TYPE_ONBOARD_DEVICE_EXTENDED_INFO = 41,
59 FF_SMBIOS_TYPE_MANAGEMENT_CONTROLLER_HOST_INTERFACE = 42,
60 FF_SMBIOS_TYPE_TPM_DEVICE = 43,
61 FF_SMBIOS_TYPE_PROCESSOR_ADDITIONAL_INFO = 44,
62 FF_SMBIOS_TYPE_FIRMWARE_INVENTORY_INFO = 45,
63 FF_SMBIOS_TYPE_STRING_PROPERTY = 46,
64 FF_SMBIOS_TYPE_INACTIVE = 126,
65 FF_SMBIOS_TYPE_END_OF_TABLE = 127,
66 FF_SMBIOS_TYPE__MAX,
67 // system- and OEM-specific information 128~256
68} FFSmbiosType;
69static_assert(sizeof(FFSmbiosType) == 1, "FFSmbiosType should be 1 byte");
70
71typedef struct [[gnu::packed]] FFSmbiosHeader {
72 // Type of SMBIOS structure. Do NOT test `Type == FF_SMBIOS_END_OF_TABLE` to determine the end of the table,
73 // as malformed tables may be missing the end-of-table marker.
74 // **Use FFSmbiosHeaderTable[FF_SMBIOS_TYPE_END_OF_TABLE] pointer instead.**
75 FFSmbiosType Type;
76 // Length of formatted section, excluding unformatted string section
77 // Must be at least 4 (sizeof(FFSmbiosHeader)) to be valid
78 uint8_t Length;
79 // Unique handle, used to reference this structure from other structures.
80 // Not guaranteed to be consistent across reboots or even multiple reads of the same table.
81 // Must be less than 0xFF00
82 uint16_t Handle;
83} FFSmbiosHeader;
84static_assert(sizeof(FFSmbiosHeader) == 4, "FFSmbiosHeader should be 4 bytes");
85
86// `start` points into the unformatted string section and is walked with `strlen`, so it may not be null
87[[gnu::nonnull(1), gnu::pure, nodiscard]] static inline const char* ffSmbiosLocateString(const char* start, uint8_t index /* start from 1 */) {
88 if (index == 0 || *start == '\0') {
89 return nullptr;
90 }
91 while (--index) {
92 start += strlen(start) + 1;
93 }
94 return start;
95}
96
97typedef const FFSmbiosHeader* FFSmbiosHeaderTable[FF_SMBIOS_TYPE__MAX];
98
99[[gnu::nonnull(1), gnu::pure, nodiscard]] const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header);
100[[nodiscard]] const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable(void);
101
102#ifdef __linux__
103[[gnu::nonnull(1, 2, 3)]] bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer);
104#endif