From 8a5a5a318a303c213f009d7ffc992972851489b5 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Mon, 1 Apr 2024 02:16:41 +0100 Subject: [PATCH] [misc] improve readability of error code handling * Also don't pass a read size value in WriteFileWithRetry() if we don't use it. --- .gitignore | 13 +++ src/badblocks.c | 4 +- src/badblocks.h | 11 ++- src/dos.c | 10 +-- src/drive.c | 10 +-- src/drive.h | 2 +- src/ext2fs/nt_io.c | 4 +- src/format.c | 201 ++++++++++++++++++++++----------------------- src/format_ext.c | 10 +-- src/format_fat32.c | 14 ++-- src/hash.c | 10 +-- src/icon.c | 14 ++-- src/iso.c | 34 ++++---- src/ms-sys/file.c | 4 +- src/net.c | 30 +++---- src/pki.c | 4 +- src/rufus.c | 44 +++++----- src/rufus.h | 6 +- src/rufus.rc | 10 +-- src/stdfn.c | 2 +- src/stdio.c | 6 +- src/stdlg.c | 8 +- src/syslinux.c | 18 ++-- src/vhd.c | 22 ++--- src/wue.c | 18 ++-- 25 files changed, 257 insertions(+), 252 deletions(-) diff --git a/.gitignore b/.gitignore index 222ea94c544..b15858583a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,27 +1,40 @@ *.a *.aps *.appx +*.appxupload +*.bak *.db *.db-shm *.db-wal *.dep +*.diff +*.dll +*.efi *.exe *.htm *.idb *.ipch *.la +*.lib *.lo +*.lock *.log *.mac *.mo +*.mp4 *.ncb +*.nope *.o *.obj +*.old *.opendb *.opt +*.org +*.p7x *.patch *.pc *.pdb +*.pdf *.plg *.res *.sig diff --git a/src/badblocks.c b/src/badblocks.c index a20d55f85bd..9fd29d280e8 100644 --- a/src/badblocks.c +++ b/src/badblocks.c @@ -4,7 +4,7 @@ * Copyright 1992-1994 Remy Card * Copyright 1995-1999 Theodore Ts'o * Copyright 1999 David Beattie - * Copyright 2011-2023 Pete Batard + * Copyright 2011-2024 Pete Batard * * This file is based on the minix file system programs fsck and mkfs * written and copyrighted by Linus Torvalds @@ -318,7 +318,7 @@ static void CALLBACK alarm_intr(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dw { if (!num_blocks) return; - if (FormatStatus) { + if (ErrorStatus) { uprintf("%sInterrupting at block %" PRIu64 "\n", bb_prefix, (unsigned long long) currently_testing); cancel_ops = -1; diff --git a/src/badblocks.h b/src/badblocks.h index 809a95efdb0..9eb09677e17 100644 --- a/src/badblocks.h +++ b/src/badblocks.h @@ -7,7 +7,7 @@ * * Copyright 1995, 1996, 1997, 1998, 1999 by Theodore Ts'o * Copyright 1999 by David Beattie - * Copyright 2011-2018 by Pete Batard + * Copyright 2011-2024 by Pete Batard * * This file is based on the minix file system programs fsck and mkfs * written and copyrighted by Linus Torvalds @@ -28,12 +28,11 @@ typedef struct bb_struct_u64_iterate *bb_badblocks_iterate; typedef struct bb_struct_u64_list *bb_u64_list; typedef struct bb_struct_u64_iterate *bb_u64_iterate; -#define BB_ET_NO_MEMORY (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY) -#define BB_ET_MAGIC_BADBLOCKS_LIST (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OBJECT_IN_LIST) -#define BB_ET_MAGIC_BADBLOCKS_ITERATE (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INVALID_BLOCK) +#define BB_ET_NO_MEMORY RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY) +#define BB_ET_MAGIC_BADBLOCKS_LIST RUFUS_ERROR(ERROR_OBJECT_IN_LIST) +#define BB_ET_MAGIC_BADBLOCKS_ITERATE RUFUS_ERROR(ERROR_INVALID_BLOCK) -#define BB_CHECK_MAGIC(struct, code) \ - if ((struct)->magic != (code)) return (code) +#define BB_CHECK_MAGIC(struct, code) if ((struct)->magic != (code)) return (code) #define BB_BAD_BLOCKS_THRESHOLD 256 #define BB_BLOCKS_AT_ONCE 64 #define BB_SYS_PAGE_SIZE 4096 diff --git a/src/dos.c b/src/dos.c index c5a228ece34..f4b3f1cc5ba 100644 --- a/src/dos.c +++ b/src/dos.c @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll * (MS WinME DOS) or from the embedded FreeDOS resource files - * Copyright © 2011-2023 Pete Batard + * Copyright © 2011-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 @@ -352,7 +352,7 @@ BOOL ExtractFreeDOS(const char* path) IDR_FD_EGA17_CPX, IDR_FD_EGA18_CPX }; char filename[MAX_PATH], locale_path[MAX_PATH]; BYTE* res_data; - DWORD res_size, Size; + DWORD res_size; HANDLE hFile; int i; @@ -366,10 +366,10 @@ BOOL ExtractFreeDOS(const char* path) static_strcat(locale_path, "LOCALE\\"); CreateDirectoryA(locale_path, NULL); - for (i=0; i - * Copyright (C) 2018-2019 Pete Batard + * Copyright (C) 2018-2024 Pete Batard * * %Begin-Header% * This file may be redistributed under the terms of the GNU Library @@ -180,7 +180,7 @@ static __inline unsigned _MapNtStatus(IN NTSTATUS Status) // Return the last Windows Error DWORD ext2_last_winerror(DWORD default_error) { - return ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (LastWinError ? LastWinError : default_error); + return RUFUS_ERROR(LastWinError ? LastWinError : default_error); } // diff --git a/src/format.c b/src/format.c index 4abe5105587..256ee539742 100644 --- a/src/format.c +++ b/src/format.c @@ -65,7 +65,7 @@ * Globals */ const char* FileSystemLabel[FS_MAX] = { "FAT", "FAT32", "NTFS", "UDF", "exFAT", "ReFS", "ext2", "ext3", "ext4" }; -DWORD FormatStatus = 0, LastWriteError = 0; +DWORD ErrorStatus = 0, LastWriteError = 0; badblocks_report report = { 0 }; static float format_percent = 0.0f; static int task_number = 0, actual_fs_type; @@ -114,7 +114,7 @@ static void OutputUTF8Message(const char* src) static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID pData) { char percent_str[8]; - if (IS_ERROR(FormatStatus)) + if (IS_ERROR(ErrorStatus)) return FALSE; assert((actual_fs_type >= 0) && (actual_fs_type < FS_MAX)); @@ -141,38 +141,38 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, UpdateProgress(OP_CREATE_FS, 100.0f); if(*(BOOLEAN*)pData == FALSE) { uprintf("Error while formatting"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; + ErrorStatus = RUFUS_ERROR(ERROR_GEN_FAILURE); } break; case FCC_DONE_WITH_STRUCTURE: break; case FCC_INCOMPATIBLE_FILE_SYSTEM: uprintf("Incompatible File System"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INCOMPATIBLE_FS); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_INCOMPATIBLE_FS)); break; case FCC_ACCESS_DENIED: uprintf("Access denied"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_ACCESS_DENIED; + ErrorStatus = RUFUS_ERROR(ERROR_ACCESS_DENIED); break; case FCC_MEDIA_WRITE_PROTECTED: uprintf("Media is write protected"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_PROTECT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_PROTECT); break; case FCC_VOLUME_IN_USE: uprintf("Volume is in use"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_DEVICE_IN_USE; + ErrorStatus = RUFUS_ERROR(ERROR_DEVICE_IN_USE); break; case FCC_DEVICE_NOT_READY: uprintf("The device is not ready"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_READY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_READY); break; case FCC_CANT_QUICK_FORMAT: uprintf("Cannot quick format this volume"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_QUICK_FORMAT); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_QUICK_FORMAT)); break; case FCC_BAD_LABEL: uprintf("Bad label"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_LABEL_TOO_LONG; + ErrorStatus = RUFUS_ERROR(ERROR_LABEL_TOO_LONG); break; case FCC_OUTPUT: OutputUTF8Message(((PTEXTOUTPUT)pData)->Output); @@ -180,27 +180,27 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, case FCC_CLUSTER_SIZE_TOO_BIG: case FCC_CLUSTER_SIZE_TOO_SMALL: uprintf("Unsupported cluster size"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INVALID_CLUSTER_SIZE); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_INVALID_CLUSTER_SIZE)); break; case FCC_VOLUME_TOO_BIG: case FCC_VOLUME_TOO_SMALL: - uprintf("Volume is too %s", (Command == FCC_VOLUME_TOO_BIG)?"big":"small"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_INVALID_VOLUME_SIZE); + uprintf("Volume is too %s", (Command == FCC_VOLUME_TOO_BIG) ? "big" : "small"); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_INVALID_VOLUME_SIZE)); break; case FCC_NO_MEDIA_IN_DRIVE: uprintf("No media in drive"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NO_MEDIA_IN_DRIVE; + ErrorStatus = RUFUS_ERROR(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; + ErrorStatus = RUFUS_ERROR(ERROR_OFFSET_ALIGNMENT_VIOLATION); break; default: uprintf("FormatExCallback: Received unhandled command 0x%02X - aborting", Command); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_SUPPORTED; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_SUPPORTED); break; } - return (!IS_ERROR(FormatStatus)); + return (!IS_ERROR(ErrorStatus)); } /* @@ -209,7 +209,7 @@ static BOOLEAN __stdcall FormatExCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, static BOOLEAN __stdcall ChkdskCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DWORD Action, PVOID pData) { DWORD* percent; - if (IS_ERROR(FormatStatus)) + if (IS_ERROR(ErrorStatus)) return FALSE; switch (Command) { @@ -359,7 +359,7 @@ static BOOL FormatNativeVds(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Cl wVolumeName = utf8_to_wchar(VolumeName); if (wVolumeName == NULL) { uprintf("Could not read volume name"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_GEN_FAILURE; + ErrorStatus = RUFUS_ERROR(ERROR_GEN_FAILURE); goto out; } @@ -530,7 +530,7 @@ static BOOL FormatNativeVds(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Cl hr = IVdsVolumeMF3_FormatEx2(pVolumeMF3, wFSName, usFsVersion, ClusterSize, wLabel, Flags, &pAsync); while (SUCCEEDED(hr)) { - if (IS_ERROR(FormatStatus)) { + if (IS_ERROR(ErrorStatus)) { IVdsAsync_Cancel(pAsync); break; } @@ -560,7 +560,7 @@ static BOOL FormatNativeVds(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Cl IVdsAsync_Release(pAsync); IVdsVolumeMF3_Release(pVolumeMF3); - if (!IS_ERROR(FormatStatus)) { + if (!IS_ERROR(ErrorStatus)) { uprintf("Format completed."); r = TRUE; } @@ -570,8 +570,8 @@ static BOOL FormatNativeVds(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Cl } out: - if ((!bFoundVolume) && (FormatStatus == 0)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_PATH_NOT_FOUND; + if ((!bFoundVolume) && (ErrorStatus == 0)) + ErrorStatus = RUFUS_ERROR(ERROR_PATH_NOT_FOUND); safe_free(VolumeName); safe_free(wVolumeName); safe_free(wLabel); @@ -603,7 +603,7 @@ static BOOL FormatNative(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Clust wVolumeName = utf8_to_wchar(VolumeName); if (wVolumeName == NULL) { uprintf("Could not read volume name (%s)", VolumeName); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; + ErrorStatus = RUFUS_ERROR(ERROR_GEN_FAILURE); goto out; } // Hey, nice consistency here, Microsoft! - FormatEx() fails if wVolumeName has @@ -632,12 +632,12 @@ static BOOL FormatNative(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Clust for (i = 0; i < WRITE_RETRIES; i++) { pfFormatEx(wVolumeName, SelectedDrive.MediaType, wFSName, wLabel, (Flags & FP_QUICK), ClusterSize, FormatExCallback); - if (!IS_ERROR(FormatStatus) || (HRESULT_CODE(FormatStatus) == ERROR_CANCELLED)) + if (!IS_ERROR(ErrorStatus) || (HRESULT_CODE(ErrorStatus) == ERROR_CANCELLED)) break; uprintf("%s - Retrying...", WindowsErrorString()); Sleep(WRITE_TIMEOUT); } - if (IS_ERROR(FormatStatus)) + if (IS_ERROR(ErrorStatus)) goto out; if (Flags & FP_COMPRESSION) { @@ -649,14 +649,14 @@ static BOOL FormatNative(DWORD DriveIndex, uint64_t PartitionOffset, DWORD Clust } } - if (!IS_ERROR(FormatStatus)) { + if (!IS_ERROR(ErrorStatus)) { uprintf("Format completed."); r = TRUE; } out: - if (!r && !IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|SCODE_CODE(GetLastError()); + if (!r && !IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(SCODE_CODE(GetLastError())); safe_free(VolumeName); safe_free(wVolumeName); safe_free(wLabel); @@ -668,7 +668,7 @@ BOOL FormatPartition(DWORD DriveIndex, uint64_t PartitionOffset, DWORD UnitAlloc { if ((DriveIndex < 0x80) || (DriveIndex > 0x100) || (FSType >= FS_MAX) || ((UnitAllocationSize != 0) && (!IS_POWER_OF_2(UnitAllocationSize)))) { - ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_INVALID_PARAMETER; + ErrorStatus = RUFUS_ERROR(ERROR_INVALID_PARAMETER); return FALSE; } actual_fs_type = FSType; @@ -708,7 +708,7 @@ static BOOL CheckDisk(char DriveLetter) } pfChkdsk(wDriveRoot, wFSType, FALSE, FALSE, FALSE, FALSE, NULL, NULL, ChkdskCallback); - if (!IS_ERROR(FormatStatus)) { + if (!IS_ERROR(ErrorStatus)) { uprintf("NTFS Fixup completed."); r = TRUE; } @@ -742,7 +742,7 @@ static BOOL ClearMBRGPT(HANDLE hPhysicalDrive, LONGLONG DiskSize, DWORD SectorSi uprintf("Erasing %llu sectors", num_sectors_to_clear); pZeroBuf = calloc(SectorSize, (size_t)num_sectors_to_clear); if (pZeroBuf == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); goto out; } liFilePointer.QuadPart = 0ULL; @@ -794,13 +794,13 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) buffer = (unsigned char*)_mm_malloc(SelectedDrive.SectorSize, 16); if (buffer == NULL) { uprintf("Could not allocate memory for MBR"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); goto out; } if (!read_sectors(hPhysicalDrive, SelectedDrive.SectorSize, 0, 1, buffer)) { uprintf("Could not read MBR"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_READ_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_READ_FAULT); goto out; } @@ -824,14 +824,13 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive) } if ((boot_type != BT_NON_BOOTABLE) && (target_type == TT_BIOS)) { // Set first partition bootable - masquerade as per the DiskID selected - buffer[0x1be] = IsChecked(IDC_RUFUS_MBR) ? - (BYTE)ComboBox_GetCurItemData(hDiskID):0x80; + buffer[0x1be] = IsChecked(IDC_RUFUS_MBR) ? (BYTE)ComboBox_GetCurItemData(hDiskID) : 0x80; uprintf("Set bootable USB partition as 0x%02X", buffer[0x1be]); } if (!write_sectors(hPhysicalDrive, SelectedDrive.SectorSize, 0, 1, buffer)) { uprintf("Could not write MBR"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } @@ -1080,7 +1079,7 @@ BOOL WritePBR(HANDLE hLogicalVolume) uprintf("Unsupported FS for FS BR processing - aborting"); break; } - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); return FALSE; } @@ -1177,7 +1176,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) buf_size = ((DD_BUFFER_SIZE + SelectedDrive.SectorSize - 1) / SelectedDrive.SectorSize) * SelectedDrive.SectorSize; buffer = (uint8_t*)_mm_malloc(buf_size, SelectedDrive.SectorSize); if (buffer == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); uprintf("Could not allocate disk zeroing buffer"); goto out; } @@ -1189,7 +1188,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) if (fast_zeroing) { cmp_buffer = (uint32_t*)_mm_malloc(buf_size, SelectedDrive.SectorSize); if (cmp_buffer == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); uprintf("Could not allocate disk comparison buffer"); goto out; } @@ -1267,7 +1266,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) goto out; } } else { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } Sleep(200); @@ -1282,18 +1281,18 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (hSourceImage == INVALID_HANDLE_VALUE) { uprintf("Could not open image '%s': %s", image_path, WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } sec_buf = (uint8_t*)_mm_malloc(SelectedDrive.SectorSize, SelectedDrive.SectorSize); if (sec_buf == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); uprintf("Could not allocate disk write buffer"); goto out; } assert((uintptr_t)sec_buf % SelectedDrive.SectorSize == 0); sec_buf_pos = 0; - bled_init(256 * KB, uprintf, NULL, sector_write, update_progress, NULL, &FormatStatus); + bled_init(256 * KB, uprintf, NULL, sector_write, update_progress, NULL, &ErrorStatus); bled_ret = bled_uncompress_with_handles(hSourceImage, hPhysicalDrive, img_report.compression_type); bled_exit(); uprintfs("\r\n"); @@ -1306,10 +1305,10 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) WriteFile(hPhysicalDrive, sec_buf, SelectedDrive.SectorSize, &write_size, NULL); } safe_mm_free(sec_buf); - if ((bled_ret < 0) && (SCODE_CODE(FormatStatus) != ERROR_CANCELLED)) { + if ((bled_ret < 0) && (SCODE_CODE(ErrorStatus) != ERROR_CANCELLED)) { // Unfortunately, different compression backends return different negative error codes uprintf("Could not write compressed image: %lld", bled_ret); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } } else { @@ -1327,7 +1326,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN); if (hSourceImage == NULL) { uprintf("Could not open image '%s': %s", image_path, WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } @@ -1335,7 +1334,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) buf_size = ((DD_BUFFER_SIZE + SelectedDrive.SectorSize - 1) / SelectedDrive.SectorSize) * SelectedDrive.SectorSize; buffer = (uint8_t*)_mm_malloc(buf_size * NUM_BUFFERS, SelectedDrive.SectorSize); if (buffer == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); uprintf("Could not allocate disk write buffer"); goto out; } @@ -1359,7 +1358,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) if ((!WaitFileAsync(hSourceImage, DRIVE_ACCESS_TIMEOUT)) || (!GetSizeAsync(hSourceImage, &read_size[read_bufnum]))) { uprintf("\r\nRead error: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_READ_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_READ_FAULT); goto out; } @@ -1398,7 +1397,7 @@ static BOOL WriteDrive(HANDLE hPhysicalDrive, BOOL bZeroDrive) goto out; } } else { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } Sleep(200); @@ -1496,14 +1495,14 @@ DWORD WINAPI FormatThread(void* param) PrintInfoDebug(0, MSG_225); hPhysicalDrive = GetPhysicalHandle(DriveIndex, actual_lock_drive, FALSE, !actual_lock_drive); if (hPhysicalDrive == INVALID_HANDLE_VALUE) { - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } // At this stage we have both a handle and a lock to the physical drive if (!GetDriveLetters(DriveIndex, drive_letters)) { uprintf("Failed to get a drive letter"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_ASSIGN_LETTER); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_ASSIGN_LETTER)); goto out; } @@ -1511,7 +1510,7 @@ DWORD WINAPI FormatThread(void* param) drive_name[0] = RemoveDriveLetters(DriveIndex, TRUE, FALSE); if (drive_name[0] == 0) { uprintf("Unable to find a drive letter to use"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_ASSIGN_LETTER); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_ASSIGN_LETTER)); goto out; } uprintf("Will use '%c:' as volume mountpoint", toupper(drive_name[0])); @@ -1522,8 +1521,8 @@ DWORD WINAPI FormatThread(void* param) PrintInfo(0, MSG_239, lmprintf(MSG_307)); if (!is_vds_available || !DeletePartition(DriveIndex, 0, TRUE)) { uprintf("Warning: Could not delete partition(s): %s", is_vds_available ? WindowsErrorString() : "VDS is not available"); - SetLastError(FormatStatus); - FormatStatus = 0; + SetLastError(ErrorStatus); + ErrorStatus = 0; // If we couldn't delete partitions, Windows give us trouble unless we // request access to the logical drive. Don't ask me why! need_logical = TRUE; @@ -1537,7 +1536,7 @@ DWORD WINAPI FormatThread(void* param) // Now get RW access to the physical drive hPhysicalDrive = GetPhysicalHandle(DriveIndex, actual_lock_drive, TRUE, !actual_lock_drive); if (hPhysicalDrive == INVALID_HANDLE_VALUE) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } RefreshDriveLayout(hPhysicalDrive); @@ -1550,7 +1549,7 @@ DWORD WINAPI FormatThread(void* param) hLogicalVolume = GetLogicalHandle(DriveIndex, 0, TRUE, FALSE, !actual_lock_drive); if (hLogicalVolume == INVALID_HANDLE_VALUE) { uprintf("Could not access logical volume"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; // If the call succeeds (and we don't get a NULL logical handle as returned for // unpartitioned drives), try to unmount the volume. @@ -1579,7 +1578,7 @@ DWORD WINAPI FormatThread(void* param) if ((!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.SectorSize, use_large_fat32)) || (!InitializeDisk(hPhysicalDrive))) { uprintf("Could not reset partitions"); - FormatStatus = (LastWriteError != 0) ? LastWriteError : (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE); + ErrorStatus = (LastWriteError != 0) ? LastWriteError : RUFUS_ERROR(ERROR_PARTITION_FAILURE); goto out; } } @@ -1594,7 +1593,7 @@ DWORD WINAPI FormatThread(void* param) static_strcpy(logfile, userdir); safe_free(userdir); GetLocalTime(<); - safe_sprintf(&logfile[strlen(logfile)], sizeof(logfile)-strlen(logfile)-1, + safe_sprintf(&logfile[strlen(logfile)], sizeof(logfile) - strlen(logfile) - 1, "\\rufus_%04d%02d%02d_%02d%02d%02d.log", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond); log_fd = fopenU(logfile, "w+"); @@ -1609,8 +1608,8 @@ DWORD WINAPI FormatThread(void* param) if (!BadBlocks(hPhysicalDrive, SelectedDrive.DiskSize, (sel >= 2) ? 4 : sel +1, sel, &report, log_fd)) { uprintf("Bad blocks: Check failed."); - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_BADBLOCKS_FAILURE); + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_BADBLOCKS_FAILURE)); ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.SectorSize, FALSE); fclose(log_fd); DeleteFileU(logfile); @@ -1629,7 +1628,7 @@ DWORD WINAPI FormatThread(void* param) lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond); fclose(log_fd); r = MessageBoxExU(hMainDialog, lmprintf(MSG_012, bb_msg, logfile), - lmprintf(MSG_010), MB_ABORTRETRYIGNORE|MB_ICONWARNING|MB_IS_RTL, selected_langid); + lmprintf(MSG_010), MB_ABORTRETRYIGNORE | MB_ICONWARNING | MB_IS_RTL, selected_langid); } else { // We didn't get any errors => delete the log file fclose(log_fd); @@ -1637,7 +1636,7 @@ DWORD WINAPI FormatThread(void* param) } } while (r == IDRETRY); if (r == IDABORT) { - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; + ErrorStatus = RUFUS_ERROR(ERROR_CANCELLED); goto out; } @@ -1645,8 +1644,8 @@ DWORD WINAPI FormatThread(void* param) // before repartitioning. Else, all kind of bad things happen. if (!ClearMBRGPT(hPhysicalDrive, SelectedDrive.DiskSize, SelectedDrive.SectorSize, use_large_fat32)) { uprintf("unable to zero MBR/GPT"); - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } } @@ -1664,10 +1663,10 @@ DWORD WINAPI FormatThread(void* param) safe_free(physical); uprintf("Running command: '%s", cmd); cr = RunCommandWithProgress(cmd, sysnative_dir, TRUE, MSG_261); - if (cr != 0 && !IS_ERROR(FormatStatus)) { + if (cr != 0 && !IS_ERROR(ErrorStatus)) { SetLastError(cr); uprintf("Failed to apply FFU image: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_WINDOWS) | SCODE_CODE(cr); + ErrorStatus = RUFUS_ERROR(SCODE_CODE(cr)); } } else { WriteDrive(hPhysicalDrive, FALSE); @@ -1680,7 +1679,7 @@ DWORD WINAPI FormatThread(void* param) if (!CreatePartition(hPhysicalDrive, partition_type, fs_type, (partition_type == PARTITION_STYLE_MBR) && (target_type == TT_UEFI), extra_partitions)) { - FormatStatus = (LastWriteError != 0) ? LastWriteError : (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_PARTITION_FAILURE); + ErrorStatus = (LastWriteError != 0) ? LastWriteError : RUFUS_ERROR(ERROR_PARTITION_FAILURE); goto out; } UpdateProgress(OP_PARTITION, -1.0f); @@ -1691,7 +1690,7 @@ DWORD WINAPI FormatThread(void* param) if (!CloseHandle(hLogicalVolume)) { hLogicalVolume = INVALID_HANDLE_VALUE; uprintf("Could not close volume: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_ACCESS_DENIED; + ErrorStatus = RUFUS_ERROR(ERROR_ACCESS_DENIED); goto out; } } @@ -1724,14 +1723,14 @@ DWORD WINAPI FormatThread(void* param) // Can't format ESPs or ext2/ext3 partitions unless we mount them ourselves volume_name = AltMountVolume(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset, FALSE); if (volume_name == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_ASSIGN_LETTER); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_ASSIGN_LETTER)); goto out; } } else { if (!WaitForLogical(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset)) { uprintf("Logical drive was not found - aborting"); - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_TIMEOUT; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_TIMEOUT); goto out; } } @@ -1748,8 +1747,8 @@ DWORD WINAPI FormatThread(void* param) img_report.uses_casper ? "casper-rw" : "persistence", (img_report.uses_casper ? 0 : FP_CREATE_PERSISTENCE_CONF) | (IsChecked(IDC_QUICK_FORMAT) ? FP_QUICK : 0))) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } } @@ -1771,8 +1770,8 @@ DWORD WINAPI FormatThread(void* param) ret = FormatPartition(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset, ClusterSize, fs_type, label, Flags); if (!ret) { - // Error will be set by FormatPartition() in FormatStatus - uprintf("Format error: %s", StrError(FormatStatus, TRUE)); + // Error will be set by FormatPartition() in ErrorStatus + uprintf("Format error: %s", StrError(ErrorStatus, TRUE)); goto out; } @@ -1780,7 +1779,7 @@ DWORD WINAPI FormatThread(void* param) // Get RW access back to the physical drive... hPhysicalDrive = GetPhysicalHandle(DriveIndex, actual_lock_drive, TRUE, !actual_lock_drive); if (hPhysicalDrive == INVALID_HANDLE_VALUE) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } } @@ -1789,8 +1788,8 @@ DWORD WINAPI FormatThread(void* param) if ((partition_type == PARTITION_STYLE_MBR) || ((boot_type != BT_NON_BOOTABLE) && (partition_type == PARTITION_STYLE_GPT))) { PrintInfoDebug(0, MSG_228); // "Writing master boot record..." if ((!WriteMBR(hPhysicalDrive)) || (!WriteSBR(hPhysicalDrive))) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } UpdateProgress(OP_FIX_MBR, -1.0f); @@ -1805,7 +1804,7 @@ DWORD WINAPI FormatThread(void* param) volume_name = GetLogicalName(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset, TRUE, TRUE); if (volume_name == NULL) { uprintf("Could not get volume name"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NO_VOLUME_ID; + ErrorStatus = RUFUS_ERROR(ERROR_NO_VOLUME_ID); goto out; } uprintf("Found volume %s", volume_name); @@ -1816,7 +1815,7 @@ DWORD WINAPI FormatThread(void* param) RemoveDriveLetters(DriveIndex, FALSE, TRUE); if (!MountVolume(drive_name, volume_name)) { uprintf("Could not remount %s as %c: %s", volume_name, toupper(drive_name[0]), WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_MOUNT_VOLUME); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_MOUNT_VOLUME)); goto out; } CHECK_FOR_USER_CANCEL; @@ -1847,14 +1846,14 @@ DWORD WINAPI FormatThread(void* param) // For once, no need to do anything - just check our sanity assert((boot_type == BT_IMAGE) && IS_EFI_BOOTABLE(img_report) && (fs_type <= FS_NTFS)); if ( (boot_type != BT_IMAGE) || !IS_EFI_BOOTABLE(img_report) || (fs_type > FS_NTFS) ) { - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE; + ErrorStatus = RUFUS_ERROR(ERROR_INSTALL_FAILURE); goto out; } } else if ( (boot_type == BT_SYSLINUX_V4) || (boot_type == BT_SYSLINUX_V6) || ((boot_type == BT_IMAGE) && (HAS_SYSLINUX(img_report) || HAS_REACTOS(img_report)) && (!HAS_WINDOWS(img_report) || !allow_dual_uefi_bios)) ) { if (!InstallSyslinux(DriveIndex, drive_name[0], fs_type)) { - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE; + ErrorStatus = RUFUS_ERROR(ERROR_INSTALL_FAILURE); goto out; } } else { @@ -1863,15 +1862,15 @@ DWORD WINAPI FormatThread(void* param) hLogicalVolume = GetLogicalHandle(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset, FALSE, TRUE, FALSE); if ((hLogicalVolume == INVALID_HANDLE_VALUE) || (hLogicalVolume == NULL)) { uprintf("Could not re-mount volume for partition boot record access"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } // NB: if you unmount the logical volume here, XP will report error: // [0x00000456] The media in the drive may have changed PrintInfoDebug(0, MSG_229); if (!WritePBR(hLogicalVolume)) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } // We must close and unlock the volume to write files to it @@ -1895,8 +1894,8 @@ DWORD WINAPI FormatThread(void* param) UpdateProgress(OP_FILE_COPY, -1.0f); PrintInfoDebug(0, MSG_230); if (!ExtractDOS(drive_name)) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY; + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_CANNOT_COPY); goto out; } } else if (boot_type == BT_GRUB4DOS) { @@ -1912,26 +1911,26 @@ DWORD WINAPI FormatThread(void* param) if (windows_to_go) { PrintInfoDebug(0, MSG_268); if (!SetupWinToGo(DriveIndex, drive_name, (extra_partitions & XP_ESP))) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_EXTRACT)); goto out; } if (unattend_xml_path != NULL) { if (!ApplyWindowsCustomization(drive_name[0], unattend_xml_flags | UNATTEND_WINDOWS_TO_GO)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_PATCH); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH)); } } else { assert(!img_report.is_windows_img); if (!ExtractISO(image_path, drive_name, FALSE)) { - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_EXTRACT); + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_EXTRACT)); goto out; } if (HAS_KOLIBRIOS(img_report)) { kolibri_dst[0] = drive_name[0]; uprintf("Installing: %s (KolibriOS loader)", kolibri_dst); if (ExtractISOFile(image_path, "HD_Load/USB_Boot/MTLD_F32", kolibri_dst, - FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM) == 0) { + FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM) == 0) { uprintf("Warning: loader installation failed - KolibriOS will not boot!"); } } @@ -1944,12 +1943,12 @@ DWORD WINAPI FormatThread(void* param) efi_dst[sizeof(efi_dst) - sizeof("\\bootx64.efi")] = 0; if (!CreateDirectoryA(efi_dst, 0)) { uprintf("Could not create directory '%s': %s", efi_dst, WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_PATCH); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH)); } else { efi_dst[sizeof(efi_dst) - sizeof("\\bootx64.efi")] = '\\'; if (!WimExtractFile(img_report.wininst_path[0], 1, "Windows\\Boot\\EFI\\bootmgfw.efi", efi_dst, FALSE)) { uprintf("Failed to setup Win7 EFI boot"); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_PATCH); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH)); } } } @@ -1957,11 +1956,11 @@ DWORD WINAPI FormatThread(void* param) if ( (target_type == TT_BIOS) && HAS_WINPE(img_report) ) { // Apply WinPE fixup if (!SetupWinPE(drive_name[0])) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_PATCH); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH)); } if (unattend_xml_path != NULL) { if (!ApplyWindowsCustomization(drive_name[0], unattend_xml_flags)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_PATCH); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_PATCH)); } } } @@ -1988,10 +1987,10 @@ DWORD WINAPI FormatThread(void* param) } // Copy any additonal files from an optional zip archive selected by the user - if (!IS_ERROR(FormatStatus)) { + if (!IS_ERROR(ErrorStatus)) { UpdateProgress(OP_EXTRACT_ZIP, 0.0f); drive_name[2] = 0; - if (archive_path != NULL && fs_type < FS_EXT2 && !ExtractZip(archive_path, drive_name) && !IS_ERROR(FormatStatus)) + if (archive_path != NULL && fs_type < FS_EXT2 && !ExtractZip(archive_path, drive_name) && !IS_ERROR(ErrorStatus)) uprintf("Warning: Could not copy additional files"); } @@ -2021,7 +2020,7 @@ DWORD WINAPI FormatThread(void* param) } } } - if (IS_ERROR(FormatStatus)) { + if (IS_ERROR(ErrorStatus)) { volume_name = GetLogicalName(DriveIndex, SelectedDrive.Partition[partition_index[PI_MAIN]].Offset, TRUE, TRUE); if (volume_name != NULL) { if (MountVolume(drive_name, volume_name)) diff --git a/src/format_ext.c b/src/format_ext.c index f5b854ac407..69983672171 100644 --- a/src/format_ext.c +++ b/src/format_ext.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * extfs formatting - * Copyright © 2019-2021 Pete Batard + * Copyright © 2019-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 @@ -178,7 +178,7 @@ const char* error_message(errcode_t error_code) if ((error_code > EXT2_ET_BASE) && error_code < (EXT2_ET_BASE + 1000)) { static_sprintf(error_string, "Unknown ext2fs error %ld (EXT2_ET_BASE + %ld)", error_code, error_code - EXT2_ET_BASE); } else { - SetLastError((FormatStatus == 0) ? (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (error_code & 0xFFFF)) : FormatStatus); + SetLastError((ErrorStatus == 0) ? RUFUS_ERROR(error_code & 0xFFFF) : ErrorStatus); static_sprintf(error_string, "%s", WindowsErrorString()); } return error_string; @@ -196,7 +196,7 @@ errcode_t ext2fs_print_progress(int64_t cur_value, int64_t max_value) last_value = cur_value; uprintfs("+"); } - return IS_ERROR(FormatStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; + return IS_ERROR(ErrorStatus) ? EXT2_ET_CANCEL_REQUESTED : 0; } const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) @@ -223,7 +223,7 @@ const char* GetExtFsLabel(DWORD DriveIndex, uint64_t PartitionOffset) #define TEST_IMG_PATH "\\??\\C:\\tmp\\disk.img" #define TEST_IMG_SIZE 4000 // Size in MB -#define SET_EXT2_FORMAT_ERROR(x) if (!IS_ERROR(FormatStatus)) FormatStatus = ext2_last_winerror(x) +#define SET_EXT2_FORMAT_ERROR(x) if (!IS_ERROR(ErrorStatus)) ErrorStatus = ext2_last_winerror(x) BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LPCSTR FSName, LPCSTR Label, DWORD Flags) { @@ -273,7 +273,7 @@ BOOL FormatExtFs(DWORD DriveIndex, uint64_t PartitionOffset, DWORD BlockSize, LP volume_name = GetExtPartitionName(DriveIndex, PartitionOffset); #endif if ((volume_name == NULL) | (strlen(FSName) != 4) || (strncmp(FSName, "ext", 3) != 0)) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_INVALID_PARAMETER; + ErrorStatus = RUFUS_ERROR(ERROR_INVALID_PARAMETER); goto out; } if (strchr(volume_name, ' ') != NULL) diff --git a/src/format_fat32.c b/src/format_fat32.c index 230a09acce4..57cdfb77f7b 100644 --- a/src/format_fat32.c +++ b/src/format_fat32.c @@ -2,7 +2,7 @@ * Rufus: The Reliable USB Formatting Utility * Large FAT32 formatting * Copyright © 2007-2009 Tom Thornhill/Ridgecrop - * Copyright © 2011-2022 Pete Batard + * Copyright © 2011-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 @@ -38,9 +38,7 @@ #include "msapi_utf8.h" #include "localization.h" -#define die(msg, err) do { uprintf(msg); \ - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|err; \ - goto out; } while(0) +#define die(msg, err) do { uprintf(msg); ErrorStatus = RUFUS_ERROR(err); goto out; } while(0) extern BOOL write_as_esp; @@ -191,7 +189,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS ULONGLONG FatNeeded, ClusterCount; if (safe_strncmp(FSName, "FAT", 3) != 0) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_INVALID_PARAMETER; + ErrorStatus = RUFUS_ERROR(ERROR_INVALID_PARAMETER); goto out; } PrintInfoDebug(0, MSG_222, "Large FAT32"); @@ -202,7 +200,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS hLogicalVolume = write_as_esp ? AltGetLogicalHandle(DriveIndex, PartitionOffset, TRUE, TRUE, FALSE) : GetLogicalHandle(DriveIndex, PartitionOffset, TRUE, TRUE, FALSE); - if (IS_ERROR(FormatStatus)) + if (IS_ERROR(ErrorStatus)) goto out; if ((hLogicalVolume == INVALID_HANDLE_VALUE) || (hLogicalVolume == NULL)) die("Invalid logical volume handle", ERROR_INVALID_HANDLE); @@ -222,7 +220,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS } if (dgDrive.BytesPerSector < 512) dgDrive.BytesPerSector = 512; - if (IS_ERROR(FormatStatus)) goto out; + if (IS_ERROR(ErrorStatus)) goto out; if (!DeviceIoControl (hLogicalVolume, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, &piDrive, sizeof(piDrive), &cbRet, NULL)) { if (!DeviceIoControl (hLogicalVolume, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &xpiDrive, @@ -236,7 +234,7 @@ BOOL FormatLargeFAT32(DWORD DriveIndex, uint64_t PartitionOffset, DWORD ClusterS piDrive.PartitionLength.QuadPart = xpiDrive.PartitionLength.QuadPart; piDrive.HiddenSectors = (DWORD)(xpiDrive.StartingOffset.QuadPart / dgDrive.BytesPerSector); } - if (IS_ERROR(FormatStatus)) goto out; + if (IS_ERROR(ErrorStatus)) goto out; BytesPerSect = dgDrive.BytesPerSector; diff --git a/src/hash.c b/src/hash.c index 3635c8606d0..b3d278a3c71 100644 --- a/src/hash.c +++ b/src/hash.c @@ -5,7 +5,7 @@ * Copyright © 2004-2019 Tom St Denis * Copyright © 2004 g10 Code GmbH * Copyright © 2002-2015 Wei Dai & Igor Pavlov - * Copyright © 2015-2023 Pete Batard + * Copyright © 2015-2024 Pete Batard * Copyright © 2022 Jeffrey Walton * Copyright © 2016 Alexander Graf * @@ -1468,7 +1468,7 @@ BOOL HashFile(const unsigned type, const char* path, uint8_t* hash) h = CreateFileU(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (h == INVALID_HANDLE_VALUE) { uprintf("Could not open file: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } @@ -1476,7 +1476,7 @@ BOOL HashFile(const unsigned type, const char* path, uint8_t* hash) for (rb = 0; ; rb += rs) { CHECK_FOR_USER_CANCEL; if (!ReadFile(h, buf, sizeof(buf), &rs, NULL)) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_READ_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_READ_FAULT); uprintf(" Read error: %s", WindowsErrorString()); goto out; } @@ -1983,7 +1983,7 @@ DWORD WINAPI HashThread(void* param) fd = CreateFileAsync(image_path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN); if (fd == NULL) { uprintf("Could not open file: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } @@ -2004,7 +2004,7 @@ DWORD WINAPI HashThread(void* param) if ((!WaitFileAsync(fd, DRIVE_ACCESS_TIMEOUT)) || (!GetSizeAsync(fd, &read_size[read_bufnum]))) { uprintf("Read error: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_READ_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_READ_FAULT); goto out; } diff --git a/src/icon.c b/src/icon.c index 2dd5882cd28..908feda1334 100644 --- a/src/icon.c +++ b/src/icon.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * Extract icon from executable and set autorun.inf - * Copyright © 2012-2021 Pete Batard + * Copyright © 2012-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 @@ -95,7 +95,7 @@ BOOL ExtractAppIcon(const char* path, BOOL bSilent) HRSRC res; WORD i; BYTE* res_data; - DWORD res_size, Size, offset; + DWORD res_size, offset; HANDLE hFile = INVALID_HANDLE_VALUE; BOOL r = FALSE; GRPICONDIR* icondir; @@ -110,22 +110,22 @@ BOOL ExtractAppIcon(const char* path, BOOL bSilent) } // Write .ico header - if (!WriteFileWithRetry(hFile, icondir, 3*sizeof(WORD), &Size, WRITE_RETRIES)) { + if (!WriteFileWithRetry(hFile, icondir, 3 * sizeof(WORD), NULL, WRITE_RETRIES)) { uprintf("Could not write icon header: %s.", WindowsErrorString()); goto out; } // Write icon data - offset = 3*sizeof(WORD) + icondir->idCount*sizeof(ICONDIRENTRY); + offset = 3*sizeof(WORD) + icondir->idCount * sizeof(ICONDIRENTRY); for (i=0; iidCount; i++) { // Write the common part of ICONDIRENTRY - if (!WriteFileWithRetry(hFile, &icondir->idEntries[i], sizeof(GRPICONDIRENTRY)-sizeof(WORD), &Size, WRITE_RETRIES)) { + if (!WriteFileWithRetry(hFile, &icondir->idEntries[i], sizeof(GRPICONDIRENTRY)-sizeof(WORD), NULL, WRITE_RETRIES)) { uprintf("Could not write ICONDIRENTRY[%d]: %s.", i, WindowsErrorString()); goto out; } res = FindResourceA(hMainInstance, MAKEINTRESOURCEA(icondir->idEntries[i].nID), _RT_ICON); // Write the DWORD offset - if (!WriteFileWithRetry(hFile, &offset, sizeof(offset), &Size, WRITE_RETRIES)) { + if (!WriteFileWithRetry(hFile, &offset, sizeof(offset), NULL, WRITE_RETRIES)) { uprintf("Could not write ICONDIRENTRY[%d] offset: %s.", i, WindowsErrorString()); goto out; } @@ -137,7 +137,7 @@ BOOL ExtractAppIcon(const char* path, BOOL bSilent) res_handle = LoadResource(NULL, res); res_data = (BYTE*)LockResource(res_handle); res_size = SizeofResource(NULL, res); - if (!WriteFileWithRetry(hFile, res_data, res_size, &Size, WRITE_RETRIES)) { + if (!WriteFileWithRetry(hFile, res_data, res_size, NULL, WRITE_RETRIES)) { uprintf("Could not write icon data #%d: %s.", i, WindowsErrorString()); goto out; } diff --git a/src/iso.c b/src/iso.c index 391bf8ecf3a..33ab24974e7 100644 --- a/src/iso.c +++ b/src/iso.c @@ -554,7 +554,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha if (psz_path[0] == 0) UpdateProgressWithInfoInit(NULL, TRUE); while ((p_udf_dirent = udf_readdir(p_udf_dirent)) != NULL) { - if (FormatStatus) goto out; + if (ErrorStatus) goto out; psz_basename = udf_get_filename(p_udf_dirent); if (strlen(psz_basename) == 0) continue; @@ -621,7 +621,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha if (fd_md5sum != NULL) hash_init[HASH_MD5](&ctx); while (file_length > 0) { - if (FormatStatus) + if (ErrorStatus) goto out; nb = (size_t)MIN(ISO_BUFFER_SIZE / UDF_BLOCKSIZE, (file_length + UDF_BLOCKSIZE - 1) / UDF_BLOCKSIZE); read = udf_read_block(p_udf_dirent, buf, nb); @@ -722,7 +722,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) if (psz_path[0] == 0) UpdateProgressWithInfoInit(NULL, TRUE); _CDIO_LIST_FOREACH(p_entnode, p_entlist) { - if (FormatStatus) goto out; + if (ErrorStatus) goto out; p_statbuf = (iso9660_stat_t*) _cdio_list_node_data(p_entnode); free_p_statbuf = FALSE; if (scan_only && (p_statbuf->rr.b3_rock == yep) && enable_rockridge) { @@ -887,7 +887,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path) if (fd_md5sum != NULL) hash_init[HASH_MD5](&ctx); for (i = 0; file_length > 0; i += nb) { - if (FormatStatus) + if (ErrorStatus) goto out; lsn = p_statbuf->lsn + (lsn_t)i; nb = (size_t)MIN(ISO_BUFFER_SIZE / ISO_BLOCKSIZE, (file_length + ISO_BLOCKSIZE - 1) / ISO_BLOCKSIZE); @@ -1067,7 +1067,7 @@ BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan) IGNORE_RETVAL(_chdirU(app_data_dir)); if (total_blocks == 0) { uprintf("Error: ISO has not been properly scanned."); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_ISO_SCAN); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_SCAN)); goto out; } nb_blocks = 0; @@ -1388,8 +1388,8 @@ BOOL ExtractISO(const char* src_iso, const char* dest_dir, BOOL scan) } iso9660_close(p_iso); udf_close(p_udf); - if ((r != 0) && (FormatStatus == 0)) - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR((scan_only?ERROR_ISO_SCAN:ERROR_ISO_EXTRACT)); + if ((r != 0) && (ErrorStatus == 0)) + ErrorStatus = RUFUS_ERROR(APPERR(scan_only ? ERROR_ISO_SCAN : ERROR_ISO_EXTRACT)); return (r == 0); } @@ -1766,8 +1766,8 @@ BOOL DumpFatDir(const char* path, int32_t cluster) while ((s != 0) && (s < 0xFFFFFFFFULL) && (written < diritem.size)) { buf = libfat_get_sector(lf_fs, s); if (buf == NULL) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_SECTOR_NOT_FOUND; - if (IS_ERROR(FormatStatus)) + ErrorStatus = RUFUS_ERROR(ERROR_SECTOR_NOT_FOUND); + if (IS_ERROR(ErrorStatus)) goto out; size = MIN(LIBFAT_SECTOR_SIZE, diritem.size - written); if (!WriteFileWithRetry(handle, buf, size, &size, WRITE_RETRIES) || @@ -1826,7 +1826,7 @@ static DWORD WINAPI IsoSaveImageThread(void* param) hPhysicalDrive = CreateFileA(img_save->DevicePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (hPhysicalDrive == INVALID_HANDLE_VALUE) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } @@ -1838,13 +1838,13 @@ static DWORD WINAPI IsoSaveImageThread(void* param) CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hDestImage == INVALID_HANDLE_VALUE) { uprintf("Could not open image '%s': %s", img_save->ImagePath, WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_OPEN_FAILED; + ErrorStatus = RUFUS_ERROR(ERROR_OPEN_FAILED); goto out; } buffer = (uint8_t*)_mm_malloc(img_save->BufSize, 16); if (buffer == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_ENOUGH_MEMORY; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); uprintf("Could not allocate buffer"); goto out; } @@ -1864,7 +1864,7 @@ static DWORD WINAPI IsoSaveImageThread(void* param) s = ReadFile(hPhysicalDrive, buffer, (DWORD)MIN(img_save->BufSize, img_save->DeviceSize - wb), &rSize, NULL); if (!s) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_READ_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_READ_FAULT); uprintf("Read error: %s", WindowsErrorString()); goto out; } @@ -1889,7 +1889,7 @@ static DWORD WINAPI IsoSaveImageThread(void* param) goto out; } } else { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } Sleep(200); @@ -1900,7 +1900,7 @@ static DWORD WINAPI IsoSaveImageThread(void* param) if (wb != img_save->DeviceSize) { uprintf("Error: wrote %s, expected %s", SizeToHumanReadable(wb, FALSE, FALSE), SizeToHumanReadable(img_save->DeviceSize, FALSE, FALSE)); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } uprintf("Operation complete (Wrote %s).", SizeToHumanReadable(wb, FALSE, FALSE)); @@ -1941,7 +1941,7 @@ void IsoSaveImage(void) uprintf("ISO media size %s", SizeToHumanReadable(img_save.DeviceSize, FALSE, FALSE)); SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); - FormatStatus = 0; + ErrorStatus = 0; // Disable all controls except cancel EnableControls(FALSE, FALSE); InitProgress(TRUE); @@ -1952,7 +1952,7 @@ void IsoSaveImage(void) SendMessage(hMainDialog, UM_TIMER_START, 0, 0); } else { uprintf("Unable to start ISO save thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); safe_free(img_save.ImagePath); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } diff --git a/src/ms-sys/file.c b/src/ms-sys/file.c index 29ec5752d48..8e26b219ba9 100644 --- a/src/ms-sys/file.c +++ b/src/ms-sys/file.c @@ -50,7 +50,7 @@ int64_t write_sectors(HANDLE hDrive, uint64_t SectorSize, LastWriteError = 0; if(!WriteFileWithRetry(hDrive, pBuf, Size, &Size, WRITE_RETRIES)) { - LastWriteError = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|GetLastError(); + LastWriteError = RUFUS_ERROR(GetLastError()); uprintf("write_sectors: Write error %s\n", WindowsErrorString()); uprintf(" StartSector: 0x%08" PRIx64 ", nSectors: 0x%" PRIx64 ", SectorSize: 0x%" PRIx64 "\n", StartSector, nSectors, SectorSize); return -1; @@ -63,7 +63,7 @@ int64_t write_sectors(HANDLE hDrive, uint64_t SectorSize, return 0; } uprintf("write_sectors: Write error\n"); - LastWriteError = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + LastWriteError = RUFUS_ERROR(ERROR_WRITE_FAULT); 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 -1; diff --git a/src/net.c b/src/net.c index 4c47ecc8660..682fae895f6 100644 --- a/src/net.c +++ b/src/net.c @@ -204,7 +204,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char* PF_INIT_OR_OUT(HttpSendRequestA, WinInet); PF_INIT_OR_OUT(HttpQueryInfoA, WinInet); - FormatStatus = 0; + ErrorStatus = 0; DownloadStatus = 404; if (hProgressDialog != NULL) UpdateProgressWithInfoInit(hProgressDialog, FALSE); @@ -258,7 +258,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char* pfHttpQueryInfoA(hRequest, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, (LPVOID)&DownloadStatus, &dwSize, NULL); if (DownloadStatus != 200) { error_code = ERROR_INTERNET_ITEM_NOT_FOUND; - SetLastError(ERROR_SEVERITY_ERROR | FAC(FACILITY_HTTP) | error_code); + SetLastError(RUFUS_ERROR(error_code)); uprintf("%s: %d", (DownloadStatus == 404) ? "File not found" : "Unable to access file", DownloadStatus); goto out; } @@ -300,7 +300,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char* // Keep checking for data until there is nothing left. while (1) { // User may have cancelled the download - if (IS_ERROR(FormatStatus)) + if (IS_ERROR(ErrorStatus)) goto out; if (!pfInternetReadFile(hRequest, buf, sizeof(buf), &dwDownloaded) || (dwDownloaded == 0)) break; @@ -322,7 +322,7 @@ uint64_t DownloadToFileOrBufferEx(const char* url, const char* file, const char* if (size != total_size) { uprintf("Could not download complete file - read: %lld bytes, expected: %lld bytes", size, total_size); - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT; + ErrorStatus = RUFUS_ERROR(ERROR_WRITE_FAULT); goto out; } else { DownloadStatus = 200; @@ -383,7 +383,7 @@ DWORD DownloadSignedFile(const char* url, const char* file, HWND hProgressDialog if ((sig_len != RSA_SIGNATURE_SIZE) || (!ValidateOpensslSignature(buf, buf_len, sig, sig_len))) { uprintf("FATAL: Download signature is invalid ✗"); DownloadStatus = 403; // Forbidden - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_BAD_SIGNATURE); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_BAD_SIGNATURE)); SendMessage(GetDlgItem(hProgressDialog, IDC_PROGRESS), PBM_SETSTATE, (WPARAM)PBST_ERROR, 0); SetTaskbarProgressState(TASKBAR_ERROR); goto out; @@ -413,7 +413,7 @@ DWORD DownloadSignedFile(const char* url, const char* file, HWND hProgressDialog if ((bPromptOnError) && (DownloadStatus != 200)) { PrintInfo(0, MSG_242); SetLastError(error_code); - MessageBoxExU(hMainDialog, IS_ERROR(FormatStatus) ? StrError(FormatStatus, FALSE) : WindowsErrorString(), + MessageBoxExU(hMainDialog, IS_ERROR(ErrorStatus) ? StrError(ErrorStatus, FALSE) : WindowsErrorString(), lmprintf(MSG_044), MB_OK | MB_ICONERROR | MB_IS_RTL, selected_langid); } safe_closehandle(hFile); @@ -768,7 +768,7 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) dwSize = (DWORD)DownloadToFileOrBuffer(sig_url, NULL, &sig, NULL, FALSE); if ((dwSize != RSA_SIGNATURE_SIZE) || (!ValidateOpensslSignature(compressed, dwCompressedSize, sig, dwSize))) { uprintf("FATAL: Download signature is invalid ✗"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_BAD_SIGNATURE); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_BAD_SIGNATURE)); SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_ERROR, 0); SetTaskbarProgressState(TASKBAR_ERROR); safe_free(compressed); @@ -778,7 +778,7 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) free(sig); uprintf("Download signature is valid ✓"); uncompressed_size = *((uint64_t*)&compressed[5]); - if ((uncompressed_size < 1 * MB) && (bled_init(0, uprintf, NULL, NULL, NULL, NULL, &FormatStatus) >= 0)) { + if ((uncompressed_size < 1 * MB) && (bled_init(0, uprintf, NULL, NULL, NULL, NULL, &ErrorStatus) >= 0)) { fido_script = malloc((size_t)uncompressed_size); size = bled_uncompress_from_buffer_to_buffer(compressed, dwCompressedSize, fido_script, (size_t)uncompressed_size, BLED_COMPRESSION_LZMA); bled_exit(); @@ -787,7 +787,7 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) if (size != uncompressed_size) { uprintf("FATAL: Could not uncompressed download script"); safe_free(fido_script); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_INVALID_DATA; + ErrorStatus = RUFUS_ERROR(ERROR_INVALID_DATA); SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_ERROR, 0); SetTaskbarProgressState(TASKBAR_ERROR); goto out; @@ -840,7 +840,7 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) // signed, we also validate the Authenticode signature of the local script. if (ValidateSignature(INVALID_HANDLE_VALUE, script_path) != NO_ERROR) { uprintf("FATAL: Script signature is invalid ✗"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_BAD_SIGNATURE); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_BAD_SIGNATURE)); SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_ERROR, 0); SetTaskbarProgressState(TASKBAR_ERROR); goto out; @@ -848,7 +848,7 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) uprintf("Script signature is valid ✓"); #endif - FormatStatus = 0; + ErrorStatus = 0; dwExitCode = RunCommand(cmdline, app_data_dir, TRUE); uprintf("Exited download script with code: %d", dwExitCode); if ((dwExitCode == 0) && PeekNamedPipe(hPipe, NULL, dwPipeSize, NULL, &dwAvail, NULL) && (dwAvail != 0)) { @@ -876,11 +876,11 @@ static DWORD WINAPI DownloadISOThread(LPVOID param) } // Download the ISO and report errors if any SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); - FormatStatus = 0; + ErrorStatus = 0; SendMessage(hMainDialog, UM_TIMER_START, 0, 0); if (DownloadToFileOrBuffer(url, img_save.ImagePath, NULL, hMainDialog, TRUE) == 0) { SendMessage(hMainDialog, UM_PROGRESS_EXIT, 0, 0); - if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) { + if (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED) { uprintf("Download cancelled by user"); Notification(MSG_INFO, NULL, NULL, lmprintf(MSG_211), lmprintf(MSG_041)); PrintInfo(0, MSG_211); @@ -917,7 +917,7 @@ BOOL DownloadISO() { if (CreateThread(NULL, 0, DownloadISOThread, NULL, 0, NULL) == NULL) { uprintf("Unable to start Windows ISO download thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); SendMessage(hMainDialog, UM_ENABLE_CONTROLS, 0, 0); return FALSE; } @@ -949,7 +949,7 @@ BOOL IsDownloadable(const char* url) if (url == NULL) return FALSE; - FormatStatus = 0; + ErrorStatus = 0; DownloadStatus = 404; if ((!pfInternetCrackUrlA(url, (DWORD)safe_strlen(url), 0, &UrlParts)) diff --git a/src/pki.c b/src/pki.c index 1d6a674d3ff..5c69d3fce8b 100644 --- a/src/pki.c +++ b/src/pki.c @@ -1,7 +1,7 @@ /* * Rufus: The Reliable USB Formatting Utility * PKI functions (code signing, etc.) - * Copyright © 2015-2023 Pete Batard + * Copyright © 2015-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 @@ -652,7 +652,7 @@ LONG ValidateSignature(HWND hDlg, const char* path) trust_file.pcwszFilePath = utf8_to_wchar(path); if (trust_file.pcwszFilePath == NULL) { uprintf("PKI: Unable to convert '%s' to UTF16", path); - return ERROR_SEVERITY_ERROR | FAC(FACILITY_CERT) | ERROR_NOT_ENOUGH_MEMORY; + return RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY); } trust_data.cbStruct = sizeof(trust_data); diff --git a/src/rufus.c b/src/rufus.c index a2630df08fb..920bacb8d8b 100755 --- a/src/rufus.c +++ b/src/rufus.c @@ -1290,8 +1290,7 @@ DWORD WINAPI ImageScanThread(LPVOID param) ComboBox_ResetContent(hImageOption); imop_win_sel = 0; - if ((FormatStatus == (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_CANCELLED)) || - (img_report.image_size == 0) || + if ((ErrorStatus == RUFUS_ERROR(ERROR_CANCELLED)) || (img_report.image_size == 0) || (!img_report.is_iso && (img_report.is_bootable_img <= 0) && !img_report.is_windows_img)) { // Failed to scan image if (img_report.is_bootable_img < 0) @@ -2246,7 +2245,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA MB_YESNO|MB_ICONWARNING|MB_IS_RTL, selected_langid) == IDYES)) { // Operation may have completed in the meantime if (format_thread != NULL) { - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; + ErrorStatus = RUFUS_ERROR(ERROR_CANCELLED); PrintInfo(0, MSG_201); uprintf("Cancelling"); // Start a timer to detect blocking operations during ISO file extraction @@ -2262,7 +2261,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA return (INT_PTR)TRUE; } else if (op_in_progress) { // User might be trying to cancel during preliminary checks - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; + ErrorStatus = RUFUS_ERROR(ERROR_CANCELLED); PrintInfo(0, MSG_201); EnableWindow(GetDlgItem(hDlg, IDCANCEL), TRUE); return (INT_PTR)TRUE; @@ -2554,10 +2553,10 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA free(old_image_path); } } - FormatStatus = 0; + ErrorStatus = 0; if (CreateThread(NULL, 0, ImageScanThread, NULL, 0, NULL) == NULL) { uprintf("Unable to start ISO scanning thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); } } break; @@ -2585,7 +2584,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA unattend_xml_flags = 0; // Disable all controls except Cancel EnableControls(FALSE, FALSE); - FormatStatus = 0; + ErrorStatus = 0; LastWriteError = 0; StrArrayClear(&BlockingProcessList); no_confirmation_on_cancel = FALSE; @@ -2595,7 +2594,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA // On exit, this thread sends message UM_FORMAT_START back to this dialog. if (CreateThread(NULL, 0, BootCheckThread, NULL, 0, NULL) == NULL) { uprintf("Unable to start boot check thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } break; @@ -2612,7 +2611,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA case IDC_HASH: // TODO: Move this as a fn call in hash.c? if ((format_thread == NULL) && (image_path != NULL)) { - FormatStatus = 0; + ErrorStatus = 0; no_confirmation_on_cancel = TRUE; SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); // Disable all controls except cancel @@ -2626,7 +2625,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA SendMessage(hMainDialog, UM_TIMER_START, 0, 0); } else { uprintf("Unable to start hash thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } } @@ -2650,9 +2649,9 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA break; case UM_ENABLE_CONTROLS: KillTimer(hMainDialog, TID_APP_TIMER); - if (!IS_ERROR(FormatStatus)) + if (!IS_ERROR(ErrorStatus)) PrintInfo(0, MSG_210); - else switch (SCODE_CODE(FormatStatus)) { + else switch (SCODE_CODE(ErrorStatus)) { case ERROR_CANCELLED: PrintInfo(0, MSG_211); break; @@ -2935,9 +2934,9 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA if (isMarquee) { SendMessage(hProgress, PBM_SETMARQUEE, FALSE, 0); SetTaskbarProgressValue(0, MAX_PROGRESS); - } else if (!IS_ERROR(FormatStatus)) { + } else if (!IS_ERROR(ErrorStatus)) { SetTaskbarProgressValue(MAX_PROGRESS, MAX_PROGRESS); - } else if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) { + } else if (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED) { tb_state = PBST_PAUSED; tb_flags = TASKBAR_PAUSED; } else { @@ -3010,7 +3009,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA format_thread = CreateThread(NULL, 0, FormatThread, (LPVOID)(uintptr_t)DeviceNum, 0, NULL); if (format_thread == NULL) { uprintf("Unable to start formatting thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } else { SetThreadPriority(format_thread, default_thread_priority); @@ -3033,8 +3032,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA EnableControls(TRUE, FALSE); break; } - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | - ((wParam == BOOTCHECK_DOWNLOAD_ERROR) ? APPERR(ERROR_CANT_DOWNLOAD) : ERROR_GEN_FAILURE); + ErrorStatus = RUFUS_ERROR((wParam == BOOTCHECK_DOWNLOAD_ERROR) ? APPERR(ERROR_CANT_DOWNLOAD) : ERROR_GEN_FAILURE); // Fall through case UM_FORMAT_COMPLETED: @@ -3055,13 +3053,13 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA uprintf("\r\n"); GetDevices(DeviceNum); } - if (!IS_ERROR(FormatStatus)) { + if (!IS_ERROR(ErrorStatus)) { SendMessage(hProgress, PBM_SETPOS, MAX_PROGRESS, 0); SetTaskbarProgressState(TASKBAR_NOPROGRESS); PrintInfo(0, MSG_210); MessageBeep(MB_OK); FlashTaskbar(dialog_handle); - } else if (SCODE_CODE(FormatStatus) == ERROR_CANCELLED) { + } else if (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED) { SendMessage(hProgress, PBM_SETSTATE, (WPARAM)PBST_PAUSED, 0); SetTaskbarProgressState(TASKBAR_PAUSED); PrintInfo(0, MSG_211); @@ -3085,7 +3083,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA "If (Get-Command -Commandtype Function Get-MpPreference -ErrorAction SilentlyContinue) { Exit 1 } Else { Exit 0 }", // Return 1 if Controlled Folder Access is enabled "Exit (Get-MpPreference).EnableControlledFolderAccess" }; - switch (SCODE_CODE(FormatStatus)) { + switch (SCODE_CODE(ErrorStatus)) { case ERROR_PARTITION_FAILURE: case ERROR_WRITE_FAULT: // Find if PowerShell is available at its expected location @@ -3105,7 +3103,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA break; } } - if (SCODE_CODE(FormatStatus) == ERROR_NOT_READY) { + if (SCODE_CODE(ErrorStatus) == ERROR_NOT_READY) { // A port cycle usually helps with a device not ready int index = ComboBox_GetCurSel(hDeviceList); if (index >= 0) { @@ -3113,10 +3111,10 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA CyclePort(index); } } - Notification(MSG_ERROR, NULL, NULL, lmprintf(MSG_042), lmprintf(MSG_043, StrError(FormatStatus, FALSE))); + Notification(MSG_ERROR, NULL, NULL, lmprintf(MSG_042), lmprintf(MSG_043, StrError(ErrorStatus, FALSE))); } } - FormatStatus = 0; + ErrorStatus = 0; LastWriteError = 0; return (INT_PTR)TRUE; diff --git a/src/rufus.h b/src/rufus.h index 7108dde37b4..82903838473 100644 --- a/src/rufus.h +++ b/src/rufus.h @@ -140,7 +140,7 @@ #define PERCENTAGE(percent, value) ((1ULL * (percent) * (value)) / 100ULL) #define IsChecked(CheckBox_ID) (IsDlgButtonChecked(hMainDialog, CheckBox_ID) == BST_CHECKED) #define MB_IS_RTL (right_to_left_mode?MB_RTLREADING|MB_RIGHT:0) -#define CHECK_FOR_USER_CANCEL if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) goto out +#define CHECK_FOR_USER_CANCEL if (IS_ERROR(ErrorStatus) && (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED)) goto out // Bit masks used for the display of additional image options in the UI #define IMOP_WINTOGO 0x01 #define IMOP_PERSISTENCE 0x02 @@ -664,7 +664,7 @@ extern HWND hMainDialog, hLogDialog, hStatus, hDeviceList, hCapacity, hImageOpti extern HWND hPartitionScheme, hTargetSystem, hFileSystem, hClusterSize, hLabel, hBootType; extern HWND hNBPasses, hLog, hInfo, hProgress, hDiskID; extern WORD selected_langid; -extern DWORD FormatStatus, DownloadStatus, MainThreadId, LastWriteError; +extern DWORD ErrorStatus, DownloadStatus, MainThreadId, LastWriteError; extern BOOL use_own_c32[NB_OLD_C32], detect_fakes, op_in_progress, right_to_left_mode; extern BOOL allow_dual_uefi_bios, large_drive, usb_debug; extern uint8_t image_options, *pe256ssp; @@ -896,3 +896,5 @@ static __inline HMODULE GetLibraryHandle(char* szLibraryName) { #define ERROR_CANT_MOUNT_VOLUME 0x120C #define ERROR_BAD_SIGNATURE 0x120D #define ERROR_CANT_DOWNLOAD 0x120E + +#define RUFUS_ERROR(err) (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (err)) diff --git a/src/rufus.rc b/src/rufus.rc index 962ccae61da..0d494913f3a 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.2120" +CAPTION "Rufus 4.5.2121" 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,2120,0 - PRODUCTVERSION 4,5,2120,0 + FILEVERSION 4,5,2121,0 + PRODUCTVERSION 4,5,2121,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.2120" + VALUE "FileVersion", "4.5.2121" 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.2120" + VALUE "ProductVersion", "4.5.2121" END END BLOCK "VarFileInfo" diff --git a/src/stdfn.c b/src/stdfn.c index dd9d4547599..e02df860ae9 100644 --- a/src/stdfn.c +++ b/src/stdfn.c @@ -830,7 +830,7 @@ DWORD RunCommandWithProgress(const char* cmd, const char* dir, BOOL log, int msg UpdateProgressWithInfoInit(NULL, FALSE); while (1) { // Check for user cancel - if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) { + if (IS_ERROR(ErrorStatus) && (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED)) { if (!TerminateProcess(pi.hProcess, ERROR_CANCELLED)) { uprintf("Could not terminate command: %s", WindowsErrorString()); } else switch (WaitForSingleObject(pi.hProcess, 5000)) { diff --git a/src/stdio.c b/src/stdio.c index 88ca20c2aa6..61984aff8d4 100644 --- a/src/stdio.c +++ b/src/stdio.c @@ -569,7 +569,7 @@ BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWr uprintf("Wrote %d bytes but requested %d", *lpNumberOfBytesWritten, nNumberOfBytesToWrite); } else { uprintf("Write error %s", WindowsErrorString()); - LastWriteError = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|GetLastError(); + LastWriteError = RUFUS_ERROR(GetLastError()); } // If we can't reposition for the next run, just abort if (!readFilePointer) @@ -581,7 +581,7 @@ BOOL WriteFileWithRetry(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWr } } if (SCODE_CODE(GetLastError()) == ERROR_SUCCESS) - SetLastError(ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_WRITE_FAULT); + SetLastError(RUFUS_ERROR(ERROR_WRITE_FAULT)); return FALSE; } @@ -912,7 +912,7 @@ BOOL ExtractZip(const char* src_zip, const char* dest_dir) if (src_zip == NULL) return FALSE; archive_size = _filesizeU(src_zip); - if (bled_init(256 * KB, NULL, NULL, NULL, update_progress, print_extracted_file, &FormatStatus) != 0) + if (bled_init(256 * KB, NULL, NULL, NULL, update_progress, print_extracted_file, &ErrorStatus) != 0) return FALSE; uprintf("● Copying files from '%s'", src_zip); extracted_bytes = bled_uncompress_to_dir(src_zip, dest_dir, BLED_COMPRESSION_ZIP); diff --git a/src/stdlg.c b/src/stdlg.c index 11450198edf..e75987c424f 100644 --- a/src/stdlg.c +++ b/src/stdlg.c @@ -121,7 +121,7 @@ char* FileDialog(BOOL save, char* path, const ext_t* ext, UINT* selected_ext) hr = CoCreateInstance(save ? &CLSID_FileSaveDialog : &CLSID_FileOpenDialog, NULL, CLSCTX_INPROC, &IID_IFileDialog, (LPVOID)&pfd); if (SUCCEEDED(hr) && (pfd == NULL)) // Never trust Microsoft APIs to do the right thing - hr = ERROR_SEVERITY_ERROR | FAC(FACILITY_WINDOWS) | ERROR_API_UNAVAILABLE; + hr = RUFUS_ERROR(ERROR_API_UNAVAILABLE); if (FAILED(hr)) { SetLastError(hr); @@ -1590,7 +1590,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR case IDC_DOWNLOAD: // Also doubles as abort and launch function switch(download_status) { case 1: // Abort - FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANCELLED; + ErrorStatus = RUFUS_ERROR(ERROR_CANCELLED); download_status = 0; hThread = NULL; break; @@ -1653,7 +1653,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR case UM_PROGRESS_INIT: EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE); SetWindowTextU(GetDlgItem(hDlg, IDC_DOWNLOAD), lmprintf(MSG_038)); - FormatStatus = 0; + ErrorStatus = 0; download_status = 1; return (INT_PTR)TRUE; case UM_PROGRESS_EXIT: @@ -1665,7 +1665,7 @@ INT_PTR CALLBACK NewVersionCallback(HWND hDlg, UINT message, WPARAM wParam, LPAR SetWindowTextU(GetDlgItem(hDlg, IDC_DOWNLOAD), lmprintf(MSG_040)); // Disable the download button if we found an invalid signature EnableWindow(GetDlgItem(hDlg, IDC_DOWNLOAD), - FormatStatus != (ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_BAD_SIGNATURE))); + ErrorStatus != RUFUS_ERROR(APPERR(ERROR_BAD_SIGNATURE))); download_status = 0; } return (INT_PTR)TRUE; diff --git a/src/syslinux.c b/src/syslinux.c index 504cf31d94e..f798894bde7 100644 --- a/src/syslinux.c +++ b/src/syslinux.c @@ -2,7 +2,7 @@ * * Copyright 2003 Lars Munch Christensen - All Rights Reserved * Copyright 1998-2008 H. Peter Anvin - All Rights Reserved - * Copyright 2012-2023 Pete Batard + * Copyright 2012-2024 Pete Batard * * Based on the Linux installer program for SYSLINUX by H. Peter Anvin * @@ -88,7 +88,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) const LARGE_INTEGER liZero = { {0, 0} }; HANDLE f_handle = INVALID_HANDLE_VALUE; HANDLE d_handle = INVALID_HANDLE_VALUE; - DWORD bytes_read, bytes_written, err; + DWORD bytes_read, err; S_NTFSSECT_VOLINFO vol_info = { 0 }; LARGE_INTEGER vcn, lba, len; S_NTFSSECT_EXTENT extent; @@ -208,12 +208,11 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) /* Write ldlinux.sys file */ if (!WriteFileWithRetry(f_handle, (const char _force *)syslinux_ldlinux[0], - syslinux_ldlinux_len[0], &bytes_written, WRITE_RETRIES)) { + syslinux_ldlinux_len[0], NULL, WRITE_RETRIES)) { uprintf("Could not write '%s': %s", &path[3], WindowsErrorString()); goto out; } - if (!WriteFileWithRetry(f_handle, syslinux_adv, 2 * ADV_SIZE, - &bytes_written, WRITE_RETRIES)) { + if (!WriteFileWithRetry(f_handle, syslinux_adv, 2 * ADV_SIZE, NULL, WRITE_RETRIES)) { uprintf("Could not write ADV to '%s': %s", &path[3], WindowsErrorString()); goto out; } @@ -302,8 +301,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) /* Rewrite the file */ if (!SetFilePointerEx(f_handle, liZero, NULL, FILE_BEGIN) || - !WriteFileWithRetry(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0], - &bytes_written, WRITE_RETRIES)) { + !WriteFileWithRetry(f_handle, syslinux_ldlinux[0], syslinux_ldlinux_len[0], NULL, WRITE_RETRIES)) { uprintf("Could not rewrite '%s': %s\n", &path[3], WindowsErrorString()); goto out; } @@ -328,8 +326,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) /* Write boot sector back */ if (!SetFilePointerEx(d_handle, liZero, NULL, FILE_BEGIN) || - !WriteFileWithRetry(d_handle, sectbuf, SECTOR_SIZE, - &bytes_written, WRITE_RETRIES)) { + !WriteFileWithRetry(d_handle, sectbuf, SECTOR_SIZE, NULL, WRITE_RETRIES)) { uprintf("Could not write Syslinux boot record: %s", WindowsErrorString()); goto out; } @@ -368,8 +365,7 @@ BOOL InstallSyslinux(DWORD drive_index, char drive_letter, int file_system) uprintf("Unable to create '%s'\n", path); goto out; } - if (!WriteFileWithRetry(f_handle, syslinux_mboot, syslinux_mboot_len, - &bytes_written, WRITE_RETRIES)) { + if (!WriteFileWithRetry(f_handle, syslinux_mboot, syslinux_mboot_len, NULL, WRITE_RETRIES)) { uprintf("Could not write '%s'", path); goto out; } diff --git a/src/vhd.c b/src/vhd.c index 1e475a91eb1..3db702bb8f2 100644 --- a/src/vhd.c +++ b/src/vhd.c @@ -120,9 +120,9 @@ static int8_t IsCompressedBootableImage(const char* path) buf = malloc(MBR_SIZE); if (buf == NULL) return 0; - FormatStatus = 0; + ErrorStatus = 0; if (img_report.compression_type < BLED_COMPRESSION_MAX) { - bled_init(0, uprintf, NULL, NULL, NULL, NULL, &FormatStatus); + bled_init(0, uprintf, NULL, NULL, NULL, NULL, &ErrorStatus); dc = bled_uncompress_to_buffer(path, (char*)buf, MBR_SIZE, file_assoc[i].type); bled_exit(); } else if (img_report.compression_type == BLED_COMPRESSION_MAX) { @@ -258,7 +258,7 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV UpdateProgressWithInfo(progress_op, progress_msg, wim_proc_files, wim_nb_files); } // Halt on error - if (IS_ERROR(FormatStatus)) { + if (IS_ERROR(ErrorStatus)) { pbCancel = (PBOOL)lParam; *pbCancel = TRUE; break; @@ -291,7 +291,7 @@ DWORD WINAPI WimProgressCallback(DWORD dwMsgId, WPARAM wParam, LPARAM lParam, PV break; } - return IS_ERROR(FormatStatus) ? WIM_MSG_ABORT_IMAGE : WIM_MSG_SUCCESS; + return IS_ERROR(ErrorStatus) ? WIM_MSG_ABORT_IMAGE : WIM_MSG_SUCCESS; } // Find out if we have any way to extract/apply WIM files on this platform @@ -1062,7 +1062,7 @@ static DWORD WINAPI VhdSaveImageThread(void* param) if (r == ERROR_IO_PENDING) { while ((r = WaitForSingleObject(overlapped.hEvent, 100)) == WAIT_TIMEOUT) { - if (IS_ERROR(FormatStatus) && (SCODE_CODE(FormatStatus) == ERROR_CANCELLED)) { + if (IS_ERROR(ErrorStatus) && (SCODE_CODE(ErrorStatus) == ERROR_CANCELLED)) { CancelIoEx(handle, &overlapped); goto out; } @@ -1110,10 +1110,10 @@ static DWORD WINAPI FfuSaveImageThread(void* param) img_save->DevicePath, img_save->ImagePath, label, APPLICATION_NAME, RUFUS_URL); uprintf("Running command: '%s", cmd); r = RunCommandWithProgress(cmd, sysnative_dir, TRUE, MSG_261); - if (r != 0 && !IS_ERROR(FormatStatus)) { + if (r != 0 && !IS_ERROR(ErrorStatus)) { SetLastError(r); uprintf("Failed to capture FFU image: %s", WindowsErrorString()); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_WINDOWS) | SCODE_CODE(r); + ErrorStatus = RUFUS_ERROR(SCODE_CODE(r)); } safe_free(img_save->DevicePath); safe_free(img_save->ImagePath); @@ -1172,21 +1172,21 @@ void VhdSaveImage(void) if (img_save.DevicePath != NULL && img_save.ImagePath != NULL) { // Reset all progress bars SendMessage(hMainDialog, UM_PROGRESS_INIT, 0, 0); - FormatStatus = 0; + ErrorStatus = 0; if (img_save.Type == VIRTUAL_STORAGE_TYPE_DEVICE_VHD) { free_space.QuadPart = 0; if ((GetVolumePathNameA(img_save.ImagePath, path, sizeof(path))) && (GetDiskFreeSpaceExA(path, &free_space, NULL, NULL)) && ((LONGLONG)free_space.QuadPart < (SelectedDrive.DiskSize + 512))) { uprintf("The VHD size is too large for the target drive"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_FILE_TOO_LARGE; + ErrorStatus = RUFUS_ERROR(ERROR_FILE_TOO_LARGE); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); goto out; } } // Disable all controls except Cancel EnableControls(FALSE, FALSE); - FormatStatus = 0; + ErrorStatus = 0; InitProgress(TRUE); format_thread = CreateThread(NULL, 0, img_save.Type == VIRTUAL_STORAGE_TYPE_DEVICE_FFU ? FfuSaveImageThread : VhdSaveImageThread, &img_save, 0, NULL); @@ -1196,7 +1196,7 @@ void VhdSaveImage(void) SendMessage(hMainDialog, UM_TIMER_START, 0, 0); } else { uprintf("Unable to start VHD save thread"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_START_THREAD); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_START_THREAD)); PostMessage(hMainDialog, UM_FORMAT_COMPLETED, (WPARAM)FALSE, 0); } } diff --git a/src/wue.c b/src/wue.c index e43020fba92..01dec2905f9 100644 --- a/src/wue.c +++ b/src/wue.c @@ -263,7 +263,7 @@ BOOL SetupWinPE(char drive_letter) const LARGE_INTEGER liZero = { {0, 0} }; char setupsrcdev[64]; HANDLE handle = INVALID_HANDLE_VALUE; - DWORD i, j, size, rw_size, index = 0; + DWORD i, j, size, read_size, index = 0; BOOL r = FALSE; char* buffer = NULL; @@ -325,7 +325,7 @@ BOOL SetupWinPE(char drive_letter) buffer = (char*)malloc(size); if (buffer == NULL) goto out; - if ((!ReadFile(handle, buffer, size, &rw_size, NULL)) || (size != rw_size)) { + if ((!ReadFile(handle, buffer, size, &read_size, NULL)) || (size != read_size)) { uprintf("Could not read file %s: %s\n", dst, WindowsErrorString()); goto out; } @@ -373,7 +373,7 @@ BOOL SetupWinPE(char drive_letter) } } - if (!WriteFileWithRetry(handle, buffer, size, &rw_size, WRITE_RETRIES)) { + if (!WriteFileWithRetry(handle, buffer, size, NULL, WRITE_RETRIES)) { uprintf("Could not write patched file: %s\n", WindowsErrorString()); goto out; } @@ -650,7 +650,7 @@ BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp) uprintf("Windows To Go mode selected"); // Additional sanity checks if ((use_esp) && (SelectedDrive.MediaType != FixedMedia) && (WindowsVersion.BuildNumber < 15000)) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | ERROR_NOT_SUPPORTED; + ErrorStatus = RUFUS_ERROR(ERROR_NOT_SUPPORTED); return FALSE; } @@ -658,7 +658,7 @@ BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp) mounted_iso = VhdMountImage(image_path); if (mounted_iso == NULL) { uprintf("Could not mount ISO for Windows To Go installation"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_EXTRACT)); return FALSE; } static_sprintf(mounted_image_path, "%s%s", mounted_iso, &img_report.wininst_path[wininst_index][2]); @@ -668,8 +668,8 @@ BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp) // Now we use the WIM API to apply that image if (!WimApplyImage(img_report.is_windows_img ? image_path : mounted_image_path, wintogo_index, drive_name)) { uprintf("Failed to apply Windows To Go image"); - if (!IS_ERROR(FormatStatus)) - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); + if (!IS_ERROR(ErrorStatus)) + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_EXTRACT)); if (!img_report.is_windows_img) VhdUnmountImage(); return FALSE; @@ -702,7 +702,7 @@ BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp) // Need to have the ESP mounted to invoke bcdboot ms_efi = AltMountVolume(DriveIndex, SelectedDrive.Partition[partition_index[PI_ESP]].Offset, FALSE); if (ms_efi == NULL) { - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_CANT_ASSIGN_LETTER); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_ASSIGN_LETTER)); return FALSE; } } @@ -722,7 +722,7 @@ BOOL SetupWinToGo(DWORD DriveIndex, const char* drive_name, BOOL use_esp) if (RunCommand(cmd, sysnative_dir, usb_debug) != 0) { // Try to continue... but report a failure uprintf("Failed to enable boot"); - FormatStatus = ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | APPERR(ERROR_ISO_EXTRACT); + ErrorStatus = RUFUS_ERROR(APPERR(ERROR_ISO_EXTRACT)); } CopySKUSiPolicy((use_esp) ? ms_efi : drive_name);