[My Klogs] Identifying devices by minor number when a char device is registered to the same file operations

Recently, while I was writing a dummy character devices, one of my friends asked me this question “If I register a character device to the same major number, is it possible for me to identify the major number and minor of the node during file_operations”. After researching a bit, I saw a solution to it.  I could do it using the dentry structure in struct file. For reference I will paste the code here :

struct dentry * dentry = f->f_path.dentry;
struct inode * p_inode = dentry->d_inode;
minor_number = iminor(p_inode);

PS : Please suggest me alternate or better ways and point out any errors if there

About these ads

2 thoughts on “[My Klogs] Identifying devices by minor number when a char device is registered to the same file operations

  1. when I maintained a driver some years ago, it had this snippet:
    int mvcIoctl(struct inode *inode, struct file *ioctlFile,
    unsigned int ioctl, unsigned long ioctlArgs)
    {
    // int cardNum = iminor(inode); // with automatic device number assignment we cant rely on this
    MvcCard *card = ioctlFile->private_data;

    and private_data was initialized in the open function to
    container_of(inode->i_cdev, MvcCard, cdev);

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s