Linux kernel header file Kdev_t.h macro definition parsing

Source: Internet
Author: User
Tags sprintf

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;                                                         })










Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.