Skip to content

Instantly share code, notes, and snippets.

@kazuki-ma
Created August 25, 2019 12:53
Show Gist options
  • Save kazuki-ma/9c0457114e3ea0f5e249fe06b3f38471 to your computer and use it in GitHub Desktop.
Save kazuki-ma/9c0457114e3ea0f5e249fe06b3f38471 to your computer and use it in GitHub Desktop.
var (
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
procCreateServiceW = modkernel32.NewProc("GetDiskFreeSpaceW")
)
func getClusterSizeOfCurrentDirectory() (int64, error) {
var lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters int64
// cstr, _ := syscall.BytePtrFromString("C:")
_, _, errNo := syscall.Syscall6(procCreateServiceW.Addr(),
6,
0,
uintptr(unsafe.Pointer(&lpSectorsPerCluster)),
uintptr(unsafe.Pointer(&lpBytesPerSector)),
uintptr(unsafe.Pointer(&lpNumberOfFreeClusters)),
uintptr(unsafe.Pointer(&lpTotalNumberOfClusters)),
0)
if errNo != 0 {
return 0, errNo
}
return lpSectorsPerCluster * lpBytesPerSector, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment