how can I get filename from file descriptor?

Guy Harris guy at auspex.auspex.com
Sat Aug 26 04:02:12 AEST 1989


>This being the case maybe to solve the real problem is to provide one
>kernel-level mapping:
>
>char *
>Name(f)
>FILE *f;  /* Or fd... */

If it's kernel-level, it had better *not* be "FILE *", since I know of
nobody who stuffed the standard I/O library code into the kernel
(fortunately).

>Which would yield the name of any file (be it a pipe, stdin, stdout,
>stderr, file, a psudo tty or any gawd-awful thingy that exists...
>Each would have to be special cased except for the open files which
>are actual disk files (posses actual file names...).

Uhh, pseudo-ttys *do* possess actual file names (can you say "character
special file"?).

And, if done right, neither the standard input, output, nor error would
need to be special-cased, since of *course* you'd attach this name to
the file table entry, and thus it would be inherited by child processes,
right?

Of course, if it just saved the file name away, it would give you the
wrong answer if the file were unlinked or renamed after it was opened,
unless the system took pains to track down saved file names and update
them on a rename or blow them away on an unlink - the rename, of course,
including any rename of any directories above the file, and both
operations including any renames done on machines other than the one on
which you're running (if you have a distributed file system such as NFS
or RFS).

In addition, of course, you'd have to keep the current working directory
around as well, if you want the mapping operation to give you an
absolute pathname; if you want the name to be inherited by child
processes and be useful, you'd have to either do that or have
per-process names that are updated whenever a process does a "chdir". 
Said copy of the current working directory would *also* have to be kept
up-to-date after renames and unlinks, assuming you want the value always
to be correct....

It's not clear that all this would be worth the cost.



More information about the Comp.unix.wizards mailing list