disk_windows.go 758 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package stats
  2. import (
  3. "github.com/seaweedfs/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. calculateDiskRemaining(disk)
  36. return
  37. }