Date: Wed, 8 Jul 2020 18:44:52 +0200 From: Mateusz Guzik <mjguzik@gmail.com> To: Yuri <yuri@rawbw.com> Cc: Freebsd hackers list <freebsd-hackers@freebsd.org> Subject: Re: Is it possible to determine the open file path based on the file descriptor? Message-ID: <CAGudoHEjFvt4nijEUj0FwN0CTYmuxuqvSbiMefTeMvrXeuEkJg@mail.gmail.com> In-Reply-To: <21b0280d-c290-f27f-98a9-0c2242380718@rawbw.com> References: <21b0280d-c290-f27f-98a9-0c2242380718@rawbw.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 7/8/20, Yuri <yuri@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>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHEjFvt4nijEUj0FwN0CTYmuxuqvSbiMefTeMvrXeuEkJg>