mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-04-24 03:11:21 +08:00
28 lines
437 B
Go
28 lines
437 B
Go
// +build !windows
|
|
|
|
package stats
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
type DiskStatus struct {
|
|
Dir string
|
|
All uint64
|
|
Used uint64
|
|
Free uint64
|
|
}
|
|
|
|
func NewDiskStatus(path string) (disk *DiskStatus) {
|
|
disk = &DiskStatus{Dir: path}
|
|
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
|
|
}
|