2023-08-27 09:31:03 +00:00
|
|
|
package devicepath
|
|
|
|
|
2023-08-27 13:09:30 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
2023-08-27 09:31:03 +00:00
|
|
|
|
2023-08-27 13:09:30 +00:00
|
|
|
type DeviceNodeType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
HardwareDevicePath DeviceNodeType = 0x01
|
|
|
|
ACPIDevicePath DeviceNodeType = 0x02
|
|
|
|
MessagingDevicePath DeviceNodeType = 0x03
|
|
|
|
MediaDevicePath DeviceNodeType = 0x04
|
|
|
|
BIOSBootSpecificationsDevicePath DeviceNodeType = 0x05
|
|
|
|
EndOfHardwareDevicePath DeviceNodeType = 0x7F
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeviceNodeSubType uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
PCIHardware DeviceNodeSubType = 0x01
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
SATAMessaging DeviceNodeSubType = 18
|
|
|
|
)
|
|
|
|
|
|
|
|
const EndOfEntireDevicePath DeviceNodeSubType = 0xFF
|
|
|
|
|
|
|
|
const ACPISubType DeviceNodeSubType = 1
|
|
|
|
|
2023-09-16 15:21:48 +00:00
|
|
|
const (
|
|
|
|
HardDriveSubType DeviceNodeSubType = 1
|
|
|
|
FileSubType DeviceNodeSubType = 4
|
|
|
|
)
|
2023-09-16 15:00:46 +00:00
|
|
|
|
2023-08-27 13:09:30 +00:00
|
|
|
type DevicePathNode interface {
|
|
|
|
Type() DeviceNodeType
|
|
|
|
SubType() DeviceNodeSubType
|
|
|
|
ParseString(raw string) error
|
2023-08-27 09:31:03 +00:00
|
|
|
String() string
|
2023-08-27 13:09:30 +00:00
|
|
|
Bytes() []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
var ErrPathComplete = errors.New("device path already complete")
|
|
|
|
|
|
|
|
type DevicePath struct {
|
|
|
|
nodes []DevicePathNode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dp *DevicePath) complete() bool {
|
|
|
|
return len(dp.nodes) > 0 && dp.nodes[len(dp.nodes)-1].Type() == EndOfHardwareDevicePath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dp *DevicePath) PushNode(node DevicePathNode) error {
|
|
|
|
if dp.complete() {
|
|
|
|
return ErrPathComplete
|
|
|
|
}
|
|
|
|
dp.nodes = append(dp.nodes, node)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dp *DevicePath) String() string {
|
|
|
|
var res []string
|
|
|
|
for _, node := range dp.nodes {
|
|
|
|
if node.String() != "" {
|
|
|
|
res = append(res, node.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.Join(res, "/")
|
2023-08-27 09:31:03 +00:00
|
|
|
}
|