views:

44

answers:

1

The minor number is used by the kernel to determine exactly which device is being referred to.

The above explanation is just two abstract, can someone illustrate?

+3  A: 

The major number identifies the device driver to use, the minor number indicates which device. If you have multiple partitions, for instance, each gets its own minor:

brw-rw---- 1 root disk 8, 0 Jun  3 20:48 /dev/sda
brw-rw---- 1 root disk 8, 1 Jun  3 20:48 /dev/sda1
brw-rw---- 1 root disk 8, 2 Jun  3 20:48 /dev/sda2

Minor 0 in this case is the raw drive, minor 1 is partition 1, minor 2 is partition 2, etc. Not all devices use 0 as a special case, however. The serial devices start their numbering at 0, where /dev/tty0 is just the first (virtual) terminal device on the system:

crw--w---- 1 root tty  4, 0 Jun  3 20:48 /dev/tty0
crw------- 1 root root 4, 1 Jun  3 20:50 /dev/tty1
crw------- 1 root root 4, 2 Jun  3 20:50 /dev/tty2
crw------- 1 root root 4, 3 Jun  3 20:50 /dev/tty3

In either event, when the device file is opened the kernel will use the major number to determine which module will handle the file and passes the minor to the open() method of the struct file_operations structure that was registered with register_chrdev().

Hudson
The book I'm reading says `firstminor should be the requested first minor number to use; it is usually 0` in the function `int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,unsigned int count, char *name);` , how can devices usually be 0 ?
httpinterpret
I've updated the answer to cover minor 0.
Hudson
Disks are usually not numbered with 0, but with other devices, there's a 0 at the first one: /dev/rfcomm0,/dev/fd0,/dev/lp0,...
Piskvor