Can someone illustrate what's linux device number's minor number exactly for?
The minor number is used by the kernel to determine exactly which device is being referred to.
The above explanation is just开发者_StackOverflow社区 two abstract, can someone illustrate?
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()
.
as in the language C ,counting starts from 0 ...it could be a sort of convention followed by driver writers ...after all everything in Linux is based upon C or to some extent C++.Its just a numbering scheme ..You can also start naming your devices from any number between 0 and 255,but please be carefull do not cross the 255 mark for minor numbers else you may overwrite the next available major number..hope this answer helps
精彩评论