mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-14 09:14:10 +00:00
502bee9a09
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3332
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
// Copyright (C) 2016 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
// +build windows
|
|
|
|
package osutil
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func GetFilesystemRoots() ([]string, error) {
|
|
kernel32, err := syscall.LoadDLL("kernel32.dll")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
getLogicalDriveStringsHandle, err := kernel32.FindProc("GetLogicalDriveStringsA")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
buffer := [1024]byte{}
|
|
bufferSize := uint32(len(buffer))
|
|
|
|
hr, _, _ := getLogicalDriveStringsHandle.Call(uintptr(unsafe.Pointer(&bufferSize)), uintptr(unsafe.Pointer(&buffer)))
|
|
if hr == 0 {
|
|
return nil, fmt.Errorf("Syscall failed")
|
|
}
|
|
|
|
var drives []string
|
|
parts := bytes.Split(buffer[:], []byte{0})
|
|
for _, part := range parts {
|
|
if len(part) == 0 {
|
|
break
|
|
}
|
|
drives = append(drives, string(part))
|
|
}
|
|
|
|
return drives, nil
|
|
}
|