xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Snippits/fd2pathname.txt (revision 867d70fc718005c0918b8b8b2f9d7f2d52d0a0db)
1You have a file descriptor (probably from a syscall), and you want the
2corresponding pathname.
3
4If you are on newer versions of DTrace, there is the fds[] array,
5
6# dtrace -n 'syscall::read:entry { @[fds[arg0].fi_pathname] = count(); }'
7dtrace: description 'syscall::read:entry ' matched 1 probe
8^C
9
10  /etc/minor_perm                                                   2
11  /etc/mnttab                                                       2
12  /etc/motd                                                         2
13  /etc/magic                                                        4
14  /usr/sbin/clri                                                    5
15  /devices/pseudo/clone@0:ptm                                       6
16  /sbin/mount                                                       6
17  /dev/pts/28                                                       7
18  /devices/pseudo/consms@0:mouse                                   31
19  /devices/pseudo/conskbd@0:kbd                                    47
20  <unknown>                                                       351
21
22easy.
23
24but if you are on an older version of DTrace, try this to convert from
25this->fd to self->vpath,
26
27        this->filep =
28	    curthread->t_procp->p_user.u_finfo.fi_list[this->fd].uf_file;
29        this->vnodep = this->filep != 0 ? this->filep->f_vnode : 0;
30        self->vpath = this->vnodep ? (this->vnodep->v_path != 0 ?
31            cleanpath(this->vnodep->v_path) : "<unknown>") : "<unknown>";
32
33