Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Apr 1998 01:46:03 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        stesin@gu.net
Cc:        tlambert@primenet.com, scrappy@hub.org, freebsd-hackers@FreeBSD.ORG
Subject:   Re: filename from open file descriptor...
Message-ID:  <199804140146.SAA04924@usr06.primenet.com>
In-Reply-To: <Pine.BSF.3.96.980413122102.12267v-100000@beast.gu.net> from "Andrew Stesin" at Apr 13, 98 12:22:58 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> > > 	I'm trying to debug some code, and have an open file descriptor
> > > that I want to find the file name that its associated with...
> > > 
> > > 	is this possible?  my first thought was fstat(), but that appears
> > > to return everything but the name :(
> > 
> > You remember the name when you open the file.
> 
> 	How about rename()-ing the already opened file "on the fly"?
> 	(Want to note that correct discovery of filename from the filedescriptor
> 	seems to be theoretically impossible?)

Not possible.

You would have to search the entrire FS for the file, one directory
at a time.

If the file had a hard link, you could not know which of several
valid directory entries was being renamed.

You could add a VOP to the FS to allow you to link an already open
file somewhere, but you would not be able to delete the previous name
unless you changed the on disk structures and the in memory references
for how hard links are managed (I've done this before, as an experiment;
if you have a reference object that isn't the file itself, then you
can always store the parent directory id in the reference object inode,
and thus know the path used to open the file).


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199804140146.SAA04924>