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 <tklauser@distanz.ch>
This commit is contained in:
parent
727fd599fb
commit
f01b139161
@ -31,25 +31,13 @@ func setHeaderForSpecialDevice(hdr *tar.Header, name string, fi os.FileInfo) err
|
|||||||
// Currently go does not fill in the major/minors
|
// Currently go does not fill in the major/minors
|
||||||
if s.Mode&syscall.S_IFBLK != 0 ||
|
if s.Mode&syscall.S_IFBLK != 0 ||
|
||||||
s.Mode&syscall.S_IFCHR != 0 {
|
s.Mode&syscall.S_IFCHR != 0 {
|
||||||
hdr.Devmajor = int64(major(uint64(s.Rdev)))
|
hdr.Devmajor = int64(unix.Major(uint64(s.Rdev)))
|
||||||
hdr.Devminor = int64(minor(uint64(s.Rdev)))
|
hdr.Devminor = int64(unix.Minor(uint64(s.Rdev)))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
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) {
|
func open(p string) (*os.File, error) {
|
||||||
return os.Open(p)
|
return os.Open(p)
|
||||||
}
|
}
|
||||||
@ -103,7 +91,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
|
|||||||
mode |= unix.S_IFIFO
|
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 {
|
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user