github.com/system-transparency/u-root@v6.0.1-0.20190919065413-ed07a650de4c+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/ioutil"
    11  	"path/filepath"
    12  )
    13  
    14  // getData returns SMBIOS entry point and DMI table data.
    15  // If dumpFile is non-empty, it is read from that file, otherwise it is read
    16  // from sysfsPath (smbios_entry_point and DMI files respectively).
    17  func getData(dumpFile, sysfsPath string) ([]byte, []byte, error) {
    18  	var err error
    19  	var entry, data []byte
    20  	if dumpFile != "" {
    21  		data, err = ioutil.ReadFile(dumpFile)
    22  		if err != nil {
    23  			return nil, nil, fmt.Errorf("error reading dump: %s", err)
    24  		}
    25  		if len(data) < 36 {
    26  			return nil, nil, errors.New("dump is too short")
    27  		}
    28  		entry = data[:32]
    29  		data = data[32:]
    30  	} else {
    31  		entry, err = ioutil.ReadFile(filepath.Join(sysfsPath, "smbios_entry_point"))
    32  		if err != nil {
    33  			return nil, nil, fmt.Errorf("error reading DMI data: %s", err)
    34  		}
    35  		data, err = ioutil.ReadFile(filepath.Join(sysfsPath, "DMI"))
    36  		if err != nil {
    37  			return nil, nil, fmt.Errorf("error reading DMI data: %s", err)
    38  		}
    39  	}
    40  	return entry, data, nil
    41  }