I would THANK if you answer my doubts in DETAILS please.
Here's a sample code to create a device:
if(scull_major) {
dev=MKDEV(scull_major, scull_minor);
result=register_chrdev_region(dev, scull_nr_devs, "scull");
} else{
result=alloc_chrdev_region(&dev, scull_minor, scull_nr_devs, "scull");
scull_major=MAJOR(dev);
}
if(result < 0)
{
printk(KERN_WARNING "scull:can't get major %d\n", scull_major);
return result;
}
-
I didn't understand the first line! In the second and third lines, a device is created using the given minor and major numbers (I am sure this is a static allocation) and register_chrdev creates multiple instances of it.
what about the first line? I can't understand what that if(major number) doing there, what's so relevant to it? -
if the major number is not created it goes to while n creates a dynamic major number. Major number means the driver ID to which the device associates with, OK? but so far, how would the kernel know about which driver it shall connect it? it just allocates one dynamically!
!!! what's so relevant between major number and device numbers in 3? major number is the driver number the device associates with and it's not the device number (that's minor number). So, why 3 notes that?
- Why do we need a seperate script to read /proc/devices file?