STATFS(2)
π STATFS(2) β the manual page, but make it cute π
okay bestie, gather round, because today we're reading statfs(2) from the System Calls Manual and honestly? it ate. no cap. β¨
πΈ NAME πΈ
statfs β get file system statistics π
π LIBRARY π
Standard C Library (libc, -lc) π«Ά
β¨ SYNOPSIS β¨
#include <sys/param.h>
#include <sys/mount.h>
int
statfs(const char *path, struct statfs *buf);
int
fstatfs(int fd, struct statfs *buf);
π¦ DESCRIPTION π¦
so the statfs() system call is literally your little spy that goes and gets info about a mounted file system. the path argument is the path name of any file within the mounted file system (any file, she's not picky π). and the buf argument is a pointer to a statfs structure, which is defined like this:
typedef struct fsid { int32_t val[2]; } fsid_t; /* file system id type */
/*
* filesystem statistics
*/
#define MFSNAMELEN 16 /* length of type name including null */
#define MNAMELEN 1024 /* size of on/from name bufs */
#define STATFS_VERSION 0x20140518 /* current version number */
struct statfs {
uint32_t f_version; /* structure version number */
uint32_t f_type; /* type of filesystem */
uint64_t f_flags; /* copy of mount exported flags */
uint64_t f_bsize; /* filesystem fragment size */
uint64_t f_iosize; /* optimal transfer block size */
uint64_t f_blocks; /* total data blocks in filesystem */
uint64_t f_bfree; /* free blocks in filesystem */
int64_t f_bavail; /* free blocks avail to non-superuser */
uint64_t f_files; /* total file nodes in filesystem */
int64_t f_ffree; /* free nodes avail to non-superuser */
uint64_t f_syncwrites; /* count of sync writes since mount */
uint64_t f_asyncwrites; /* count of async writes since mount */
uint64_t f_syncreads; /* count of sync reads since mount */
uint64_t f_asyncreads; /* count of async reads since mount */
uint64_t f_spare[10]; /* unused spare */
uint32_t f_namemax; /* maximum filename length */
uid_t f_owner; /* user that mounted the filesystem */
fsid_t f_fsid; /* filesystem id */
char f_charspare[80]; /* spare string space */
char f_fstypename[MFSNAMELEN]; /* filesystem type name */
char f_mntfromname[MNAMELEN]; /* mounted filesystem */
char f_mntonname[MNAMELEN]; /* directory on which mounted */
};
look at her. so many fields. main character energy fr fr π
π the flags that may be returned π
MNT_RDONLYβ the file system is mounted read-only; even the superuser may not write on it. like, not even the boss. respect the boundary.MNT_NOEXECβ files may not be executed from the file system.MNT_NOSUIDβ setuid and setgid bits on files are not honored when they are executed.MNT_SYNCHRONOUSβ all I/O to the file system is done synchronously.MNT_ASYNCβ no file system I/O is done synchronously.MNT_SOFTDEPβ soft updates being done (seeffs(7)).MNT_GJOURNALβ journaling withgjournalis enabled (seegjournal(8)).MNT_SUIDDIRβ special handling of SUID bit on directories.MNT_UNIONβ union with underlying file system.MNT_NOSYMFOLLOWβ symbolic links are not followed.MNT_NOCLUSTERRβ read clustering is disabled.MNT_NOCLUSTERWβ write clustering is disabled.MNT_MULTILABELβ Mandatory Access Control (MAC) support for individual objects (seemac(4)).MNT_ACLSβ Access Control List (ACL) support enabled.MNT_LOCALβ the file system resides locally.MNT_QUOTAβ the file system has quotas enabled on it.MNT_ROOTFSβ identifies the root file system.MNT_EXRDONLYβ the file system is exported read-only.MNT_NOATIMEβ updating of file access times is disabled.MNT_USERβ the file system has been mounted by a user.MNT_EXPORTEDβ the file system is exported for both reading and writing.MNT_DEFEXPORTEDβ the file system is exported for both reading and writing to any Internet host.MNT_EXPORTANONβ the file system maps all remote accesses to the anonymous user.MNT_EXKERBβ the file system is exported with Kerberos uid mapping.MNT_EXPUBLICβ the file system is exported publicly (WebNFS).
β οΈ important bestie: fields that are undefined for a particular file system are set to -1. don't come for me, that's just the rules.
and the fstatfs() system call? she returns the same information about an open file referenced by descriptor fd. same info, different entrance, iykyk π
π RETURN VALUES π
upon successful completion, the value 0 is returned. otherwise, the value -1 is returned and the global variable errno is set to indicate the error. so if you see -1, check errno, that's your girl with the tea π
π ERRORS π
the statfs() system call fails if one or more of the following are true:
[ENOTDIR]β a component of the path prefix ofpathis not a directory.[ENAMETOOLONG]β the length of a component ofpathexceeds 255 characters, or the length ofpathexceeds 1023 characters.[ENOENT]β the file referred to bypathdoes not exist.[EACCES]β search permission is denied for a component of the path prefix ofpath.[ELOOP]β too many symbolic links were encountered in translatingpath.[EFAULT]β thebuforpathargument points to an invalid address.[EIO]β an I/O error occurred while reading from or writing to the file system.[EINTEGRITY]β corrupted data was detected while reading from the file system. yikes.
the fstatfs() system call fails if one or more of the following are true:
[EBADF]β thefdargument is not a valid open file descriptor.[EFAULT]β thebufargument points to an invalid address.[EIO]β an I/O error occurred while reading from or writing to the file system.[EINTEGRITY]β corrupted data was detected while reading from the file system.
π SEE ALSO π
fhstatfs(2), getfsstat(2) β go read those too, they're the friend group π«Ά
π HISTORY π
the statfs() system call first appeared in 4.4BSD. iconic behavior, honestly. the blueprint. periodt. π
and that's the whole page bestie!! this one's from the Debian crew, dated March 30, 2020 β mwah, thank you for your service πβ¨ go forth and stat your file systems, you've got this ππ¦
π¦ 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) 1989, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms