From 0eed453b212542b0c47cba8e63ddae15081c63bc Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 17 Oct 2017 08:30:01 +0200 Subject: [PATCH] libcontainer: use Major/Minor from x/sys/unix The Major and Minor functions were added for Linux in golang/sys@85d1495 which is already vendored in. Use these functions instead of the local re-implementation. Signed-off-by: Tobias Klauser --- libcontainer/devices/devices_linux.go | 8 ++++---- libcontainer/devices/number.go | 24 ------------------------ 2 files changed, 4 insertions(+), 28 deletions(-) delete mode 100644 libcontainer/devices/number.go diff --git a/libcontainer/devices/devices_linux.go b/libcontainer/devices/devices_linux.go index 326ad3b1..36192589 100644 --- a/libcontainer/devices/devices_linux.go +++ b/libcontainer/devices/devices_linux.go @@ -30,8 +30,8 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) { } var ( - devNumber = int(stat.Rdev) - major = Major(devNumber) + devNumber = stat.Rdev + major = unix.Major(devNumber) ) if major == 0 { return nil, ErrNotADevice @@ -50,8 +50,8 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) { return &configs.Device{ Type: devType, Path: path, - Major: major, - Minor: Minor(devNumber), + Major: int64(major), + Minor: int64(unix.Minor(devNumber)), Permissions: permissions, FileMode: os.FileMode(mode), Uid: stat.Uid, diff --git a/libcontainer/devices/number.go b/libcontainer/devices/number.go deleted file mode 100644 index 885b6e5d..00000000 --- a/libcontainer/devices/number.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build linux freebsd - -package devices - -/* - -This code provides support for manipulating linux device numbers. It should be replaced by normal syscall functions once http://code.google.com/p/go/issues/detail?id=8106 is solved. - -You can read what they are here: - - - http://www.makelinux.net/ldd3/chp-3-sect-2 - - http://www.linux-tutorial.info/modules.php?name=MContent&pageid=94 - -Note! These are NOT the same as the MAJOR(dev_t device);, MINOR(dev_t device); and MKDEV(int major, int minor); functions as defined in as the representation of device numbers used by go is different than the one used internally to the kernel! - https://github.com/torvalds/linux/blob/master/include/linux/kdev_t.h#L9 - -*/ - -func Major(devNumber int) int64 { - return int64((devNumber >> 8) & 0xfff) -} - -func Minor(devNumber int) int64 { - return int64((devNumber & 0xff) | ((devNumber >> 12) & 0xfff00)) -}