in reply to locate path to a file from inode number

You seem to assume the mapping between filenames and i-node numbers is a 1-1 mapping. It isn't. While each filename has one i-node number, more than one filename can have the same i-node number - this is called "links". If you do
ln old new
you create a new filename new, but it will have the same i-node number as old. Furthermore, it's also possible that you have a file (and hence an i-node number), without a file name. That happens for instance in the following code:
my $file = "/tmp/whatever"; open my $fh => "> $file" or die; unlink $file or die;
The file still exists (and you can write to it), it uses an i-node, but there's no directory with an entry, and hence there's no file name for it.

Abigail

Replies are listed 'Best First'.
Re^2: locate path to a file from inode number
by Aristotle (Chancellor) on Nov 09, 2002 at 20:29 UTC
    One of those questions that I've always wondered about but never been bothered enough to research: is there a way to create a new link to such a file that exists in the inode table but has no other links, using only the inode number? Not that I can supply any practical use - I guess I'm just curious for purposes of orthogonality.

    Makeshifts last the longest.

      This is what fsck does - it'll link unreferenced inodes to lost+found.

      Abigail

        I am aware of that. What I was wondering is whether there is a system call or something of the like available to a regular program, so that one could create a link to a file given merely an open handle to it. In other words, is there any way to re-link a temporary file that has no links before it vanishes?

        Makeshifts last the longest.