devicepath/file.go

44 lines
758 B
Go
Raw Normal View History

2023-09-16 15:21:48 +00:00
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
}