You've already forked go-linux-lowlevel-hw
mirror of
https://github.com/Dasharo/go-linux-lowlevel-hw.git
synced 2026-03-06 15:26:03 -08:00
fix: replace deprecated ioutils with os
Signed-off-by: Christian Walter <christian.walter@9elements.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -21,7 +20,7 @@ const (
|
||||
ebdaTop = 0xa0000
|
||||
)
|
||||
|
||||
//ACPIRsdpRev1 as defined in ACPI Spec 1
|
||||
// ACPIRsdpRev1 as defined in ACPI Spec 1
|
||||
type ACPIRsdpRev1 struct {
|
||||
Signature [8]uint8
|
||||
Checksum uint8
|
||||
@@ -30,7 +29,7 @@ type ACPIRsdpRev1 struct {
|
||||
RSDTPtr uint32
|
||||
}
|
||||
|
||||
//ACPIRsdp as defined in ACPI Spec 6.2 "5.2.5.3 Root System Description Pointer (RSDP) Structure"
|
||||
// ACPIRsdp as defined in ACPI Spec 6.2 "5.2.5.3 Root System Description Pointer (RSDP) Structure"
|
||||
type ACPIRsdp struct {
|
||||
ACPIRsdpRev1
|
||||
|
||||
@@ -52,20 +51,20 @@ type acpiHeader struct {
|
||||
CreatorRevision uint32
|
||||
}
|
||||
|
||||
//ACPIRsdt as defined in ACPI Spec 6.2 "5.2.7 Root System Description Table (RSDT)"
|
||||
// ACPIRsdt as defined in ACPI Spec 6.2 "5.2.7 Root System Description Table (RSDT)"
|
||||
type acpiRsdt struct {
|
||||
acpiHeader
|
||||
//Entry []uint32 count depend on Length field
|
||||
// Entry []uint32 count depend on Length field
|
||||
}
|
||||
|
||||
//ACPIXsdt as defined in ACPI Spec 6.2 "5.2.8 Extended System Description Table (XSDT)"
|
||||
// ACPIXsdt as defined in ACPI Spec 6.2 "5.2.8 Extended System Description Table (XSDT)"
|
||||
type acpiXsdt struct {
|
||||
acpiHeader
|
||||
//Entry []uint64 count depend on Length field
|
||||
// Entry []uint64 count depend on Length field
|
||||
}
|
||||
|
||||
func GetACPITableSysFS(h LowLevelHardwareInterfaces, n string) ([]byte, error) {
|
||||
buf, err := ioutil.ReadFile(fmt.Sprintf("%s/%s", acpiSysfsPath, n))
|
||||
buf, err := os.ReadFile(fmt.Sprintf("%s/%s", acpiSysfsPath, n))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot access sysfs path %s: %s", acpiSysfsPath, err)
|
||||
}
|
||||
@@ -229,7 +228,6 @@ func parseSystab(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
}
|
||||
|
||||
func scanLowMem(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
|
||||
var rsdp ACPIRsdp
|
||||
|
||||
buf := make([]byte, binary.Size(rsdp))
|
||||
@@ -254,7 +252,6 @@ func scanLowMem(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
}
|
||||
|
||||
func scanEBDA(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
|
||||
var rsdp ACPIRsdp
|
||||
|
||||
buf := make([]byte, binary.Size(rsdp))
|
||||
@@ -280,7 +277,6 @@ func scanEBDA(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
}
|
||||
|
||||
func scanReservedMem(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
|
||||
var rsdp ACPIRsdp
|
||||
|
||||
buf := make([]byte, binary.Size(rsdp))
|
||||
@@ -311,14 +307,12 @@ func scanReservedMem(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
}
|
||||
|
||||
func verifyRSDP(buf []byte, rsdp ACPIRsdp) error {
|
||||
|
||||
var old ACPIRsdpRev1
|
||||
|
||||
if rsdp.Revision == 0 {
|
||||
if rsdp.RSDPLen != uint32(binary.Size(old)) {
|
||||
return fmt.Errorf("ACPI RSDP has unexpected length %d", rsdp.RSDPLen)
|
||||
}
|
||||
|
||||
}
|
||||
/* Validate first checksum */
|
||||
chksum := byte(0)
|
||||
@@ -353,7 +347,6 @@ func verifyRSDP(buf []byte, rsdp ACPIRsdp) error {
|
||||
}
|
||||
|
||||
func getACPITableDevMemRSDP(l LowLevelHardwareInterfaces) ([]byte, ACPIRsdp, error) {
|
||||
|
||||
var rsdp ACPIRsdp
|
||||
|
||||
if string(backupRSDP.Signature[:]) == "RSD PTR " {
|
||||
@@ -475,7 +468,7 @@ func GetACPITableDevMem(h LowLevelHardwareInterfaces, n string) ([]byte, error)
|
||||
}
|
||||
|
||||
for k, v := range acpitables {
|
||||
if v == n { //FIXME: Handle duplicated entries like SSDT
|
||||
if v == n { // FIXME: Handle duplicated entries like SSDT
|
||||
var header acpiHeader
|
||||
|
||||
err := h.ReadPhysBuf(int64(k), buf)
|
||||
@@ -498,7 +491,7 @@ func GetACPITableDevMem(h LowLevelHardwareInterfaces, n string) ([]byte, error)
|
||||
return nil, fmt.Errorf("ACPI table not found")
|
||||
}
|
||||
|
||||
//GetACPITable returns the requested ACPI table, for DSDT use argument "DSDT"
|
||||
// GetACPITable returns the requested ACPI table, for DSDT use argument "DSDT"
|
||||
func (h HwAPI) GetACPITable(n string) ([]byte, error) {
|
||||
if n == "" || len(n) > 6 {
|
||||
return nil, fmt.Errorf("invalid ACPI name")
|
||||
|
||||
@@ -2,15 +2,13 @@ package hwapi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//iterateOverE820Ranges iterates over all e820 entries and invokes the callback for every matching type
|
||||
// iterateOverE820Ranges iterates over all e820 entries and invokes the callback for every matching type
|
||||
func (h HwAPI) IterateOverE820Ranges(target string, callback func(start uint64, end uint64) bool) (bool, error) {
|
||||
|
||||
dir, err := os.Open("/sys/firmware/memmap")
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("cannot access e820 table: %s", err)
|
||||
@@ -25,7 +23,7 @@ func (h HwAPI) IterateOverE820Ranges(target string, callback func(start uint64,
|
||||
if subdir.IsDir() {
|
||||
|
||||
path := fmt.Sprintf("/sys/firmware/memmap/%s/type", subdir.Name())
|
||||
buf, err := ioutil.ReadFile(path)
|
||||
buf, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -76,7 +74,7 @@ func UsableMemoryBelow4G(l LowLevelHardwareInterfaces) (size uint64, err error)
|
||||
return
|
||||
}
|
||||
|
||||
//IsReservedInE820 reads the e820 table exported via /sys/firmware/memmap and checks whether
|
||||
// IsReservedInE820 reads the e820 table exported via /sys/firmware/memmap and checks whether
|
||||
// the range [start; end] is marked as reserved. Returns true if it is reserved,
|
||||
// false if not.
|
||||
func IsReservedInE820(l LowLevelHardwareInterfaces, start uint64, end uint64) (bool, error) {
|
||||
@@ -97,7 +95,7 @@ func IsReservedInE820(l LowLevelHardwareInterfaces, start uint64, end uint64) (b
|
||||
}
|
||||
|
||||
func readHexInteger(path string) (uint64, error) {
|
||||
buf, err := ioutil.ReadFile(path)
|
||||
buf, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
//VTdRegisters represents the IOMMIO space
|
||||
// VTdRegisters represents the IOMMIO space
|
||||
type VTdRegisters struct {
|
||||
Version uint32 // Architecture version supported by the implementation.
|
||||
Reserved1 uint32 // Reserved
|
||||
@@ -111,7 +110,7 @@ func readVTdRegs(l LowLevelHardwareInterfaces) (VTdRegisters, error) {
|
||||
|
||||
for _, subdir := range subdirs {
|
||||
path := fmt.Sprintf("/sys/class/iommu/%s/intel-iommu/address", subdir.Name())
|
||||
addrBuf, err := ioutil.ReadFile(path)
|
||||
addrBuf, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@@ -139,7 +138,7 @@ func readVTdRegs(l LowLevelHardwareInterfaces) (VTdRegisters, error) {
|
||||
return regs, fmt.Errorf("no IOMMU found: /sys/class/iommu/*/intel-iommu/address does not exists or is malformed")
|
||||
}
|
||||
|
||||
//LookupIOAddress returns the address of the root Tbl
|
||||
// LookupIOAddress returns the address of the root Tbl
|
||||
func (h HwAPI) LookupIOAddress(addr uint64, regs VTdRegisters) ([]uint64, error) {
|
||||
rootTblAddr := regs.RootTableAddress & 0xffffffffffff000
|
||||
ttm := (regs.RootTableAddress >> 10) & 3
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
tpm1 "github.com/google/go-tpm/tpm"
|
||||
tpm2 "github.com/google/go-tpm/legacy/tpm2"
|
||||
tpm1 "github.com/google/go-tpm/tpm"
|
||||
tpmutil "github.com/google/go-tpm/tpmutil"
|
||||
)
|
||||
|
||||
@@ -21,7 +20,6 @@ import (
|
||||
type TCGVendorID uint32
|
||||
|
||||
func (id TCGVendorID) String() string {
|
||||
|
||||
s, ok := vendors[id]
|
||||
if !ok {
|
||||
return fmt.Sprintf("unknown TPM vendor (%d)", id)
|
||||
@@ -161,7 +159,7 @@ const (
|
||||
func probeSystemTPMs() ([]probedTPM, error) {
|
||||
var tpms []probedTPM
|
||||
|
||||
tpmDevs, err := ioutil.ReadDir(tpmRoot)
|
||||
tpmDevs, err := os.ReadDir(tpmRoot)
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
@@ -210,7 +208,7 @@ func newTPM(pTPM probedTPM) (*TPM, error) {
|
||||
// If the TPM has a kernel-provided resource manager, we should
|
||||
// use that instead of communicating directly.
|
||||
devPath := filepath.Join("/dev", filepath.Base(pTPM.Path))
|
||||
f, err := ioutil.ReadDir(filepath.Join(pTPM.Path, "device", "tpmrm"))
|
||||
f, err := os.ReadDir(filepath.Join(pTPM.Path, "device", "tpmrm"))
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
@@ -237,11 +235,11 @@ func newTPM(pTPM probedTPM) (*TPM, error) {
|
||||
// MeasurementLog reads the TCPA eventlog in binary format
|
||||
// from the Linux kernel
|
||||
func (t *TPM) MeasurementLog() ([]byte, error) {
|
||||
return ioutil.ReadFile("/sys/kernel/security/tpm0/binary_bios_measurements")
|
||||
return os.ReadFile("/sys/kernel/security/tpm0/binary_bios_measurements")
|
||||
}
|
||||
|
||||
func nvRead12(rwc io.ReadWriteCloser, index, offset, len uint32, auth string) ([]byte, error) {
|
||||
var ownAuth [20]byte //owner well known
|
||||
var ownAuth [20]byte // owner well known
|
||||
if auth != "" {
|
||||
ownAuth = sha1.Sum([]byte(auth))
|
||||
}
|
||||
@@ -274,7 +272,6 @@ func nvRead20(rwc io.ReadWriteCloser, index, authHandle tpmutil.Handle, password
|
||||
}
|
||||
|
||||
func readTPM12Information(rwc io.ReadWriter) (TPMInfo, error) {
|
||||
|
||||
manufacturerRaw, err := tpm1.GetManufacturer(rwc)
|
||||
if err != nil {
|
||||
return TPMInfo{}, err
|
||||
|
||||
Reference in New Issue
Block a user