package devicepath import ( "errors" "strings" ) 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 MacMessagingSubType DeviceNodeSubType = 11 IPv4MessagingSubType DeviceNodeSubType = 12 ) const EndOfEntireDevicePath DeviceNodeSubType = 0xFF const ACPISubType DeviceNodeSubType = 1 const ( HardDriveSubType DeviceNodeSubType = 1 FileSubType DeviceNodeSubType = 4 ) type DevicePathNode interface { Type() DeviceNodeType SubType() DeviceNodeSubType ParseString(raw string) error String() string 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, "/") }