LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This 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


Reply
  Search this Thread
Old 07-05-2015, 04:17 AM   #1
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Rep: Reputation: Disabled
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?

Please reply!
 
Old 07-06-2015, 12:42 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ayyasprings View Post
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?
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.
 
Old 07-06-2015, 02:29 AM   #3
ayyasprings
Member
 
Registered: Aug 2014
Posts: 118

Original Poster
Rep: Reputation: Disabled
Hi berndbausch,

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!
 
Old 07-06-2015, 03:45 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by ayyasprings View Post
Hi berndbausch,

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.

You can also see some of the ramifications from the question at:
http://stackoverflow.com/questions/2...program-in-dev

BTW, from:
http://stackoverflow.com/questions/1...mbers-in-linux

Linux major device numbers are a 12 bit value, so 4096 different drivers... and the minor number is a 20 bit value....

Last edited by jpollard; 07-06-2015 at 03:49 AM.
 
Old 07-06-2015, 04:27 AM   #5
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by jpollard View Post
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.
 
Old 07-06-2015, 04:54 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by berndbausch View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Single USB driver, multiple devices, how many driver instances? jadonovan Linux - Embedded & Single-board computer 1 01-23-2010 08:08 PM
No devices of the appropriate type were found on the driver disk macarthor Red Hat 4 08-11-2006 02:32 PM
How th chack teh raid type and attached devices procfs Linux - Hardware 2 08-09-2006 10:44 PM
determine type of device for USB devices lyar1031 Linux - Newbie 2 07-29-2004 08:02 PM
LinuxInsider.com: What Differentiates Linux from Windows? thegeekster General 1 03-13-2004 07:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration