Bios: code refactor

This commit is contained in:
李通洲
2023-06-22 22:35:09 +08:00
parent e4e5560b75
commit 466477429d
6 changed files with 34 additions and 34 deletions
+3 -3
View File
@@ -7,10 +7,10 @@
typedef struct FFBiosResult
{
FFstrbuf biosDate;
FFstrbuf date;
FFstrbuf biosRelease;
FFstrbuf biosVendor;
FFstrbuf biosVersion;
FFstrbuf vendor;
FFstrbuf version;
} FFBiosResult;
const char* ffDetectBios(FFBiosResult* bios);
+8 -8
View File
@@ -20,12 +20,12 @@ const char* ffDetectBios(FFBiosResult* bios)
return "IORegistryEntryCreateCFProperties(registryEntry) failed";
}
ffCfDictGetString(properties, CFSTR("vendor"), &bios->biosVendor);
ffCfDictGetString(properties, CFSTR("version"), &bios->biosVersion);
ffCfDictGetString(properties, CFSTR("release-date"), &bios->biosDate);
if(!ffStrbufContainC(&bios->biosDate, '-'))
ffCfDictGetString(properties, CFSTR("vendor"), &bios->vendor);
ffCfDictGetString(properties, CFSTR("version"), &bios->version);
ffCfDictGetString(properties, CFSTR("release-date"), &bios->date);
if(!ffStrbufContainC(&bios->date, '-'))
ffStrbufAppendS(&bios->biosRelease, "Efi-");
ffStrbufAppend(&bios->biosRelease, &bios->biosVersion);
ffStrbufAppend(&bios->biosRelease, &bios->version);
CFRelease(properties);
IOObjectRelease(registryEntry);
@@ -40,7 +40,7 @@ const char* ffDetectBios(FFBiosResult* bios)
CFMutableDictionaryRef properties;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess)
{
ffCfDictGetString(properties, CFSTR("manufacturer"), &bios->biosVendor);
ffCfDictGetString(properties, CFSTR("manufacturer"), &bios->vendor);
CFRelease(properties);
}
IOObjectRelease(registryEntry);
@@ -53,8 +53,8 @@ const char* ffDetectBios(FFBiosResult* bios)
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) == kIOReturnSuccess)
{
ffCfDictGetString(properties, CFSTR("system-firmware-version"), &bios->biosRelease);
ffStrbufAppend(&bios->biosVersion, &bios->biosRelease);
ffStrbufSubstrAfterFirstC(&bios->biosVersion, '-');
ffStrbufAppend(&bios->version, &bios->biosRelease);
ffStrbufSubstrAfterFirstC(&bios->version, '-');
CFRelease(properties);
}
IOObjectRelease(registryEntry);
+6 -6
View File
@@ -5,13 +5,13 @@
const char* ffDetectBios(FFBiosResult* result)
{
ffSettingsGetFreeBSDKenv("smbios.bios.reldate", &result->biosDate);
ffCleanUpSmbiosValue(&result->biosDate);
ffSettingsGetFreeBSDKenv("smbios.bios.reldate", &result->date);
ffCleanUpSmbiosValue(&result->date);
ffSettingsGetFreeBSDKenv("smbios.bios.revision", &result->biosRelease);
ffCleanUpSmbiosValue(&result->biosRelease);
ffSettingsGetFreeBSDKenv("smbios.bios.vendor", &result->biosVendor);
ffCleanUpSmbiosValue(&result->biosVendor);
ffSettingsGetFreeBSDKenv("smbios.bios.version", &result->biosVersion);
ffCleanUpSmbiosValue(&result->biosVersion);
ffSettingsGetFreeBSDKenv("smbios.bios.vendor", &result->vendor);
ffCleanUpSmbiosValue(&result->vendor);
ffSettingsGetFreeBSDKenv("smbios.bios.version", &result->version);
ffCleanUpSmbiosValue(&result->version);
return NULL;
}
+3 -3
View File
@@ -19,9 +19,9 @@ static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstr
const char* ffDetectBios(FFBiosResult* bios)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_date", "/sys/class/dmi/id/bios_date", &bios->biosDate);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_date", "/sys/class/dmi/id/bios_date", &bios->date);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->biosRelease);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->biosVendor);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->biosVersion);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->vendor);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->version);
return NULL;
}
+3 -3
View File
@@ -7,11 +7,11 @@ const char* ffDetectBios(FFBiosResult* bios)
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL))
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed";
if(!ffRegReadStrbuf(hKey, L"BIOSVersion", &bios->biosVersion, NULL))
if(!ffRegReadStrbuf(hKey, L"BIOSVersion", &bios->version, NULL))
return "\"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\BIOSVersion\" doesn't exist";
ffRegReadStrbuf(hKey, L"BIOSVendor", &bios->biosVendor, NULL);
ffRegReadStrbuf(hKey, L"BIOSReleaseDate", &bios->biosDate, NULL);
ffRegReadStrbuf(hKey, L"BIOSVendor", &bios->vendor, NULL);
ffRegReadStrbuf(hKey, L"BIOSReleaseDate", &bios->date, NULL);
uint32_t major, minor;
if(
+11 -11
View File
@@ -9,10 +9,10 @@
void ffPrintBios(FFinstance* instance, FFBiosOptions* options)
{
FFBiosResult bios;
ffStrbufInit(&bios.biosDate);
ffStrbufInit(&bios.date);
ffStrbufInit(&bios.biosRelease);
ffStrbufInit(&bios.biosVendor);
ffStrbufInit(&bios.biosVersion);
ffStrbufInit(&bios.vendor);
ffStrbufInit(&bios.version);
const char* error = ffDetectBios(&bios);
@@ -22,7 +22,7 @@ void ffPrintBios(FFinstance* instance, FFBiosOptions* options)
goto exit;
}
if(bios.biosVersion.length == 0)
if(bios.version.length == 0)
{
ffPrintError(instance, FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, "bios_version is not set.");
goto exit;
@@ -31,7 +31,7 @@ void ffPrintBios(FFinstance* instance, FFBiosOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(instance, FF_BIOS_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
ffStrbufWriteTo(&bios.biosVersion, stdout);
ffStrbufWriteTo(&bios.version, stdout);
if (bios.biosRelease.length)
printf(" (%s)", bios.biosRelease.chars);
putchar('\n');
@@ -39,18 +39,18 @@ void ffPrintBios(FFinstance* instance, FFBiosOptions* options)
else
{
ffPrintFormat(instance, FF_BIOS_MODULE_NAME, 0, &options->moduleArgs, FF_BIOS_NUM_FORMAT_ARGS, (FFformatarg[]) {
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.biosDate},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.date},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.biosRelease},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.biosVendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.biosVersion},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.vendor},
{FF_FORMAT_ARG_TYPE_STRBUF, &bios.version},
});
}
exit:
ffStrbufDestroy(&bios.biosDate);
ffStrbufDestroy(&bios.date);
ffStrbufDestroy(&bios.biosRelease);
ffStrbufDestroy(&bios.biosVendor);
ffStrbufDestroy(&bios.biosVersion);
ffStrbufDestroy(&bios.vendor);
ffStrbufDestroy(&bios.version);
}
void ffInitBiosOptions(FFBiosOptions* options)