From: VMware, Inc <> Date: Mon, 21 Nov 2011 23:17:41 +0000 (-0800) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2011.11.20-535097~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=55cef918ad4349dd8eff6ea873b12e9ba15ccbef;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/backdoor_def.h b/open-vm-tools/lib/include/backdoor_def.h index 25836af9b..adc0eb98a 100644 --- a/open-vm-tools/lib/include/backdoor_def.h +++ b/open-vm-tools/lib/include/backdoor_def.h @@ -157,7 +157,8 @@ #define BDOOR_CMD_VMK_INFO 72 #define BDOOR_CMD_EFI_BOOT_CONFIG 73 /* CPL 0 only. */ # define BDOOR_CMD_EBC_CSM_ENABLED 0 -#define BDOOR_CMD_MAX 74 +#define BDOOR_CMD_GET_HW_MODEL 74 /* CPL 0 only. */ +#define BDOOR_CMD_MAX 75 /* diff --git a/open-vm-tools/lib/include/hostinfo.h b/open-vm-tools/lib/include/hostinfo.h index ab399a374..fc1ba4316 100644 --- a/open-vm-tools/lib/include/hostinfo.h +++ b/open-vm-tools/lib/include/hostinfo.h @@ -226,6 +226,7 @@ Bool Hostinfo_GetLoadAverage(uint32 *l); #ifdef __APPLE__ size_t Hostinfo_GetKernelZoneElemSize(char const *name); +char *Hostinfo_GetHardwareModel(void); #endif #endif /* ifndef _HOSTINFO_H_ */ diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index 79eadab4d..49b01d1f1 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -2405,7 +2405,7 @@ Hostinfo_GetRatedCpuMhz(int32 cpuNumber, // IN: uint32 hz; size_t hzSize = sizeof hz; - /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */ + /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */ if (sysctlbyname(CPUMHZ_SYSCTL_NAME, &hz, &hzSize, NULL, 0) == -1) { return FALSE; @@ -2435,12 +2435,13 @@ Hostinfo_GetRatedCpuMhz(int32 cpuNumber, // IN: } +#if defined(__APPLE__) || defined(__FreeBSD__) /* *----------------------------------------------------------------------------- * - * Hostinfo_GetCpuDescription -- + * HostinfoGetSysctlStringAlloc -- * - * Get the descriptive name associated with a given CPU. + * Obtains the value of a string-type host sysctl. * * Results: * On success: Allocated, NUL-terminated string. @@ -2452,22 +2453,13 @@ Hostinfo_GetRatedCpuMhz(int32 cpuNumber, // IN: *----------------------------------------------------------------------------- */ -char * -Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN: +static char * +HostinfoGetSysctlStringAlloc(char const *sysctlName) // IN { -#if defined(__APPLE__) || defined(__FreeBSD__) -# if defined(__APPLE__) -# define CPUDESC_SYSCTL_NAME "machdep.cpu.brand_string" -# else -# define CPUDESC_SYSCTL_NAME "hw.model" -# endif - char *desc; size_t descSize; - /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */ - - if (sysctlbyname(CPUDESC_SYSCTL_NAME, NULL, &descSize, NULL, 0) == -1) { + if (sysctlbyname(sysctlName, NULL, &descSize, NULL, 0) == -1) { return NULL; } @@ -2476,13 +2468,42 @@ Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN: return NULL; } - if (sysctlbyname(CPUDESC_SYSCTL_NAME, desc, &descSize, NULL, 0) == -1) { + if (sysctlbyname(sysctlName, desc, &descSize, NULL, 0) == -1) { free(desc); return NULL; } return desc; +} +#endif + + +/* + *----------------------------------------------------------------------------- + * + * Hostinfo_GetCpuDescription -- + * + * Get the descriptive name associated with a given CPU. + * + * Results: + * On success: Allocated, NUL-terminated string. + * On failure: NULL. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +char * +Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN: +{ +#if defined(__APPLE__) + /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */ + return HostinfoGetSysctlStringAlloc("machdep.cpu.brand_string"); +#elif defined(__FreeBSD__) + return HostinfoGetSysctlStringAlloc("hw.model"); #else #ifdef VMX86_SERVER if (HostType_OSIsVMK()) { @@ -2492,7 +2513,7 @@ Hostinfo_GetCpuDescription(uint32 cpuNumber) // IN: mName[0] = '\0'; if (VMKernel_GetCPUModelName(cpuNumber, mName, sizeof(mName)) == VMK_OK) { - mName[sizeof(mName) - 1] = '\0'; + mName[sizeof(mName) - 1] = '\0'; return strdup(mName); } @@ -2723,6 +2744,30 @@ Hostinfo_GetKernelZoneElemSize(char const *name) // IN: Kernel zone name return retval; } + + +/* + *----------------------------------------------------------------------------- + * + * Hostinfo_GetHardwareModel -- + * + * Obtains the hardware model identifier (i.e. "MacPro5,1") from the host. + * + * Results: + * On success: Allocated, NUL-terminated string. + * On failure: NULL. + * + * Side effects: + * None. + * + *----------------------------------------------------------------------------- + */ + +char * +Hostinfo_GetHardwareModel(void) +{ + return HostinfoGetSysctlStringAlloc("hw.model"); +} #endif /* __APPLE__ */