FHOPEN(2)
π FHOPEN(2) π
okay bestie, gather round, because today we're talking about fhopen, fhstat, and fhstatfs β the trio that lets you access a file via file handle. yes, via file handle. not via path. it's giving backdoor-but-make-it-official energy and honestly? iconic. π
β¨ LIBRARY β¨
Standard C Library (libc, -lc) β you know her, you love her, she's already linked in. π
β¨ SYNOPSIS β¨
so first you gotta invite the whole squad in:
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
then, the moment you've been waiting for:
int
fhopen(const fhandle_t *fhp, int flags);
int
fhstat(const fhandle_t *fhp, struct stat *sb);
int
fhstatfs(const fhandle_t *fhp, struct statfs *buf);
three little functions, three little glow-ups. π¦
β¨ DESCRIPTION β¨
okay so here's the tea. these system calls are your way to reach a file when all you've got is the file handle fhp. and the way that this bypasses directory access restrictions?? yeah. that's exactly why these calls are restricted to the superuser. no cap, you need root for this one. it's VIP-only, the bouncer does NOT care how cute your outfit is. π«β¨
The fhopen() system call opens the file referenced by fhp for reading and/or writing as specified by the argument flags, and hands the file descriptor back to the calling process. the flags argument is specified by or'ing together the flags used for the open(2) system call. all said flags are valid except for O_CREAT β that one's a hard no, sorry babe. π
The fhstat() and fhstatfs() system calls provide the functionality of the fstat(2) and fstatfs(2) calls, except that they return information for the file referred to by fhp rather than an open file. same vibe, different source of truth. π
β¨ RETURN VALUES β¨
Upon successful completion, fhopen() returns the file descriptor for the opened file. otherwise the value -1 is returned and the global variable errno is set to indicate the error. slay when it works, sob when it doesn't. π«Ά
The fhstat() and fhstatfs() functions return the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. classic.
β¨ ERRORS β¨
In addition to the errors returned by open(2), fstat(2), and fstatfs(2) respectively, fhopen(), fhstat(), and fhstatfs() will return:
[EINVAL]β Callingfhopen()withO_CREATset. bestie we TOLD you,O_CREATis not invited to this party. π[ESTALE]β The file handle fhp is no longer valid. it's giving expired group chat invite. it's over, it's stale, let it go. π
β¨ SEE ALSO β¨
go read the extended universe, it's all connected:
iykyk. π
β¨ HISTORY β¨
The fhopen(), fhstat(), and fhstatfs() system calls first appeared in NetBSD 1.5 and were adapted to FreeBSD 4.0 by Alfred Perlstein. a glow-up arc across two BSDs, we love to see it. β
β¨ AUTHORS β¨
This manual page was written by William Studenmund for NetBSD. king behavior, honestly. π
πΈ and that's the whole page, bestie! this little beauty comes to you from Debian, dated June 29, 1999 β yeah she's a vintage queen and she still ate. go forth and fhopen responsibly (with root, obviously). mwah! πβ¨π
π¦ 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) 1999 National Aeronautics & Space Administration
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms