smbios

package module
v0.0.0-...-81a76c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: Apache-2.0 Imports: 8 Imported by: 1

README

go-smbios Build Status GoDoc Go Report Card

Package smbios provides detection and access to System Management BIOS (SMBIOS) and Desktop Management Interface (DMI) data and structures. Apache 2.0 Licensed.

Introduction

SMBIOS is a standard mechanism for fetching BIOS and hardware information from within an operating system. It shares some similarities with the older DMI standard, and the two are often confused.

To install this package, run:

$ go get github.com/digitalocean/go-smbios/smbios

This package is based on the SMBIOS 3.1.1 specification, but should work with SMBIOS 2.0 and above.

In general, it's up to hardware manufacturers to properly populate SMBIOS data, and many structures may not be populated correctly or at all; especially on consumer hardware.

The smbios.Structure types created by this package can be decoded using the structure information in the SMBIOS specification. In the future, some common structures may be parsed and readily available by using this package.

Supported operating systems and their SMBIOS retrieval mechanisms include:

  • DragonFlyBSD (/dev/mem)
  • FreeBSD (/dev/mem)
  • Linux (sysfs and /dev/mem)
  • NetBSD (/dev/mem)
  • OpenBSD (/dev/mem)
  • Solaris (/dev/mem)
  • Windows (GetSystemFirmwareTable)

At this time, macOS is not supported, as it does not expose SMBIOS information in the same way as the supported operating systems. Pull requests are welcome to add support for additional operating systems.

Example

See cmd/lssmbios for a runnable example. Note that retrieving SMBIOS information is a privileged operation. On Linux, you may invoke the binary as root directly, or apply the CAP_DAC_OVERRIDE capability to enable reading the information without superuser access.

Here's the gist of it:

// Find SMBIOS data in operating system-specific location.
rc, ep, err := smbios.Stream()
if err != nil {
	log.Fatalf("failed to open stream: %v", err)
}
// Be sure to close the stream!
defer rc.Close()

// Decode SMBIOS structures from the stream.
d := smbios.NewDecoder(rc)
ss, err := d.Decode()
if err != nil {
	log.Fatalf("failed to decode structures: %v", err)
}

// Determine SMBIOS version and table location from entry point.
major, minor, rev := ep.Version()
addr, size := ep.Table()

fmt.Printf("SMBIOS %d.%d.%d - table: address: %#x, size: %d\n",
	major, minor, rev, addr, size)

for _, s := range ss {
	fmt.Println(s)
}

Documentation

Overview

Package smbios provides detection and access to System Management BIOS (SMBIOS) and Desktop Management Interface (DMI) data and structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

A Decoder decodes Structures from a stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a Decoder which decodes Structures from the input stream.

func (*Decoder) Decode

func (d *Decoder) Decode() ([]*Structure, error)

Decode decodes Structures from the Decoder's stream until an End-of-table structure is found.

type EntryPoint

type EntryPoint interface {
	// Table returns the memory address and maximum size of the SMBIOS table.
	Table() (address, size int)

	// Version returns the system's SMBIOS version.
	Version() (major, minor, revision int)
}

An EntryPoint is an SMBIOS entry point. EntryPoints contain various properties about SMBIOS.

Use a type assertion to access detailed EntryPoint information.

func ParseEntryPoint

func ParseEntryPoint(r io.Reader) (EntryPoint, error)

ParseEntryPoint parses an EntryPoint from the input stream.

func Stream

func Stream() (io.ReadCloser, EntryPoint, error)

Stream locates and opens a stream of SMBIOS data and the SMBIOS entry point from an operating system-specific location. The stream must be closed after decoding to free its resources.

If no suitable location is found, an error is returned.

type EntryPoint32Bit

type EntryPoint32Bit struct {
	Anchor                string
	Checksum              uint8
	Length                uint8
	Major                 uint8
	Minor                 uint8
	MaxStructureSize      uint16
	EntryPointRevision    uint8
	FormattedArea         [5]byte
	IntermediateAnchor    string
	IntermediateChecksum  uint8
	StructureTableLength  uint16
	StructureTableAddress uint32
	NumberStructures      uint16
	BCDRevision           uint8
}

EntryPoint32Bit is the SMBIOS 32-bit Entry Point structure, used starting in SMBIOS 2.1.

func (*EntryPoint32Bit) Table

func (e *EntryPoint32Bit) Table() (address, size int)

Table implements EntryPoint.

func (*EntryPoint32Bit) Version

func (e *EntryPoint32Bit) Version() (major, minor, revision int)

Version implements EntryPoint.

type EntryPoint64Bit

type EntryPoint64Bit struct {
	Anchor                string
	Checksum              uint8
	Length                uint8
	Major                 uint8
	Minor                 uint8
	Revision              uint8
	EntryPointRevision    uint8
	Reserved              uint8
	StructureTableMaxSize uint32
	StructureTableAddress uint64
}

EntryPoint64Bit is the SMBIOS 64-bit Entry Point structure, used starting in SMBIOS 3.0.

func (*EntryPoint64Bit) Table

func (e *EntryPoint64Bit) Table() (address, size int)

Table implements EntryPoint.

func (*EntryPoint64Bit) Version

func (e *EntryPoint64Bit) Version() (major, minor, revision int)

Version implements EntryPoint.

type Header struct {
	Type   uint8
	Length uint8
	Handle uint16
}

A Header is a Structure's header.

type Structure

type Structure struct {
	Header    Header
	Formatted []byte
	Strings   []string
}

A Structure is an SMBIOS structure.

type WindowsEntryPoint

type WindowsEntryPoint struct {
	Size         uint32
	MajorVersion byte
	MinorVersion byte
	Revision     byte
}

WindowsEntryPoint contains SMBIOS Table entry point data returned from GetSystemFirmwareTable. As raw access to the underlying memory is not given, the full breadth of information is not available.

func (*WindowsEntryPoint) Table

func (e *WindowsEntryPoint) Table() (address, size int)

Table implements EntryPoint. The returned address will always be 0, as it is not returned by GetSystemFirmwareTable.

func (*WindowsEntryPoint) Version

func (e *WindowsEntryPoint) Version() (major, minor, revision int)

Version implements EntryPoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL