dev_aix_ppc64.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build aix
  5. // +build ppc64
  6. // Functions to access/create device major and minor numbers matching the
  7. // encoding used by the Linux kernel and glibc.
  8. //
  9. // The information below is extracted and adapted from bits/sysmacros.h in the
  10. // glibc sources:
  11. //
  12. // dev_t in glibc is 64-bit, with 32-bit major and minor numbers. glibc's
  13. // default encoding is MMMM Mmmm mmmM MMmm, where M is a hex digit of the major
  14. // number and m is a hex digit of the minor number. This is backward compatible
  15. // with legacy systems where dev_t is 16 bits wide, encoded as MMmm. It is also
  16. // backward compatible with the Linux kernel, which for some architectures uses
  17. // 32-bit dev_t, encoded as mmmM MMmm.
  18. package unix
  19. // Major returns the major component of a Linux device number.
  20. func Major(dev uint64) uint32 {
  21. return uint32((dev & 0x3fffffff00000000) >> 32)
  22. }
  23. // Minor returns the minor component of a Linux device number.
  24. func Minor(dev uint64) uint32 {
  25. return uint32((dev & 0x00000000ffffffff) >> 0)
  26. }
  27. // Mkdev returns a Linux device number generated from the given major and minor
  28. // components.
  29. func Mkdev(major, minor uint32) uint64 {
  30. var DEVNO64 uint64
  31. DEVNO64 = 0x8000000000000000
  32. return ((uint64(major) << 32) | (uint64(minor) & 0x00000000FFFFFFFF) | DEVNO64)
  33. }