github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/runc/libcontainer/configs/device.go (about) 1 package configs 2 3 import ( 4 "fmt" 5 "os" 6 ) 7 8 const ( 9 Wildcard = -1 10 ) 11 12 // TODO Windows: This can be factored out in the future 13 14 type Device struct { 15 // Device type, block, char, etc. 16 Type rune `json:"type"` 17 18 // Path to the device. 19 Path string `json:"path"` 20 21 // Major is the device's major number. 22 Major int64 `json:"major"` 23 24 // Minor is the device's minor number. 25 Minor int64 `json:"minor"` 26 27 // Cgroup permissions format, rwm. 28 Permissions string `json:"permissions"` 29 30 // FileMode permission bits for the device. 31 FileMode os.FileMode `json:"file_mode"` 32 33 // Uid of the device. 34 Uid uint32 `json:"uid"` 35 36 // Gid of the device. 37 Gid uint32 `json:"gid"` 38 39 // Write the file to the allowed list 40 Allow bool `json:"allow"` 41 } 42 43 func (d *Device) CgroupString() string { 44 return fmt.Sprintf("%c %s:%s %s", d.Type, deviceNumberString(d.Major), deviceNumberString(d.Minor), d.Permissions) 45 } 46 47 func (d *Device) Mkdev() int { 48 return int((d.Major << 8) | (d.Minor & 0xff) | ((d.Minor & 0xfff00) << 12)) 49 } 50 51 // deviceNumberString converts the device number to a string return result. 52 func deviceNumberString(number int64) string { 53 if number == Wildcard { 54 return "*" 55 } 56 return fmt.Sprint(number) 57 }