标记一下,容易忘,以免每次查代码。
./include/linux/types.h:21:typedef __u32 __kernel_dev_t;
./include/linux/types.h:24:typedef __kernel_dev_t dev_t;
所以 dev_t实际上就是个 无符号 32位 整形。
./include/linux/kdev_t.h:98:#define MKDEV(ma,mi) ((ma)<<8 | (mi))
./include/linux/kdev_t.h:96:#define MAJOR(dev) ((dev)>>8)
#define MINORBITS 20
#define MINORMASK ((1U << MINORBITS) - 1)
#define MAJOR(dev) ((unsigned int) ((dev) >> MINORBITS))
#define MINOR(dev) ((unsigned int) ((dev) & MINORMASK))
#define MKDEV(ma,mi) (((ma) << MINORBITS) | (mi))
从上面的宏中可以看出,major占高12位,minor占低20位