From 39a5ae6d3681e55acb23586f063321242065554f Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Wed, 1 May 2024 12:48:42 +0100 Subject: [PATCH] [core] fix "drive cannot find the sector requested" when writing VHDs * As opposed to the ERROR_HANDLE_EOF we get when reading sectors from the VHD file directly, now that we mount VHD/VHDX for reading, and access them as regular disks, we also need to process ERROR_SECTOR_NOT_FOUND as an indicator for the end of the drive. * Also switch to using GetOverlappedResultEx() with a timeout since we no longer have to cater for Windows 7. * Closes #2468. --- src/rufus.rc | 10 +++++----- src/winio.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/rufus.rc b/src/rufus.rc index 18f77096..da315559 100644 --- a/src/rufus.rc +++ b/src/rufus.rc @@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL IDD_DIALOG DIALOGEX 12, 12, 232, 326 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_ACCEPTFILES -CAPTION "Rufus 4.5.2154" +CAPTION "Rufus 4.5.2155" FONT 9, "Segoe UI Symbol", 400, 0, 0x0 BEGIN LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP @@ -397,8 +397,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 4,5,2154,0 - PRODUCTVERSION 4,5,2154,0 + FILEVERSION 4,5,2155,0 + PRODUCTVERSION 4,5,2155,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -416,13 +416,13 @@ BEGIN VALUE "Comments", "https://rufus.ie" VALUE "CompanyName", "Akeo Consulting" VALUE "FileDescription", "Rufus" - VALUE "FileVersion", "4.5.2154" + VALUE "FileVersion", "4.5.2155" VALUE "InternalName", "Rufus" VALUE "LegalCopyright", "� 2011-2024 Pete Batard (GPL v3)" VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" VALUE "OriginalFilename", "rufus-4.5.exe" VALUE "ProductName", "Rufus" - VALUE "ProductVersion", "4.5.2154" + VALUE "ProductVersion", "4.5.2155" END END BLOCK "VarFileInfo" diff --git a/src/winio.h b/src/winio.h index 6213721b..00782808 100644 --- a/src/winio.h +++ b/src/winio.h @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Windows I/O redefinitions, that would be totally unnecessary had * Microsoft done a proper job with their asynchronous APIs. -* Copyright © 2021 Pete Batard +* Copyright © 2021-2024 Pete Batard * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -165,10 +165,10 @@ static __inline BOOL GetSizeAsync(HANDLE h, LPDWORD lpNumberOfBytes) SetLastError(ERROR_NO_MORE_ITEMS); return FALSE; } - // TODO: Use a timeout and call GetOverlappedResultEx() on Windows 8 and later - if (!GetOverlappedResult(fd->hFile, (OVERLAPPED*)&fd->Overlapped, - lpNumberOfBytes, (fd->iStatus < 0))) - return (GetLastError() == ERROR_HANDLE_EOF); + if (!GetOverlappedResultEx(fd->hFile, (OVERLAPPED*)&fd->Overlapped, + lpNumberOfBytes, WRITE_TIMEOUT, (fd->iStatus < 0))) + // When reading from VHD/VHDX we get SECTOR_NOT_FOUND rather than EOF for the end of the drive + return (GetLastError() == ERROR_HANDLE_EOF || GetLastError() == ERROR_SECTOR_NOT_FOUND); fd->Overlapped.Offset += *lpNumberOfBytes; fd->Overlapped.bOffsetUpdated = TRUE; return TRUE;