MCPcopy Create free account
hub / github.com/containers/common / Device

Function Device

pkg/parse/parse.go:102–136  ·  view source on GitHub ↗

Device parses device mapping string to a src, dest & permissions string Valid values for device looklike: '/dev/sdc" '/dev/sdc:/dev/xvdc" '/dev/sdc:/dev/xvdc:rwm" '/dev/sdc:rm"

(device string)

Source from the content-addressed store, hash-verified

100// '/dev/sdc:/dev/xvdc:rwm"
101// '/dev/sdc:rm"
102func Device(device string) (src, dest, permissions string, err error) {
103 permissions = "rwm"
104 arr := strings.Split(device, ":")
105 switch len(arr) {
106 case 3:
107 if !isValidDeviceMode(arr[2]) {
108 return "", "", "", errors.Errorf("invalid device mode: %s", arr[2])
109 }
110 permissions = arr[2]
111 fallthrough
112 case 2:
113 if isValidDeviceMode(arr[1]) {
114 permissions = arr[1]
115 } else {
116 if arr[1] == "" || arr[1][0] != '/' {
117 return "", "", "", errors.Errorf("invalid device mode: %s", arr[1])
118 }
119 dest = arr[1]
120 }
121 fallthrough
122 case 1:
123 if len(arr[0]) > 0 {
124 src = arr[0]
125 break
126 }
127 fallthrough
128 default:
129 return "", "", "", errors.Errorf("invalid device specification: %s", device)
130 }
131
132 if dest == "" {
133 dest = src
134 }
135 return src, dest, permissions, nil
136}
137
138// isValidDeviceMode checks if the mode for device is valid or not.
139// isValid mode is a composition of r (read), w (write), and m (mknod).

Callers 2

TestDeviceParserFunction · 0.70
DeviceFromPathFunction · 0.70

Calls 1

isValidDeviceModeFunction · 0.85

Tested by 1

TestDeviceParserFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…