EmbLogic's Blog

Regarding Char Device Registration

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.

3 Responses to Regarding Char Device Registration

  1. manjeet says:

    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..

  2. shivdeep says:

    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…

  3. gaurav says:

    A call to register_chrdev() actually registers 0-255 minor numbers for a given major no and sets up default cdev structure for each.

Leave a Reply to shivdeep Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>