number.go 900 B

12345678910111213141516171819202122232425
  1. // +build linux freebsd
  2. package devices
  3. /*
  4. This code provides support for manipulating linux device numbers. It should be replaced by normal syscall functions once http://code.google.com/p/go/issues/detail?id=8106 is solved.
  5. You can read what they are here:
  6. - http://www.makelinux.net/ldd3/chp-3-sect-2
  7. - http://www.linux-tutorial.info/modules.php?name=MContent&pageid=94
  8. Note! These are NOT the same as the MAJOR(dev_t device);, MINOR(dev_t device); and MKDEV(int major, int minor); functions as defined in <linux/kdev_t.h> as the representation of device numbers used by go is different than the one used internally to the kernel! - https://github.com/torvalds/linux/blob/master/include/linux/kdev_t.h#L9
  9. */
  10. func Major(devNumber int) int64 {
  11. return int64((devNumber >> 8) & 0xfff)
  12. }
  13. func Minor(devNumber int) int64 {
  14. return int64((devNumber & 0xff) | ((devNumber >> 12) & 0xfff00))
  15. }