[misc] fix XP compatibility

* MinGW's gcc 4.9.2 seems to implement a broken "%lld" format 64 bit integer is
  followed by more variables and the app executes on XP => use PRI macros
* Also fix partition ID being ignored when using Rufus MBR
* Also fix some global vars shadowing and add other improvements
This commit is contained in:
Pete Batard 2015-01-28 23:22:11 +00:00
parent 5638519ca0
commit b830c040d2
10 changed files with 48 additions and 45 deletions

View File

@ -342,7 +342,7 @@ static void CALLBACK alarm_intr(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dw
if (!num_blocks)
return;
if (FormatStatus) {
uprintf("%sInterrupting at block %llu\n", bb_prefix,
uprintf("%sInterrupting at block %" PRIu64 "\n", bb_prefix,
(unsigned long long) currently_testing);
cancel_ops = -1;
}

View File

@ -220,7 +220,7 @@ static __inline uint64_t bswap_64(uint64_t x)
#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
# define BB_BIG_ENDIAN 0
# define BB_LITTLE_ENDIAN 1
#elif defined(__386__) || defined(_M_IX86) || defined(_M_AMD64)
#elif defined(__386__) || defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)
# define BB_BIG_ENDIAN 0
# define BB_LITTLE_ENDIAN 1
#else
@ -292,7 +292,7 @@ typedef uint64_t bb__aliased_uint64_t FIX_ALIASING;
/* ---- Size-saving "small" ints (arch-dependent) ----------- */
#if defined(i386) || defined(__x86_64__) || defined(__mips__) || defined(__cris__)
#if defined(__386__) || defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64) || defined(__mips__) || defined(__cris__)
/* add other arches which benefit from this... */
typedef signed char smallint;
typedef unsigned char smalluint;

View File

@ -656,16 +656,19 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
{
// MBR partition types that can be mounted in Windows
const uint8_t mbr_mountable[] = { 0x01, 0x04, 0x06, 0x07, 0x0b, 0x0c, 0x0e, 0xef };
BOOL r, ret = FALSE, isUefiTogo;
BOOL r, ret = FALSE, isUefiTogo = FALSE;
HANDLE hPhysical;
DWORD size;
BYTE geometry[256], layout[4096], part_type;
BYTE geometry[256] = {0}, layout[4096] = {0}, part_type;
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)(void*)layout;
char* volume_name;
char tmp[256];
DWORD i, j;
if (FileSystemName == NULL)
return FALSE;
SelectedDrive.nPartitions = 0;
// Populate the filesystem data
FileSystemName[0] = 0;
@ -698,7 +701,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
suprintf("Disk type: %s, Sector Size: %d bytes\n", (DiskGeometry->Geometry.MediaType == FixedMedia)?"Fixed":"Removable",
DiskGeometry->Geometry.BytesPerSector);
suprintf("Cylinders: %lld, TracksPerCylinder: %d, SectorsPerTrack: %d\n",
suprintf("Cylinders: %" PRIi64 ", TracksPerCylinder: %d, SectorsPerTrack: %d\n",
DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder, DiskGeometry->Geometry.SectorsPerTrack);
r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
@ -737,10 +740,11 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
break;
}
}
suprintf(" Type: %s (0x%02x)\r\n Size: %s (%lld bytes)\r\n Start Sector: %d, Boot: %s, Recognized: %s\n",
// NB: MinGW's gcc 4.9.2 broke "%lld" printout on XP so we use the inttypes.h "PRI##" qualifiers
suprintf(" Type: %s (0x%02x)\r\n Size: %s (%" PRIi64 " bytes)\r\n Start Sector: %d, Boot: %s, Recognized: %s\n",
((part_type==0x07)&&(FileSystemName[0]!=0))?FileSystemName:GetPartitionType(part_type), part_type,
SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No");
if ((part_type == RUFUS_EXTRA_PARTITION_TYPE) || (isUefiTogo))
@ -755,7 +759,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
SelectedDrive.PartitionType = PARTITION_STYLE_GPT;
suprintf("Partition type: GPT, NB Partitions: %d\n", DriveLayout->PartitionCount);
suprintf("Disk GUID: %s\n", GuidToString(&DriveLayout->Gpt.DiskId));
suprintf("Max parts: %d, Start Offset: %lld, Usable = %lld bytes\n",
suprintf("Max parts: %d, Start Offset: %" PRIi64 ", Usable = %" PRIi64 " bytes\n",
DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart);
for (i=0; i<DriveLayout->PartitionCount; i++) {
SelectedDrive.nPartitions++;
@ -763,7 +767,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
wchar_to_utf8_no_alloc(DriveLayout->PartitionEntry[i].Gpt.Name, tmp, sizeof(tmp));
suprintf("Partition %d:\r\n Type: %s\r\n Name: '%s'\n", i+1,
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
suprintf(" ID: %s\r\n Size: %s (%lld bytes)\r\n Start Sector: %lld, Attributes: 0x%016llX\n",
suprintf(" ID: %s\r\n Size: %s (%" PRIi64 " bytes)\r\n Start Sector: %" PRIi64 ", Attributes: 0x%016" PRIX64 "\n",
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength.QuadPart, TRUE, FALSE),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector,
DriveLayout->PartitionEntry[i].Gpt.Attributes);
@ -1090,7 +1094,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
extra_part_size_in_tracks = (MIN_EXTRA_PART_SIZE + bytes_per_track - 1) / bytes_per_track;
else if (extra_partitions & XP_COMPAT)
extra_part_size_in_tracks = 1; // One track for the extra partition
uprintf("Reserved %lld tracks (%s) for extra partition", extra_part_size_in_tracks,
uprintf("Reserved %" PRIi64" tracks (%s) for extra partition", extra_part_size_in_tracks,
SizeToHumanReadable(extra_part_size_in_tracks * bytes_per_track, TRUE, FALSE));
main_part_size_in_sectors = ((main_part_size_in_sectors / SelectedDrive.Geometry.SectorsPerTrack) -
extra_part_size_in_tracks) * SelectedDrive.Geometry.SectorsPerTrack;

View File

@ -853,10 +853,12 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
{
BOOL r = FALSE;
DWORD size;
int dt, fs, bt;
unsigned char* buf = NULL;
FILE fake_fd = { 0 };
const char* using_msg = "Using %s MBR\n";
int fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
int dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
int bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
AnalyzeMBR(hPhysicalDrive, "Drive");
@ -893,9 +895,9 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
buf[0x1c2] = 0x0c;
break;
}
if (IsChecked(IDC_BOOT)) {
if ((IsChecked(IDC_BOOT)) && (bt == BT_BIOS)) {
// Set first partition bootable - masquerade as per the DiskID selected
buf[0x1be] = (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && IsChecked(IDC_RUFUS_MBR)) ?
buf[0x1be] = IsChecked(IDC_RUFUS_MBR) ?
(BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80;
uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]);
}
@ -908,9 +910,6 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
if ((bt == BT_UEFI) && (!allow_dual_uefi_bios)) {
uprintf(using_msg, "zeroed");
r = write_zero_mbr(&fake_fd); // Force UEFI boot only by zeroing the MBR
@ -1998,11 +1997,11 @@ DWORD WINAPI SaveImageThread(void* param)
if (i >= WRITE_RETRIES) goto out;
}
if (wb != SelectedDrive.DiskSize) {
uprintf("Error: wrote %llu bytes, expected %llu", wb, SelectedDrive.DiskSize);
uprintf("Error: wrote %" PRIu64 " bytes, expected %" PRIu64, wb, SelectedDrive.DiskSize);
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;
goto out;
}
uprintf("%llu bytes written", wb);
uprintf("%" PRIu64 " bytes written", wb);
uprintf("Appending VHD footer...");
if (!AppendVHDFooter(image_path)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT;

View File

@ -1,6 +1,6 @@
/******************************************************************
Copyright (C) 2009 Henrik Carlqvist
Modified for Rufus/Windows (C) 2011-2012 Pete Batard
Modified for Rufus/Windows (C) 2011-2015 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
@ -41,15 +41,15 @@ int64_t write_sectors(HANDLE hDrive, uint64_t SectorSize,
ptr.QuadPart = StartSector*SectorSize;
if(!SetFilePointerEx(hDrive, ptr, NULL, FILE_BEGIN))
{
uprintf("write_sectors: Could not access sector 0x%08llx - %s\n", StartSector, WindowsErrorString());
uprintf("write_sectors: Could not access sector 0x%08" PRIx64 " - %s\n", StartSector, WindowsErrorString());
return -1;
}
if((!WriteFile(hDrive, pBuf, Size, &Size, NULL)) || (Size != nSectors*SectorSize))
{
uprintf("write_sectors: Write error %s\n", (GetLastError()!=ERROR_SUCCESS)?WindowsErrorString():"");
uprintf(" Wrote: %d, Expected: %lld\n", Size, nSectors*SectorSize);
uprintf(" StartSector: 0x%08llx, nSectors: 0x%llx, SectorSize: 0x%llx\n", StartSector, nSectors, SectorSize);
uprintf(" Wrote: %d, Expected: %" PRIu64 "\n", Size, nSectors*SectorSize);
uprintf(" StartSector: 0x%08" PRIx64 ", nSectors: 0x%" PRIx64 ", SectorSize: 0x%" PRIx64 "\n", StartSector, nSectors, SectorSize);
return Size;
}
@ -74,15 +74,15 @@ int64_t read_sectors(HANDLE hDrive, uint64_t SectorSize,
ptr.QuadPart = StartSector*SectorSize;
if(!SetFilePointerEx(hDrive, ptr, NULL, FILE_BEGIN))
{
uprintf("read_sectors: Could not access sector 0x%08llx - %s\n", StartSector, WindowsErrorString());
uprintf("read_sectors: Could not access sector 0x%08" PRIx64 " - %s\n", StartSector, WindowsErrorString());
return -1;
}
if((!ReadFile(hDrive, pBuf, Size, &Size, NULL)) || (Size != nSectors*SectorSize))
{
uprintf("read_sectors: Read error %s\n", (GetLastError()!=ERROR_SUCCESS)?WindowsErrorString():"");
uprintf(" Read: %d, Expected: %lld\n", Size, nSectors*SectorSize);
uprintf(" StartSector: 0x%08llx, nSectors: 0x%llx, SectorSize: 0x%llx\n", StartSector, nSectors, SectorSize);
uprintf(" Read: %d, Expected: %" PRIu64 "\n", Size, nSectors*SectorSize);
uprintf(" StartSector: 0x%08" PRIx64 ", nSectors: 0x%" PRIx64 ", SectorSize: 0x%" PRIx64 "\n", StartSector, nSectors, SectorSize);
}
return (int64_t)Size;

View File

@ -915,7 +915,7 @@ static void DisplayISOProps(void)
// TODO: Only report features that are present
uprintf("ISO label: %s", iso_report.label);
uprintf(" Size: %lld bytes", iso_report.projected_size);
uprintf(" Size: %" PRIu64 " bytes", iso_report.projected_size);
uprintf(" Has a >64 chars filename: %s", YesNo(iso_report.has_long_filename));
uprintf(" Has Symlinks: %s", YesNo(iso_report.has_symlinks));
uprintf(" Has a >4GB file: %s", YesNo(iso_report.has_4GB_file));
@ -1686,18 +1686,18 @@ void ShowLanguageMenu(HWND hDlg)
loc_cmd* lcmd = NULL;
char lang[256];
char *search = "()";
char *l, *r, *dup;
char *l, *r, *str;
UM_LANGUAGE_MENU_MAX = UM_LANGUAGE_MENU;
menu = CreatePopupMenu();
list_for_each_entry(lcmd, &locale_list, loc_cmd, list) {
// The appearance of LTR languages must be fixed for RTL menus
if ((right_to_left_mode) && (!(lcmd->ctrl_id & LOC_RIGHT_TO_LEFT))) {
dup = safe_strdup(lcmd->txt[1]);
l = strtok(dup, search);
str = safe_strdup(lcmd->txt[1]);
l = strtok(str, search);
r = strtok(NULL, search);
static_sprintf(lang, LEFT_TO_RIGHT_MARK "(%s) " LEFT_TO_RIGHT_MARK "%s", r, l);
safe_free(dup);
safe_free(str);
} else {
safe_strcpy(lang, sizeof(lang), lcmd->txt[1]);
}

View File

@ -18,7 +18,7 @@
#include <windows.h>
#include <winioctl.h> // for DISK_GEOMETRY
#include <malloc.h>
#include <stdint.h>
#include <inttypes.h>
#if defined(_MSC_VER)
// Disable some VS2012 Code Analysis warnings
@ -368,7 +368,7 @@ extern void PrintStatusInfo(BOOL info, BOOL debug, unsigned int duration, int ms
extern void UpdateProgress(int op, float percent);
extern const char* StrError(DWORD error_code, BOOL use_default_locale);
extern char* GuidToString(const GUID* guid);
extern char* SizeToHumanReadable(uint64_t size, BOOL log, BOOL fake_units);
extern char* SizeToHumanReadable(uint64_t size, BOOL copy_to_log, BOOL fake_units);
extern void CenterDialog(HWND hDlg);
extern void ResizeMoveCtrl(HWND hDlg, HWND hCtrl, int dx, int dy, int dw, int dh);
extern void CreateStatusBar(void);

View File

@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 2.0.0.588"
CAPTION "Rufus 2.0.0.589"
FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,127,339,50,14
@ -157,7 +157,7 @@ END
IDD_DIALOG_XP DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Rufus 2.0.0.588"
CAPTION "Rufus 2.0.0.589"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,127,339,50,14
@ -283,7 +283,7 @@ END
IDD_DIALOG_RTL DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 2.0.0.588"
CAPTION "Rufus 2.0.0.589"
FONT 8, "Segoe UI", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,127,339,50,14
@ -415,7 +415,7 @@ END
IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
CAPTION "Rufus 2.0.0.588"
CAPTION "Rufus 2.0.0.589"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,127,339,50,14
@ -671,8 +671,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,0,0,588
PRODUCTVERSION 2,0,0,588
FILEVERSION 2,0,0,589
PRODUCTVERSION 2,0,0,589
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -689,13 +689,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.0.0.588"
VALUE "FileVersion", "2.0.0.589"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2015 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.0.0.588"
VALUE "ProductVersion", "2.0.0.589"
END
END
BLOCK "VarFileInfo"

View File

@ -57,7 +57,7 @@ static __inline int64_t ReadIniKey64(const char* key) {
}
static __inline BOOL WriteIniKey64(const char* key, int64_t val) {
char str[24];
static_sprintf(str, "%lld", val);
static_sprintf(str, "%" PRIi64, val);
return (set_token_data_file(key, str, ini_file) != NULL);
}

View File

@ -160,15 +160,15 @@ static __inline uint16_t upo2(uint16_t v)
}
// Convert a size to human readable
char* SizeToHumanReadable(uint64_t size, BOOL log, BOOL fake_units)
char* SizeToHumanReadable(uint64_t size, BOOL copy_to_log, BOOL fake_units)
{
int suffix;
static char str_size[32];
const char* dir = ((right_to_left_mode)&&(!log))?RIGHT_TO_LEFT_MARK:"";
const char* dir = ((right_to_left_mode)&&(!copy_to_log))?RIGHT_TO_LEFT_MARK:"";
double hr_size = (double)size;
double t;
uint16_t i_size;
char **_msg_table = log?default_msg_table:msg_table;
char **_msg_table = copy_to_log?default_msg_table:msg_table;
const double divider = fake_units?1000.0:1024.0;
for (suffix=0; suffix<MAX_SIZE_SUFFIXES-1; suffix++) {