What are major and minor numbers?
Short answer: Every device node has a device number (dev_t) made of a major number, which identifies the driver, and a minor number, which the driver uses to identify the device instance. ls -l /dev/ttyS0 shows 4, 64 (major 4, minor 64). Use MAJOR(), MINOR() and MKDEV() to work with them, and allocate numbers dynamically with alloc_chrdev_region rather than hard-coding a major.
Details
dev_tis 32 bits: 12 bits major and 20 bits minor.- Character and block devices have separate number spaces;
/proc/deviceslists registered majors. - The
/devnode is just a pointer (type + major + minor);mknod /dev/x c 240 0creates one manually, but devtmpfs and udev normally create them automatically whendevice_create()is called. - In
open(), a driver can find the instance withiminor(inode)or, better,container_of(inode->i_cdev, struct mydev, cdev). - Well-known fixed majors exist (1 = mem, 4 = tty, 8 = SCSI disks), documented in
Documentation/admin-guide/devices.txt; new drivers should not take fixed ones. - Misc devices all share major 10 with different minors.