github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+incompatible/pkg/smbios/info.go (about) 1 // Copyright 2016-2019 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package smbios 6 7 // Info contains the SMBIOS information. 8 type Info struct { 9 // TODO(rojer): Add entrypoint information. 10 Tables []*Table 11 } 12 13 // ParseInfo parses SMBIOS information from binary data. 14 func ParseInfo(entry, data []byte) (*Info, error) { 15 var tables []*Table 16 for len(data) > 0 { 17 t, remainder, err := ParseTable(data) 18 if err != nil && err != errEndOfTable { 19 return nil, err 20 } 21 tables = append(tables, t) 22 data = remainder 23 } 24 return &Info{Tables: tables}, nil 25 } 26 27 // GetTablesByType returns tables of specific type. 28 func (i *Info) GetTablesByType(tt TableType) []*Table { 29 var res []*Table 30 for _, t := range i.Tables { 31 if t.Type == tt { 32 res = append(res, t) 33 } 34 } 35 return res 36 } 37 38 // GetBIOSInformation returns the Bios Information (type 0) table, if present. 39 func (i *Info) GetBIOSInformation() (*BIOSInformation, error) { 40 bt := i.GetTablesByType(TableTypeBIOSInformation) 41 if len(bt) == 0 { 42 return nil, ErrTableNotFound 43 } 44 // There can only be one of these. 45 return NewBIOSInformation(bt[0]) 46 } 47 48 // GetSystemInformation returns the System Information (type 1) table, if present. 49 func (i *Info) GetSystemInformation() (*SystemInformation, error) { 50 bt := i.GetTablesByType(TableTypeSystemInformation) 51 if len(bt) == 0 { 52 return nil, ErrTableNotFound 53 } 54 // There can only be one of these. 55 return NewSystemInformation(bt[0]) 56 }