When we used : register_chrdev(unsigned int major, const char *name,
struct file_operations *fops);
We never initialized struct cdev. Still we were very much able to call all the functions mapped in the file_operatins structure using fop.
Why we have to initialize it in the case of alloc_chardev_region
or register_chardev_region ???? Will these function not work ,if we dont initialize cdev in this case.
Why struct cdev is so nessary.
u askd a gd questn…i think d reason behind this is ,whnevr we have to implement scull,we need various kind of operations (read,write,lseek etc)..and to make a pointer to such structure,struct file_operations (which keeps all such function pointers)…we must initialize cdev…so dat we cn access all those functions….to implement scull..
register_chrdev() function internally automatically initialises cdev…ie it adds pointer oof file operations to the cdev structure element ops, but when we are using scull, cdev is not a global structure but it is taken as an element of scull_dev structure, so as to include attrbutes of device in the scull structure itself. In this case we have to manually initialise cdev object, which is inside scull, using register_chrdev_region…
A call to register_chrdev() actually registers 0-255 minor numbers for a given major no and sets up default cdev structure for each.