77 "os"
88 "path/filepath"
99
10+ "github.com/opencontainers/cgroups/devices/config"
1011 "golang.org/x/sys/unix"
1112)
1213
@@ -22,36 +23,36 @@ var (
2223// DeviceFromPath takes the path to a device and its cgroup_permissions (which
2324// cannot be easily queried) to look up the information about a linux device
2425// and returns that information as a Device struct.
25- func DeviceFromPath (path , permissions string ) (* Device , error ) {
26+ func DeviceFromPath (path , permissions string ) (* config. Device , error ) {
2627 var stat unix.Stat_t
2728 err := unixLstat (path , & stat )
2829 if err != nil {
2930 return nil , err
3031 }
3132
3233 var (
33- devType Type
34+ devType config. Type
3435 mode = stat .Mode
3536 devNumber = uint64 (stat .Rdev ) //nolint:unconvert // Rdev is uint32 on e.g. MIPS.
3637 major = unix .Major (devNumber )
3738 minor = unix .Minor (devNumber )
3839 )
3940 switch mode & unix .S_IFMT {
4041 case unix .S_IFBLK :
41- devType = BlockDevice
42+ devType = config . BlockDevice
4243 case unix .S_IFCHR :
43- devType = CharDevice
44+ devType = config . CharDevice
4445 case unix .S_IFIFO :
45- devType = FifoDevice
46+ devType = config . FifoDevice
4647 default :
4748 return nil , ErrNotADevice
4849 }
49- return & Device {
50- Rule : Rule {
50+ return & config. Device {
51+ Rule : config. Rule {
5152 Type : devType ,
5253 Major : int64 (major ),
5354 Minor : int64 (minor ),
54- Permissions : Permissions (permissions ),
55+ Permissions : config . Permissions (permissions ),
5556 },
5657 Path : path ,
5758 FileMode : os .FileMode (mode &^ unix .S_IFMT ),
@@ -61,18 +62,18 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
6162}
6263
6364// HostDevices returns all devices that can be found under /dev directory.
64- func HostDevices () ([]* Device , error ) {
65+ func HostDevices () ([]* config. Device , error ) {
6566 return GetDevices ("/dev" )
6667}
6768
6869// GetDevices recursively traverses a directory specified by path
6970// and returns all devices found there.
70- func GetDevices (path string ) ([]* Device , error ) {
71+ func GetDevices (path string ) ([]* config. Device , error ) {
7172 files , err := osReadDir (path )
7273 if err != nil {
7374 return nil , err
7475 }
75- var out []* Device
76+ var out []* config. Device
7677 for _ , f := range files {
7778 switch {
7879 case f .IsDir ():
@@ -103,7 +104,7 @@ func GetDevices(path string) ([]*Device, error) {
103104 }
104105 return nil , err
105106 }
106- if device .Type == FifoDevice {
107+ if device .Type == config . FifoDevice {
107108 continue
108109 }
109110 out = append (out , device )
0 commit comments