2020-06-02 16:52:16 +08:00
|
|
|
package stats
|
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
2020-06-02 16:52:16 +08:00
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
"syscall"
|
|
|
|
"unsafe"
|
|
|
|
)
|
2020-06-06 06:27:10 +08:00
|
|
|
|
2020-06-02 16:52:16 +08:00
|
|
|
var (
|
|
|
|
kernel32 = windows.NewLazySystemDLL("Kernel32.dll")
|
|
|
|
getDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW")
|
|
|
|
)
|
|
|
|
|
|
|
|
func fillInDiskStatus(disk *volume_server_pb.DiskStatus) {
|
|
|
|
|
|
|
|
ptr, err := syscall.UTF16PtrFromString(disk.Dir)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var _temp uint64
|
|
|
|
/* #nosec */
|
|
|
|
r, _, e := syscall.Syscall6(
|
|
|
|
getDiskFreeSpaceEx.Addr(),
|
|
|
|
4,
|
|
|
|
uintptr(unsafe.Pointer(ptr)),
|
|
|
|
uintptr(unsafe.Pointer(&disk.Free)),
|
|
|
|
uintptr(unsafe.Pointer(&disk.All)),
|
|
|
|
uintptr(unsafe.Pointer(&_temp)),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
|
|
|
|
if r == 0 {
|
|
|
|
if e != 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
disk.Used = disk.All - disk.Free
|
|
|
|
disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100)
|
|
|
|
disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|