@@ -50,7 +50,7 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
5050 return (const FFSmbiosHeader * ) (p + 1 );
5151}
5252
53- #if defined(__linux__ ) || defined(__FreeBSD__ ) || defined(__sun ) || defined(__HAIKU__ )
53+ #if defined(__linux__ ) || defined(__FreeBSD__ ) || defined(__NetBSD__ ) || defined( __sun ) || defined(__HAIKU__ )
5454#include <fcntl.h>
5555#include <sys/stat.h>
5656#include <sys/mman.h>
@@ -63,6 +63,9 @@ const FFSmbiosHeader* ffSmbiosNextEntry(const FFSmbiosHeader* header)
6363 #define loff_t off_t // FreeBSD doesn't have loff_t
6464#elif defined(__sun )
6565 #define loff_t off_t
66+ #elif defined(__NetBSD__ )
67+ #include "common/sysctl.h"
68+ #define loff_t off_t
6669#endif
6770
6871bool ffGetSmbiosValue (const char * devicesPath , const char * classPath , FFstrbuf * buffer )
@@ -140,7 +143,7 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
140143 if (!ffAppendFileBuffer ("/sys/firmware/dmi/tables/DMI" , & buffer ))
141144 #endif
142145 {
143- #ifndef __sun
146+ #if !defined( __sun ) && !defined( __NetBSD__ )
144147 FF_STRBUF_AUTO_DESTROY strEntryAddress = ffStrbufCreate ();
145148 #ifdef __FreeBSD__
146149 if (!ffSettingsGetFreeBSDKenv ("hint.smbios.0.mem" , & strEntryAddress ))
@@ -177,7 +180,13 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
177180 if (fd < 0 ) return NULL ;
178181
179182 FFSmbiosEntryPoint entryPoint ;
180- if (!ffReadFDData (fd , sizeof (entryPoint ), & entryPoint )) return NULL ;
183+ #ifdef __NetBSD__
184+ off_t addr = (off_t ) ffSysctlGetInt64 ("machdep.smbios" , 0 );
185+ if (addr == 0 ) return NULL ;
186+ if (pread (fd , & entryPoint , sizeof (entryPoint ), addr ) < 1 ) return NULL ;
187+ #else
188+ if (ffReadFDData (fd , sizeof (entryPoint ), & entryPoint ) < 1 ) return NULL ;
189+ #endif
181190 #endif
182191
183192 uint32_t tableLength = 0 ;
@@ -196,9 +205,11 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
196205 tableLength = entryPoint .Smbios30 .StructureTableMaximumSize ;
197206 tableAddress = (loff_t ) entryPoint .Smbios30 .StructureTableAddress ;
198207 }
208+ else
209+ return NULL ;
199210
200211 ffStrbufEnsureFixedLengthFree (& buffer , tableLength );
201- if (pread (fd , buffer .chars , tableLength , tableAddress ) == tableLength )
212+ if (pread (fd , buffer .chars , tableLength , tableAddress ) == ( ssize_t ) tableLength )
202213 {
203214 buffer .length = tableLength ;
204215 buffer .chars [buffer .length ] = '\0' ;
0 commit comments