2020-09-28 23:29:04 +02:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2021-02-26 23:37:07 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
2020-09-28 23:29:04 +02:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2021-02-26 23:37:07 +01:00
|
|
|
func mustGetFreeSpace(path string) uint64 {
|
|
|
|
d, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
|
|
|
}
|
|
|
|
defer MustClose(d)
|
|
|
|
|
|
|
|
fd := d.Fd()
|
|
|
|
var stat unix.Statfs_t
|
|
|
|
if err := unix.Fstatfs(int(fd), &stat); err != nil {
|
|
|
|
logger.Panicf("FATAL: cannot determine free disk space on %q: %s", path, err)
|
|
|
|
}
|
|
|
|
return freeSpace(stat)
|
|
|
|
}
|
|
|
|
|
2020-09-28 23:29:04 +02:00
|
|
|
func freeSpace(stat unix.Statfs_t) uint64 {
|
|
|
|
return uint64(stat.F_bavail) * uint64(stat.F_bsize)
|
|
|
|
}
|