Creating a device node
The creation of a device node makes it visible to users and allows users to interact with the underlying device. Linux requires intermediate steps before the device node is created and the following section discusses these steps.
Device identification
To precisely identify devices, their identifiers must be unique. Although identifiers can be dynamically allocated, most drivers still use static identifiers for compatibility reasons. Whatever the allocation method, the Linux kernel stores file device numbers in elements of dev_t
type, which is a 32-bit unsigned integer in which the major is represented by the first 12
bits, and the minor is coded on the 20
remaining bits.
All of this is stated in include/linux/kdev_t.h
, which contains several macros, including those that, given a dev_t
type variable, can return either a minor or a major number:
#define MINORBITS 20 #define MINORMASK ((1U << MINORBITS...