archive_unix.go 871 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. func setHeaderForSpecialDevice(hdr *tar.Header, ta *tarAppender, name string, stat interface{}) (nlink uint32, inode uint64, err error) {
  9. s, ok := stat.(*syscall.Stat_t)
  10. if !ok {
  11. err = errors.New("cannot convert stat value to syscall.Stat_t")
  12. return
  13. }
  14. nlink = uint32(s.Nlink)
  15. inode = uint64(s.Ino)
  16. // Currently go does not fil in the major/minors
  17. if s.Mode&syscall.S_IFBLK == syscall.S_IFBLK ||
  18. s.Mode&syscall.S_IFCHR == syscall.S_IFCHR {
  19. hdr.Devmajor = int64(major(uint64(s.Rdev)))
  20. hdr.Devminor = int64(minor(uint64(s.Rdev)))
  21. }
  22. return
  23. }
  24. func major(device uint64) uint64 {
  25. return (device >> 8) & 0xfff
  26. }
  27. func minor(device uint64) uint64 {
  28. return (device & 0xff) | ((device >> 12) & 0xfff00)
  29. }