archive_unix.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // +build !windows
  2. package archive
  3. import (
  4. "errors"
  5. "syscall"
  6. "github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
  7. )
  8. // canonicalTarNameForPath returns platform-specific filepath
  9. // to canonical posix-style path for tar archival. p is relative
  10. // path.
  11. func canonicalTarNameForPath(p string) (string, error) {
  12. return p, nil // already unix-style
  13. }
  14. func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (nlink uint32, inode uint64, err error) {
  15. s, ok := stat.(*syscall.Stat_t)
  16. if !ok {
  17. err = errors.New("cannot convert stat value to syscall.Stat_t")
  18. return
  19. }
  20. nlink = uint32(s.Nlink)
  21. inode = uint64(s.Ino)
  22. // Currently go does not fil in the major/minors
  23. if s.Mode&syscall.S_IFBLK == syscall.S_IFBLK ||
  24. s.Mode&syscall.S_IFCHR == syscall.S_IFCHR {
  25. hdr.Devmajor = int64(major(uint64(s.Rdev)))
  26. hdr.Devminor = int64(minor(uint64(s.Rdev)))
  27. }
  28. return
  29. }
  30. func major(device uint64) uint64 {
  31. return (device >> 8) & 0xfff
  32. }
  33. func minor(device uint64) uint64 {
  34. return (device & 0xff) | ((device >> 12) & 0xfff00)
  35. }