STATVFS(5)
β¨ NAME β¨
statvfs β file system statistics. okay so this is the statvfs(5) page, and it's literally your bestie for reading mounted filesystem info. no cap π
π¦ SYNOPSIS π¦
#include <sys/types.h>
#include <sys/statvfs.h>
π DESCRIPTION π
okay so the <sys/statvfs.h> header defines the structures and functions that return information about a mounted file system. the statvfs structure is defined as follows β copy it exactly, bestie:
typedef struct { int32_t val[2]; } fsid_t; /* file system id type */
#define VFS_NAMELEN 32 /* length of fs type name, including nul */
#define VFS_MNAMELEN 1024 /* length of buffer for returned name */
struct statvfs {
unsigned long f_flag; /* copy of mount exported flags */
unsigned long f_bsize; /* system block size */
unsigned long f_frsize; /* system fragment size */
unsigned long f_iosize; /* optimal file system block size */
/* The following are in units of f_frsize */
fsblkcnt_t f_blocks; /* number of blocks in file system */
fsblkcnt_t f_bfree; /* free blocks avail in file system */
fsblkcnt_t f_bavail; /* free blocks avail to non-root */
fsblkcnt_t f_bresvd; /* blocks reserved for root */
fsfilcnt_t f_files; /* total file nodes in file system */
fsfilcnt_t f_ffree; /* free file nodes in file system */
fsfilcnt_t f_favail /* free file nodes avail to non-root */
fsfilcnt_t f_fresvd; /* file nodes reserved for root */
uint64_t f_syncreads; /* count of sync reads since mount */
uint64_t f_syncwrites; /* count of sync writes since mount */
uint64_t f_asyncreads; /* count of async reads since mount */
uint64_t f_asyncwrites; /* count of async writes since mount */
fsid_t f_fsidx; /* NetBSD compatible file system id */
unsigned long f_fsid; /* POSIX compliant file system id */
unsigned long f_namemax; /* maximum filename length */
uid_t f_owner; /* user that mounted the file system */
uint64_t f_spare[4]; /* spare space */
char f_fstypename[VFS_NAMELEN]; /* fs type name */
char f_mntonname[VFS_MNAMELEN]; /* directory on which mounted */
char f_mntfromname[VFS_MNAMELEN]; /* mounted file system */
char f_mntfromlabel[_VFS_MNAMELEN]; /* disk label name if avail */
};
the f_flag argument can have the following bits set, and we're listing every single one because we don't gatekeep:
ST_RDONLYβ the filesystem is mounted read-only; even the super-user may not write on it.ST_NOEXECβ files may not be executed from the filesystem.ST_NOSUIDβ setuid and setgid bits on files are not honored when they are executed.ST_NODEVβ special files in the filesystem may not be opened.ST_UNIONβ union with underlying filesystem instead of obscuring it.ST_SYNCHRONOUSβ all I/O to the filesystem is done synchronously.ST_ASYNCβ no filesystem I/O is done synchronously.ST_NOCOREDUMPβ don't write core dumps to this file system.ST_NOATIMEβ never update access times.ST_SYMPERMβ recognize symbolic link permission.ST_NODEVMTIMEβ never update modification times for device files.ST_LOGβ use logging (journaling).ST_LOCALβ the filesystem resides locally.ST_QUOTAβ the filesystem has quotas enabled on it.ST_ROOTFSβ identifies the root filesystem.ST_EXRDONLYβ the filesystem is exported read-only.ST_EXPORTEDβ the filesystem is exported for both reading and writing.ST_DEFEXPORTEDβ the filesystem is exported for both reading and writing to any Internet host.ST_EXPORTANONβ the filesystem maps all remote accesses to the anonymous user.ST_EXKERBβ the filesystem is exported with Kerberos uid mapping.ST_EXNORESPORTβ don't enforce reserved ports (NFS).ST_EXPUBLICβ public export (WebNFS).
π¨ fields that are undefined for a particular file system are set to -1. that's the rule, periodt.
π NOTES π
some fine-print tea, bestie β:
f_flagβ thef_flagfield is the same as thef_flagsfield in the 4.3BSDstatfssystem call.f_fsidβ is defined to beunsigned longby the X/Open standard. unfortunately this is not enough space to store ourfsid_t, so we define an additionalf_fsidxfield.f_bavailβ could historically be negative (in thestatfssystem call) when the used space has exceeded the non-superuser free space. in order to comply with the X/Open standard, we have to definefsblkcnt_tas an unsigned type, so in all cases wheref_bavailwould have been negative, we set it to0. in addition we providef_bresvdwhich contains the amount of reserved blocks for the superuser, so the old value off_bavailcan be easily computed as:
old_bavail = f_bfree - f_bresvd;
π SEE ALSO π
statvfs(2)β go read it next, iykyk π
π HISTORY π
the <sys/statvfs.h> header first appeared in NetBSD 3.0. iconic debut, honestly. π
okay byeee π this page is Debian-flavored, dated February 13, 2025, and it's giving filesystem-statistics main character energy. π«Άβ¨
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 1989, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms