package main
import (
"fmt"
"syscall"
)
func main() {
fmt.Println(DiskUsage("./"))
}
func DiskUsage(path string) uint64 {
fs := syscall.Statfs_t{}
err := syscall.Statfs(path, &fs)
if err != nil {
return 0
}
return fs.Bfree * uint64(fs.Bsize)
}
import (
"fmt"
"syscall"
)
func main() {
fmt.Println(DiskUsage("./"))
}
func DiskUsage(path string) uint64 {
fs := syscall.Statfs_t{}
err := syscall.Statfs(path, &fs)
if err != nil {
return 0
}
return fs.Bfree * uint64(fs.Bsize)
}
//All space = fs.Blocks * uint64(fs.Bsize)
//Free space = fs.Bfree * uint64(fs.Bsize)
//Used space= fs.All - disk.Free
//Free space = fs.Bfree * uint64(fs.Bsize)
//Used space= fs.All - disk.Free
no ,golang's version 1.9,error:undefined: syscall.Statvfs_t
回复删除