|Just another Perl shrine|
Re: locate path to a file from inode numberby Daruma (Curate)
|on Nov 08, 2002 at 17:00 UTC||Need Help??|
I have run accross this issue in the past and solved it by writing Bourne, Korn and BASH shell scripts to find all paths to a single inode.
In Unix/Linux operating systems, a hard link is basically another path pointing to the same inode. Unfortunately, there's no quick and easy solution for finding all the places (paths) that point to that same inode. Here's the basics of how I've done this in the past.
Note that this is searching from the root, and can take quite a while. Not necessarily the most desirable of solutions, but it's worked in the past.
One of our applications makes very heavy use of hard links. Often our clients do not understand hard linking and might move things around or inadvertently break links. I've taken this very shell script idea and used it to help me reconcile the links and report on those that are misplaced, broken or completely missing.
Are you looking for a perl solution to your problem? If so, I've not yet developed something to trace down inodes. I would certainly like to give it a try, however. If you are looking for a basic shell utility, it's not hard to write one up.
I note that you mention the utility you saw previously did not use ls -i filename. However, many utilities on Unix systems are collections of the basic shell functions of the system, like ls and find. You might find that down in the workings of this utility, it is making use of good old Unix standard utilites.
Alternatively, it could be that this utility, if written in something like C, made use of the underlying C functions behind ls and find.
With a perl solution, it might be hard to get away from the heavy IO you are experiencing in File::Find. I do think it is worth a shot.