The Moving Parts
Outcome: when duf surprises you — a filesystem missing, a number that differs from df's — you can say which part produced the surprise. Duf is one binary, but its work falls into five parts, and every behaviour in this guide belongs to one of them.
The mount table
The kernel keeps a list of everything
currently mounted: each entry names a
device (the storage itself), a
mount point (the folder where
that storage appears in the tree of
files), a filesystem type (btrfs,
tmpfs, overlay, and their kin), and
the options it was mounted with. On
Linux the list lives in
/proc/self/mounts. The lab machine's
list was 76 entries long — and duf's
--all view and its JSON both listed
76, which is the first check this
guide runs: duf starts from the same
list the kernel keeps, neither
inventing nor losing entries at this
stage (transcript t02).
The question: statfs
For each mount, duf asks the kernel
one question — the statfs system
call — and receives counts: how many
blocks the filesystem has, how many
are free, how many are available to
an ordinary user, the size of a
block, and the same story for
inodes (the filesystem's supply
of file slots, chapter 8). Every
number duf prints is arithmetic on
those counts. This is also exactly
what df does, which is why the two
tools can be checked against each
other byte for byte — and were, in
transcript t06.
The groups
A raw list of 76 mounts is not an answer, so duf sorts mounts into groups by what kind of thing they are:
- local — storage attached to this machine: disks, partitions, volumes.
- network — filesystems served by another machine (NFS, Samba and their kin).
- special — the system's own housekeeping: memory filesystems, kernel interfaces, and other mounts that are not really "disks" at all.
- fuse, loops and binds — three more categories duf names for filtering (filesystems in userspace, loop devices, and bind mounts, where one folder is mounted again somewhere else).
Each group gets its own table in the
output, titled with its count — 19
local devices, 34 special devices
on the lab machine. Chapters 4 and 7
work with these tables throughout.
The filter
Between the kernel's list and the
tables sits duf's least visible part:
a filter that tidies the default
view. Out of the box, duf leaves out
mounts it classes as pseudo,
duplicate, or inaccessible — the
--all flag exists to switch that
filter off ("include pseudo,
duplicate, inaccessible file
systems", in the help text's own
words). On an ordinary machine this
tidying is a kindness. On the lab
machine it was the guide's biggest
surprise: the root filesystem — the
overlay the whole system runs from —
was filtered out of the default
table, while 53 of the 76 mounts
were shown. The filter's decisions
are not announced; a missing row
looks exactly like a missing disk.
Chapter 7 shows how to see the whole
list, and chapter 14 names the empty
answer as this tool's signature trap.
The renderer
Last, the renderer draws the
tables: it chooses column widths to
fit your terminal (80 columns when
output is piped and no terminal can
be asked), wraps long mount points
rather than truncating them, drops
the usage bar when space runs out,
and colours the bar and the AVAIL
column by thresholds — green, yellow,
red — when the terminal cooperates.
Almost everything in chapter 10
(width, style, themes) is the
renderer being steered. And when you
ask for --json, the renderer is
bypassed entirely: the groups, the
filter and the colours all fall away,
and what remains is the kernel's list
and the statfs counts, as data.