mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[efi] add mbr UEFI marker for partition scheme reselection
* without the marker, an UFD created as MBR for UEFI will be seen as MBR for BIOS + UEFI. We want Rufus to be able to select the settings that were used for the drive creation. * Also hides #116 under the carpet and fix non RUFUS_DEBUG compilation
This commit is contained in:
parent
09b7314f98
commit
0cc39d0222
5 changed files with 35 additions and 17 deletions
17
src/drive.c
17
src/drive.c
|
@ -239,7 +239,8 @@ BOOL GetDrivePartitionData(DWORD DeviceNumber, char* FileSystemName, DWORD FileS
|
|||
}
|
||||
}
|
||||
uprintf("Partition type: MBR, NB Partitions: %d\n", nb_partitions);
|
||||
uprintf("Disk ID: 0x%08X\n", DriveLayout->Mbr.Signature);
|
||||
SelectedDrive.has_mbr_uefi_marker = (DriveLayout->Mbr.Signature == MBR_UEFI_MARKER);
|
||||
uprintf("Disk ID: 0x%08X %s\n", DriveLayout->Mbr.Signature, SelectedDrive.has_mbr_uefi_marker?"(UEFI target)":"");
|
||||
for (i=0; i<DriveLayout->PartitionCount; i++) {
|
||||
if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
|
||||
uprintf("Partition %d:\n", DriveLayout->PartitionEntry[i].PartitionNumber);
|
||||
|
@ -311,12 +312,14 @@ typedef struct _DRIVE_LAYOUT_INFORMATION_EX4 {
|
|||
|
||||
/*
|
||||
* Create a partition table
|
||||
*/
|
||||
// See http://technet.microsoft.com/en-us/library/cc739412.aspx for some background info
|
||||
* See http://technet.microsoft.com/en-us/library/cc739412.aspx for some background info
|
||||
* NB: if you modify the MBR outside of using the Windows API, Windows still uses the cached
|
||||
* copy it got from the last IOCTL, and ignore your changes until you replug the drive...
|
||||
*/
|
||||
#if !defined(PARTITION_BASIC_DATA_GUID)
|
||||
const GUID PARTITION_BASIC_DATA_GUID = { 0xebd0a0a2, 0xb9e5, 0x4433, {0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7} };
|
||||
#endif
|
||||
BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system)
|
||||
BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL mbr_uefi_marker)
|
||||
{
|
||||
const char* PartitionTypeName[2] = { "MBR", "GPT" };
|
||||
CREATE_DISK CreateDisk = {PARTITION_STYLE_RAW, {{0}}};
|
||||
|
@ -340,7 +343,11 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system)
|
|||
switch (partition_style) {
|
||||
case PARTITION_STYLE_MBR:
|
||||
CreateDisk.PartitionStyle = PARTITION_STYLE_MBR;
|
||||
CreateDisk.Mbr.Signature = GetTickCount();
|
||||
// If MBR+UEFI is selected, write an UEFI marker in lieu of the regular MBR signature.
|
||||
// This helps us reselect the partition scheme option that was used when creating the
|
||||
// drive in Rufus. As far as I can tell, Windows doesn't care much if this signature
|
||||
// isn't unique for USB drives.
|
||||
CreateDisk.Mbr.Signature = mbr_uefi_marker?MBR_UEFI_MARKER:GetTickCount();
|
||||
|
||||
DriveLayoutEx.PartitionStyle = PARTITION_STYLE_MBR;
|
||||
DriveLayoutEx.PartitionCount = 4; // Must be multiple of 4 for MBR
|
||||
|
|
|
@ -1210,7 +1210,7 @@ DWORD WINAPI FormatThread(LPVOID param)
|
|||
}
|
||||
UpdateProgress(OP_ZERO_MBR, -1.0f);
|
||||
|
||||
if (!CreatePartition(hPhysicalDrive, pt, fs)) {
|
||||
if (!CreatePartition(hPhysicalDrive, pt, fs, (pt==PARTITION_STYLE_MBR)&&(bt==BT_UEFI))) {
|
||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE;
|
||||
goto out;
|
||||
}
|
||||
|
|
10
src/rufus.c
10
src/rufus.c
|
@ -501,7 +501,7 @@ static BOOL PopulateProperties(int ComboIndex)
|
|||
uprintf("Could not populate partition scheme data\n");
|
||||
if (SelectedDrive.PartitionType == PARTITION_STYLE_GPT) {
|
||||
j = 2;
|
||||
} else if (SelectedDrive.has_protective_mbr) {
|
||||
} else if (SelectedDrive.has_protective_mbr || SelectedDrive.has_mbr_uefi_marker) {
|
||||
j = 1;
|
||||
} else {
|
||||
j = 0;
|
||||
|
@ -762,15 +762,15 @@ void UpdateProgress(int op, float percent)
|
|||
int pos;
|
||||
|
||||
if ((op < 0) || (op > OP_MAX)) {
|
||||
uprintf("UpdateProgress: invalid op %d\n", op);
|
||||
duprintf("UpdateProgress: invalid op %d\n", op);
|
||||
return;
|
||||
}
|
||||
if (percent > 100.1f) {
|
||||
uprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
|
||||
duprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
|
||||
return;
|
||||
}
|
||||
if ((percent < 0.0f) && (nb_slots[op] <= 0)) {
|
||||
uprintf("UpdateProgress(%d): error negative percentage sent for negative slot value\n", op);
|
||||
duprintf("UpdateProgress(%d): error negative percentage sent for negative slot value\n", op);
|
||||
return;
|
||||
}
|
||||
if (nb_slots[op] == 0)
|
||||
|
@ -787,7 +787,7 @@ void UpdateProgress(int op, float percent)
|
|||
pos = (int)((previous_end + ((slot_end[op+1] - previous_end) * (percent / 100.0f))) / 100.0f * MAX_PROGRESS);
|
||||
}
|
||||
if (pos > MAX_PROGRESS) {
|
||||
uprintf("UpdateProgress(%d): rounding error - pos %d is greater than %d\n", op, pos, MAX_PROGRESS);
|
||||
duprintf("UpdateProgress(%d): rounding error - pos %d is greater than %d\n", op, pos, MAX_PROGRESS);
|
||||
pos = MAX_PROGRESS;
|
||||
}
|
||||
|
||||
|
|
13
src/rufus.h
13
src/rufus.h
|
@ -45,6 +45,7 @@
|
|||
#define MAX_GUID_STRING_LENGTH 40
|
||||
#define MAX_GPT_PARTITIONS 128
|
||||
#define MAX_SECTORS_TO_CLEAR 128 // nb sectors to zap when clearing the MBR/GPT (must be >34)
|
||||
#define MBR_UEFI_MARKER 0x49464555 // 'U', 'E', 'F', 'I', as a 32 bit little endian longword
|
||||
#define PROPOSEDLABEL_TOLERANCE 0.10
|
||||
#define FS_DEFAULT FS_FAT32
|
||||
#define LARGE_FAT32_SIZE (32*1073741824LL) // Size at which we need to use fat32format
|
||||
|
@ -86,8 +87,17 @@ extern void _uprintf(const char *format, ...);
|
|||
#define uprintf(...) _uprintf(__VA_ARGS__)
|
||||
#define vuprintf(...) if (verbose) _uprintf(__VA_ARGS__)
|
||||
#define vvuprintf(...) if (verbose > 1) _uprintf(__VA_ARGS__)
|
||||
#ifdef _CRTDBG_MAP_ALLOC
|
||||
// Use the _CRTDBG as our general debug flag
|
||||
#define duprintf(...) _uprintf(__VA_ARGS__)
|
||||
#else
|
||||
#define duprintf(...)
|
||||
#endif
|
||||
#else
|
||||
#define uprintf(...)
|
||||
#define vuprintf(...)
|
||||
#define vvuprintf(...)
|
||||
#define duprintf(...)
|
||||
#endif
|
||||
|
||||
/* Custom Windows messages */
|
||||
|
@ -170,6 +180,7 @@ typedef struct {
|
|||
int PartitionType;
|
||||
int FSType;
|
||||
BOOL has_protective_mbr;
|
||||
BOOL has_mbr_uefi_marker;
|
||||
struct {
|
||||
ULONG Allowed;
|
||||
ULONG Default;
|
||||
|
@ -284,7 +295,7 @@ extern BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan);
|
|||
extern BOOL ExtractISOFile(const char* iso, const char* iso_file, const char* dest_file);
|
||||
extern BOOL InstallSyslinux(DWORD num, const char* drive_name);
|
||||
DWORD WINAPI FormatThread(void* param);
|
||||
extern BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system);
|
||||
extern BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL mbr_uefi_marker);
|
||||
extern const char* GetPartitionType(BYTE Type);
|
||||
extern BOOL GetDrivePartitionData(DWORD DeviceNumber, char* FileSystemName, DWORD FileSystemNameSize);
|
||||
extern HANDLE GetDriveHandle(DWORD DriveIndex, char* DriveLetter, BOOL bWriteAccess, BOOL bLockDrive);
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -30,7 +30,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
|
|||
IDD_DIALOG DIALOGEX 12, 12, 206, 316
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_APPWINDOW
|
||||
CAPTION "Rufus v1.3.2.230"
|
||||
CAPTION "Rufus v1.3.2.231"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,94,278,50,14
|
||||
|
@ -274,8 +274,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,3,2,230
|
||||
PRODUCTVERSION 1,3,2,230
|
||||
FILEVERSION 1,3,2,231
|
||||
PRODUCTVERSION 1,3,2,231
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -292,13 +292,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "1.3.2.230"
|
||||
VALUE "FileVersion", "1.3.2.231"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "(c) 2011-2012 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "1.3.2.230"
|
||||
VALUE "ProductVersion", "1.3.2.231"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue