Documentation
¶
Overview ¶
Package diskspace reports filesystem capacity for a path using a single statfs-class syscall (statfs(2) on Linux/macOS, GetDiskFreeSpaceExW on Windows). A Check call costs microseconds, so callers may poll it on a short interval or inline it on a hot path such as "before pulling an image".
It deliberately does NOT walk directories. A du-style traversal of <data-dir>/containerd is minutes of I/O on a node with hundreds of overlay snapshots and would itself become a source of load — the whole point of this helper is that asking the filesystem is free.
The per-OS implementations live in usage_unix.go, usage_windows.go and usage_unsupported.go; they were lifted from the equivalent checks in cmd/ephemerd/doctor_*.go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Usage ¶
type Usage struct {
// Path is the path that was measured (not necessarily a mount point).
Path string
// TotalBytes is the filesystem's total capacity.
TotalBytes uint64
// FreeBytes is the space available to this process.
FreeBytes uint64
}
Usage is a point-in-time capacity reading for the filesystem backing a path.
FreeBytes is the space available to the *calling user*, not the raw free count: on Linux/macOS that is statfs.Bavail (which excludes the root-reserved blocks) and on Windows it is GetDiskFreeSpaceExW's lpFreeBytesAvailable (which respects quotas). UsedBytes is therefore derived as Total-Free and counts reserved space as used — deliberately conservative, since ephemerd does not run as a user that can spend the reserve.
func Check ¶
Check returns a capacity reading for the filesystem containing path. path need not be a mount point; any existing file or directory on the filesystem works.
func (Usage) FreePercent ¶
FreePercent returns available capacity as a percentage in [0,100].
func (Usage) UsedPercent ¶
UsedPercent returns used capacity as a percentage in [0,100]. A zero-size filesystem (unreadable, or a stub value from a failed probe) reports 0 so callers never trigger garbage collection on a division artifact.