43 lines
758 B
Go
43 lines
758 B
Go
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
|
|
}
|