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
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);
[...] Originally Posted on Sysbyte Technologies. [...]