file descriptors --> filenames

gwyn%brl-vld at sri-unix.UUCP gwyn%brl-vld at sri-unix.UUCP
Tue Feb 21 12:29:06 AEST 1984


From:      Doug Gwyn (VLD/VMB) <gwyn at brl-vld>

There is no practical way to obtain the "file" name (really, the link
name) of a file from its file descriptor.  The kernel does not keep
this information after opening the file.  It is in fact possible for
the link under which the file was opened to have gone away although the
data may remain (under some new name), by the time you inspect the file
descriptor.  This "feature" is a consequence of the more general idea
of file names ("links") that UNIX uses.

Although all the file (inode) information of real value is in the stat
return structure, it is true that on most UNIXes one cannot change this
information (permissions, etc.) without using some link name to access
the file.  4.2BSD supplies some new system calls (fchmod, etc.) to let
one change inode information via the file descriptor alone.  Although
I think a more general interface might have been a better way to go, I
am glad to see the new system calls IF they work their way into the AT&T
distribution.  However, I would recommend that you not rely on them for
the time being, which is to say, you may well need to pass the file name
to the module that needs to change file permissions.  The name must
exist somewhere in the system you are converting.



More information about the Comp.unix mailing list