Skip to content

Commit 4a33056

Browse files
committed
devices: drop deprecated aliases from runc
These are old APIs from runc that we should not export at all. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 5ce8494 commit 4a33056

3 files changed

Lines changed: 16 additions & 34 deletions

File tree

devices/device_deprecated.go

Lines changed: 0 additions & 20 deletions
This file was deleted.

devices/device_unix.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
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)

devices/device_unix_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"testing"
1010

11+
"github.com/opencontainers/cgroups/devices/config"
1112
"golang.org/x/sys/unix"
1213
)
1314

@@ -85,8 +86,8 @@ func TestHostDevicesAllValid(t *testing.T) {
8586
t.Errorf("device entry %+v has zero major number", device)
8687
}
8788
switch device.Type {
88-
case BlockDevice, CharDevice:
89-
case FifoDevice:
89+
case config.BlockDevice, config.CharDevice:
90+
case config.FifoDevice:
9091
t.Logf("fifo devices shouldn't show up from HostDevices")
9192
fallthrough
9293
default:

0 commit comments

Comments
 (0)