Reputation: 2753
I do have some clarifications with regard to the concept of major and minor device numbers. I understand the following concepts.
dev_t
type.register_chrdev_region
The question I have is where in exactly these numbers are used. As of I checked, It lead me to the following answer
The kernel uses this number to identify the driver associated with the device
Can anyone help me with this.
Upvotes: 1
Views: 13780
Reputation: 19
brw-rw---- 1 root disk 3, 1 Jul 5 2000 /dev/hda1
brw-rw---- 1 root disk 3, 2 Jul 5 2000 /dev/hda2
brw-rw---- 1 root disk 3, 3 Jul 5 2000 /dev/hda3
Notice the column of numbers separated by a comma. The first number is called the device’s major number.The second number is the minor number.
The major number tells you which driver is used to access the hardware. Each driver is assigned a unique major number; all device files with the same major number are controlled by the same driver. All the above major numbers are 3, because they’re all controlled by the same driver.
The minor number is used by the driver to distinguish between the various hardware it controls. Returning to the example above, although all three devices are handled by the same driver they have unique minor numbers because the driver sees them as being different pieces of hardware.
$ ls -l /dev/sda /dev/sdb
brw-rw---- 1 root disk 8, 0 Jan 3 09:02 /dev/sda
brw-rw---- 1 root disk 8, 16 Jan 3 09:02 /dev/sdb
By now you can look at these two device files and know instantly that they are block devices and are handled by same driver (block major 8). Sometimes two device files with the same major but different minor number can actually represent the same piece of physical hardware. So just be aware that the word “hardware” in our discussion can mean something very abstract.
Upvotes: 1
Reputation: 11
In linux Communication between user space and kernel space happens through device files which located in /dev
directory
if user want to send data to hardware device, Simply it app will open the device file and write indented data
Now question is how device file will find appropriate driver ?
Here device number comes into picture, it is used to find associated driver device number is the combination of Major and Minor number
Major number used to identify device type, example i2c devices or spi device, Minor number used to identify particular driver.
https://linuxdeveloper.quora.com/What-is-Device-Number-in-Linux This article explains in detail.
Upvotes: 1
Reputation: 7852
The major number and minor number tell the kernel how to access the device.
A common major number is assigned to all devices that are being controlled by the same device driver. The minor number helps to distinguish between the exact device type/controller using the same device driver.
Upvotes: 1
Reputation: 9484
In simple terms,
Major Number tells which driver is used. This number is allotted while registering a device driver.
Minor Number tells which device exactly used of that device type.
Say Hard-disk may have four partitions. Each partition will have separate minor numbers where as only one major number. Because same Storage driver is used for all the partitions.
For more details, http://www.makelinux.net/ldd3/
Upvotes: 1
Reputation: 21460
Doing a ls -l /dev/*
will show something along the lines of
...
crw-rw---T+ 1 root audio 116, 33 sept. 21 09:19 timer
...
The 116, 33
are the major and the minor of this specific device.
Tha major sets the type of the device, usually the driver associated with it. The minor list the first, second, third, ... device of that type.
There's only one driver per major number and multiple minors are handled by it.
Of course, now it is possible to dynamically allocate those numbers.
Upvotes: 5