From f01b139161af407c239bc9b3ce1425d9677712ab Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 2 Oct 2017 15:13:03 +0200 Subject: [PATCH] archive: use Mkdev, Major and Minor functions from golang.org/x/sys/unix Now that golang.org/x/sys/unix provides the Mkdev, Major and Minor functions for every OS, use them instead of the locally defined version which uses the Linux specific device major/minor encoding. This also means that the device number should now be properly encoded on e.g. Darwin, FreeBSD or Solaris. Signed-off-by: Tobias Klauser --- archive/tar_unix.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/archive/tar_unix.go b/archive/tar_unix.go index 75bc15b6b..7400d0058 100644 --- a/archive/tar_unix.go +++ b/archive/tar_unix.go @@ -31,25 +31,13 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err // Currently go does not fill in the major/minors if s.Mode&syscall.S_IFBLK != 0 || s.Mode&syscall.S_IFCHR != 0 { - hdr.Devmajor = int64(major(uint64(s.Rdev))) - hdr.Devminor = int64(minor(uint64(s.Rdev))) + hdr.Devmajor = int64(unix.Major(uint64(s.Rdev))) + hdr.Devminor = int64(unix.Minor(uint64(s.Rdev))) } return nil } -func major(device uint64) uint64 { - return (device >> 8) & 0xfff -} - -func minor(device uint64) uint64 { - return (device & 0xff) | ((device >> 12) & 0xfff00) -} - -func mkdev(major int64, minor int64) uint32 { - return uint32(((minor & 0xfff00) << 12) | ((major & 0xfff) << 8) | (minor & 0xff)) -} - func open(p string) (*os.File, error) { return os.Open(p) } @@ -103,7 +91,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { mode |= unix.S_IFIFO } - return unix.Mknod(path, mode, int(mkdev(hdr.Devmajor, hdr.Devminor))) + return unix.Mknod(path, mode, int(unix.Mkdev(uint32(hdr.Devmajor), uint32(hdr.Devminor)))) } func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {