It's not uncommon that people using filesystems want to map from an internal object number (an 'inode number' for normal filesystems, an object id or object number in ZFS) to a path. ZFS itself wants to do this efficiently for things like '
zfs diff
' and the '
zpool status
' report on what files are damaged. To help with this, ZFS stores the likely parent object for every normal filesystem object . If you use
zdb
to do a sufficiently verbose dump of any particular object, you can find this as the 'parent' attribute.
If you want to do this mapping yourself, you can use
zdb
or something like it to manually follow these 'parent' pointers (and also look up the name of everything in its parent directory). However, that would require high privileges, and ZFS doesn't want to make things like '
zpool status
' require that, so the kernel and libzfs expose an API for this. In libzfs, this is '
zpool_obj_to_path()
', which uses the kernel's
ZFS_IOC_OBJ_TO_PATH
ioctl(). Because it's intended for internal usage, this API doesn't take a pool and filesystem name (in addition to the object ID); instead it takes a pool handle and a dataset ID. It's up to callers, such as '
zpool
status
', to do the mapping.
(One reason you might want to go from an inode number (object id) to a path is that various things only give you inode numbers, such as NFS v4 locks on Linux NFS servers . Or you might have NFS activity tracing software that can only reliably report the inode number of files and directories that people are using heavily.)
In OpenZFS, years ago someone wrote a command that used this libzfs API to do all the work for us, zfs_ids_to_path ( also ). Like the API, this requires the dataset ID. Helpfully we don't need to use '
zdb
' to get this; instead we can ask '
zfs list
' for it. This gives us:
# zfs list -o name,objsetid ssddata/homes NAME OBJSETID ssddata/homes 431 # zfs_ids_to_path 431 1920047 /homes/cks/.rcenv
Illumos and FreeBSD don't ship a version of zfs_ids_to_path , but the source code is sufficiently small and self contained that you could probably compile it yourself.
(Although my test FreeBSD 15 instance doesn't have the libshare.h header that's needed by libzfs.h, presumably through a packing mistake.)
If you needed to do this frequently and found it annoying to look up the dataset ID every time, I believe that it wouldn't be too hard to work out and write the code you needed in order to go from a name like 'ssddata/homes' to a pool object and a dataset ID. Sorting through, for example, the source code for 'zfs list' might take some work (there's a whole collection of callbacks and so on), but it's doable (and perhaps someday people will write a slightly handier version).
(The lazy person can write a front end script today that combines 'zfs list' with zfs_ids_to_path .)