github.com/codemac/docker@v1.2.1-0.20150518222241-6a18412d5b9c/pkg/archive/archive_unix.go (about)

     1  // +build !windows
     2  
     3  package archive
     4  
     5  import (
     6  	"archive/tar"
     7  	"errors"
     8  	"os"
     9  	"syscall"
    10  )
    11  
    12  // canonicalTarNameForPath returns platform-specific filepath
    13  // to canonical posix-style path for tar archival. p is relative
    14  // path.
    15  func CanonicalTarNameForPath(p string) (string, error) {
    16  	return p, nil // already unix-style
    17  }
    18  
    19  // chmodTarEntry is used to adjust the file permissions used in tar header based
    20  // on the platform the archival is done.
    21  
    22  func chmodTarEntry(perm os.FileMode) os.FileMode {
    23  	return perm // noop for unix as golang APIs provide perm bits correctly
    24  }
    25  
    26  func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (nlink uint32, inode uint64, err error) {
    27  	s, ok := stat.(*syscall.Stat_t)
    28  
    29  	if !ok {
    30  		err = errors.New("cannot convert stat value to syscall.Stat_t")
    31  		return
    32  	}
    33  
    34  	nlink = uint32(s.Nlink)
    35  	inode = uint64(s.Ino)
    36  
    37  	// Currently go does not fil in the major/minors
    38  	if s.Mode&syscall.S_IFBLK != 0 ||
    39  		s.Mode&syscall.S_IFCHR != 0 {
    40  		hdr.Devmajor = int64(major(uint64(s.Rdev)))
    41  		hdr.Devminor = int64(minor(uint64(s.Rdev)))
    42  	}
    43  
    44  	return
    45  }
    46  
    47  func major(device uint64) uint64 {
    48  	return (device >> 8) & 0xfff
    49  }
    50  
    51  func minor(device uint64) uint64 {
    52  	return (device & 0xff) | ((device >> 12) & 0xfff00)
    53  }