[SOLVED] How the driver differentiates multiple devices of exactly same type?
Linux - Embedded & Single-board computerThis forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How the driver differentiates multiple devices of exactly same type?
Hi,
When multiple devices of exactly same type is attached to the system and is available in the same time in the system, how does the driver differentiates between the devices while processing the system calls?
Does each devices of same type should have different minor numbers and separate device files for each?
When multiple devices of exactly same type is attached to the system and is available in the same time in the system, how does the driver differentiates between the devices while processing the system calls?
Does each devices of same type should have different minor numbers and separate device files for each?
Yes.
The major number stands for the driver, in other words the device type. The minor number encodes both the device's identity and sometimes also device capabilities such as rewind-after-close for a tape device.
Also do the each entity of same type of device have different device files?
Also is there any mechanism to handle if the minor number overflows to the next major number in case that much number of devices of same type added to the system in the same time? Is there any cases of this situation happening in real world?
Also do the each entity of same type of device have different device files?
Also is there any mechanism to handle if the minor number overflows to the next major number in case that much number of devices of same type added to the system in the same time? Is there any cases of this situation happening in real world?
Please reply!
Whenever there are multiple minor numbers, there are multiple devices.
If you look at the device tables (cat /proc/devices), it will show the major numbers assigned by default. The minor numbers get assigned as individual units of the same type are identified by their driver. This is why /dev/sdb on one boot, may not be the same on the next (it might be /dev/sdc...). This is due to timing issues - two identical disks may spin up at slightly different times. And two devices that happen to be VERY close... can alternate. This result is why it is better to use either UUID mounts (or LABEL=...) in /etc/fstab. The udev process will create these as the kernel notifies it of a new device being created (such as a USB device being plugged in).
If you look in /sys/bus/scsi you will see the PCI device identification for both the controllers, AND how the individual units are attached (the symbolic links are what provides the shorter names)
The /dev entries are created by udev... and provide some simplicity in access, but they are only valid for a single boot - and things can change with the next boot. You can't depend on the names very well - they CAN be controlled by udev rules that direct how to identify a particular device, and give it a particular name.
Explore the /dev filesystem. It can be very interesting - then look at the /sys filesystem where these names are defined.
And no, I don't know all the cross connections that tie from the given device name to the controller - that information is in the /sys filesystem that provides an interface into the kernel tables. You should be able to trace it through the /sys/(block, bus, class, dev, devices) directories.
Whenever there are multiple minor numbers, there are multiple devices.
Not quite - you can have different minor numbers for the same physical device, each minor number standing for a different capability of that device. The example I mentioned is tape drives - the same tape drive can have a rewinding and non-rewinding device file with different minor numbers.
Quote:
Also do the each entity of same type of device have different device files?
If the device is discovered by the system, yes. The device file is usually created by a system component named udev, or, if the devtmpfs filesystem type is used, directly by the kernel.
Not quite - you can have different minor numbers for the same physical device, each minor number standing for a different capability of that device. The example I mentioned is tape drives - the same tape drive can have a rewinding and non-rewinding device file with different minor numbers.
True.. each one gets a /dev entry, which is what I should have said. To the user, these are presented as different devices, it is the driver that combines them.
Quote:
If the device is discovered by the system, yes. The device file is usually created by a system component named udev, or, if the devtmpfs filesystem type is used, directly by the kernel.
Devices not discovered by the system don't exist. Even if you load the driver, they don't exist. It is my understanding that the controller sends a notification (picked up by udev), then udev directs how the kernel is to interpret the new device, to the point of even loading drivers to handle it. If there is no driver identified by udev, the only presence the unit has is what the controller may have from the original event. As far as the system goes, it still doesn't exist.
Some controllers don't send a notification - my SATA controllers don't, I have to manually initiate
a SCSI rescan (of the right adapter) for it to get a hot plugged disk recognized (or removed for that matter). But udev still gets the message to finish setting up the disk for use.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.