Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!gem.mps.ohio-state.edu!ginosko!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.wizards Subject: Re: how can I get filename from file descriptor? Keywords: Name of file given the FILE * or fd. Message-ID: <2385@auspex.auspex.com> Date: 25 Aug 89 18:02:12 GMT References: <20613@adm.BRL.MIL> <1019@virtech.UUCP> <20482@sequent.UUCP> <19208@mimsy.UUCP> <20644@sequent.UUCP> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 43 >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.