Skip to content

Commit eec528d

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 ea16e93 commit eec528d

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
@@ -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)

devices/device_unix_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"os"
2929
"testing"
3030

31+
"github.com/opencontainers/cgroups/devices/config"
3132
"golang.org/x/sys/unix"
3233
)
3334

@@ -105,8 +106,8 @@ func TestHostDevicesAllValid(t *testing.T) {
105106
t.Errorf("device entry %+v has zero major number", device)
106107
}
107108
switch device.Type {
108-
case BlockDevice, CharDevice:
109-
case FifoDevice:
109+
case config.BlockDevice, config.CharDevice:
110+
case config.FifoDevice:
110111
t.Logf("fifo devices shouldn't show up from HostDevices")
111112
fallthrough
112113
default:

0 commit comments

Comments
 (0)