github.com/lmars/docker@v1.6.0-rc2/pkg/archive/archive_unix.go (about)

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