If i know the inode reference i.e.

struct inode *inode;

and struct dentry structure will be containing path information for a particular dentry in d_iname variable.

How can I map from &inode->i_dentry to know the path of corresponding inode? also How to map from struct inode to struct dentry?

2 Answers 2


In the general case, you can't. There isn't a one-to-one correspondence between inodes and directory entries:

$ touch file1.txt
$ ln file1.txt file2.txt
$ ls -li file*.txt
1332145968 -rw-r--r-- 2 mark mark 0 Oct 17 17:02 file1.txt
1332145968 -rw-r--r-- 2 mark mark 0 Oct 17 17:02 file2.txt

Which path is the "real" one for inode 1332145968?

$ rm file2.txt 
$ tail -f file1.txt &
[1] 7781
$ rm file1.txt

What about now? Inode 1332145968 is still in use, as you can see using lsof, but it has no path.


Path you can trace using d_parent field from d_entry and saving the names. This will take you till the root of the file system. But be careful in case the inode object belongs to mounted file system, in such case the trace back will stop at mount point.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .