1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_KDEV_T_H
3 #define _LINUX_KDEV_T_H
5 #include <uapi/linux/kdev_t.h>
8 #define MINORMASK ((1U << MINORBITS) - 1)
10 #define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
11 #define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
12 #define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
14 #define print_dev_t(buffer, dev) \
15 sprintf((buffer), "%u:%u\n", MAJOR(dev), MINOR(dev))
17 #define format_dev_t(buffer, dev) \
19 sprintf(buffer, "%u:%u", MAJOR(dev), MINOR(dev)); \
23 /* acceptable for old filesystems */
24 static inline bool old_valid_dev(dev_t dev
)
26 return MAJOR(dev
) < 256 && MINOR(dev
) < 256;
29 static inline u16
old_encode_dev(dev_t dev
)
31 return (MAJOR(dev
) << 8) | MINOR(dev
);
34 static inline dev_t
old_decode_dev(u16 val
)
36 return MKDEV((val
>> 8) & 255, val
& 255);
39 static inline u32
new_encode_dev(dev_t dev
)
41 unsigned major
= MAJOR(dev
);
42 unsigned minor
= MINOR(dev
);
43 return (minor
& 0xff) | (major
<< 8) | ((minor
& ~0xff) << 12);
46 static inline dev_t
new_decode_dev(u32 dev
)
48 unsigned major
= (dev
& 0xfff00) >> 8;
49 unsigned minor
= (dev
& 0xff) | ((dev
>> 12) & 0xfff00);
50 return MKDEV(major
, minor
);
53 static inline u64
huge_encode_dev(dev_t dev
)
55 return new_encode_dev(dev
);
58 static inline dev_t
huge_decode_dev(u64 dev
)
60 return new_decode_dev(dev
);
63 static inline int sysv_valid_dev(dev_t dev
)
65 return MAJOR(dev
) < (1<<14) && MINOR(dev
) < (1<<18);
68 static inline u32
sysv_encode_dev(dev_t dev
)
70 return MINOR(dev
) | (MAJOR(dev
) << 18);
73 static inline unsigned sysv_major(u32 dev
)
75 return (dev
>> 18) & 0x3fff;
78 static inline unsigned sysv_minor(u32 dev
)