add support for file nodes
This commit is contained in:
parent
23ec82f4ec
commit
08ff7799ab
5 changed files with 68 additions and 3 deletions
5
base.go
5
base.go
|
@ -30,7 +30,10 @@ const EndOfEntireDevicePath DeviceNodeSubType = 0xFF
|
||||||
|
|
||||||
const ACPISubType DeviceNodeSubType = 1
|
const ACPISubType DeviceNodeSubType = 1
|
||||||
|
|
||||||
const HardDriveSubType DeviceNodeSubType = 1
|
const (
|
||||||
|
HardDriveSubType DeviceNodeSubType = 1
|
||||||
|
FileSubType DeviceNodeSubType = 4
|
||||||
|
)
|
||||||
|
|
||||||
type DevicePathNode interface {
|
type DevicePathNode interface {
|
||||||
Type() DeviceNodeType
|
Type() DeviceNodeType
|
||||||
|
|
43
file.go
Normal file
43
file.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package devicepath
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
filePrefix = "File"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileDevicePath struct {
|
||||||
|
path string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FileDevicePath) Type() DeviceNodeType {
|
||||||
|
return MediaDevicePath
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FileDevicePath) SubType() DeviceNodeSubType {
|
||||||
|
return FileSubType
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FileDevicePath) Bytes() []byte {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FileDevicePath) String() string {
|
||||||
|
return fmt.Sprintf("%s(%s)", filePrefix, fp.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fp *FileDevicePath) ParseString(raw string) error {
|
||||||
|
if !checkStringFormat(raw, filePrefix, -1) {
|
||||||
|
return ErrMalformedString
|
||||||
|
}
|
||||||
|
args := strings.Split(raw[len(filePrefix)+1:len(raw)-1], ",")
|
||||||
|
if len(args) != 1 {
|
||||||
|
return errors.New("unexpected number of arguments")
|
||||||
|
}
|
||||||
|
fp.path = args[0]
|
||||||
|
return nil
|
||||||
|
}
|
18
file_test.go
Normal file
18
file_test.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package devicepath_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.faercol.me/faercol/devicepath"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseFileString(t *testing.T) {
|
||||||
|
t.Run("ok", func(t *testing.T) {
|
||||||
|
var fileDev devicepath.FileDevicePath
|
||||||
|
expected := `File(\\EFI\\HTTPBOOT\\HTTP_BOOT_CLIENT.EFI)`
|
||||||
|
require.NoError(t, fileDev.ParseString(expected))
|
||||||
|
assert.Equal(t, expected, fileDev.String())
|
||||||
|
})
|
||||||
|
}
|
|
@ -35,6 +35,7 @@ var prefixTypeAssociation = map[string]nodeGenerator{
|
||||||
pciPrefix: func() DevicePathNode { return &PCIDevicePath{} },
|
pciPrefix: func() DevicePathNode { return &PCIDevicePath{} },
|
||||||
pciRootPrefix: func() DevicePathNode { return &PCIRootDevicePath{} },
|
pciRootPrefix: func() DevicePathNode { return &PCIRootDevicePath{} },
|
||||||
hdPrefix: func() DevicePathNode { return &HardDriveDevicePath{} },
|
hdPrefix: func() DevicePathNode { return &HardDriveDevicePath{} },
|
||||||
|
filePrefix: func() DevicePathNode { return &FileDevicePath{} },
|
||||||
}
|
}
|
||||||
|
|
||||||
func Parsenode(raw string) (DevicePathNode, error) {
|
func Parsenode(raw string) (DevicePathNode, error) {
|
||||||
|
|
|
@ -18,8 +18,8 @@ func TestOK(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDevicePathOK(t *testing.T) {
|
func TestParseDevicePathOK(t *testing.T) {
|
||||||
input := "PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x1)/Sata(0,65535,0)"
|
input := "PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x1)/Sata(0,65535,0)/HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\\EFI\\HTTPBOOT\\HTTP_BOOT_CLIENT.EFI)"
|
||||||
res, err := devicepath.ParseDevicePath(input)
|
res, err := devicepath.ParseDevicePath(input)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x1)/Sata(0,65535,0)", res.String())
|
assert.Equal(t, "PciRoot(0x0)/Pci(0x1,0x2)/Pci(0x0,0x1)/Sata(0,65535,0)/HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\\EFI\\HTTPBOOT\\HTTP_BOOT_CLIENT.EFI)", res.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue