statvfs(3)
๐ statvfs(3) ๐
okay bestie, welcome to the <sys/statvfs.h> corner of the Library Functions Manual โ this is statvfs(3) and her lil sibling fstatvfs(3), and they are literally the glow-up you need when you wanna know how much room is left on a filesystem. no cap. ๐ฆ
โจ NAME โจ
statvfs, fstatvfs โ get filesystem statistics ๐ธ
๐ LIBRARY ๐
Standard C library (libc, -lc) ๐
๐ SYNOPSIS ๐
#include <sys/statvfs.h>
int statvfs(const char *restrict path, struct statvfs *restrict buf);
int fstatvfs(int fd, struct statvfs *buf);
๐ซถ DESCRIPTION ๐ซถ
so statvfs() hands you the tea about a mounted filesystem. path is the pathname of any file inside that mounted filesystem (yes, literally any file in there, she doesn't need the mountpoint itself, iykyk). and buf is a pointer to a statvfs structure, which looks approximately like this:
struct statvfs {
unsigned long f_bsize; /* Filesystem block size */
unsigned long f_frsize; /* Fragment size */
fsblkcnt_t f_blocks; /* Size of fs in f_frsize units */
fsblkcnt_t f_bfree; /* Number of free blocks */
fsblkcnt_t f_bavail; /* Number of free blocks for
unprivileged users */
fsfilcnt_t f_files; /* Number of inodes */
fsfilcnt_t f_ffree; /* Number of free inodes */
fsfilcnt_t f_favail; /* Number of free inodes for
unprivileged users */
unsigned long f_fsid; /* Filesystem ID */
unsigned long f_flag; /* Mount flags */
unsigned long f_namemax; /* Maximum filename length */
};
quick lil note about those types: fsblkcnt_t and fsfilcnt_t live in <sys/types.h>, and both of them used to be unsigned long. the more you know ๐ซ
๐ the f_flag field ๐
so f_flag is a bit mask โ it's giving "which options were used when this filesystem got mounted". it contains zero or more of these flags, and each one is a whole vibe:
ST_MANDLOCKโ mandatory locking is permitted on the filesystem (peepfcntl(2)).ST_NOATIMEโ do not update access times; seemount(2).ST_NODEVโ access to device special files on this filesystem is disallowed. nope, not today.ST_NODIRATIMEโ do not update directory access times; seemount(2).ST_NOEXECโ running programs on this filesystem is disallowed.ST_NOSUIDโ the set-user-ID and set-group-ID bits are ignored byexec(3)for executable files on this filesystem.ST_RDONLYโ this filesystem is mounted read-only. tiny lock, cute, permanent. ๐ST_RELATIMEโ update atime relative to mtime/ctime; seemount(2).ST_SYNCHRONOUSโ writes are synched to the filesystem immediately (see the description ofO_SYNCinopen(2)).
โ ๏ธ real talk: it is unspecified whether all members of the returned struct have meaningful values on all filesystems. so don't come for me if some field is just. there. ๐
and fstatvfs()? she serves you the exact same info, but about an open file referenced by the descriptor fd. same energy, different doorway. โจ
๐ฅ RETURN VALUE ๐ฅ
- on success? zero. slay.
- on error? -1 is returned, and
errnogets set to tell you what the drama was.
๐ญ ERRORS ๐ญ
EACCESโ (statvfs()) search permission is denied for a component of the path prefix ofpath. (also go look atpath_resolution(7).)EBADFโ (fstatvfs())fdis not a valid open file descriptor.EFAULTโBuforpathpoints to an invalid address.EINTRโ this call was interrupted by a signal; seesignal(7).EIOโ an I/O error occurred while reading from the filesystem. ๐ELOOPโ (statvfs()) too many symbolic links were encountered in translatingpath.ENAMETOOLONGโ (statvfs())pathis too long.ENOENTโ (statvfs()) the file referred to bypathdoes not exist.ENOMEMโ insufficient kernel memory was available.ENOSYSโ the filesystem does not support this call.ENOTDIRโ (statvfs()) a component of the path prefix ofpathis not a directory.EOVERFLOWโ some values were too large to be represented in the returnedstruct. the numbers were simply too big for the fit, bestie. ๐
๐ ATTRIBUTES ๐
for the explanation of the terms used in this section, see attributes(7). here's the chart, but make it a bullet list:
statvfs(),fstatvfs()โ Thread safety: MT-Safe ๐ง
๐ฆ VERSIONS ๐ฆ
POSIX.1 only specifies ST_NOSUID and ST_RDONLY out of the f_flag field. if you want definitions of the remaining flags, you gotta define _GNU_SOURCE. manifest it, bestie. ๐
๐ธ NOTES ๐ธ
the Linux kernel has the system calls statfs(2) and fstatfs(2) to support this library call. so yeah, she's a libc girl with a syscall backbone. iconic.
also, the glibc implementations of
pathconf(path, _PC_REC_XFER_ALIGN);
pathconf(path, _PC_ALLOC_SIZE_MIN);
pathconf(path, _PC_REC_MIN_XFER_SIZE);
respectively use the f_frsize, f_frsize, and f_bsize fields returned by a call to statvfs() with the argument path. (yes, f_frsize shows up twice. that's not me being messy, that's just the lore. ๐)
and under Linux, f_favail is always the same as f_ffree, and there's literally no way for a filesystem to report otherwise. not a problem tho, since no filesystems with an inode root reservation exist. so we move. ๐ซถ
โญ STANDARDS โญ
POSIX.1-2008. periodt.
๐ HISTORY ๐
POSIX.1-2001. throwback.
before glibc 2.13, statvfs() populated the bits of the f_flag field by scanning the mount options shown in /proc/mounts. but starting with Linux 2.6.36, the underlying statfs(2) system call provides the necessary information via the f_flags field, and since glibc 2.13, the statvfs() function will use information from that field rather than scanning /proc/mounts. character development fr fr. ๐
๐ SEE ALSO ๐
and that's the whole page, bestie!! ๐ this was statvfs(3) from Linux man-pages 6.20, dated 2026-02-08 โ go forth and check your disk space with main character energy, ily, bye!! ๐โจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 2003, Andries E. Brouwer <aeb@cwi.nl>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms