LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Dynamic Allocation of Major Numbers (https://www.linuxquestions.org/questions/programming-9/dynamic-allocation-of-major-numbers-943251/)

utkarshrawat 05-04-2012 06:57 AM

Dynamic Allocation of Major Numbers
 
I have a question in driver when ever we do
Code:

register_chrdev (major, “name”,*fops)
when major = 0, it returns a dynamically
allocated major number

But the disadvantage is that we can’t create the device nodes because the major number assigned to
your module can’t be guaranteed to always be the same.
How can we retrieve major number from /proc/devices/ before doing mknod .i.e . I dont want to see mknod everytime ,how it can be done dynamically. I think some script file is required to write .

Nominal Animal 05-05-2012 03:18 AM

Quote:

Originally Posted by utkarshrawat (Post 4670230)
But the disadvantage is that we can’t create the device nodes because the major number assigned to your module can’t be guaranteed to always be the same.

You mean, you can't create a device node that persists between reboots. This is exactly why we use udev.

If you don't want to use udev, write an init script that retrieves the major and minor number of your device node by reading the /sys/devices/.../yourdevice/dev file (which I believe is provided by the device subsystem core; available immediately after the register_chrdev() call has completed), then creates or recreates the device node in /dev.


All times are GMT -5. The time now is 05:55 AM.