From d32ca586552691da5f2605f48183b0a1d08cf598 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Fri, 3 Apr 2026 14:14:20 +0800 Subject: [PATCH 1/2] Fix file not found when unmounting with absolute path --- src/windows/common/WslClient.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/windows/common/WslClient.cpp b/src/windows/common/WslClient.cpp index e1f3a0f1f..c31880f9b 100644 --- a/src/windows/common/WslClient.cpp +++ b/src/windows/common/WslClient.cpp @@ -1218,9 +1218,8 @@ int Unmount(_In_ const std::wstring& arg) wsl::windows::common::SvcComm service; const HRESULT result = wil::ResultFromException([&] { value = service.DetachDisk(disk); }); - // support relative paths in unmount - // check is the result is the error code for "file not found" and the path is relative - if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) && PathIsRelative(disk)) + // Retry with the normalized path to handle relative paths and \\?\ prefix mismatches. + if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { // retry dismounting with the absolute path const auto absoluteDisk = wsl::windows::common::filesystem::GetFullPath(filesystem::UnquotePath(disk).c_str()); From a54d67a6e4e96d33d3cffc6e17adfda5751f10b2 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Tue, 7 Apr 2026 13:26:33 +0800 Subject: [PATCH 2/2] Add unit test --- test/windows/MountTests.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/windows/MountTests.cpp b/test/windows/MountTests.cpp index 00447a062..8722bae62 100644 --- a/test/windows/MountTests.cpp +++ b/test/windows/MountTests.cpp @@ -450,6 +450,29 @@ class MountTests VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--unmount " + absolutePath.wstring()), (DWORD)0); } + TEST_METHOD(AbsolutePathVhdUnmountAfterVMTimeout) + { + SKIP_UNSUPPORTED_ARM64_MOUNT_TEST(); + WSL2_TEST_ONLY(); + + WslKeepAlive keepAlive; + + VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--mount " TEST_MOUNT_VHD L" --vhd --bare"), (DWORD)0); + + const auto disk = GetBlockDeviceInWsl(); + VERIFY_IS_TRUE(IsBlockDevicePresent(disk)); + + WaitForVmTimeout(keepAlive); + + const auto absolutePath = std::filesystem::absolute(TEST_MOUNT_VHD); + + // Validate that the vhd path doesn't start with '\\?' + VERIFY_IS_FALSE(absolutePath.wstring().starts_with(L"\\")); + + // Validate the unmounting by absolute path is successful + VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"--unmount " + absolutePath.wstring()), (DWORD)0); + } + // Attach a disk, but don't mount it TEST_METHOD(TestBareMount) {