@@ -27,6 +27,7 @@ import (
2727 "os"
2828 "path/filepath"
2929
30+ "github.com/opencontainers/cgroups/devices/config"
3031 "golang.org/x/sys/unix"
3132)
3233
@@ -42,36 +43,36 @@ var (
4243// DeviceFromPath takes the path to a device and its cgroup_permissions (which
4344// cannot be easily queried) to look up the information about a linux device
4445// and returns that information as a Device struct.
45- func DeviceFromPath (path , permissions string ) (* Device , error ) {
46+ func DeviceFromPath (path , permissions string ) (* config. Device , error ) {
4647 var stat unix.Stat_t
4748 err := unixLstat (path , & stat )
4849 if err != nil {
4950 return nil , err
5051 }
5152
5253 var (
53- devType Type
54+ devType config. Type
5455 mode = stat .Mode
5556 devNumber = uint64 (stat .Rdev ) //nolint:unconvert // Rdev is uint32 on e.g. MIPS.
5657 major = unix .Major (devNumber )
5758 minor = unix .Minor (devNumber )
5859 )
5960 switch mode & unix .S_IFMT {
6061 case unix .S_IFBLK :
61- devType = BlockDevice
62+ devType = config . BlockDevice
6263 case unix .S_IFCHR :
63- devType = CharDevice
64+ devType = config . CharDevice
6465 case unix .S_IFIFO :
65- devType = FifoDevice
66+ devType = config . FifoDevice
6667 default :
6768 return nil , ErrNotADevice
6869 }
69- return & Device {
70- Rule : Rule {
70+ return & config. Device {
71+ Rule : config. Rule {
7172 Type : devType ,
7273 Major : int64 (major ),
7374 Minor : int64 (minor ),
74- Permissions : Permissions (permissions ),
75+ Permissions : config . Permissions (permissions ),
7576 },
7677 Path : path ,
7778 FileMode : os .FileMode (mode &^ unix .S_IFMT ),
@@ -81,18 +82,18 @@ func DeviceFromPath(path, permissions string) (*Device, error) {
8182}
8283
8384// HostDevices returns all devices that can be found under /dev directory.
84- func HostDevices () ([]* Device , error ) {
85+ func HostDevices () ([]* config. Device , error ) {
8586 return GetDevices ("/dev" )
8687}
8788
8889// GetDevices recursively traverses a directory specified by path
8990// and returns all devices found there.
90- func GetDevices (path string ) ([]* Device , error ) {
91+ func GetDevices (path string ) ([]* config. Device , error ) {
9192 files , err := osReadDir (path )
9293 if err != nil {
9394 return nil , err
9495 }
95- var out []* Device
96+ var out []* config. Device
9697 for _ , f := range files {
9798 switch {
9899 case f .IsDir ():
@@ -123,7 +124,7 @@ func GetDevices(path string) ([]*Device, error) {
123124 }
124125 return nil , err
125126 }
126- if device .Type == FifoDevice {
127+ if device .Type == config . FifoDevice {
127128 continue
128129 }
129130 out = append (out , device )
0 commit comments