dev_aix_ppc.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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 ppc
  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 >> 16) & 0xffff)
  22. }
  23. // Minor returns the minor component of a Linux device number.
  24. func Minor(dev uint64) uint32 {
  25. return uint32(dev & 0xffff)
  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. return uint64(((major) << 16) | (minor))
  31. }