From bd47d8efe1e3b4b7a44fc7ec315025936bf02ef6 Mon Sep 17 00:00:00 2001 From: Ayan George Date: Mon, 26 Oct 2020 05:32:04 -0400 Subject: [PATCH] fix: Type-convert fs.Bavail for portability (#19816) Prior to this patch, DiskUsage() would calculate bytes available by multiplying blocks available by block size in bytes: disk.Avail = fs.Bavail * uint64(fs.Bsize) Under some versions of Unix, fs.Bavail is of type uint64 and on others (like FreeBSD) it is of type int64. This causes a compile time error: $ go build # github.com/influxdata/influxdb/v2/pkg/fs ./fs_unix.go:81:25: invalid operation: fs.Bavail * uint64(fs.Bsize) (mismatched types int64 and uint64) This patch type-converts fs.Bavail to unit64 to ensure that all types in the expression align. This prevents compile time errors under FreeBSD and other platforms where fs.Bavail isn't uint64. --- pkg/fs/fs_unix.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/fs/fs_unix.go b/pkg/fs/fs_unix.go index 43bbf2b376..82143b01c3 100644 --- a/pkg/fs/fs_unix.go +++ b/pkg/fs/fs_unix.go @@ -71,14 +71,14 @@ func CreateFile(newpath string) (*os.File, error) { // DiskUsage returns disk usage of disk of path func DiskUsage(path string) (*DiskStatus, error) { - var disk DiskStatus fs := unix.Statfs_t{} - err := unix.Statfs(path, &fs) - if err != nil { + if err := unix.Statfs(path, &fs); err != nil { return nil, err } + + var disk DiskStatus disk.All = fs.Blocks * uint64(fs.Bsize) - disk.Avail = fs.Bavail * uint64(fs.Bsize) + disk.Avail = uint64(fs.Bavail) * uint64(fs.Bsize) disk.Free = fs.Bfree * uint64(fs.Bsize) disk.Used = disk.All - disk.Free return &disk, nil