The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



Thread: absolute path
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 06-05-2007
jim mcnamara jim mcnamara is offline
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,373
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.
Reply With Quote