Is it possible to determine the open file path based on the file descriptor?

Mateusz Guzik mjguzik at gmail.com
Fri Jul 10 07:22:40 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.
>

I had a look at the program at hand. It seems to predominantly use
F_GETPATH for de facto realpath, it looks like this:

  auto handle = openFileHandle(path, options);
  return handle.getOpenedPath();

That said, for this program on FreeBSD, the right thing to do is to
convert it to actual realpath(3). In head this will be performant just
fine as it is implemented as a syscall. I can MFC it for stable/12.

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the freebsd-hackers mailing list