Host: detect mac model in FreeBSD & Windows

This commit is contained in:
Carter Li
2024-12-08 23:23:51 +08:00
committed by 李通洲
parent d897472572
commit 5c01685d69
7 changed files with 33 additions and 15 deletions
+2
View File
@@ -13,4 +13,6 @@ typedef struct FFHostResult
FFstrbuf vendor;
} FFHostResult;
const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel);
bool ffHostDetectMac(FFHostResult* host);
const char* ffDetectHost(FFHostResult* host);
-2
View File
@@ -39,8 +39,6 @@ const char* getOthersByIokit(FFHostResult* host)
return NULL;
}
const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel);
const char* ffDetectHost(FFHostResult* host)
{
const char* error = ffSysctlGetString("hw.model", &host->family);
+4
View File
@@ -19,5 +19,9 @@ const char* ffDetectHost(FFHostResult* host)
ffSettingsGetFreeBSDKenv("smbios.system.maker", &host->vendor);
ffCleanUpSmbiosValue(&host->vendor);
#ifdef __x86_64__
ffHostDetectMac(host);
#endif
return NULL;
}
+2 -12
View File
@@ -5,8 +5,6 @@
#include <stdlib.h>
const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel);
static void getHostProductName(FFstrbuf* name)
{
if (ffReadFileBuffer("/sys/firmware/devicetree/base/model", name))
@@ -64,17 +62,9 @@ const char* ffDetectHost(FFHostResult* host)
if (ffStrbufStartsWithS(&host->name, "Apple "))
ffStrbufSetStatic(&host->vendor, "Apple Inc.");
}
#ifdef __x86_64__
else if (ffStrbufEqualS(&host->family, "Mac") && ffStrbufEqualS(&host->vendor, "Apple Inc."))
{
const char* productName = ffHostGetMacProductNameWithHwModel(&host->name);
if (productName)
{
ffStrbufDestroy(&host->family);
ffStrbufInitMove(&host->family, &host->name);
ffStrbufSetStatic(&host->name, productName);
}
}
ffHostDetectMac(host);
#endif
//KVM/Qemu virtual machine
+19 -1
View File
@@ -1,4 +1,4 @@
#include "util/FFstrbuf.h"
#include "host.h"
#include "util/stringUtils.h"
const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel)
@@ -173,3 +173,21 @@ const char* ffHostGetMacProductNameWithHwModel(const FFstrbuf* hwModel)
}
return NULL;
}
bool ffHostDetectMac(FFHostResult* host)
{
#ifdef __x86_64__
if (ffStrbufEqualS(&host->family, "Mac") && ffStrbufEqualS(&host->vendor, "Apple Inc."))
{
const char* productName = ffHostGetMacProductNameWithHwModel(&host->name);
if (productName)
{
ffStrbufDestroy(&host->family);
ffStrbufInitMove(&host->family, &host->name);
ffStrbufSetStatic(&host->name, productName);
return true;
}
}
#endif
return false;
}
+4
View File
@@ -72,5 +72,9 @@ const char* ffDetectHost(FFHostResult* host)
ffCleanUpSmbiosValue(&host->family);
}
#ifdef __x86_64__
ffHostDetectMac(host);
#endif
return NULL;
}