fix(unix): handle Statfs field types for disk space check (#646)
* fix(unix): handle Statfs field types for disk space check Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> * fix(freebsd): build disk space check without type mismatch Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --------- Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
25
cmd/bd/daemon_health_freebsd.go
Normal file
25
cmd/bd/daemon_health_freebsd.go
Normal file
@@ -0,0 +1,25 @@
|
||||
//go:build freebsd && !wasm
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// checkDiskSpace returns the available disk space in MB for the given path.
|
||||
// Returns (availableMB, true) on success, (0, false) on failure.
|
||||
func checkDiskSpace(path string) (uint64, bool) {
|
||||
var stat unix.Statfs_t
|
||||
if err := unix.Statfs(path, &stat); err != nil {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
if stat.Bavail < 0 {
|
||||
return 0, true
|
||||
}
|
||||
|
||||
availableBytes := uint64(stat.Bavail) * stat.Bsize //nolint:gosec
|
||||
availableMB := availableBytes / (1024 * 1024)
|
||||
|
||||
return availableMB, true
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !wasm
|
||||
//go:build !windows && !wasm && !freebsd
|
||||
|
||||
package main
|
||||
|
||||
@@ -14,8 +14,8 @@ func checkDiskSpace(path string) (uint64, bool) {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// Calculate available space in bytes, then convert to MB
|
||||
// Bavail is uint64, Bsize is int64; overflow is intentional/safe in this context
|
||||
// Calculate available space in bytes, then convert to MB.
|
||||
// On most unix platforms, Bavail is unsigned but Bsize is signed.
|
||||
availableBytes := stat.Bavail * uint64(stat.Bsize) //nolint:gosec
|
||||
availableMB := availableBytes / (1024 * 1024)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user