(chapter 3)
The internal representation of Device number
type: dev_t (define in <linux/types.h>)
dev_t: 32bit total whit 12 bit for major number, 20 bit for minor number.
some macros define in <linux/kdev_t.h>:
MAJOR(dev_t dev);
MINOR(dev_t dev);
// return major/minor number of a devt.
MKDEV(int major, int minor); // This funtion turn major num and minor num into dev_t.
Allocating and freeing device number
To obtain one or more device number
int register_chrdev_region(dev_t first, unsigned int count, char *name);
//declared in <linux/fs.h>
allocate device number from first to first+count-1
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,
unsigned int count, char *name);
void unregister_chrdev_region(dev_t first, unsigned int count);
Dynomic allocation of major number
Some major device numbers are statically assigned to the most common devices.
A list of those device can be found in Documentation/devices.txt