Discussion:
Is there a namei utility in FreeBSD?
James E Keenan
2017-03-06 14:12:14 UTC
Permalink
In Linux, there is a userland utility 'namei' which enables a user to
"follow a pathname until a terminal point is found". Invoking it on,
say, a symlink produces output like this:

#####
$ namei /usr/bin/bundledoc
f: /usr/bin/bundledoc
d /
d usr
d bin
l bundledoc -> ../share/texlive/texmf-dist/scripts/bundledoc/bundledoc
d ..
d share
d texlive
d texmf-dist
d scripts
d bundledoc
- bundledoc
#####

Is there an equivalent utility in FreeBSD? In 10.3 and 11.0, I could
only find namei in man 9, which is C-level facility, not an executable
utility.

Thank you very much.
Jim Keenan
Anton Yuzhaninov
2017-03-06 16:02:15 UTC
Permalink
Post by James E Keenan
In Linux, there is a userland utility 'namei' which enables a user to
"follow a pathname until a terminal point is found". Invoking it on,
If you need to find a target of symlink (or symlink chain) you can use
realpath(1).
James E Keenan
2017-03-06 16:43:25 UTC
Permalink
Post by Anton Yuzhaninov
Post by James E Keenan
In Linux, there is a userland utility 'namei' which enables a user to
"follow a pathname until a terminal point is found". Invoking it on,
If you need to find a target of symlink (or symlink chain) you can use
realpath(1).
Thanks for mentioning that. However, while the example I gave was that
of a symlink, and while both namei and realpath are good for displaying
information about symlinks, my central question was whether there was an
equivalent to namei in FreeBSD. namei identifies the nature of each
component in the resolved path; realpath does not.

Thank you very much.
Jim Keenan
Trond Endrestøl
2017-03-08 08:23:46 UTC
Permalink
Post by Anton Yuzhaninov
Post by James E Keenan
In Linux, there is a userland utility 'namei' which enables a user to
"follow a pathname until a terminal point is found". Invoking it on,
If you need to find a target of symlink (or symlink chain) you can use
realpath(1).
Thanks for mentioning that. However, while the example I gave was that of a
symlink, and while both namei and realpath are good for displaying information
about symlinks, my central question was whether there was an equivalent to
namei in FreeBSD. namei identifies the nature of each component in the
resolved path; realpath does not.
I couldn't resist creating my own version of namei(1). This one is BSD
two-clause licensed, and I swear I only looked at the two URLs
mentioned in the comments and the many man pages of FreeBSD.

http://ximalas.info/~trond/namei/c/namei.c

The code is a mess and I don't know if the output matches the original
beyond what was presented in this thread. Bugs are probably in
abundance, and the -v flag isn't implemented yet.

The code does work to some extent:

$ namei /etc/rc.d/local_unbound
f: = /etc/rc.d/local_unbound
d /
d etc
d rc.d
- local_unbound

$ namei /sys/amd64/conf/GENERIC
f: = /sys/amd64/conf/GENERIC
d /
l sys -> usr/src/sys
d usr
d src
d sys
d amd64
d conf
- GENERIC

$ namei -l /sys/i386/conf/GENERIC
f: = /sys/i386/conf/GENERIC
drwxr-xr-x root wheel /
lrwxr-xr-x root wheel sys -> usr/src/sys
drwxr-xr-x root wheel usr
drwxr-xr-x root wheel src
drwxr-xr-x root wheel sys
drwxr-xr-x root wheel i386
drwxr-xr-x root wheel conf
-rw-r--r-- root wheel GENERIC

Happy hacking.
--
+-------------------------------+------------------------------------+
| Vennlig hilsen, | Best regards, |
| Trond Endrestøl, | Trond Endrestøl, |
| IT-ansvarlig, | System administrator, |
| Fagskolen Innlandet, | Gjøvik Technical College, Norway, |
| tlf. mob. 952 62 567, | Cellular...: +47 952 62 567, |
| sentralbord 61 14 54 00. | Switchboard: +47 61 14 54 00. |
+-------------------------------+------------------------------------+
Loading...