Home | Projects | Notes > Linux Device Drivers > Character Driver

Character Driver

 

Character Driver (char driver)

 

Character Driver File Operations

Creation of a Device File

  1. Create device file using udev (init_special_inode() gets called)

    rdev - Device number

    mode - Device type (e.g., char device, block device, etc.)

  2. inode object gets created in memory and inode->i_rdev field is initialized with the device number

  3. inode->i_fop field is set to dummy default file operations (i.e., def_chr_fops)

 

When a User Process Executes open() System Call

  1. User invokes open() system call on the device file

  2. file object gets created (VFS opens a file by creating a new file object and linking it to the corresponding inode object.)

  3. inode's i_fop gets copied to file object's f_op (dummy default file operations of char device file def_chr_fops)

  4. Open function of dummy default file operations gets called (chrdev_open)

  5. inode->i_cdev field is initialized to cdev that you added during cdev_add (lookup happens using inode->i_rdev field)

  6. inode->cdev->fops (this is a actual file operations of the driver) gets copied to file->f_op

  7. file->f_op->open method gets called (actual open method of the driver)

open() System Call Behind the Scenes

 

open-system-call-behind-the-scenes-1

 

 

open-system-call-behind-the-scenes-2

 

 

inode Object & file Object