HANDLE(3)
π HANDLE(3) β file handle operations π
okay so bestie, welcome to the Library Functions Manual, section 3 (that's the C library functions girlies, not the syscall girlies, not the admin girls β we're in library functions territory). this whole page is about β¨ handles β¨ and it's genuinely iconic, let's get into it.
πΈ NAME πΈ
path_to_handle, path_to_fshandle, fd_to_handle, handle_to_fshandle, open_by_handle, readlink_by_handle, attr_multi_by_handle, attr_list_by_handle, fssetdm_by_handle, free_handle, getparents_by_handle, getparentpaths_by_handle β file handle operations π«Ά
π C SYNOPSIS π
#include <sys/types.h>
#include <xfs/handle.h>
int path_to_handle(char *path, void **hanp, size_t *hlen);
int path_to_fshandle(char *path, void **hanp, size_t *hlen);
int fd_to_handle(int fd, void **hanp, size_t *hlen);
int handle_to_fshandle(void *hanp, size_t hlen, void **fshanp, size_t
*fshlen);
int open_by_handle(void *hanp, size_t hlen, int oflag);
int readlink_by_handle(void *hanp, size_t hlen, void *buf, size_t bs);
int attr_multi_by_handle(void *hanp, size_t hlen, void *buf, int
rtrvcnt, int flags);
int attr_list_by_handle(void *hanp, size_t hlen, char *buf, size_t
bufsiz, int flags, struct attrlist_cursor *cursor);
int fssetdm_by_handle(void *hanp, size_t hlen, struct fsdmidata
*fssetdm);
void free_handle(void *hanp, size_t hlen);
int getparents_by_handle(void *hanp, size_t hlen, parent_t *buf, size_t
bufsiz, parent_cursor_t *cursor, unsigned int *count, unsigned
int *more);
int getparentpaths_by_handle(void *hanp, size_t hlen, parent_t *buf,
size_t bufsiz, parent_cursor_t *cursor, unsigned int *count,
unsigned int *more);
look at that list. twelve functions. no cap. π
β¨ DESCRIPTION β¨
so these functions let you do certain filesystem operations without needing a file descriptor to get at filesystem objects. it's giving "i don't have an fd but i still need answers." they're meant for a limited set of system utilities β backup programs and that kind of thing, the girlies who need to reach objects directly. and heads up: they are supported only by the XFS filesystem. to actually use these, you link with the libhandle library. π¦
a handle, hanp, uniquely identifies a filesystem object or an entire filesystem. there is one and only one handle per filesystem or filesystem object β monogamy, periodt. handles consist of some number of bytes. the size of a handle (i.e. the number of bytes comprising it) varies by the type of handle and may vary for different objects of the same type. the content of a handle is opaque to applications, meaning you don't get to peek, that's not your business π. since handle sizes vary and their contents are opaque, handles are described by two quantities: a pointer (hanp) and a size (hlen). the size, hlen, tells you the number of bytes in the handle which are pointed to by the pointer. dynamic sizing, we love to see it. π
here's the function-by-function tea:
path_to_handle()β returns the handle for the object given by thepathargument. and bestie, important detail: if the final component of the path name is a symbolic link, the handle returned is that of the link itself π (not what it points to, the link, the link).path_to_fshandle()β returns the handle for the filesystem in which the object given by thepathargument resides.fd_to_handle()β returns the handle for the object referenced by thefdargument, which must be a valid file descriptor.handle_to_fshandle()β returns the handle for the filesystem in which the object referenced by the handle given by thehanpandhlenarguments resides.open_by_handle()β opens a file descriptor for the object referenced by a handle. it's analogous and identical toopen(2), with the one exception that it accepts handles instead of path names. glow up.readlink_by_handle()β returns the contents of a symbolic link referenced by a handle.attr_multi_by_handle()β manipulates multiple user attributes on a filesystem object. analogous and identical toattr_multif(3)except that a handle is specified instead of a file descriptor.attr_list_by_handle()β returns the names of the user attributes of a filesystem object. analogous and identical toattr_listf(3)except that a handle is specified instead of a file descriptor.fssetdm_by_handle()β sets thedi_dmevmaskanddi_dmstatefields in an XFS on-disk inode. it's analogous to theXFS_IOC_FSSETDMxfsctl(3)command, except that a handle is specified instead of a file. > β οΈ this function is not supported on Linux. sorry babe.free_handle()β frees the storage allocated for handles returned by the following functions:path_to_handle(),path_to_fshandle(),fd_to_handle(), andhandle_to_fshandle(). clean up after yourself, be a good citizen π§getparents_by_handle()β returns an array ofparent_tstructures for each hardlink to the inode represented by the given handle. the parent structure encodes the parent inode number, generation number and the basename of the link. > β οΈ this function is not operational on Linux.getparentpaths_by_handle()β identical to thegetparents_by_handle()function except that instead of returning the basename it returns the path of the link up to the mount point. > β οΈ this function is also not operational on Linux.
π RETURN VALUE π
free_handle() has no failure indication β it just vibes, it can't fail at you. the other functions return the value 0 to the calling process if they succeed; otherwise they return the value -1 and set errno to indicate the error. classic zero-or-minus-one situation, iykyk.
π ERRORS π
EACCESβ search permission was denied for a component ofpath.EBADFβfdis not a valid and open file descriptor.EFAULTβ an argument pointed to an invalid address.EINVALβpathis in a filesystem that does not support these functions.ELOOPβ too many symbolic links were encountered in translating the path name.ENAMETOOLONGβ a component ofpathor the entire length ofpathexceeds filesystem limits.ENOENTβ a component ofpathdoes not exist.EPERMβ the caller does not have sufficient privileges.
π SEE ALSO π
open(2), readlink(2), attr_multi(3), attr_list(3), xfsctl(3), xfs(5).
and that's the whole page bestie, go forth and handle responsibly π«Άπ β¨
this has been HANDLE(3), page three of the Library Functions Manual β mwah, you ate that reading session, no crumbs left ππ
π¦ where this page comes from
- alpine 3.22: xfsprogs-doc 6.14.0-r0 Β· LGPL-2.1-or-later
- alpine 3.23: xfsprogs-doc 6.17.0-r0 Β· LGPL-2.1-or-later
- alpine 3.24: xfsprogs-doc 7.0.1-r0 Β· LGPL-2.1-or-later
- arch rolling: xfsprogs 7.2.0-1
- arch rolling: xfsprogs 7.2.1-1 Β· GPL-2.0-only AND LGPL-2.1-only
- centos-stream 10: xfsprogs-devel 6.16.0-1.el10 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- centos-stream 9: xfsprogs-devel 6.4.0-9.el9 Β· GPL+ and LGPLv2+
- centos-stream 9: xfsprogs-devel 6.4.0-9.el9 Β· GPL+ and LGPLv2+
- debian bookworm: xfslibs-dev 6.1.0-1 Β· GPL-2.0-only
- debian trixie: xfslibs-dev 6.13.0-2+deb13u1 Β· GPL-2.0-only
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 43: xfsprogs-devel 6.15.0-3.fc43 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 6.18.0-2.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- fedora 44: xfsprogs-devel 7.1.1-1.fc44 Β· GPL-1.0-or-later AND LGPL-2.1-or-later
- nixos 26.05: xfsprogs 6.19.0
- nixpkgs unstable: xfsprogs 7.2.1
- opensuse-leap 16.0: xfsprogs-devel 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs-devel 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs-devel 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- opensuse-leap 16.0: xfsprogs-devel 6.19.0-160000.3.1 Β· GPL-2.0-or-later
- ubuntu noble: xfslibs-dev 6.6.0-1ubuntu2 Β· GPL-2.0-only
- ubuntu noble: xfslibs-dev 6.6.0-1ubuntu2.1 Β· GPL-2.0-only
- ubuntu questing: xfslibs-dev 6.13.0-2ubuntu2
- ubuntu resolute: xfslibs-dev 6.18.0-3 Β· GPL-2.0-only
- ubuntu stonking: xfslibs-dev 6.19.0-1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms