Is it possible to determine the open file path based on the file descriptor?
Mateusz Guzik
mjguzik at gmail.com
Wed Jul 8 16:44:55 UTC 2020
On 7/8/20, Yuri <yuri at rawbw.com> wrote:
> Hi Hackers,
>
>
> One of the ports (sysutils/watchman) attempts to find the path of the
> file based on the file descriptor assuming that this descriptor
> represents an open file.
>
>
> Is this possible?
>
>
Yes and no. procstat -f can report that, but not always. The crux is
that the namecache is optional -- no name may be present and then we
don't have good means to find it. There is a side corner case where
you can have *more* than one name and then the kernel has no idea
which was used to reach the file for given fd.
I think the namecache should start getting new names in all cases and
that's perhaps something to change for 13.
Even for the working case the interface used by procstat is a bad pick.
That said, I can add a fcntl which will translate the fd into a full
path if the name can be found, but I don't know how useful it can be
with this program given the stipulation above.
--
Mateusz Guzik <mjguzik gmail.com>
More information about the freebsd-hackers
mailing list