Merge tag 'fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/arm...
[linux-2.6.git] / include / linux / kdev_t.h
blobc838abe3ee0a80dfccfb2bfbf1bc1e5067fa9dca
1 #ifndef _LINUX_KDEV_T_H
2 #define _LINUX_KDEV_T_H
4 #include <uapi/linux/kdev_t.h>
6 #define MINORBITS 20
7 #define MINORMASK ((1U << MINORBITS) - 1)
9 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
10 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
11 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
13 #define print_dev_t(buffer, dev) \
14 sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
16 #define format_dev_t(buffer, dev) \
17 ({ \
18 sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \
19 buffer; \
22 /* acceptable for old filesystems */
23 static inline int old_valid_dev(dev_t dev)
25 return MAJOR(dev) < 256 && MINOR(dev) < 256;
28 static inline u16 old_encode_dev(dev_t dev)
30 return (MAJOR(dev) << 8) | MINOR(dev);
33 static inline dev_t old_decode_dev(u16 val)
35 return MKDEV((val >> 8) & 255, val & 255);
38 static inline int new_valid_dev(dev_t dev)
40 return 1;
43 static inline u32 new_encode_dev(dev_t dev)
45 unsigned major = MAJOR(dev);
46 unsigned minor = MINOR(dev);
47 return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
50 static inline dev_t new_decode_dev(u32 dev)
52 unsigned major = (dev & 0xfff00) >> 8;
53 unsigned minor = (dev & 0xff) | ((dev >> 12) & 0xfff00);
54 return MKDEV(major, minor);
57 static inline int huge_valid_dev(dev_t dev)
59 return 1;
62 static inline u64 huge_encode_dev(dev_t dev)
64 return new_encode_dev(dev);
67 static inline dev_t huge_decode_dev(u64 dev)
69 return new_decode_dev(dev);
72 static inline int sysv_valid_dev(dev_t dev)
74 return MAJOR(dev) < (1<<14) && MINOR(dev) < (1<<18);
77 static inline u32 sysv_encode_dev(dev_t dev)
79 return MINOR(dev) | (MAJOR(dev) << 18);
82 static inline unsigned sysv_major(u32 dev)
84 return (dev >> 18) & 0x3fff;
87 static inline unsigned sysv_minor(u32 dev)
89 return dev & 0x3ffff;
92 #endif