views:

52

answers:

3

I have multiple processes in my linux environment that have to use the same device driver to access a number of similar devices. My problem is that if one process instantaiates a device(by instantiate, I mean mknod ) file, and uses a minor number say 0 and 1 for two devices. So how does the other process while doing the same thing come to know that which minor number to use?

In short, in application space is it possible to find the number of device files that use the same driver?

+2  A: 

My problem is that if one process instantaiates a device(by instantiate, I mean mknod ) file

In *NIX world devices generally assigned major/minor numbers statically and inside of kernel. Statically in a sense that most devices now under Linux have dynamic major/minors and are accessed via devices nodes under /dev (or /proc or /sys).

IOW, user space application cannot do it, because to communicate with the driver (or device) it has to know how the major/minor to already be able to access the driver.

Details would be many, better read on the 3rd chapter of LDD where discussion about major/minor assignment are discussed.

Automatic creation of devices under /dev/ now generally handled by udev which I'm not very familiar with.

Dummy00001
Yeah, device numbers are now assigned automatically, your driver can have as many as it wants, it has them assigned when it detects that the hardware becomes physically available (i.e. in response to hotplug events, or at initialisation)
MarkR
A: 

Assuming that you are referring to a driver that you are creating or at least have the source to, try using minor numbers in numerical order (for simplicity) starting with zero. Have your driver keep track of how many minor numbers/devices have been instantiated and expose that count via an entry in sysfs. When you go to instantiate a new device, use the current value of the variable for the new device's minor number and increment the variable (inside the driver).

bta
A: 

The minor numbers being used by the devices registered by your driver should be visible to applications in the /sys pseudo-filesystem. The dev file, located in the /sys/class/... directory/directories associated with your device, contains the major:minor.

Likely, your driver is using /sys/class/misc/.../.

caf