diff --git a/frontend/src/components/SettingsModal.tsx b/frontend/src/components/SettingsModal.tsx index 6416d9f..1f97612 100644 --- a/frontend/src/components/SettingsModal.tsx +++ b/frontend/src/components/SettingsModal.tsx @@ -690,7 +690,7 @@ export const SettingsModal: React.FC = ({ locale, detail, driverID, stats locale={locale} value={(form.disk_cache as DiskCache) || 'default'} dirty={dirty('disk_cache')} - disabled={!diskCacheSupported} + supported={diskCacheSupported} reason={tr('diskCacheRequiresRuntime')} onReset={reset('disk_cache')} resetLabel={tr('resetField')} diff --git a/frontend/src/components/vmSettings/disk.tsx b/frontend/src/components/vmSettings/disk.tsx index ed1c587..d3c7e6d 100644 --- a/frontend/src/components/vmSettings/disk.tsx +++ b/frontend/src/components/vmSettings/disk.tsx @@ -20,7 +20,7 @@ interface DiskOptions { function isWindowsRawDevicePath(disk?: string): boolean { const s = (disk ?? '').trim().replace(/\//g, '\\') - return /^\\\\[.?]\\(physicaldrive|harddiskvolume|harddisk|volume\{)/i.test(s) + return /^\\\\\.\\(physicaldrive|harddiskvolume|harddisk|volume\{)|^\\\\\?\\volume\{/i.test(s) } /** Resizing, compacting and optimizing the VM's disk, one at a time. */ diff --git a/frontend/src/components/vmSettings/diskCache.tsx b/frontend/src/components/vmSettings/diskCache.tsx index 57ddb66..a20056e 100644 --- a/frontend/src/components/vmSettings/diskCache.tsx +++ b/frontend/src/components/vmSettings/diskCache.tsx @@ -7,7 +7,7 @@ interface Props { locale: Locale value: DiskCache dirty: boolean - disabled?: boolean + supported?: boolean reason?: string onReset: () => void resetLabel: string @@ -15,21 +15,26 @@ interface Props { onChange: (cache: DiskCache) => void } -export const DiskCacheRow: React.FC = ({ locale, value, dirty, disabled = false, reason, onReset, resetLabel, error, onChange }) => { +export const DiskCacheRow: React.FC = ({ locale, value, dirty, supported = true, reason, onReset, resetLabel, error, onChange }) => { const tr = (k: I18nKey, v?: Record) => t(locale, k, v) - const desc = value === 'writeback' + const baseDesc = value === 'writeback' ? tr('diskCacheDescWriteback') : value === 'none' ? tr('diskCacheDescNone') : value === 'unsafe' ? tr('diskCacheDescUnsafe') : tr('diskCacheDescDefault') + const rowDisabled = !supported && value === 'default' + const disableNonDefault = !supported + const desc = !supported && value !== 'default' && reason + ? `${baseDesc} ยท ${reason}` + : baseDesc return ( = ({ locale, value, dirty, disabled = onChange={onChange} options={[ { value: 'default', label: tr('diskCacheOptionDefault') }, - { value: 'writeback', label: tr('diskCacheOptionWriteback') }, - { value: 'none', label: tr('diskCacheOptionNone') }, - { value: 'unsafe', label: tr('diskCacheOptionUnsafe') }, + { value: 'writeback', label: tr('diskCacheOptionWriteback'), disabled: disableNonDefault }, + { value: 'none', label: tr('diskCacheOptionNone'), disabled: disableNonDefault }, + { value: 'unsafe', label: tr('diskCacheOptionUnsafe'), disabled: disableNonDefault }, ]} /> } diff --git a/internal/app/create_flow.go b/internal/app/create_flow.go index e54cc68..35fda23 100644 --- a/internal/app/create_flow.go +++ b/internal/app/create_flow.go @@ -44,6 +44,15 @@ func (a *App) createVMFlow(opts reims.CreateOpts) (err error) { if err != nil { return err } + if !active.Manifest.HasCapability("win32-native-aio") { + loc := i18n.EffectiveLocale(cfgCopy.Locale) + if dcache := strings.TrimSpace(opts.DiskCache); dcache != "" && !strings.EqualFold(dcache, "default") { + return errors.New(i18n.T(loc, "validate.disk_cache_requires_runtime")) + } + if reims.IsWindowsRawDevicePath(opts.Disk) { + return errors.New(i18n.T(loc, "validate.raw_disk_requires_runtime")) + } + } c := reims.NewClient(&cfgCopy, *active) // Always defer starting to StartVM so commit-memory checks, Win10 cold-reboot diff --git a/internal/cli/cli.go b/internal/cli/cli.go index dc836d8..b65e672 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -529,8 +529,8 @@ func vmCreate(ctx context.Context, cfg *config.Config, loc i18n.Locale, args []s if err != nil { return err } - if strings.TrimSpace(*disk) != "" || strings.TrimSpace(*diskMode) != "" { - return fmt.Errorf("--disk and --disk-mode are only supported by the %s driver", driver.BuiltinReimsMacOSDriverID) + if strings.TrimSpace(*disk) != "" || strings.TrimSpace(*diskMode) != "" || strings.TrimSpace(*diskCache) != "" { + return fmt.Errorf("--disk, --disk-mode, and --disk-cache are only supported by the %s driver", driver.BuiltinReimsMacOSDriverID) } req := driver.CreateRequest{ DriverID: drv.ID(), @@ -542,9 +542,6 @@ func vmCreate(ctx context.Context, cfg *config.Config, loc i18n.Locale, args []s "disk_size": *diskSize, }, } - if *diskCache != "" { - req.Options["disk_cache"] = *diskCache - } if issues := drv.ValidateCreate(ctx, req); len(issues) > 0 { return fmt.Errorf("%s", issues[0].Message) } diff --git a/internal/host/rawdisk_test.go b/internal/host/rawdisk_test.go index b7ca193..4d7aa03 100644 --- a/internal/host/rawdisk_test.go +++ b/internal/host/rawdisk_test.go @@ -98,3 +98,13 @@ func TestApplyPartitionExtentMatches(t *testing.T) { t.Fatalf("expected only clean APFS candidate, got %+v", got) } } + +func TestInspectDiskUsageSkipsRawDevice(t *testing.T) { + du, err := InspectDiskUsage(`\\.\Harddisk1Partition2`) + if err != nil { + t.Fatalf("InspectDiskUsage on raw device returned error: %v", err) + } + if du.Format != "raw" || du.Path != `\\.\Harddisk1Partition2` { + t.Fatalf("unexpected DiskUsage for raw device: %+v", du) + } +} diff --git a/internal/host/stats.go b/internal/host/stats.go index 7615319..11206db 100644 --- a/internal/host/stats.go +++ b/internal/host/stats.go @@ -76,6 +76,9 @@ func ComputeCPUPercent(prev, cur ProcessSample, logicalCPUs int) float64 { // InspectDiskUsage returns actual host bytes consumed and virtual logical capacity // for a .qcow2 or raw disk image without spawning qemu-img. func InspectDiskUsage(path string) (DiskUsage, error) { + if IsWindowsRawDevicePath(path) { + return DiskUsage{Path: path, Format: "raw"}, nil + } info, err := os.Stat(path) if err != nil { return DiskUsage{}, err diff --git a/internal/macos/reims/cow_guard.go b/internal/macos/reims/cow_guard.go index 854fd49..742aeb1 100644 --- a/internal/macos/reims/cow_guard.go +++ b/internal/macos/reims/cow_guard.go @@ -247,7 +247,11 @@ func (c *Client) createWithDisk(ctx context.Context, o CreateOpts, args []string } defer release() - switch o.DiskMode { + mode := strings.ToLower(strings.TrimSpace(o.DiskMode)) + if mode == "" && IsWindowsRawDevicePath(disk) { + mode = "in-place" + } + switch mode { case "in-place", "inplace", "link": default: // reims-ctl may copy a large image. Its source and backing files are