[Linux driver]How to have multiple file_operations in a character driver


In the Init function of the character driver , follow the following steps

Register a character driver with the file_operations structure with only open function defined . This is the selector for real open .

Now  create class for the module , using  class_create

Now create devices under this class , using device_create . Each devices will be having separate minor and name

In the real open function ,

Depending on the minor , which can be determined by iminor function where argument to the function is inode which is passed to the function when application calls open ,  Assign file_operations structure for different devices to  filp->f_op, where filp (data type  – struct file *)  is the second argument passed in to the open function .

 

 

 

 

 

 

 

 

 

 

 

Published by RNP

A person who likes learning new languages.

Leave a comment