You do realize there can be more than one hard link for a given file, plus there may be multiple symlinks as well. When you call fopen ("/path/to/foo", "r"), foo can easily be a link. So you may not have the real path to start with.
So going "up" the file tree is not going to give you a perfect answer all the time.
I'm not giving you a hard time, it's just that working out whre a file is in all the filesystems on one box is a daunting task. find / -name <> -
inode <> is about as good as it gets, even if it is really slow.
In your example, if you're postive foldera or folderb or folderc are under /root then your task is:
get st_dev and st_ino for the file you do have
with popen(), "find /root -name afile -
inode st_ino", then stat all of the files returned.
check the st_dev values, when you have a match you have the file.