You mean that you're given a filename like "foo.txt" and you want to find it in the filesystem to see that it's in a given path, example: /somepath/to/myfiles/foo.txt?
stat the file, get the
inode number of the file, call popen with
ls -i /somepath/to/myfiles/foo.txt
and check the
inode you get back. It has to match the
inode number you started with.
The other case is nasty - when you have no idea where the file is located.
The reason is that the one unique identifier for a file in a given filesystem is the
inode.
It can be duplicated in all of the other filesystems mounted on the machine.
So you could have several foo.txt files with the same
inode number.
You can try using ftw() or nftw(), or call find from a popen() call.
It is not efficient to use either of these from the root directory /, plus it is possible to find more than one matching filename/
inode.
The find syntax is:
Code:
find / -type f -name foo.txt -inode <inode number>
Edit: note that st_dev plus st_inode give a unique identifier for a file.
You have to call ftw(), as there is no way to identify an st_dev value for find to use.