GETFSSTAT(2)

✨ getfsstat β€” bestie, let's get a list of ALL the mounted file systems ✨

Okay so this is getfsstat(2) β€” the 2 is the manual section, meaning she's a system call, not some little library helper. Main character energy fr fr. πŸ’…


πŸ’– LIBRARY πŸ’–

Standard C Library (libc, -lc) β€” that's where she lives, periodt.


πŸŽ€ SYNOPSIS πŸŽ€

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

int
getfsstat(struct statfs *buf, long bufsize, int mode);

πŸ¦‹ DESCRIPTION πŸ¦‹

The getfsstat() system call hands you the tea on every single mounted file system on the system. The buf argument is a pointer to a bunch of statfs structures β€” the whole statfs thing is described over in statfs(2), go look, she's iconic.

Any fields that are undefined for a particular file system get set to -1. The buffer gets filled with an array of statfs structures, one per mounted file system, up to the byte count you specified in bufsize. And listen β€” this is the part everyone gets wrong β€” bufsize is the number of bytes that buf can hold, not the number of statfs structures it can hold. Bytes, bestie. Bytes. 😭

If you pass buf as NULL, getfsstat() is just gonna tell you how many mounted file systems there are and nothing else. Like, she's giving you the headcount, not the whole roster. 🫢

Normally mode should be MNT_WAIT. If you set mode to MNT_NOWAIT, getfsstat() will hand over the info it already has lying around without requesting an update from each file system. So yeah, some of that info will be stale, but the trade-off is that getfsstat() won't block waiting on a file system that literally cannot respond. She'll also skip any file system that's in the middle of being unmounted β€” even if that unmount would eventually fail. Ghosted, basically. πŸ’€


🌈 RETURN VALUES 🌈

If everything goes slay, the number of statfs structures gets returned. If not β€” -1, and the global variable errno gets set to say what went wrong. 🚨


πŸ”₯ ERRORS πŸ”₯

The getfsstat() system call fails if one or more of these are true:

  • [EFAULT] β€” the buf argument points to an invalid address. Bad pointer, bad vibes. πŸ™ˆ
  • [EINVAL] β€” mode is set to a value that isn't MNT_WAIT or MNT_NOWAIT. Pick one of the two, girl. πŸ’…
  • [EIO] β€” an I/O error happened while reading from or writing to the file system. 😭
  • [EINTEGRITY] β€” corrupted data was detected while reading from the file system. Yikes, corrupted. πŸ’€

πŸ‘‘ SEE ALSO πŸ‘‘

statfs(2), fstab(5), mount(8)


⭐ HISTORY ⭐

The getfsstat() system call first appeared in 4.4BSD. An OG. A legend. Periodt. 🌸


ngl that's the whole page, bestie. Go forth and count your mounts. 🧚

This was the Debian build of the page, dated March 30, 2020 β€” so that's the source/version tea, mwah, love u, bye πŸ’–

πŸ“¦ where this page comes from