github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/lib/diskusage/diskusage_unix.go (about) 1 //go:build aix || android || darwin || dragonfly || freebsd || ios || linux 2 3 package diskusage 4 5 import ( 6 "golang.org/x/sys/unix" 7 ) 8 9 // New returns the disk status for dir. 10 // 11 // May return Unsupported error if it doesn't work on this platform. 12 func New(dir string) (info Info, err error) { 13 var statfs unix.Statfs_t 14 err = unix.Statfs(dir, &statfs) 15 if err != nil { 16 return info, err 17 } 18 // Note that these can be different sizes on different OSes so 19 // we upcast them all to uint64 20 //nolint:unconvert 21 info.Free = uint64(statfs.Bfree) * uint64(statfs.Bsize) 22 //nolint:unconvert 23 info.Available = uint64(statfs.Bavail) * uint64(statfs.Bsize) 24 //nolint:unconvert 25 info.Total = uint64(statfs.Blocks) * uint64(statfs.Bsize) 26 return info, nil 27 }