LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-30-2004, 07:52 AM   #1
appas
Member
 
Registered: Jul 2004
Posts: 72

Rep: Reputation: 15
how to create device node for dynamically allocated major number


Hi all,
I am writing a char driver for which the major number is not statically assigned.
i pass zero as argument for 'register_chrdev' so that major number is dynamically generated.
But now I do not know how to create the device node since i the major number is not known.
Could someone help me how to get the major number to create device node.
I did not find any information in /proc/devices after loading the driver.
 
Old 09-30-2004, 09:12 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
I know next-to-nothing about kernel-programming, but I doubt it's actually possible to have dynamic major devie numbers.

AFAIK the new devfs is made to overcome this limitation, but I assume it does not have anything to do with major number etc. like with the "old" device-driver system.

Or am I wrong about this?
 
Old 10-01-2004, 03:53 AM   #3
appas
Member
 
Registered: Jul 2004
Posts: 72

Original Poster
Rep: Reputation: 15
Hi Hko,
It is certainly possible to dynamically allocate a major number while registering the driver. This can be done by passing zero as the argument for 'register_chr_dev' function which was confirmed in my driver by printing the return value of 'register_chr_dev'.
I do not know anything about devfs and i will look into that.
 
Old 10-01-2004, 04:15 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Quote:
Originally posted by appas
It is certainly possible to dynamically allocate a major number while registering the driver. This can be done by passing zero as the argument for 'register_chr_dev' function which was confirmed in my driver by printing the return value of 'register_chr_dev'.
OK. Learned something new here. Thanks.
I didn't know, and I didn't expect it, because how would you know which major number to use for the /dev node? Which is exactly your question...
 
Old 10-01-2004, 09:09 AM   #5
appas
Member
 
Registered: Jul 2004
Posts: 72

Original Poster
Rep: Reputation: 15
Hi all,
First of all, sorry for the misleading statement i used in the thread starting
Quote:
" I did not find any information in /proc/devices after loading the driver."
After loading the module, /proc/devices contains information about the major number and device.
Now i can get the major number for the device and then execute "mknod" to create the device.
 
Old 11-01-2004, 09:37 AM   #6
kadissie
LQ Newbie
 
Registered: Jul 2003
Location: UK
Distribution: Fedora 5, Knoppix, Ubuntu
Posts: 27

Rep: Reputation: 15
According to the Linux LKM programming guide you should use the mknod system call. Try "man 2 mknod" for more info.

Don't forget to delete the file when you cleanup!

R.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
In C, using qsort for dynamically allocated array ntmsz Programming 7 08-23-2005 10:33 AM
Major number for device driver... Elric of Grans Programming 2 07-12-2005 04:06 PM
Need help: Seg fault, Memcpy, and dynamically allocated arrays benobi Programming 3 06-09-2005 10:58 PM
I can`t create a device node in /dev gcasados Slackware 8 02-21-2005 05:17 AM
udev does not create scsi device node maenho Linux - Software 0 11-27-2004 05:08 AM


All times are GMT -5. The time now is 01:17 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration