2011年12月8日 星期四

Linux driver的major number 與 minor number

根據維基百科http://en.wikipedia.org/wiki/Device_node


Generally, the major number identifies the device driver and the minor number identifies a particular device (possibly out of many) that the driver controls: in this case, the system may pass the minor number to a driver. However, in the presence of dynamic number allocation, this may not be the case (e.g. on FreeBSD 5 and up).


major#分辨driver;minor#分辨一個driver所控制的特定device。
看來是一個driver可以控很多device,所以是以driver:device的方式來分辨每一個不同的device的。
感覺是個不錯的設計!




再回頭看看ldd(第三版)第三章是怎麼寫的:



Traditionally, the major number identifies the driver associated with the device. For example, /dev/null and /dev/zero are both managed by driver 1, whereas virtual con- soles and serial terminals are managed by driver 4; similarly, both vcs1 and vcsa1 devices are managed by driver 7. Modern Linux kernels allow multiple drivers to share major numbers, but most devices that you will see are still organized on the one-major-one-driver principle.

The minor number is used by the kernel to determine exactly which device is being referred to. Depending on how your driver is written (as we will see below), you can either get a direct pointer to your device from the kernel, or you can use the minor number yourself as an index into a local array of devices. Either way, the kernel itself knows almost nothing about minor numbers beyond the fact that they refer to devices implemented by your driver.

嗯,還是看的霧煞煞XDDDDDD

沒有留言:

張貼留言