Take a look at the struct file definition from this code of Linux kernel version 2.6.18.
I'm trying to compare two struct file variables in my code and determine if they're referring to the same file. Is there any unique identifier in that structure that would help me make this comparison? Or are there any helper functions available?
Joachim is on the right track, but besides the inode number, one would have to compare its device since each filesystem would likely have an inode 1, inode 2, ...:
if (f1->f_dentry.d_inode == f2->f_dentry.d_inode &&
!strcmp (f1->f_vfsmnt->mnt_devname, f2->f_vfsmnt->mnt_devname))
// it is the exact same file
I thought there was a major/minor device i.d., but I have not been able to find it. So comparing the device name (/dev/dsk/hda1) is deterministic, if not as quick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With