Skip to content

Commit 8a5a5a3

Browse files
committed
[misc] improve readability of error code handling
* Also don't pass a read size value in WriteFileWithRetry() if we don't use it.
1 parent 52ca798 commit 8a5a5a3

25 files changed

+257
-252
lines changed

Diff for: .gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
*.a
22
*.aps
33
*.appx
4+
*.appxupload
5+
*.bak
46
*.db
57
*.db-shm
68
*.db-wal
79
*.dep
10+
*.diff
11+
*.dll
12+
*.efi
813
*.exe
914
*.htm
1015
*.idb
1116
*.ipch
1217
*.la
18+
*.lib
1319
*.lo
20+
*.lock
1421
*.log
1522
*.mac
1623
*.mo
24+
*.mp4
1725
*.ncb
26+
*.nope
1827
*.o
1928
*.obj
29+
*.old
2030
*.opendb
2131
*.opt
32+
*.org
33+
*.p7x
2234
*.patch
2335
*.pc
2436
*.pdb
37+
*.pdf
2538
*.plg
2639
*.res
2740
*.sig

Diff for: src/badblocks.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright 1992-1994 Remy Card <[email protected]>
55
* Copyright 1995-1999 Theodore Ts'o
66
* Copyright 1999 David Beattie
7-
* Copyright 2011-2023 Pete Batard <[email protected]>
7+
* Copyright 2011-2024 Pete Batard <[email protected]>
88
*
99
* This file is based on the minix file system programs fsck and mkfs
1010
* written and copyrighted by Linus Torvalds <[email protected]>
@@ -318,7 +318,7 @@ static void CALLBACK alarm_intr(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dw
318318
{
319319
if (!num_blocks)
320320
return;
321-
if (FormatStatus) {
321+
if (ErrorStatus) {
322322
uprintf("%sInterrupting at block %" PRIu64 "\n", bb_prefix,
323323
(unsigned long long) currently_testing);
324324
cancel_ops = -1;

Diff for: src/badblocks.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Copyright 1995, 1996, 1997, 1998, 1999 by Theodore Ts'o
99
* Copyright 1999 by David Beattie
10-
* Copyright 2011-2018 by Pete Batard
10+
* Copyright 2011-2024 by Pete Batard
1111
*
1212
* This file is based on the minix file system programs fsck and mkfs
1313
* written and copyrighted by Linus Torvalds <[email protected]>
@@ -28,12 +28,11 @@ typedef struct bb_struct_u64_iterate *bb_badblocks_iterate;
2828
typedef struct bb_struct_u64_list *bb_u64_list;
2929
typedef struct bb_struct_u64_iterate *bb_u64_iterate;
3030

31-
#define BB_ET_NO_MEMORY (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_NOT_ENOUGH_MEMORY)
32-
#define BB_ET_MAGIC_BADBLOCKS_LIST (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OBJECT_IN_LIST)
33-
#define BB_ET_MAGIC_BADBLOCKS_ITERATE (ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INVALID_BLOCK)
31+
#define BB_ET_NO_MEMORY RUFUS_ERROR(ERROR_NOT_ENOUGH_MEMORY)
32+
#define BB_ET_MAGIC_BADBLOCKS_LIST RUFUS_ERROR(ERROR_OBJECT_IN_LIST)
33+
#define BB_ET_MAGIC_BADBLOCKS_ITERATE RUFUS_ERROR(ERROR_INVALID_BLOCK)
3434

35-
#define BB_CHECK_MAGIC(struct, code) \
36-
if ((struct)->magic != (code)) return (code)
35+
#define BB_CHECK_MAGIC(struct, code) if ((struct)->magic != (code)) return (code)
3736
#define BB_BAD_BLOCKS_THRESHOLD 256
3837
#define BB_BLOCKS_AT_ONCE 64
3938
#define BB_SYS_PAGE_SIZE 4096

Diff for: src/dos.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Rufus: The Reliable USB Formatting Utility
33
* DOS boot file extraction, from the FAT12 floppy image in diskcopy.dll
44
* (MS WinME DOS) or from the embedded FreeDOS resource files
5-
* Copyright © 2011-2023 Pete Batard <[email protected]>
5+
* Copyright © 2011-2024 Pete Batard <[email protected]>
66
*
77
* This program is free software: you can redistribute it and/or modify
88
* it under the terms of the GNU General Public License as published by
@@ -352,7 +352,7 @@ BOOL ExtractFreeDOS(const char* path)
352352
IDR_FD_EGA17_CPX, IDR_FD_EGA18_CPX };
353353
char filename[MAX_PATH], locale_path[MAX_PATH];
354354
BYTE* res_data;
355-
DWORD res_size, Size;
355+
DWORD res_size;
356356
HANDLE hFile;
357357
int i;
358358

@@ -366,10 +366,10 @@ BOOL ExtractFreeDOS(const char* path)
366366
static_strcat(locale_path, "LOCALE\\");
367367
CreateDirectoryA(locale_path, NULL);
368368

369-
for (i=0; i<ARRAYSIZE(res_name); i++) {
369+
for (i = 0; i < ARRAYSIZE(res_name); i++) {
370370
res_data = (BYTE*)GetResource(hMainInstance, MAKEINTRESOURCEA(res_id[i]), _RT_RCDATA, res_name[i], &res_size, FALSE);
371371

372-
static_strcpy(filename, ((i<2)?path:locale_path));
372+
static_strcpy(filename, ((i<2) ? path : locale_path));
373373
static_strcat(filename, res_name[i]);
374374

375375
hFile = CreateFileA(filename, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL,
@@ -379,7 +379,7 @@ BOOL ExtractFreeDOS(const char* path)
379379
return FALSE;
380380
}
381381

382-
if (!WriteFileWithRetry(hFile, res_data, res_size, &Size, WRITE_RETRIES)) {
382+
if (!WriteFileWithRetry(hFile, res_data, res_size, NULL, WRITE_RETRIES)) {
383383
uprintf("Could not write file '%s': %s.", filename, WindowsErrorString());
384384
safe_closehandle(hFile);
385385
return FALSE;

Diff for: src/drive.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
194194
do {
195195
if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL))
196196
goto out;
197-
if (IS_ERROR(FormatStatus)) // User cancel
197+
if (IS_ERROR(ErrorStatus)) // User cancel
198198
break;
199199
Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES);
200200
} while (GetTickCount64() < EndTime);
201201
// If we reached this section, either we didn't manage to get a lock or the user cancelled
202202
uprintf("Could not lock access to %s: %s", Path, WindowsErrorString());
203203
// See if we can report the processes are accessing the drive
204-
if (!IS_ERROR(FormatStatus) && (access_mask == 0))
204+
if (!IS_ERROR(ErrorStatus) && (access_mask == 0))
205205
access_mask = GetProcessSearch(SEARCH_PROCESS_TIMEOUT, 0x07, FALSE);
206206
// Try to continue if the only access rights we saw were for read-only
207207
if ((access_mask & 0x07) != 0x01)
@@ -1006,7 +1006,7 @@ BOOL WaitForLogical(DWORD DriveIndex, uint64_t PartitionOffset)
10061006
return TRUE;
10071007
}
10081008
free(LogicalPath);
1009-
if (IS_ERROR(FormatStatus)) // User cancel
1009+
if (IS_ERROR(ErrorStatus)) // User cancel
10101010
return FALSE;
10111011
Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES);
10121012
} while (GetTickCount64() < EndTime);
@@ -2219,7 +2219,7 @@ BOOL RemountVolume(char* drive_name, BOOL bSilent)
22192219
} else {
22202220
suprintf("Could not remount %s as %c: %s", volume_name, toupper(drive_name[0]), WindowsErrorString());
22212221
// This will leave the drive inaccessible and must be flagged as an error
2222-
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_REMOUNT_VOLUME);
2222+
ErrorStatus = RUFUS_ERROR(APPERR(ERROR_CANT_REMOUNT_VOLUME));
22232223
return FALSE;
22242224
}
22252225
}
@@ -2493,7 +2493,7 @@ BOOL CreatePartition(HANDLE hDrive, int partition_style, int file_system, BOOL m
24932493
uprintf(" Could not access source image");
24942494
return FALSE;
24952495
}
2496-
if(!WriteFileWithRetry(hDrive, buffer, bufsize, &size, WRITE_RETRIES)) {
2496+
if(!WriteFileWithRetry(hDrive, buffer, bufsize, NULL, WRITE_RETRIES)) {
24972497
uprintf(" Write error: %s", WindowsErrorString());
24982498
return FALSE;
24992499
}

Diff for: src/drive.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#define VDS_RESCAN_REFRESH 0x00000001
5959
#define VDS_RESCAN_REENUMERATE 0x00000002
6060

61-
#define VDS_SET_ERROR(hr) do { if (hr != S_OK) { SetLastError((DWORD)hr); FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_GEN_FAILURE; } } while(0)
61+
#define VDS_SET_ERROR(hr) do { if (hr != S_OK) { SetLastError((DWORD)hr); ErrorStatus = RUFUS_ERROR(ERROR_GEN_FAILURE); } } while(0)
6262

6363
#if !defined(__MINGW32__)
6464
typedef enum _FSINFOCLASS {

Diff for: src/ext2fs/nt_io.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (C) 1993, 1994, 1995 Theodore Ts'o.
77
* Copyright (C) 1998 Andrey Shedel <[email protected]>
8-
* Copyright (C) 2018-2019 Pete Batard <[email protected]>
8+
* Copyright (C) 2018-2024 Pete Batard <[email protected]>
99
*
1010
* %Begin-Header%
1111
* This file may be redistributed under the terms of the GNU Library
@@ -180,7 +180,7 @@ static __inline unsigned _MapNtStatus(IN NTSTATUS Status)
180180
// Return the last Windows Error
181181
DWORD ext2_last_winerror(DWORD default_error)
182182
{
183-
return ERROR_SEVERITY_ERROR | FAC(FACILITY_STORAGE) | (LastWinError ? LastWinError : default_error);
183+
return RUFUS_ERROR(LastWinError ? LastWinError : default_error);
184184
}
185185

186186
//

0 commit comments

Comments
 (0)