[core] fix format error when trying to use old BIOS fixes with VHDs

* And other improvements
* Closes #1409
This commit is contained in:
Pete Batard 2020-07-03 15:24:37 +01:00
parent 0dc13e5283
commit 500172a7a3
No known key found for this signature in database
GPG Key ID: 38E0CF5E69EDD671
6 changed files with 38 additions and 15 deletions

View File

@ -22,6 +22,7 @@
#endif
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@ -507,7 +508,7 @@ BOOL RefreshLayout(DWORD DriveIndex)
*/
BOOL DeletePartitions(DWORD DriveIndex)
{
BOOL r = FALSE;
BOOL r = FALSE, bNeverFound = TRUE;
HRESULT hr;
ULONG ulFetched;
wchar_t wPhysicalName[24];
@ -642,6 +643,7 @@ BOOL DeletePartitions(DWORD DriveIndex)
IVdsDisk_Release(pDisk);
continue;
}
bNeverFound = FALSE;
// Instantiate the AdvanceDisk interface for our disk.
hr = IVdsDisk_QueryInterface(pDisk, &IID_IVdsAdvancedDisk, (void **)&pAdvancedDisk);
@ -707,6 +709,8 @@ BOOL DeletePartitions(DWORD DriveIndex)
}
out:
if (bNeverFound)
FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_PATH_NOT_FOUND;
return r;
}
@ -1354,10 +1358,6 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
return FALSE;
}
#if defined(__GNUC__)
// GCC 4.9 bugs us about the fact that MS defined an expandable array as array[1]
#pragma GCC diagnostic ignored "-Warray-bounds"
#endif
switch (DriveLayout->PartitionStyle) {
case PARTITION_STYLE_MBR:
SelectedDrive.PartitionStyle = PARTITION_STYLE_MBR;
@ -1716,8 +1716,19 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
// Go with the MS 1 MB wastage at the beginning...
DriveLayoutEx.PartitionEntry[pn].StartingOffset.QuadPart = MB;
} else {
// Align on Cylinder
DriveLayoutEx.PartitionEntry[pn].StartingOffset.QuadPart = bytes_per_track;
// Some folks appear to think that 'Fixes for old BIOSes' is some kind of magic
// wand and are adamant to try to apply them when creating *MODERN* VHD drives.
// This, however, wrecks havok on MS' internal format calls because, as opposed
// to what is the case for regular drives, VHDs require each cluster block to
// be aligned to the cluster size, and that may not be the case with the stupid
// CHS sizes that IBM imparted upon us. Long story short, we now align to a
// cylinder size that is itself aligned to the cluster size.
// If this actually breaks old systems, please send your complaints to IBM.
LONGLONG ClusterSize = (LONGLONG)ComboBox_GetItemData(hClusterSize, ComboBox_GetCurSel(hClusterSize));
if (ClusterSize == 0)
ClusterSize = 0x200;
DriveLayoutEx.PartitionEntry[pn].StartingOffset.QuadPart =
((bytes_per_track + (ClusterSize - 1)) / ClusterSize) * ClusterSize;
}
// If required, set the MSR partition (GPT only - must be created before the data part)

View File

@ -181,8 +181,12 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command,
uprintf("No media in drive");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NO_MEDIA_IN_DRIVE;
break;
case FCC_ALIGNMENT_VIOLATION:
uprintf("Partition start offset is not aligned to the cluster size");
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OFFSET_ALIGNMENT_VIOLATION;
break;
default:
uprintf("FormatExCallback: Received unhandled command 0x02%X - aborting", Command);
uprintf("FormatExCallback: Received unhandled command 0x%02X - aborting", Command);
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_SUPPORTED;
break;
}

View File

@ -22,7 +22,7 @@
#pragma once
/* Callback command types (some errorcode were filled from HPUSBFW V2.2.3 and their
designation from msdn.microsoft.com/en-us/library/windows/desktop/aa819439.aspx */
designation from docs.microsoft.com/windows/win32/api/vds/nf-vds-ivdsvolumemf2-formatex */
typedef enum {
FCC_PROGRESS,
FCC_DONE_WITH_STRUCTURE,
@ -57,6 +57,11 @@ typedef enum {
FCC_UNKNOWN1E,
FCC_UNKNOWN1F,
FCC_READ_ONLY_MODE,
FCC_UNKNOWN21,
FCC_UNKNOWN22,
FCC_UNKNOWN23,
FCC_UNKNOWN24,
FCC_ALIGNMENT_VIOLATION,
} FILE_SYSTEM_CALLBACK_COMMAND;
typedef struct {

View File

@ -118,6 +118,9 @@ static __inline void *_reallocf(void *ptr, size_t size) {
#ifndef HTTP_PROTOCOL_FLAG_HTTP2
#define HTTP_PROTOCOL_FLAG_HTTP2 2
#endif
#ifndef ERROR_OFFSET_ALIGNMENT_VIOLATION
#define ERROR_OFFSET_ALIGNMENT_VIOLATION 327
#endif
/* The following is used for native ISO mounting in Windows 8 or later */
#define VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT \

View File

@ -2230,7 +2230,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA
// Try to reselect current FS from the drive for non-bootable
tmp[0] = 0;
if ((selected_fs == FS_UNKNOWN) && (SelectedDrive.DeviceNumber != 0))
GetDrivePartitionData(SelectedDrive.DeviceNumber, tmp, sizeof(tmp), TRUE);
GetDrivePartitionData(SelectedDrive.DeviceNumber, tmp, sizeof(tmp), !usb_debug);
SetFileSystemAndClusterSize(tmp);
ToggleImageOptions();
SetProposedLabel(ComboBox_GetCurSel(hDeviceList));

View File

@ -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 3.12.1686"
CAPTION "Rufus 3.12.1687"
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 3,12,1686,0
PRODUCTVERSION 3,12,1686,0
FILEVERSION 3,12,1687,0
PRODUCTVERSION 3,12,1687,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", "3.12.1686"
VALUE "FileVersion", "3.12.1687"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.12.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.12.1686"
VALUE "ProductVersion", "3.12.1687"
END
END
BLOCK "VarFileInfo"