- Runtime: list and fetch runtimes from this repo's GitHub Releases (stable by default, candidate on request), with SHA256 check and resume. CLI gains `runtime available` and `runtime fetch`; the host page gets an online install row and a "receive candidates" switch. - First launch: pick a data folder (non-system drives first, USB never recommended); the choice is recorded in %APPDATA%\reims-go\location.json. Existing installs in the default folder are adopted without asking. - pack-runtime.ps1: also builds the matching source package, records every patch with its SHA256 and the channel, and refuses undeclared changes in the build trees. - patches: declare reims-vgpu-cargo-lock.patch (Cargo.lock source lines). - UI: sidebar and VM page restyle, new design tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
//go:build windows
|
|
|
|
package host
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"os"
|
|
"strings"
|
|
"syscall"
|
|
"unsafe"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
var (
|
|
procGetLogicalDrives = kernel32.NewProc("GetLogicalDrives")
|
|
procGetDriveTypeW = kernel32.NewProc("GetDriveTypeW")
|
|
)
|
|
|
|
const driveFixed = 3 // DRIVE_FIXED
|
|
|
|
// Drive is a local fixed disk a data folder could go on.
|
|
type Drive struct {
|
|
Root string `json:"root"` // `D:\`
|
|
FreeGB float64 `json:"free_gb"` // bytes available to this user
|
|
System bool `json:"system"` // holds Windows
|
|
External bool `json:"external"` // on a USB bus (Windows still calls USB disks "fixed")
|
|
}
|
|
|
|
// ListDrives returns local fixed drives (no removable, network or optical).
|
|
func ListDrives() []Drive {
|
|
mask, _, _ := procGetLogicalDrives.Call()
|
|
sys := strings.ToUpper(strings.TrimSuffix(os.Getenv("SystemDrive"), `\`))
|
|
if sys == "" {
|
|
sys = "C:"
|
|
}
|
|
var out []Drive
|
|
for i := 0; i < 26; i++ {
|
|
if mask&(1<<uint(i)) == 0 {
|
|
continue
|
|
}
|
|
root := string(rune('A'+i)) + `:\`
|
|
p, err := syscall.UTF16PtrFromString(root)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
t, _, _ := procGetDriveTypeW.Call(uintptr(unsafe.Pointer(p)))
|
|
if t != driveFixed {
|
|
continue
|
|
}
|
|
free, ok := probeFreeDiskGB(root)
|
|
if !ok {
|
|
continue
|
|
}
|
|
out = append(out, Drive{
|
|
Root: root,
|
|
FreeGB: free,
|
|
System: strings.EqualFold(root[:2], sys),
|
|
External: isUSB(root[:2]),
|
|
})
|
|
}
|
|
return out
|
|
}
|
|
|
|
// isUSB asks the volume's storage device for its bus type
|
|
// (IOCTL_STORAGE_QUERY_PROPERTY, StorageDeviceProperty). Opening with no
|
|
// access rights needs no elevation.
|
|
func isUSB(drive string) bool {
|
|
path, err := windows.UTF16PtrFromString(`\\.\` + drive)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
h, err := windows.CreateFile(path, 0, windows.FILE_SHARE_READ|windows.FILE_SHARE_WRITE, nil, windows.OPEN_EXISTING, 0, 0)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
defer windows.CloseHandle(h)
|
|
|
|
const ioctlStorageQueryProperty = 0x002D1400
|
|
const busTypeUSB = 7
|
|
// STORAGE_PROPERTY_QUERY{PropertyId: StorageDeviceProperty(0), QueryType: PropertyStandardQuery(0)}
|
|
query := make([]byte, 12)
|
|
out := make([]byte, 1024)
|
|
var n uint32
|
|
if err := windows.DeviceIoControl(h, ioctlStorageQueryProperty, &query[0], uint32(len(query)), &out[0], uint32(len(out)), &n, nil); err != nil {
|
|
return false
|
|
}
|
|
// STORAGE_DEVICE_DESCRIPTOR.BusType is the DWORD at offset 28.
|
|
if n < 32 {
|
|
return false
|
|
}
|
|
return binary.LittleEndian.Uint32(out[28:32]) == busTypeUSB
|
|
}
|
|
|
|
// FreeGB is the free space on the volume holding path.
|
|
func FreeGB(path string) (float64, bool) { return probeFreeDiskGB(path) }
|