Add mountpoint(1), which reports whether a directory is a mount point. This revision reworks it following kib's review. Git branch: https://github.com/sobomax/freebsd/tree/mountpoint
The first version compared realpath(3) of the argument with realpath(3) of statfs(2)'s f_mntonname. As kib pointed out, that cannot work for deep enough hierarchies, and it is unreliable after chroot(2) or inside a jail. D59910 (now in main as 0d5d8872931c) makes stat(2) set SFBSD_MNTPOINT in st_bsdflags when the vnode is the root of a mounted file system. With that, the answer comes from the kernel with a single stat(2), so mountpoint(1) becomes a hardlink to stat(1), the same way readlink(1) is.
- stat.c: when invoked as mountpoint, main() hands off to mountpoint_main(). It calls stat(2) on the argument (symbolic links are followed), requires a directory, and checks SFBSD_MNTPOINT. The interface is mountpoint [-q] directory. It prints <dir> is a mount point or <dir> is not a mount point, and -q suppresses that line but not error messages. Exit status is 0 for a mount point, 1 for not a mount point, and 2 on error, including usage errors.
- stat/Makefile: mountpoint is added to LINKS and MLINKS, next to readlink, so man mountpoint opens stat(1).
- stat.1: mountpoint is documented in NAME, SYNOPSIS, DESCRIPTION, the -q entry (whose meaning differs for mountpoint), EXIT STATUS and EXAMPLES.
- tests/mountpoint_test.sh: new ATF tests, described in the test plan.
Because the kernel reports what is true of the vnode, a chroot or jail root that is not itself a mount point is reported as "not a mount point". .. from that root stays inside it, so a mount point above the root is never reported.
Files: usr.bin/stat/Makefile, stat.1, stat.c, tests/Makefile, tests/mountpoint_test.sh (479 insertions, 5 deletions against main).