statfs(2)
๐ statfs, fstatfs โ get filesystem statistics ๐
hiii bestie ๐ so this is statfs(2) โ yeah, section 2, the System Calls Manual, the real syscall zone, not some libc wrapper pretending. We're getting the tea on a mounted filesystem: how much space, how many inodes, what kind of filesystem it even is. Let's get into it, no cap.
โจ NAME โจ
statfs, fstatfs โ get filesystem statistics ๐
๐ LIBRARY ๐
Standard C library (libc, -lc). yes, the classic. ๐ซถ
๐ธ SYNOPSIS ๐ธ
#include <sys/vfs.h> /* or <sys/statfs.h> */
int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);
okay so real talk: unless you specifically need thef_typefield, you should be using the standardstatvfs(3)interface instead. that's the glow-up version, bestie. ๐
๐ฆ DESCRIPTION ๐ฆ
So statfs() is a system call that hands you info about a mounted filesystem. path is the pathname of any file inside that mounted filesystem โ doesn't have to be the mount point itself, any file hanging out in there works. And buf is a pointer to a statfs structure, which looks approximately like this:
struct statfs {
__fsword_t f_type; /* Type of filesystem (see below) */
__fsword_t f_bsize; /* Optimal transfer block size */
fsblkcnt_t f_blocks; /* Total data blocks in filesystem */
fsblkcnt_t f_bfree; /* Free blocks in filesystem */
fsblkcnt_t f_bavail; /* Free blocks available to
unprivileged user */
fsfilcnt_t f_files; /* Total inodes in filesystem */
fsfilcnt_t f_ffree; /* Free inodes in filesystem */
fsid_t f_fsid; /* Filesystem ID */
__fsword_t f_namelen; /* Maximum length of filenames */
__fsword_t f_frsize; /* Fragment size (since Linux 2.6) */
__fsword_t f_flags; /* Mount flags of filesystem
(since Linux 2.6.36) */
__fsword_t f_spare[xxx];
/* Padding bytes reserved for future use */
};
๐ the f_type mood board ๐
These are the filesystem types that can show up in f_type. it's giving โจpokรฉdexโจ, there's SO many, I'm obsessed:
ADFS_SUPER_MAGIC 0xadf5
AFFS_SUPER_MAGIC 0xadff
AFS_SUPER_MAGIC 0x5346414f
ANON_INODE_FS_MAGIC 0x09041934 /* Anonymous inode FS (for
pseudofiles that have no name;
e.g., epoll, signalfd, bpf) */
AUTOFS_SUPER_MAGIC 0x0187
BDEVFS_MAGIC 0x62646576
BEFS_SUPER_MAGIC 0x42465331
BFS_MAGIC 0x1badface
BINFMTFS_MAGIC 0x42494e4d
BPF_FS_MAGIC 0xcafe4a11
BTRFS_SUPER_MAGIC 0x9123683e
BTRFS_TEST_MAGIC 0x73727279
CGROUP_SUPER_MAGIC 0x27e0eb /* Cgroup pseudo FS */
CGROUP2_SUPER_MAGIC 0x63677270 /* Cgroup v2 pseudo FS */
CIFS_MAGIC_NUMBER 0xff534d42
CODA_SUPER_MAGIC 0x73757245
COH_SUPER_MAGIC 0x012ff7b7
CRAMFS_MAGIC 0x28cd3d45
DEBUGFS_MAGIC 0x64626720
DEVFS_SUPER_MAGIC 0x1373 /* Linux 2.6.17 and earlier */
DEVPTS_SUPER_MAGIC 0x1cd1
ECRYPTFS_SUPER_MAGIC 0xf15f
EFIVARFS_MAGIC 0xde5e81e4
EFS_SUPER_MAGIC 0x00414a53
EXT_SUPER_MAGIC 0x137d /* Linux 2.0 and earlier */
EXT2_OLD_SUPER_MAGIC 0xef51
EXT2_SUPER_MAGIC 0xef53
EXT3_SUPER_MAGIC 0xef53
EXT4_SUPER_MAGIC 0xef53
F2FS_SUPER_MAGIC 0xf2f52010
FUSE_SUPER_MAGIC 0x65735546
FUTEXFS_SUPER_MAGIC 0xbad1dea /* Unused */
HFS_SUPER_MAGIC 0x4244
HOSTFS_SUPER_MAGIC 0x00c0ffee
HPFS_SUPER_MAGIC 0xf995e849
HUGETLBFS_MAGIC 0x958458f6
ISOFS_SUPER_MAGIC 0x9660
JFFS2_SUPER_MAGIC 0x72b6
JFS_SUPER_MAGIC 0x3153464a
MINIX_SUPER_MAGIC 0x137f /* original minix FS */
MINIX_SUPER_MAGIC2 0x138f /* 30 char minix FS */
MINIX2_SUPER_MAGIC 0x2468 /* minix V2 FS */
MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 FS, 30 char names */
MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 FS, 60 char names */
MQUEUE_MAGIC 0x19800202 /* POSIX message queue FS */
MSDOS_SUPER_MAGIC 0x4d44
MTD_INODE_FS_MAGIC 0x11307854
NCP_SUPER_MAGIC 0x564c
NFS_SUPER_MAGIC 0x6969
NILFS_SUPER_MAGIC 0x3434
NSFS_MAGIC 0x6e736673
NTFS_SB_MAGIC 0x5346544e
OCFS2_SUPER_MAGIC 0x7461636f
OPENPROM_SUPER_MAGIC 0x9fa1
OVERLAYFS_SUPER_MAGIC 0x794c7630
PIPEFS_MAGIC 0x50495045
PROC_SUPER_MAGIC 0x9fa0 /* /proc FS */
PSTOREFS_MAGIC 0x6165676c
QNX4_SUPER_MAGIC 0x002f
QNX6_SUPER_MAGIC 0x68191122
RAMFS_MAGIC 0x858458f6
REISERFS_SUPER_MAGIC 0x52654973
ROMFS_MAGIC 0x7275
SECURITYFS_MAGIC 0x73636673
SELINUX_MAGIC 0xf97cff8c
SMACK_MAGIC 0x43415d53
SMB_SUPER_MAGIC 0x517b
SMB2_MAGIC_NUMBER 0xfe534d42
SOCKFS_MAGIC 0x534f434b
SQUASHFS_MAGIC 0x73717368
SYSFS_MAGIC 0x62656572
SYSV2_SUPER_MAGIC 0x012ff7b6
SYSV4_SUPER_MAGIC 0x012ff7b5
TMPFS_MAGIC 0x01021994
TRACEFS_MAGIC 0x74726163
UDF_SUPER_MAGIC 0x15013346
UFS_MAGIC 0x00011954
USBDEVICE_SUPER_MAGIC 0x9fa2
V9FS_MAGIC 0x01021997
VXFS_SUPER_MAGIC 0xa501fcf5
XENFS_SUPER_MAGIC 0xabba1974
XENIX_SUPER_MAGIC 0x012ff7b4
XFS_SUPER_MAGIC 0x58465342
_XIAFS_SUPER_MAGIC 0x012fd16d /* Linux 2.0 and earlier */
Most of these MAGIC constants live in /usr/include/linux/magic.h, and a few are just hardcoded straight into kernel sources. iykyk ๐ง
๐ฅ f_flags โ the mount-option bitmask ๐ฅ
The f_flags field is a bit mask that tells you the mount options for the filesystem. It holds zero or more of these bits:
ST_MANDLOCKโ mandatory locking is permitted on the filesystem (peepfcntl(2)for that one).ST_NOATIMEโ do not update access times; seemount(2).ST_NODEVโ access to device special files is disallowed on this filesystem.ST_NODIRATIMEโ do not update directory access times; seemount(2).ST_NOEXECโ executing programs is disallowed on this filesystem.ST_NOSUIDโ the set-user-ID and set-group-ID bits get ignored byexec(3)for executable files on this filesystem.ST_RDONLYโ this filesystem is mounted read-only.ST_RELATIMEโ update atime relative to mtime/ctime; seemount(2).ST_SYNCHRONOUSโ writes get synched to the filesystem immediately (check the description ofO_SYNCinopen(2)).ST_NOSYMFOLLOW(since Linux 5.10) โ symbolic links are not followed when resolving paths; seemount(2).
Nobody knows what f_fsid is supposed to contain. (but see below ๐).
Fields that are undefined for a particular filesystem get set to 0. simple as that.
And fstatfs() gives you the exact same info about an open file referenced by the descriptor fd. same energy, different entry point. ๐ซ
๐ RETURN VALUE ๐
- Success? zero comes back. slay.
- Error? -1 comes back, and
errnogets set to tell you what went wrong.
๐ ERRORS ๐
EACCES(statfs()) โ search permission is denied for a component of the path prefix ofpath. (also seepath_resolution(7))EBADF(fstatfs()) โfdis not a valid open file descriptor.EFAULTโbuforpathpoints to an invalid address.EINTRโ the call got interrupted by a signal; seesignal(7).EIOโ an I/O error happened while reading from the filesystem.ELOOP(statfs()) โ too many symbolic links were encountered while translatingpath.ENAMETOOLONG(statfs()) โpathis too long.ENOENT(statfs()) โ the file referred to bypathdoes not exist.ENOMEMโ not enough kernel memory was available.ENOSYSโ the filesystem does not support this call.ENOTDIR(statfs()) โ a component of the path prefix ofpathis not a directory.EOVERFLOWโ some values were too large to be represented in the returned struct. ๐ญ
๐ง VERSIONS ๐ง
๐ the f_fsid field ๐
Solaris, Irix, and POSIX all have a system call statvfs(2) that returns a struct statvfs (defined over in <sys/statvfs.h>) containing an unsigned long f_fsid. Meanwhile Linux, SunOS, HP-UX, and 4.4BSD have a system call statfs() returning a struct statfs (defined in <sys/vfs.h>) containing a fsid_t f_fsid, where fsid_t is defined as struct { int val[2]; }. Same deal for FreeBSD, except it pulls from the include file <sys/mount.h>.
The general idea is that f_fsid holds some random stuff such that the pair (f_fsid,ino) uniquely determines a file. Some operating systems use (a variation on) the device number, or the device number combined with the filesystem type. And several operating systems only hand out the f_fsid field to the superuser (zeroing it for unprivileged users), because that field gets used in the filehandle of the filesystem when it's NFS-exported, and giving it out is a security concern. ๐จ not the vibes.
Under some operating systems, the fsid can be used as the second argument to the sysfs(2) system call.
โญ STANDARDS โญ
Linux. that's it, that's the standard. periodt. ๐
๐ HISTORY ๐
The Linux statfs() was inspired by the 4.4BSD one โ but they do not use the same structure, so don't get it twisted.
The original Linux statfs() and fstatfs() system calls were not designed with extremely large file sizes in mind. ๐ Then Linux 2.6 came through and added new statfs64() and fstatfs64() system calls that use a new structure, statfs64. That new structure contains the same fields as the original statfs structure, but the sizes of various fields got increased to accommodate large file sizes. The glibc statfs() and fstatfs() wrapper functions transparently deal with the kernel differences, so you don't gotta worry about it. ๐ซถ
LSB has deprecated the library calls statfs() and fstatfs(), and it tells us to use statvfs(3) and fstatvfs(3) instead.
๐ NOTES ๐
The __fsword_t type used for various fields in the statfs structure definition is a glibc internal type, not intended for public use. Which leaves the programmer in a bit of a conundrum when trying to copy or compare these fields to local variables in a program. Using unsigned int for such variables suffices on most systems โ problem solved, bestie. โจ
Some systems have only <sys/vfs.h>, other systems also have <sys/statfs.h>, where the former includes the latter. So it seems including the former is the best choice.
๐ BUGS ๐
From Linux 2.6.38 up to and including Linux 3.1, fstatfs() failed with the error ENOSYS for file descriptors created by pipe(2). we don't talk about that era. ๐
๐ SEE ALSO ๐
stat(2), statvfs(3), path_resolution(7)
okay that's the whole page, you ate it, go check your filesystems ๐ this was Linux man-pages 6.20, dated 2026-02-08 โ bye bestie, mwah! ๐๐๐ฆ
๐ฆ 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