Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/windows: GetDriveType should call "GetDriveTypeW" #23121

Closed
zosmac opened this issue Dec 13, 2017 · 1 comment
Closed

x/sys/windows: GetDriveType should call "GetDriveTypeW" #23121

zosmac opened this issue Dec 13, 2017 · 1 comment
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@zosmac
Copy link

zosmac commented Dec 13, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.9.2 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
uname -a
Darwin [elided.com] 17.3.0 Darwin Kernel Version 17.3.0: Thu Nov 9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64

What did you do?

// getdrivetype project main.go
package main

import (
	"fmt"
	"path/filepath"
	"unsafe"

	"golang.org/x/sys/windows"
)

var (
	modkernel32      = windows.NewLazySystemDLL("kernel32.dll")
	procGetDriveType = modkernel32.NewProc("GetDriveTypeW")
)

func main() {
	path, _ := filepath.Abs(".")
	wpath, _ := windows.UTF16PtrFromString(path)
	wvolume := make([]uint16, len(path)+1)
	if err := windows.GetVolumePathName(wpath, &wvolume[0], uint32(len(wvolume))); err != nil {
		fmt.Println(err)
		return
	}
	volume := windows.UTF16ToString(wvolume)

	dtp, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(&wvolume[0])))
	fmt.Printf("path: %s volume: %s type: %s\n", path, volume, driveType(uint32(dtp)))

	dt32 := windows.GetDriveType(&wvolume[0])
	fmt.Printf("drive type for %s is %s\n", path, driveType(dt32))
}

func driveType(dt uint32) string {
	switch dt {
	case windows.DRIVE_CDROM:
		return "cd-rom"
	case windows.DRIVE_FIXED:
		return "fixed"
	case windows.DRIVE_NO_ROOT_DIR:
		return "no-root-dir"
	case windows.DRIVE_RAMDISK:
		return "ram-disk"
	case windows.DRIVE_REMOTE:
		return "remote"
	case windows.DRIVE_REMOVABLE:
		return "removable"
	case windows.DRIVE_UNKNOWN:
		return "unknown"
	}
	return "unrecognized"
}

What did you expect to see?

path: c:\Users\zosmac volume: c:\ type: fixed
path: c:\Users\zosmac volume: c:\ type: fixed

What did you see instead?

c:\Users\zosmac>u:\bin\getdrivetype.exe
path: c:\Users\zosmac volume: c:\ type: fixed
panic: Failed to find GetDriveType procedure in kernel32.dll: The specified procedure could not be found.

goroutine 1 [running]:
golang.org/x/sys/windows.(*LazyProc).mustFind(0xc04206bc80)
        /Users/zosmac/go/src/golang.org/x/sys/windows/dll_windows.go:286 +0x5f
golang.org/x/sys/windows.(*LazyProc).Addr(0xc04206bc80, 0x4d977c)
        /Users/zosmac/go/src/golang.org/x/sys/windows/dll_windows.go:294 +0x32
golang.org/x/sys/windows.GetDriveType(0xc04200a460, 0x1d)
        /Users/zosmac/go/src/golang.org/x/sys/windows/zsyscall_windows.go:1965 +0x34
main.main()
        /Users/zosmac/go/src/tests/getdrivetype/main.go:30 +0x341
@bradfitz bradfitz changed the title windows.GetDriveType should call "GetDriveTypeW" x/sys/windows: GetDriveType should call "GetDriveTypeW" Dec 13, 2017
@gopherbot gopherbot added this to the Unreleased milestone Dec 13, 2017
@bradfitz bradfitz added help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows labels Dec 13, 2017
@gopherbot
Copy link

Change https://golang.org/cl/83855 mentions this issue: windows: make GetDriveType use GetDriveTypeW

@golang golang locked and limited conversation to collaborators Dec 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

3 participants