From mboxrd@z Thu Jan 1 00:00:00 1970 From: bjorn@mork.no (=?utf-8?Q?Bj=C3=B8rn_Mork?=) Date: Sun, 10 Jul 2016 18:02:23 +0200 Subject: Proper way to get device file minor number from struct file In-Reply-To: (Matwey V. Kornilov's message of "Sun, 10 Jul 2016 18:22:25 +0300") References: Message-ID: <877fcta3cg.fsf@miraculix.mork.no> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org "Matwey V. Kornilov" writes: > Hello, > > I am looking through some legacy out of tree custom linux kernel device > driver. > > It is full of lines like the following: > > iminor(fp->f_dentry->d_inode) > > here struct file *fp is an argument of callback of struct file_operations. > > Documentation/filesystems/porting says: > > "f_dentry is gone; use f_path.dentry, or, better yet, see if you can > avoid it entirely" > > So, is there a proper compatible way to do the same? Don't know how proper it is, but a "git grep iminor drivers/" shows that minor = iminor(file_inode(file)); is a very common construct. Or alternatively, do the iminor(inode) lookup once in open() to lookup up your device struct or whatever, and then save that reference in file->private_data, thereby avoiding the need to know the minor anywhere else. Bj?rn