本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1013B

  1. // Copyright 2017 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. // Functions to access/create device major and minor numbers matching the
  5. // encoding used in FreeBSD's sys/types.h header.
  6. //
  7. // The information below is extracted and adapted from sys/types.h:
  8. //
  9. // Minor gives a cookie instead of an index since in order to avoid changing the
  10. // meanings of bits 0-15 or wasting time and space shifting bits 16-31 for
  11. // devices that don't use them.
  12. package unix
  13. // Major returns the major component of a FreeBSD device number.
  14. func Major(dev uint64) uint32 {
  15. return uint32((dev >> 8) & 0xff)
  16. }
  17. // Minor returns the minor component of a FreeBSD device number.
  18. func Minor(dev uint64) uint32 {
  19. return uint32(dev & 0xffff00ff)
  20. }
  21. // Mkdev returns a FreeBSD device number generated from the given major and
  22. // minor components.
  23. func Mkdev(major, minor uint32) uint64 {
  24. return (uint64(major) << 8) | uint64(minor)
  25. }
上海开阖软件有限公司 沪ICP备12045867号-1