Currently mounted file systems only
If you are willing to limit yourself to currently mounted ZFS file systems, you can parse /proc/mounts
and don't need any particular ZFS knowledge (unless you specifically want to restrict yourself to ZFS file systems).
This may or may not work on non-Linux systems.
/proc/mounts is basically /etc/mtab, but is maintained by the kernel. It contains a list of file system backing devices, mount paths, file system types, and file system flags.
For example, to list the mount points of all mounted ZFS file systems, you could do something like
$ awk '$3 == "zfs" { print $2 }' < /proc/mounts
To check whether a given directory corresponds to a mount point for a mounted ZFS file system,
$ awk '$3 == "zfs" && $2 == "/some/particular/absolute/path" { print "yes" }' < /proc/mounts
To allow for all file systems (not just ZFS), simply remove the $3 == "zfs"
check.
Mounted or unmounted ZFS file systems
If you need to include unmounted file systems on currently imported pools, then you need to use zfs get
to get a list of all ZFS mountpoints within currently imported pools:
$ sudo zfs list -pH -o mountpoint | grep -q '^/some/particular/absolute/path$' && echo yes
will print yes
if a file system with a mount point of /some/particular/absolute/path
exists on a pool that is currently imported, whether or not that file system is currently mounted.
File systems on exported pools
I am not aware of any way of listing file systems on exported pools without out-of-band knowledge about the file systems on the pools in question. Hence, I do not believe this combination is possible.
Finishing notes
Always consider whether there exists a utility that does what you want. For example, df
, as a side effect, prints the list of currently mounted file systems and their backing devices, and can be expected to not partake in any kernel magic (only using interfaces intended for public use). strace df 2>&1 | less
is a good start in that case to see how one might go about finding the information you require.