KDEV_T.H macro Definition Parsing
This header file is not much anyway, the direct reason is--met, just fix it!
A variable of type dev_t is defined in Linux/types.h to hold the device number-including the main device number and the secondary device number. Dev_t is a 32-bit number, where 12 bits are used to represent the device number, and the remaining 20 bits are used to represent the secondary device number.
Always do not make assumptions about whether the 32-bit high 12-bit is the main device number or the low 2-bit is the main device number, which is not conducive to the portability of the code, always remember to use the macro definition to handle dev_t!
It's all here:
#define MINORBITS 20//Secondary device number placeholder # Minormask ((1U << minorbits)-1)//low 20-bit mask equivalent to 0xfffff#define MAJOR (Dev) (( unsigned int) ((dev) >> minorbits)//Get Master device number # define MINOR (Dev) (( Dev) & Minormask) //Get second device number # define MKDEV (Ma,mi) ((MA) << minorbits) | (MI)) Re-"synthesize" the primary, secondary device number to a number that returns the # define print_dev_t (buffer, dev) sprintf ((buffer), "%u:%u\n", MAJOR (Dev), MINOR (Dev)) //Print primary and secondary device number # define format_dev_t (buffer, dev) ({ \//To write the primary, secondary device number to the memory pointed to in buffer sprintf (buffer, "%u:%u", MAJOR (Dev), MINOR (Dev)); buffer; })