Files
Reims-Go/internal/host/stubs_hardware_other.go
T
千川白浪 107a8d73e0 refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积 (#200)
* refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积

* fix: preserve download recovery and bound PBZX decoding

Keep VM diagnostics available during plugin initialization failures and verify settings through the unified driver lifecycle.
2026-12-05 20:54:41 +08:00

153 lines
4.6 KiB
Go

//go:build !windows
package host
import (
"fmt"
"os"
"path/filepath"
"runtime"
"syscall"
"github.com/Nwflower/reims-go/internal/i18n"
)
// Inspect returns basic host facts on non-Windows dev machines (e.g., macOS).
func Inspect(dataRoot string) Report {
displays := probeDisplays()
primary := PrimaryDisplayOf(displays)
presets, rec := RecommendDisplayPresets(primary)
return Report{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
LogicalCPUs: runtime.NumCPU(),
CPUTopology: DefaultCPUTopology(runtime.NumCPU()),
DataRoot: dataRoot,
Timezone: DetectHostTimezone(),
DeepBackingChains: InspectVMDiskChains(dataRoot),
WHPX: WHPXUnsupported,
Displays: displays,
PrimaryDisplay: primary,
RecommendedResolution: rec,
DisplayPresets: presets,
ProcessorScheduling: probeProcessorScheduling(),
Audio: ProbeAudio(),
}
}
func ConfigureVulkanDrivers() {}
// ProbeVulkanGPUs returns no adapters on hosts without Windows Vulkan probing.
func ProbeVulkanGPUs() []GPUInfo { return nil }
func SetProcessAffinityMask(pid uint32, mask uint64) error {
return fmt.Errorf("process CPU affinity is only supported on Windows (current OS: %s)", runtime.GOOS)
}
func GetProcessAffinityMask(pid uint32) (uint64, uint64, error) {
return 0, 0, fmt.Errorf("process CPU affinity is only supported on Windows (current OS: %s)", runtime.GOOS)
}
func DisableProcessPowerThrottling(pid uint32) error {
return fmt.Errorf("process power throttling control is only supported on Windows (current OS: %s)", runtime.GOOS)
}
// ProbeAudio returns a non-Windows stub audio report for dev/test hosts.
func ProbeAudio() AudioInfo {
def := "pipewire"
if runtime.GOOS == "darwin" {
def = "coreaudio"
}
return AudioInfo{OutputCount: 1, InputCount: 1, DefaultBackend: def}
}
// FreeDiskBytesAt returns (0, false) on non-Windows stubs.
func FreeDiskBytesAt(_ string) (uint64, bool) { return 0, false }
// CommitAvailGB is unknown on dev/preview hosts.
func CommitAvailGB() (float64, bool) { return 0, false }
func probeHostMemorySpec() *HostMemorySpec { return nil }
func CheckMissingLocaleFontsForUI(targetLocale string, uiLocale i18n.Locale) string { return "" }
func SampleProcessStats(pid int) (ProcessSample, error) {
return ProcessSample{}, fmt.Errorf("process stats sampling is only supported on Windows")
}
func fileActualSize(_ string, fallback uint64) uint64 { return fallback }
// ListRawPartitions returns eligible unmounted partitions or offline whole disks.
// Currently only Windows raw device passthrough is implemented.
func ListRawPartitions(dataRoot string) ([]RawDiskCandidate, error) { return nil, nil }
// Drive is a disk a data folder could go on.
type Drive struct {
Root string `json:"root"`
FreeGB float64 `json:"free_gb"`
System bool `json:"system"`
External bool `json:"external"`
VolumeGUID string `json:"volume_guid,omitempty"`
}
// ListDrives returns the home directory's volume on dev/preview hosts.
func ListDrives() []Drive {
home, err := os.UserHomeDir()
if err != nil {
return nil
}
free, _ := FreeGB(home)
return []Drive{{Root: home, FreeGB: free, System: true}}
}
// FreeGB is the free space on the volume holding path.
func FreeGB(path string) (float64, bool) {
var st syscall.Statfs_t
if err := syscall.Statfs(path, &st); err != nil {
return 0, false
}
return float64(st.Bavail) * float64(st.Bsize) / (1 << 30), true
}
func ResolveDirectoryVolume(dir string) (DirectoryVolume, error) {
if invalidDirectoryPath(dir) {
return DirectoryVolume{}, os.ErrInvalid
}
abs, err := filepath.Abs(dir)
if err != nil {
return DirectoryVolume{}, err
}
resolved, err := filepath.EvalSymlinks(abs)
if err != nil {
return DirectoryVolume{}, err
}
info, err := os.Stat(resolved)
if err != nil {
return DirectoryVolume{}, err
}
if !info.IsDir() {
return DirectoryVolume{}, os.ErrInvalid
}
return DirectoryVolume{CanonicalPath: resolved, FixedInternal: true, IsVolumeRoot: filepath.Dir(resolved) == resolved}, nil
}
// ResolveOpenDirectoryVolume verifies the path still identifies the opened directory.
func ResolveOpenDirectoryVolume(dir string, opened *os.File) (DirectoryVolume, error) {
volume, err := ResolveDirectoryVolume(dir)
if err != nil {
return DirectoryVolume{}, err
}
info, err := os.Stat(volume.CanonicalPath)
if err != nil {
return DirectoryVolume{}, err
}
openedInfo, err := opened.Stat()
if err != nil {
return DirectoryVolume{}, err
}
if !os.SameFile(info, openedInfo) {
return DirectoryVolume{}, os.ErrPermission
}
return volume, nil
}