package devicepath import ( "errors" "fmt" "strconv" "strings" ) const ( defaultPortMultiplier = 0xffff defaultLogicalUnitNumber = 0 sataLength uint16 = 10 sataPrefix string = "Sata" ) type SataDevicePath struct { hbaPortNumber uint16 portMultiplierPortNumber uint16 logicalUnitNumber uint16 } func (sp *SataDevicePath) Type() DeviceNodeType { return MessagingDevicePath } func (sp *SataDevicePath) SubType() DeviceNodeSubType { return SATAMessaging } func (sp *SataDevicePath) Bytes() []byte { return nil } func (sp *SataDevicePath) String() string { return fmt.Sprintf("%s(%d,%d,%d)", sataPrefix, sp.hbaPortNumber, sp.portMultiplierPortNumber, sp.logicalUnitNumber) } func (sp *SataDevicePath) ParseString(raw string) error { if !checkStringFormat(raw, sataPrefix, -1) { return ErrMalformedString } args := strings.Split(raw[len(sataPrefix)+1:len(raw)-1], ",") if len(args) != 3 { return errors.New("unexpected number of arguments") } if hbaPortNumber, err := strconv.Atoi(args[0]); err != nil { return err } else { sp.hbaPortNumber = uint16(hbaPortNumber) } if portMultiplierPortNumber, err := strconv.Atoi(args[1]); err != nil { return err } else { sp.portMultiplierPortNumber = uint16(portMultiplierPortNumber) } if logicalUnitNumber, err := strconv.Atoi(args[2]); err != nil { return err } else { sp.logicalUnitNumber = uint16(logicalUnitNumber) } return nil } func NewSataFromPortNumber(portNumber uint16) *SataDevicePath { return &SataDevicePath{ hbaPortNumber: portNumber, portMultiplierPortNumber: defaultPortMultiplier, logicalUnitNumber: defaultLogicalUnitNumber, } }