Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_KDEV_T_H |
| 2 | #define _LINUX_KDEV_T_H |
| 3 | #ifdef __KERNEL__ |
| 4 | #define MINORBITS 20 |
| 5 | #define MINORMASK ((1U << MINORBITS) - 1) |
| 6 | |
| 7 | #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS)) |
| 8 | #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK)) |
| 9 | #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi)) |
| 10 | |
| 11 | #define print_dev_t(buffer, dev) \ |
| 12 | sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev)) |
| 13 | |
| 14 | #define format_dev_t(buffer, dev) \ |
| 15 | ({ \ |
| 16 | sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \ |
| 17 | buffer; \ |
| 18 | }) |
| 19 | |
| 20 | /* acceptable for old filesystems */ |
| 21 | static inline int old_valid_dev(dev_t dev) |
| 22 | { |
| 23 | return MAJOR(dev) < 256 && MINOR(dev) < 256; |
| 24 | } |
| 25 | |
| 26 | static inline u16 old_encode_dev(dev_t dev) |
| 27 | { |
| 28 | return (MAJOR(dev) << 8) | MINOR(dev); |
| 29 | } |
| 30 | |
| 31 | static inline dev_t old_decode_dev(u16 val) |
| 32 | { |
| 33 | return MKDEV((val >> 8) & 255, val & 255); |
| 34 | } |
| 35 | |
| 36 | static inline int new_valid_dev(dev_t dev) |
| 37 | { |
| 38 | return 1; |
| 39 | } |
| 40 | |
| 41 | static inline u32 new_encode_dev(dev_t dev) |
| 42 | { |
| 43 | unsigned major = MAJOR(dev); |
| 44 | unsigned minor = MINOR(dev); |
| 45 | return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12); |
| 46 | } |
| 47 | |
| 48 | static inline dev_t new_decode_dev(u32 dev) |
| 49 | { |
| 50 | unsigned major = (dev & 0xfff00) >> 8; |
| 51 | unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00); |
| 52 | return MKDEV(major, minor); |
| 53 | } |
| 54 | |
| 55 | static inline int huge_valid_dev(dev_t dev) |
| 56 | { |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | static inline u64 huge_encode_dev(dev_t dev) |
| 61 | { |
| 62 | return new_encode_dev(dev); |
| 63 | } |
| 64 | |
| 65 | static inline dev_t huge_decode_dev(u64 dev) |
| 66 | { |
| 67 | return new_decode_dev(dev); |
| 68 | } |
| 69 | |
| 70 | static inline int sysv_valid_dev(dev_t dev) |
| 71 | { |
| 72 | return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18); |
| 73 | } |
| 74 | |
| 75 | static inline u32 sysv_encode_dev(dev_t dev) |
| 76 | { |
| 77 | return MINOR(dev) | (MAJOR(dev) << 18); |
| 78 | } |
| 79 | |
| 80 | static inline unsigned sysv_major(u32 dev) |
| 81 | { |
| 82 | return (dev >> 18) & 0x3fff; |
| 83 | } |
| 84 | |
| 85 | static inline unsigned sysv_minor(u32 dev) |
| 86 | { |
| 87 | return dev & 0x3ffff; |
| 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | #else /* __KERNEL__ */ |
| 91 | |
| 92 | /* |
| 93 | Some programs want their definitions of MAJOR and MINOR and MKDEV |
| 94 | from the kernel sources. These must be the externally visible ones. |
| 95 | */ |
| 96 | #define MAJOR(dev) ((dev)>>8) |
| 97 | #define MINOR(dev) ((dev) & 0xff) |
| 98 | #define MKDEV(ma,mi) ((ma)<<8 | (mi)) |
| 99 | #endif /* __KERNEL__ */ |
| 100 | #endif |