From 66fc81d36d7e2cd33fa77189199782e278a07869 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 3 Dec 2013 14:45:49 +0800 Subject: [PATCH] add volume type fun for windows --- cmd/helper_windows.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/helper_windows.go b/cmd/helper_windows.go index da38f5919..f07dcd835 100644 --- a/cmd/helper_windows.go +++ b/cmd/helper_windows.go @@ -20,6 +20,38 @@ func makeLink(srcPath, destPath string) error { return com.CopyDir(srcPath, destPath) } +func volumnType(dir string) string { + pd := dir[:3] + dll := syscall.MustLoadDLL("kernel32.dll") + GetVolumeInformation := dll.MustFindProc("GetVolumeInformationW") + + var volumeNameSize uint32 = 260 + var nFileSystemNameSize, lpVolumeSerialNumber uint32 + var lpFileSystemFlags, lpMaximumComponentLength uint32 + var lpFileSystemNameBuffer, volumeName [260]byte + var ps *uint16 = syscall.StringToUTF16Ptr(pd) + + _, _, _ = GetVolumeInformation.Call(uintptr(unsafe.Pointer(ps)), + uintptr(unsafe.Pointer(&volumeName)), + uintptr(volumeNameSize), + uintptr(unsafe.Pointer(&lpVolumeSerialNumber)), + uintptr(unsafe.Pointer(&lpMaximumComponentLength)), + uintptr(unsafe.Pointer(&lpFileSystemFlags)), + uintptr(unsafe.Pointer(&lpFileSystemNameBuffer)), + uintptr(unsafe.Pointer(&nFileSystemNameSize)), 0) + + var bytes []byte + if lpFileSystemNameBuffer[6] == 0 { + bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2], + lpFileSystemNameBuffer[4]} + } else { + bytes = []byte{lpFileSystemNameBuffer[0], lpFileSystemNameBuffer[2], + lpFileSystemNameBuffer[4], lpFileSystemNameBuffer[6]} + } + + return string(bytes) +} + func getWindowsVersion() int { dll := syscall.MustLoadDLL("kernel32.dll") p := dll.MustFindProc("GetVersion")