github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+incompatible/pkg/smbios/table_type.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 import ( 8 "fmt" 9 ) 10 11 // TableType specifies the DMI type of the table. 12 // Types are defined in DMTF DSP0134. 13 type TableType uint8 14 15 // Supported table types. 16 const ( 17 TableTypeBIOSInformation TableType = 0 18 TableTypeSystemInformation = 1 19 TableTypeInactive = 126 20 TableTypeEndOfTable = 127 21 ) 22 23 func (t TableType) String() string { 24 switch t { 25 case TableTypeBIOSInformation: 26 return "BIOS Information" 27 case TableTypeSystemInformation: 28 return "System Information" 29 case TableTypeInactive: 30 return "Inactive" 31 case TableTypeEndOfTable: 32 return "End Of Table" 33 default: 34 if t >= 0x80 { 35 return "OEM-specific Type" 36 } 37 return "Unsupported" 38 } 39 } 40 41 // ParseTypedTable parses generic Table into a typed struct. 42 func ParseTypedTable(t *Table) (fmt.Stringer, error) { 43 switch t.Type { 44 case TableTypeBIOSInformation: 45 return NewBIOSInformation(t) 46 case TableTypeSystemInformation: 47 return NewSystemInformation(t) 48 case TableTypeInactive: 49 // Inactive table cannot be further parsed. Documentation suggests that it can be any table 50 // that is temporarily marked inactive by tweaking the type field. 51 return t, nil 52 } 53 return nil, ErrUnsupportedTableType 54 }