disk_windows.go 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package stats
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  4. "golang.org/x/sys/windows"
  5. "syscall"
  6. "unsafe"
  7. )
  8. var (
  9. kernel32 = windows.NewLazySystemDLL("Kernel32.dll")
  10. getDiskFreeSpaceEx = kernel32.NewProc("GetDiskFreeSpaceExW")
  11. )
  12. func fillInDiskStatus(disk *volume_server_pb.DiskStatus) {
  13. ptr, err := syscall.UTF16PtrFromString(disk.Dir)
  14. if err != nil {
  15. return
  16. }
  17. var _temp uint64
  18. /* #nosec */
  19. r, _, e := syscall.Syscall6(
  20. getDiskFreeSpaceEx.Addr(),
  21. 4,
  22. uintptr(unsafe.Pointer(ptr)),
  23. uintptr(unsafe.Pointer(&disk.Free)),
  24. uintptr(unsafe.Pointer(&disk.All)),
  25. uintptr(unsafe.Pointer(&_temp)),
  26. 0,
  27. 0,
  28. )
  29. if r == 0 {
  30. if e != 0 {
  31. return
  32. }
  33. return
  34. }
  35. disk.Used = disk.All - disk.Free
  36. disk.PercentFree = float32((float64(disk.Free) / float64(disk.All)) * 100)
  37. disk.PercentUsed = float32((float64(disk.Used) / float64(disk.All)) * 100)
  38. return
  39. }