___
From: kernelnewbies-boun...@kernelnewbies.org
[kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Sankar P
[sankar.curios...@gmail.com]
Sent: Tuesday, February 08, 2011 4:26 PM
To: Kernelnewbies@kernelnewbies.org
Subject: Doubt regarding Minor Numbers and alloc_chrdev_region
Hi,
I am going through LDD3 (scull0 section) and have a doubt regarding
minor numbers. I have the following code-snippet:
#define FIRST_MINOR_NUMBER 0
#define COUNT_OF_CONTIGOUS_DEVICES 1
/* Device that we will use */
dev_t helloworld_device;
/* Initialization Function for the kernel module */
static int helloworld_driver_init(void)
{
printk(KERN_INFO Hello World);
/* Allocate a dynamic device number for your driver. If you want to
hardcode a fixed major number for your
* driver, you should use different APIs 'register_chrdev_region',
'MKDEV'. But the following is better. */
if (!alloc_chrdev_region(helloworld_device, FIRST_MINOR_NUMBER,
COUNT_OF_CONTIGOUS_DEVICES, HelloWorldDriver)) {
printk(KERN_INFO Device Number successfully allocated.);
/* If you do a cat /proc/devices you should be able to find our
Driver registered. */
} else
printk(KERN_ALERT HelloWorldDriver could not get a Device
number);
return 0;
}
==
Now if I compile and insert the .ko file for this module, the driver
gets registered with a major number of 250 (seen from /proc/devices).
However, I don't understand the significance of the FIRST_MINOR_NUMBER
and the COUNT_OF_CONTIGOUS_DEVICES that we pass to the
alloc_chrdev_region function.
If I try to create a file using, 'mknod /dev/scull2 c 250 7' , the
character device file gets created with a minor number of 7.
I have set COUNT_OF_CONTIGOUS_DEVICES to 1. However, I am able to create
multiple files /dev/scull[1-10] using this driver and mknod.
So, what is the significance of these two variables (first minor number
and count of devices) that we pass to the alloc_chrdev_region api, if
they can be over-ridden on mknod time ? Or have I misunderstood
something ?
Any help will be appreciated. Thanks.
As far as i know ,
alloc_chardev_region () helps you register your character driver with the
kernel using particular major number and minor number .. Thats pretty much of
it.
It's your responsibility to create a matching char device file in the user
space .
When you perform any read / write operations on such a file then kernel first
identifies ..Do I have any registrations of such a driver with __these__ major
number and minor number.
and correspondingly the read / write routines of your driver gets called.
In your case the any IO operations done on scull2 will not be mapped to any
character driver in the kernel ..
You can try doing : cat /dev/scull2
Regards,
Smital Desai
--
Sankar P
http://psankar.blogspot.com
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
__
The contents of this e-mail and any attachment(s) may contain confidential or
privileged information for the intended recipient(s). Unintended recipients are
prohibited from taking action on the basis of information in this e-mail and
using or disseminating the information, and must notify the sender and delete
it from their system. LT Infotech will not accept responsibility or liability
for the accuracy or completeness of, or the presence of any virus or disabling
code in this e-mail
__
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies