how can I get filename from file descriptor?

Conor P. Cahill cpcahil at virtech.UUCP
Sun Aug 27 02:39:02 AEST 1989


In article <580 at ccssrv.UUCP>, perry at ccssrv.UUCP (Perry Hutchison) writes:
> In article <9353 at chinet.chi.il.us> les at chinet.chi.il.us
> (Leslie Mikesell) writes:
> 
> >What I had in mind was the magic involved in certain open()/close()
> >routines.  Suppose you are a cpio-like program that wants to handle
> >multiple volumes.  How can you do that if some other program (the
> >shell) has opened the device via redirection?  What if you want to
> >do a verify pass on a tape device where the only way to rewind is
> >to close() and open()?  What if you need to twiddle the handshake
> >lines on a tty device?  What if you want to send EOF to something
> >on the other end of a FIFO without losing the ability to send more
> >data later?  It's all magic and you need the name of the file for
> >the incantations.
> 
> For error-message purposes, as well as for Leslie's examples (which seem
> to involve special files and FIFO's, which are rarely renamed or removed)
> the name originally passed to open should suffice.  To allow for changes
> of cwd, the absolute pathname could be saved during open.
> 
> Granted that now and then the saved name may no longer be accurate, I
> still think that it would be more user-helpful than no info at all.


What about the overhead caused by such a thing.  On my "little" 386 I have
configured the kernel to allow for 400 file descriptors.  If we are going
to allow for storing the full path for every open file we have to have
room for 400 * 256 (PATH_MAX in limits.h) bytes.  I could loose 100K of 
space in the kernel just for a very little used utility that could be
programmed around.  What about larger systems with more users?

If there is some special operation that you need to perform related to 
a file whose file descriptor you have, maybe a less inefficient method
would be to add yet another f* system call (fchmod, fchown, fstat...).

I worked on a project that had the same problem in that login needed to 
perform some operations on the device special file and all it gets 
from getty is the file descriptor.  We had to add additional f* system 
calls.




-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+



More information about the Comp.unix.wizards mailing list