MCPcopy Index your code
hub / github.com/docker/cli / parseLinuxDevice

Function parseLinuxDevice

cli/command/container/opts.go:1009–1040  ·  view source on GitHub ↗

parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct knowing that the target is a Linux daemon

(device string)

Source from the content-addressed store, hash-verified

1007// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
1008// knowing that the target is a Linux daemon
1009func parseLinuxDevice(device string) (container.DeviceMapping, error) {
1010 var src, dst string
1011 permissions := "rwm"
1012 // We expect 3 parts at maximum; limit to 4 parts to detect invalid options.
1013 arr := strings.SplitN(device, ":", 4)
1014 switch len(arr) {
1015 case 3:
1016 permissions = arr[2]
1017 fallthrough
1018 case 2:
1019 if validDeviceMode(arr[1]) {
1020 permissions = arr[1]
1021 } else {
1022 dst = arr[1]
1023 }
1024 fallthrough
1025 case 1:
1026 src = arr[0]
1027 default:
1028 return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
1029 }
1030
1031 if dst == "" {
1032 dst = src
1033 }
1034
1035 return container.DeviceMapping{
1036 PathOnHost: src,
1037 PathInContainer: dst,
1038 CgroupPermissions: permissions,
1039 }, nil
1040}
1041
1042// validateDeviceCgroupRule validates a device cgroup rule string format
1043// It will make sure 'val' is in the form:

Callers 1

parseDeviceFunction · 0.85

Calls 1

validDeviceModeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…