Skip to content

Commit

Permalink
SunOS: make SMBIOS related modules work
Browse files Browse the repository at this point in the history
  • Loading branch information
CarterLi committed Jun 16, 2024
1 parent d35490a commit d727547
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,11 @@ elseif(SunOS)
src/common/networking_linux.c
src/common/processing_linux.c
src/detection/battery/battery_nosupport.c
src/detection/bios/bios_nosupport.c
src/detection/board/board_nosupport.c
src/detection/bios/bios_windows.c
src/detection/board/board_windows.c
src/detection/bootmgr/bootmgr_nosupport.c
src/detection/brightness/brightness_nosupport.c
src/detection/chassis/chassis_nosupport.c
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_nosupport.c
src/detection/cpucache/cpucache_nosupport.c
src/detection/cpuusage/cpuusage_nosupport.c
Expand All @@ -756,7 +756,7 @@ elseif(SunOS)
src/detection/disk/disk_nosupport.c
src/detection/dns/dns_linux.c
src/detection/physicaldisk/physicaldisk_nosupport.c
src/detection/physicalmemory/physicalmemory_nosupport.c
src/detection/physicalmemory/physicalmemory_linux.c
src/detection/diskio/diskio_nosupport.c
src/detection/displayserver/linux/displayserver_linux.c
src/detection/displayserver/linux/drm.c
Expand All @@ -771,8 +771,8 @@ elseif(SunOS)
src/detection/gpu/gpu_nosupport.c
src/detection/gpu/gpu_pci.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_nosupport.c
src/detection/icons/icons_nosupport.c
src/detection/host/host_windows.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_nosupport.c
src/detection/libc/libc_nosupport.c
src/detection/lm/lm_nosupport.c
Expand Down
6 changes: 5 additions & 1 deletion src/detection/bios/bios_windows.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "bios.h"
#include "util/smbiosHelper.h"

#ifdef _WIN32
#include "util/windows/registry.h"

#include <ntstatus.h>
Expand All @@ -25,7 +27,7 @@ typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION
};
};
} SYSTEM_BOOT_ENVIRONMENT_INFORMATION;

#endif

typedef struct FFSmbiosBios
{
Expand Down Expand Up @@ -74,6 +76,7 @@ const char* ffDetectBios(FFBiosResult* bios)
if (data->Header.Length > offsetof(FFSmbiosBios, SystemBiosMajorRelease))
ffStrbufSetF(&bios->release, "%u.%u", data->SystemBiosMajorRelease, data->SystemBiosMinorRelease);

#ifdef _WIN32
// Same as GetFirmwareType, but support (?) Windows 7
// https://ntdoc.m417z.com/system_information_class
SYSTEM_BOOT_ENVIRONMENT_INFORMATION sbei;
Expand All @@ -86,6 +89,7 @@ const char* ffDetectBios(FFBiosResult* bios)
default: break;
}
}
#endif

return NULL;
}
17 changes: 14 additions & 3 deletions src/util/smbiosHelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
return (const FFSmbiosHeader*) (p + 1);
}

#if defined(__linux__) || defined(__FreeBSD__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun)
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stddef.h>

#ifdef __linux__
#include "common/properties.h"
#else
#elif defined(__FreeBSD__)
#include "common/settings.h"
#define loff_t off_t // FreeBSD doesn't have loff_t
#elif defined(__sun)
#define loff_t off_t
#endif

bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
Expand Down Expand Up @@ -134,11 +137,12 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
if (!ffAppendFileBuffer("/sys/firmware/dmi/tables/DMI", &buffer))
#endif
{
#ifndef __sun
FF_STRBUF_AUTO_DESTROY strEntryAddress = ffStrbufCreate();
#ifdef __FreeBSD__
if (!ffSettingsGetFreeBSDKenv("hint.smbios.0.mem", &strEntryAddress))
return NULL;
#else
#elif defined(__linux__)
{
FF_STRBUF_AUTO_DESTROY systab = ffStrbufCreate();
if (!ffAppendFileBuffer("/sys/firmware/efi/systab", &systab))
Expand All @@ -165,6 +169,13 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
memcpy(&entryPoint, p, sizeof(entryPoint));
munmap(p, sizeof(entryPoint));
}
#else
FF_AUTO_CLOSE_FD int fd = open("/dev/smbios", O_RDONLY);
if (fd < 0) return NULL;

FFSmbiosEntryPoint entryPoint;
if (!ffReadFDData(fd, sizeof(entryPoint), &entryPoint)) return NULL;
#endif

uint32_t tableLength = 0;
loff_t tableAddress = 0;
Expand Down

0 comments on commit d727547

Please sign in to comment.