diff --git a/fstat/fstat.go b/fstat/fstat.go index 39be4a8..bf3d7bd 100644 --- a/fstat/fstat.go +++ b/fstat/fstat.go @@ -11,8 +11,8 @@ func (fs FilesystemStat) Used() uint64 { return (fs.Blocks - fs.Bavail) * uint64(fs.Bsize) } -// Free returns the number of bytes available to a non-privileged user. -func (fs FilesystemStat) Free() uint64 { +// Available returns the number of bytes available to a non-privileged user. +func (fs FilesystemStat) Available() uint64 { return fs.Bavail * uint64(fs.Bsize) } diff --git a/fstat/fstat_test.go b/fstat/fstat_test.go index 6d245fc..4afd549 100644 --- a/fstat/fstat_test.go +++ b/fstat/fstat_test.go @@ -7,7 +7,7 @@ import ( ) func TestFilesystemStat(t *testing.T) { - t.Run("FreeTotalUsed", func(t *testing.T) { + t.Run("AvailableTotalUsed", func(t *testing.T) { fs := FilesystemStat(unix.Statfs_t{ Ffree: 200, // total free disk space Bavail: 100, // free disk space accessible by a non-privileged user @@ -15,14 +15,14 @@ func TestFilesystemStat(t *testing.T) { Bsize: 1024, }) - if want := uint64(100 * 1024); fs.Free() != want { - t.Errorf("FilesystemStat.Free() got %d, want %d", fs.Free(), want) + if want := uint64(100 * 1024); fs.Available() != want { + t.Errorf("FilesystemStat.Available() got %d, want %d", fs.Available(), want) } if want := uint64(400 * 1024); fs.Total() != want { - t.Errorf("FilesystemStat.Total() got %d, want %d", fs.Free(), want) + t.Errorf("FilesystemStat.Total() got %d, want %d", fs.Total(), want) } if want := uint64((400 - 100) * 1024); fs.Used() != want { - t.Errorf("FilesystemStat.Used() got %d, want %d", fs.Free(), want) + t.Errorf("FilesystemStat.Used() got %d, want %d", fs.Used(), want) } }) t.Run("HasReachedLimit", func(t *testing.T) { diff --git a/usage/usage.go b/usage/usage.go index 36aebb6..70f2bfe 100644 --- a/usage/usage.go +++ b/usage/usage.go @@ -96,7 +96,7 @@ func checkDiskUsage(basedir string, limit uint64) (Report, error) { if fstat.HasReachedLimit(limit) { r.Limits = append(r.Limits, Stats{ Path: file.Name(), - Free: fstat.Free(), + Free: fstat.Available(), Used: fstat.Used(), Total: fstat.Total(), })