Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing two struct files (Linux kernel)

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?

like image 566
Casey Patton Avatar asked Dec 31 '25 00:12

Casey Patton


1 Answers

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.

like image 104
wallyk Avatar answered Jan 02 '26 14:01

wallyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!