Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Jul 2004 11:31:14 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Tyler Durdan <ewemasq@yahoo.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: mmap()ed filenames?
Message-ID:  <20040714103114.GC71531@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <20040714085040.12143.qmail@web52204.mail.yahoo.com>
References:  <20040714085040.12143.qmail@web52204.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--eRtJSFbw+EEWtPj3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jul 14, 2004 at 01:50:40AM -0700, Tyler Durdan wrote:
> Is there a way to get the filename of an mmap()ed file
> in the current process? For example, in Linux I can
> open /proc/self/maps and get the filenames right
> there. However, if I try to open /proc/getpid()/map on
> FBSD, the only mapping info is "vnode" or "default" on
> FBSD 4.10-BETA.         =20
>                                                      =20
>                         =20
> Is there any way to convert this info into the
> filenames of mapped files?      =20
>                                                      =20
>                         =20
> Or perhaps an alternate method to accomplish this
> goal?                        =20

That's a generally hard problem -- given some sort of open file, find
the file name it was opened as.  Most unixoid OSes don't record
filenames used on open(2) to go with file descriptors or areas of
mmapped data because it's a waste of space.  And there's no reliable
way to work backwards from the open file to a file name.

The problem is the filename comes out of the directory structure: it's
not kept with the file contents.  And any particular file my have
links from any number of directories under as many different names
(none of which is /the/ name of the file: hard links are all equal
precedence).  It can even have *no* filename at all -- if you (for
example) open the file in one process, and then delete it from
another, the first process will be able to read and write to the file
completely normally, although closing and then re-opening the file
will be impossible.  Similarly for renaming an already open file.

You might think of extracting the inode number (easily done using
fstat(2)) and searching the whole partition for file paths matching
that inode number.  That is, if you like horribly inefficient code
vulnerable to all sorts of race conditions and other nastyness.

The best answer is to redesign your application so that if it needs to
know filenames, it saves the filenames it originally used to open
those files with.

	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--eRtJSFbw+EEWtPj3
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFA9QtyiD657aJF7eIRAo15AKCf6siHG2HMpTqEExwp7+WxgG8KVgCeOISI
suibipYa88HbqWSrHwuRWxk=
=uuuy
-----END PGP SIGNATURE-----

--eRtJSFbw+EEWtPj3--



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