1 #ifndef _LINUX_KDEV_T_H
2 #define _LINUX_KDEV_T_H
5 #define MINORMASK ((1U << MINORBITS) - 1)
7 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
8 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
9 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
11 #define print_dev_t(buffer, dev) \
12 sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
14 #define format_dev_t(buffer, dev) \
16 sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \
20 /* acceptable for old filesystems */
21 static inline int old_valid_dev(dev_t dev
)
23 return MAJOR(dev
) < 256 && MINOR(dev
) < 256;
26 static inline u16
old_encode_dev(dev_t dev
)
28 return (MAJOR(dev
) << 8) | MINOR(dev
);
31 static inline dev_t
old_decode_dev(u16 val
)
33 return MKDEV((val
>> 8) & 255, val
& 255);
36 static inline int new_valid_dev(dev_t dev
)
41 static inline u32
new_encode_dev(dev_t dev
)
43 unsigned major
= MAJOR(dev
);
44 unsigned minor
= MINOR(dev
);
45 return (minor
& 0xff) | (major
<< 8) | ((minor
& ~0xff) << 12);
48 static inline dev_t
new_decode_dev(u32 dev
)
50 unsigned major
= (dev
& 0xfff00) >> 8;
51 unsigned minor
= (dev
& 0xff) | ((dev
>> 12) & 0xfff00);
52 return MKDEV(major
, minor
);
55 static inline int huge_valid_dev(dev_t dev
)
60 static inline u64
huge_encode_dev(dev_t dev
)
62 return new_encode_dev(dev
);
65 static inline dev_t
huge_decode_dev(u64 dev
)
67 return new_decode_dev(dev
);
70 static inline int sysv_valid_dev(dev_t dev
)
72 return MAJOR(dev
) < (1<<14) && MINOR(dev
) < (1<<18);
75 static inline u32
sysv_encode_dev(dev_t dev
)
77 return MINOR(dev
) | (MAJOR(dev
) << 18);
80 static inline unsigned sysv_major(u32 dev
)
82 return (dev
>> 18) & 0x3fff;
85 static inline unsigned sysv_minor(u32 dev
)
90 #else /* __KERNEL__ */
93 Some programs want their definitions of MAJOR and MINOR and MKDEV
94 from the kernel sources. These must be the externally visible ones.
96 #define MAJOR(dev) ((dev)>>8)
97 #define MINOR(dev) ((dev) & 0xff)
98 #define MKDEV(ma,mi) ((ma)<<8 | (mi))
99 #endif /* __KERNEL__ */