github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/cmds/exp/dmidecode/data_linux.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 main 6 7 import ( 8 "errors" 9 "fmt" 10 "io" 11 "io/ioutil" 12 "path/filepath" 13 ) 14 15 // getData returns SMBIOS entry point and DMI table data. 16 // If dumpFile is non-empty, it is read from that file, otherwise it is read 17 // from sysfsPath (smbios_entry_point and DMI files respectively). 18 func getData(textOut io.Writer, dumpFile, sysfsPath string) ([]byte, []byte, error) { 19 var err error 20 var entry, data []byte 21 if dumpFile != "" { 22 fmt.Fprintf(textOut, "Reading SMBIOS/DMI data from file %s.\n", dumpFile) 23 data, err = ioutil.ReadFile(dumpFile) 24 if err != nil { 25 return nil, nil, fmt.Errorf("error reading dump: %v", err) 26 } 27 if len(data) < 36 { 28 return nil, nil, errors.New("dump is too short") 29 } 30 entry = data[:32] 31 data = data[32:] 32 } else { 33 fmt.Fprintf(textOut, "Reading SMBIOS/DMI data from sysfs.\n") 34 entry, err = ioutil.ReadFile(filepath.Join(sysfsPath, "smbios_entry_point")) 35 if err != nil { 36 return nil, nil, fmt.Errorf("error reading DMI data: %v", err) 37 } 38 data, err = ioutil.ReadFile(filepath.Join(sysfsPath, "DMI")) 39 if err != nil { 40 return nil, nil, fmt.Errorf("error reading DMI data: %v", err) 41 } 42 } 43 return entry, data, nil 44 }