2020-07-08 14:58:09 +00:00
|
|
|
package fsutil
|
|
|
|
|
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Statfs(path string) (FsStat, error) {
|
|
|
|
var stat syscall.Statfs_t
|
|
|
|
if err := syscall.Statfs(path, &stat); err != nil {
|
|
|
|
return FsStat{}, xerrors.Errorf("statfs: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-08-20 04:49:10 +00:00
|
|
|
// force int64 to handle platform specific differences
|
|
|
|
//nolint:unconvert
|
2020-07-08 14:58:09 +00:00
|
|
|
return FsStat{
|
2021-02-18 15:44:34 +00:00
|
|
|
Capacity: int64(stat.Blocks) * int64(stat.Bsize),
|
|
|
|
|
|
|
|
Available: int64(stat.Bavail) * int64(stat.Bsize),
|
|
|
|
FSAvailable: int64(stat.Bavail) * int64(stat.Bsize),
|
2020-07-08 14:58:09 +00:00
|
|
|
}, nil
|
|
|
|
}
|