github.com/Jeffail/benthos/v3@v3.65.0/lib/util/disk/check_windows.go (about)

     1  //go:build windows
     2  // +build windows
     3  
     4  package disk
     5  
     6  import (
     7  	"syscall"
     8  	"unsafe"
     9  )
    10  
    11  // TotalRemaining returns the space remaining on the disk in bytes.
    12  func TotalRemaining(path string) uint64 {
    13  	var freeBytes, totalBytes, availableBytes int64
    14  
    15  	h := syscall.MustLoadDLL("kernel32.dll")
    16  	c := h.MustFindProc("GetDiskFreeSpaceExW")
    17  
    18  	c.Call(
    19  		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
    20  		uintptr(unsafe.Pointer(&freeBytes)),
    21  		uintptr(unsafe.Pointer(&totalBytes)),
    22  		uintptr(unsafe.Pointer(&availableBytes)))
    23  
    24  	return uint64(freeBytes)
    25  }