FHREADLINK(2)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

okay so bestie, we're in System Calls Manual territory today and this one is a little niche but it slaps once you get it, i promise 🫢


🌸 NAME 🌸

fhreadlink β€” read the value of a symbolic link, but like… by file handle πŸ”—


πŸŽ€ LIBRARY πŸŽ€

Standard C Library (libc, -lc) β€” the classic, the icon, the one you already link against πŸ’–


✨ SYNOPSIS ✨

#include <sys/param.h>
#include <sys/mount.h>

int
fhreadlink(fhandle_t *fhp, char *buf, size_t bufsize);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so fhreadlink() is the system call that takes the contents of the symbolic link fhp and drops them straight into the buffer buf, which has size bufsiz πŸ’«

and here's the part that gets people: fhreadlink() does not append a NUL character to buf. like, at all. no null terminator, no little gift at the end πŸ™ˆ so if you're planning to treat it like a string you gotta handle that yourself, bestie. that's on you.


πŸ‘‘ RETURN VALUES πŸ‘‘

if it works? the call returns the count of characters it placed in the buffer, slay πŸ’…

if it doesn't? it returns a -1 and tucks the error code into the global variable errno so you can go look at what went wrong 😭


πŸ”₯ ERRORS πŸ”₯

the fhreadlink() system call will fail if any of these happen:

  • [ENOENT] β€” the named file does not exist. it's giving ~nothing~ πŸ’€
  • [ELOOP] β€” too many symbolic links were encountered while translating the file handle fhp. link-ception, we're not doing that today πŸŒ€
  • [EINVAL] β€” the named file is not a symbolic link. wrong vibe entirely, not the main character you were looking for πŸ™…
  • [EIO] β€” an I/O error occurred while reading from the file system. the filesystem is having a moment 🫠
  • [EINTEGRITY] β€” corrupted data was detected while reading from the file system. something is rotten and it's not the algorithm πŸ“
  • [EFAULT] β€” the buf argument extends outside the process's allocated address space. you're colouring outside the lines, literally ⚠️
  • [ESTALE] β€” the file handle fhp is no longer valid. expired, deceased, gone girl πŸ’”

πŸ’œ SEE ALSO πŸ’œ

fhlink(2), fhstat(2), readlink(2) β€” go read these next, you'll be obsessed πŸ“š


⭐ HISTORY ⭐

the fhreadlink() system call first appeared in FreeBSD 12.1 πŸŽ‚ a Scorpio, presumably.


ngl bestie, the whole "no NUL at the end" thing is the number one thing to remember here. everything else is just vibes and errno checks πŸ’€

mwah πŸ’‹ this page came to you from Debian, dated November 30, 2022 β€” consider this your cute little sign-off, take care of yourself, hydrate, and check your return values πŸ§šβ€β™€οΈ

πŸ“¦ where this page comes from