mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-12-11 15:59:06 +08:00
27 lines
452 B
Go
27 lines
452 B
Go
|
// +build !windows
|
||
|
|
||
|
package stats
|
||
|
|
||
|
import (
|
||
|
"syscall"
|
||
|
)
|
||
|
|
||
|
type DiskStatus struct {
|
||
|
All uint64 `json:"all"`
|
||
|
Used uint64 `json:"used"`
|
||
|
Free uint64 `json:"free"`
|
||
|
}
|
||
|
|
||
|
func DiskUsage(path string) (disk *DiskStatus) {
|
||
|
disk = &DiskStatus{}
|
||
|
fs := syscall.Statfs_t{}
|
||
|
err := syscall.Statfs(path, &fs)
|
||
|
if err != nil {
|
||
|
return
|
||
|
}
|
||
|
disk.All = fs.Blocks * uint64(fs.Bsize)
|
||
|
disk.Free = fs.Bfree * uint64(fs.Bsize)
|
||
|
disk.Used = disk.All - disk.Free
|
||
|
return
|
||
|
}
|