diff --git a/internal/disk/usage_default.go b/internal/disk/usage_default.go index 68b4ab53..748bc176 100644 --- a/internal/disk/usage_default.go +++ b/internal/disk/usage_default.go @@ -1,4 +1,4 @@ -//go:build !windows +//go:build !windows && !openbsd package disk @@ -11,6 +11,9 @@ func Usage(p string) (free, total uint64, err error) { if err := unix.Statfs(p, &stat); err != nil { return 0, 0, err } + // Linux-based systems and Darwin use bfree and blocks to represent the + // number of free and total blocks in the filesystem. Multiplying by f_bsize + // converts that to the number of free and total bytes of a filesystem. return stat.Bfree * uint64(stat.Bsize), stat.Blocks * uint64(stat.Bsize), nil } diff --git a/internal/disk/usage_openbsd.go b/internal/disk/usage_openbsd.go new file mode 100644 index 00000000..8411fc7e --- /dev/null +++ b/internal/disk/usage_openbsd.go @@ -0,0 +1,23 @@ +//go:build openbsd + +package disk + +import "golang.org/x/sys/unix" + +// Usage returns the free and total bytes on the filesystem containing the +// specified path. +func Usage(p string) (free, total uint64, err error) { + var stat unix.Statfs_t + if err := unix.Statfs(p, &stat); err != nil { + return 0, 0, err + } + // OpenBSD uses f_bfree and f_blocks to represent the number of free and + // total blocks in the filesystem. Multiplying by f_bsize converts that to + // the number of free and total bytes of a filesystem. + return stat.F_bfree * uint64(stat.F_bsize), stat.F_blocks * uint64(stat.F_bsize), nil +} + +// Drives returns the paths of all drives on Windows. It is a no-op on other systems +func Drives() ([]string, error) { + return nil, nil +}