[X-Unix] Can you get the path from an inode?

Wing Wong wingedpower at gmail.com
Mon May 1 10:24:02 PDT 2006


On 4/29/06, Eugene <list-themacintoshguy at fsck.net> wrote:

> Blah, anyone can do a brute-force search.  But I wonder if there
> is a simple function call where you input an inode and a device,
> and get a path.
> Eugene
> http://www.coxar.pwp.blueyonder.co.uk/

[mild humour]

Well, you _could_ create a device driver or hook that intercepts all
filesystem accesses and creates an alternate lookup table, per device,
which would allow you to do an inode->path/file lookup.

Then, once this was implemented, you could create a set of utilities
that perform the following functions:

- (re)sync inode tables (for pre-inode-db filesystems)
- reverse lookup
- inode table enable/disable
- lookup inode information
- perform function(chmod/chown/etc) against inode instead of path/file

Don't know whether this would count as "brute force" ^_- but one would
imagine that the brute force approach would be easier than writing in
the function into the system.

[/mild humour]

Seriously, though, unless you are performance tuning something or
performing recovery/maintenance on a filesystem, the need for reverse
inode lookup doesn't seem to be a pressing matter. (I'm sure it IS a
pressing matter to the individuals who need it at any particular
moment, though.)

If inode=>path/file is important, just crontab a nightly job that
updates a flatfile or a database with all of the inode=>path/file
entries. Write a bunch of wrapper scripts which will be able to
perform queries against the flatfile or db(perl/python/etc+db api) and
have it perform the tasks you need. I'm thinking in terms of the
locatedb/locate tool on some Unix(s). It's run nightly/whenever and
when you need to find a file, you do a "locate <filename>". Simple and
straightforward.

While it is a "brute force" approach, it is fairly straightforward.
The only issue would be the "per device" restriction. If you performed
a find against "/", you would get duplicate inodes if you have more
than one device mounted. Of course, you could just have your scripts
code around that. :) Note that duplicate inode numbers would rule out
a hash(ing) database.

Wing
--
Wing Wong
wingedpower at gmail.com


More information about the X-Unix mailing list