GETFH(2)
β¨ GETFH(2) β the get-file-handle girlies β¨
okay so bestie, welcome to GETFH(2) π this is the System Calls Manual page and it's literally all about grabbing file handles. three whole syscalls, one vibe. let's go π«Ά
πΈ NAME πΈ
getfh, lgetfh, getfhat β get file handle. that's it, that's the whole name, iconic.
π LIBRARY π
Standard C Library (libc, -lc). yes queen, link the lib π
π SYNOPSIS π
#include <sys/param.h>
#include <sys/mount.h>
int
getfh(const char *path, fhandle_t *fhp);
int
lgetfh(const char *path, fhandle_t *fhp);
int
getfhat(int fd, const char *path, fhandle_t *fhp, int flag);
π« DESCRIPTION π«
so the getfh() system call hands you back a file handle for whatever file or directory you point it at, and it drops that handle into the file handle that fhp is pointing to. cute, right? π
lgetfh() is giving getfh() energy EXCEPT β and this is the whole plot twist β when the file you named is a symbolic link. in that case lgetfh() gives you info about the link itself, while getfh() gives you info about the file the link references. not me being obsessed with that distinction π
getfhat() is equivalent to getfh() and lgetfh() except when the path specifies a relative path, or when the AT_BENEATH flag is provided. so like:
- for
getfhat()with a relative path, the status gets retrieved from a file relative to the directory associated with the file descriptorfdβ not the current working directory, bestie, keep up β¨ - for
AT_BENEATHwith an absolute path, the status gets retrieved from a file specified bypath, but with extra permission checks on top. see below π
the values for the flag are constructed by a bitwise-inclusive OR of flags from this list, defined in <fcntl.h>:
AT_SYMLINK_NOFOLLOWβ ifpathnames a symbolic link, the status of the symbolic link is returned. don't follow, just vibe πAT_BENEATHβ only stat files and directories below the topping directory. see the description of theO_BENEATHflag in theopen(2)manual page. iykyk π₯
if getfhat() gets passed the special value AT_FDCWD in the fd parameter, then the current working directory is used, and the behavior is identical to a call to getfth() or lgetfh() respectively β depending on whether or not the AT_SYMLINK_NOFOLLOW bit is set in flag. (yes, the manpage really says getfth() there, we don't make the rules π)
when getfhat() is called with an absolute path without the AT_BENEATH flag, it ignores the fd argument. when AT_BENEATH is specified with an absolute path, a directory passed by the fd argument is used as the topping point for the resolution. and bestie, listen β these system calls are restricted to the superuser. main character privilege only π
β RETURN VALUES β
upon successful completion, the value 0 is returned. otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic -1 and errno moment π
π ERRORS π
the getfh() and lgetfh() system calls fail if one or more of the following are true:
[ENOTDIR]β a component of the path prefix ofpathis not a directory.[ENAMETOOLONG]β the length of a component ofpathexceeds 255 characters, or the length ofpathexceeds 1023 characters.[ENOENT]β the file referred to bypathdoes not exist.[EACCES]β search permission is denied for a component of the path prefix ofpath.[ELOOP]β too many symbolic links were encountered in translatingpath.[EFAULT]β thefhpargument points to an invalid address.[EFAULT]β thepathargument points to an invalid address.[EIO]β an I/O error occurred while reading from or writing to the file system.[EINTEGRITY]β corrupted data was detected while reading from the file system.[ESTALE]β the file handlefhpis no longer valid.
in addition to the errors returned by getfh(), and lgetfh(), the getfhat() system call may fail if:
[EBADF]β thepathargument does not specify an absolute path and thefdargument, is neitherAT_FDCWDnor a valid file descriptor open for searching.[EINVAL]β the value of theflagargument is not valid.[ENOTDIR]β thepathargument is not an absolute path andfdis neitherAT_FDCWDnor a file descriptor associated with a directory.
fr fr, that last batch is allgetfhat()-only drama. don't @ me, @ yourfdπ
π SEE ALSO π
π¦ HISTORY π¦
the getfh() system call first appeared in 4.4BSD. a legend from the start, no cap π
and that's the whole page bestie!! this lil masterpiece is from the Debian crew, dated March 30, 2020 β go forth and handle files responsibly π§πβ¨
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1989, 1991, 1993 The Regents of the University of California. All rights reserved
- Copyright (c) 2018 Gandi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms