mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] miscellaneous code cleanup and fixes
* Don't use hDrive handle for longer than necessary * Move all the popcount() function calls into missing.h * Ensure that the thread_affinity[] array is properly sized * Improve timeouts for conflicting process search
This commit is contained in:
		
							parent
							
								
									7df88aa931
								
							
						
					
					
						commit
						b3caf638b6
					
				
					 6 changed files with 25 additions and 33 deletions
				
			
		
							
								
								
									
										12
									
								
								src/dev.c
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								src/dev.c
									
										
									
									
									
								
							|  | @ -799,10 +799,8 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 				uprintf("NOTE: This device is a USB 3.%c device operating at lower speed...", '0' + props.lower_speed - 1); | 				uprintf("NOTE: This device is a USB 3.%c device operating at lower speed...", '0' + props.lower_speed - 1); | ||||||
| 		} | 		} | ||||||
| 		devint_data.cbSize = sizeof(devint_data); | 		devint_data.cbSize = sizeof(devint_data); | ||||||
| 		hDrive = INVALID_HANDLE_VALUE; |  | ||||||
| 		devint_detail_data = NULL; | 		devint_detail_data = NULL; | ||||||
| 		for (j = 0; ; j++) { | 		for (j = 0; ; j++) { | ||||||
| 			safe_closehandle(hDrive); |  | ||||||
| 			safe_free(devint_detail_data); | 			safe_free(devint_detail_data); | ||||||
| 
 | 
 | ||||||
| 			if (!SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &GUID_DEVINTERFACE_DISK, j, &devint_data)) { | 			if (!SetupDiEnumDeviceInterfaces(dev_info, &dev_info_data, &GUID_DEVINTERFACE_DISK, j, &devint_data)) { | ||||||
|  | @ -844,19 +842,18 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
| 			drive_number = GetDriveNumber(hDrive, devint_detail_data->DevicePath); | 			drive_number = GetDriveNumber(hDrive, devint_detail_data->DevicePath); | ||||||
|  | 			CloseHandle(hDrive); | ||||||
| 			if (drive_number < 0) | 			if (drive_number < 0) | ||||||
| 				continue; | 				continue; | ||||||
| 
 | 
 | ||||||
| 			drive_index = drive_number + DRIVE_INDEX_MIN; | 			drive_index = drive_number + DRIVE_INDEX_MIN; | ||||||
| 			if (!IsMediaPresent(drive_index)) { | 			if (!IsMediaPresent(drive_index)) { | ||||||
| 				uprintf("Device eliminated because it appears to contain no media"); | 				uprintf("Device eliminated because it appears to contain no media"); | ||||||
| 				safe_closehandle(hDrive); |  | ||||||
| 				safe_free(devint_detail_data); | 				safe_free(devint_detail_data); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
| 			if (GetDriveSize(drive_index) < (MIN_DRIVE_SIZE*MB)) { | 			if (GetDriveSize(drive_index) < (MIN_DRIVE_SIZE*MB)) { | ||||||
| 				uprintf("Device eliminated because it is smaller than %d MB", MIN_DRIVE_SIZE); | 				uprintf("Device eliminated because it is smaller than %d MB", MIN_DRIVE_SIZE); | ||||||
| 				safe_closehandle(hDrive); |  | ||||||
| 				safe_free(devint_detail_data); | 				safe_free(devint_detail_data); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
|  | @ -866,7 +863,6 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 					if (!props.is_Removable) { | 					if (!props.is_Removable) { | ||||||
| 						// Non removables should have been eliminated above, but since we
 | 						// Non removables should have been eliminated above, but since we
 | ||||||
| 						// are potentially dealing with system drives, better safe than sorry
 | 						// are potentially dealing with system drives, better safe than sorry
 | ||||||
| 						safe_closehandle(hDrive); |  | ||||||
| 						safe_free(devint_detail_data); | 						safe_free(devint_detail_data); | ||||||
| 						break; | 						break; | ||||||
| 					} | 					} | ||||||
|  | @ -880,7 +876,6 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 						} | 						} | ||||||
| 						if (*p) { | 						if (*p) { | ||||||
| 							uprintf("Device eliminated because it contains a mounted partition that is set as non-removable"); | 							uprintf("Device eliminated because it contains a mounted partition that is set as non-removable"); | ||||||
| 							safe_closehandle(hDrive); |  | ||||||
| 							safe_free(devint_detail_data); | 							safe_free(devint_detail_data); | ||||||
| 							break; | 							break; | ||||||
| 						} | 						} | ||||||
|  | @ -892,20 +887,17 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 					if (!list_non_usb_removable_drives) | 					if (!list_non_usb_removable_drives) | ||||||
| 						uprintf("If this device is not a Hard Drive, please e-mail the author of this application"); | 						uprintf("If this device is not a Hard Drive, please e-mail the author of this application"); | ||||||
| 					uprintf("NOTE: You can enable the listing of Hard Drives under 'advanced drive properties'"); | 					uprintf("NOTE: You can enable the listing of Hard Drives under 'advanced drive properties'"); | ||||||
| 					safe_closehandle(hDrive); |  | ||||||
| 					safe_free(devint_detail_data); | 					safe_free(devint_detail_data); | ||||||
| 					break; | 					break; | ||||||
| 				} | 				} | ||||||
| 				// Windows 10 19H1 mounts a 'PortableBaseLayer' for its Windows Sandbox feature => unlist those
 | 				// Windows 10 19H1 mounts a 'PortableBaseLayer' for its Windows Sandbox feature => unlist those
 | ||||||
| 				if (safe_strcmp(label, windows_sandbox_vhd_label) == 0) { | 				if (safe_strcmp(label, windows_sandbox_vhd_label) == 0) { | ||||||
| 					uprintf("Device eliminated because it is a Windows Sandbox VHD"); | 					uprintf("Device eliminated because it is a Windows Sandbox VHD"); | ||||||
| 					safe_closehandle(hDrive); |  | ||||||
| 					safe_free(devint_detail_data); | 					safe_free(devint_detail_data); | ||||||
| 					break; | 					break; | ||||||
| 				} | 				} | ||||||
| 				if (props.is_VHD && (!enable_VHDs)) { | 				if (props.is_VHD && (!enable_VHDs)) { | ||||||
| 					uprintf("Device eliminated because listing of VHDs is disabled (Alt-G)"); | 					uprintf("Device eliminated because listing of VHDs is disabled (Alt-G)"); | ||||||
| 					safe_closehandle(hDrive); |  | ||||||
| 					safe_free(devint_detail_data); | 					safe_free(devint_detail_data); | ||||||
| 					break; | 					break; | ||||||
| 				} | 				} | ||||||
|  | @ -943,7 +935,6 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 					if (remove_drive) { | 					if (remove_drive) { | ||||||
| 						uprintf("Removing %C: from the list: This is the %s!", drive_letters[--k], | 						uprintf("Removing %C: from the list: This is the %s!", drive_letters[--k], | ||||||
| 							(remove_drive==1)?"disk from which " APPLICATION_NAME " is running":"system disk"); | 							(remove_drive==1)?"disk from which " APPLICATION_NAME " is running":"system disk"); | ||||||
| 						safe_closehandle(hDrive); |  | ||||||
| 						safe_free(devint_detail_data); | 						safe_free(devint_detail_data); | ||||||
| 						break; | 						break; | ||||||
| 					} | 					} | ||||||
|  | @ -961,7 +952,6 @@ BOOL GetDevices(DWORD devnum) | ||||||
| 
 | 
 | ||||||
| 				IGNORE_RETVAL(ComboBox_SetItemData(hDeviceList, ComboBox_AddStringU(hDeviceList, entry), drive_index)); | 				IGNORE_RETVAL(ComboBox_SetItemData(hDeviceList, ComboBox_AddStringU(hDeviceList, entry), drive_index)); | ||||||
| 				maxwidth = max(maxwidth, GetEntryWidth(hDeviceList, entry)); | 				maxwidth = max(maxwidth, GetEntryWidth(hDeviceList, entry)); | ||||||
| 				safe_closehandle(hDrive); |  | ||||||
| 				safe_free(devint_detail_data); | 				safe_free(devint_detail_data); | ||||||
| 				break; | 				break; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -76,9 +76,18 @@ | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * Nibbled from https://github.com/hanji/popcnt/blob/master/populationcount.cpp
 |  * Nibbled from https://github.com/hanji/popcnt/blob/master/populationcount.cpp
 | ||||||
|  * Since MSVC x86_32 does not have intrinsic popcount64 and I don't have all day |  * Since MSVC x86_32 and/or ARM don't have intrinsic popcount and I don't have all day | ||||||
|  */ |  */ | ||||||
| static __inline int popcnt64(register uint64_t u) | static __inline uint8_t popcnt8(uint8_t val) | ||||||
|  | { | ||||||
|  | 	static const uint8_t nibble_lookup[16] = { | ||||||
|  | 		0, 1, 1, 2, 1, 2, 2, 3, | ||||||
|  | 		1, 2, 2, 3, 2, 3, 3, 4 | ||||||
|  | 	}; | ||||||
|  | 	return nibble_lookup[val & 0x0F] + nibble_lookup[val >> 4]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | static __inline uint8_t popcnt64(register uint64_t u) | ||||||
| { | { | ||||||
| 	u = (u & 0x5555555555555555) + ((u >> 1) & 0x5555555555555555); | 	u = (u & 0x5555555555555555) + ((u >> 1) & 0x5555555555555555); | ||||||
| 	u = (u & 0x3333333333333333) + ((u >> 2) & 0x3333333333333333); | 	u = (u & 0x3333333333333333) + ((u >> 2) & 0x3333333333333333); | ||||||
|  | @ -86,7 +95,7 @@ static __inline int popcnt64(register uint64_t u) | ||||||
| 	u = (u & 0x00ff00ff00ff00ff) + ((u >> 8) & 0x00ff00ff00ff00ff); | 	u = (u & 0x00ff00ff00ff00ff) + ((u >> 8) & 0x00ff00ff00ff00ff); | ||||||
| 	u = (u & 0x0000ffff0000ffff) + ((u >> 16) & 0x0000ffff0000ffff); | 	u = (u & 0x0000ffff0000ffff) + ((u >> 16) & 0x0000ffff0000ffff); | ||||||
| 	u = (u & 0x00000000ffffffff) + ((u >> 32) & 0x00000000ffffffff); | 	u = (u & 0x00000000ffffffff) + ((u >> 32) & 0x00000000ffffffff); | ||||||
| 	return (int)u; | 	return (uint8_t)u; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| static __inline void *_reallocf(void *ptr, size_t size) { | static __inline void *_reallocf(void *ptr, size_t size) { | ||||||
|  |  | ||||||
|  | @ -2052,7 +2052,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | ||||||
| 	static ULONG ulRegister = 0; | 	static ULONG ulRegister = 0; | ||||||
| 	static LPITEMIDLIST pidlDesktop = NULL; | 	static LPITEMIDLIST pidlDesktop = NULL; | ||||||
| 	static SHChangeNotifyEntry NotifyEntry; | 	static SHChangeNotifyEntry NotifyEntry; | ||||||
| 	static DWORD_PTR thread_affinity[4]; | 	static DWORD_PTR thread_affinity[CHECKSUM_MAX + 1]; | ||||||
| 	static HFONT hyperlink_font = NULL; | 	static HFONT hyperlink_font = NULL; | ||||||
| 	LONG lPos; | 	LONG lPos; | ||||||
| 	BOOL set_selected_fs; | 	BOOL set_selected_fs; | ||||||
|  | @ -2851,7 +2851,7 @@ static INT_PTR CALLBACK MainCallback(HWND hDlg, UINT message, WPARAM wParam, LPA | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if (!CheckDriveAccess(CHECK_DRIVE_TIMEOUT, TRUE)) | 		if (!CheckDriveAccess(SEARCH_PROCESS_TIMEOUT, TRUE)) | ||||||
| 			goto aborted_start; | 			goto aborted_start; | ||||||
| 
 | 
 | ||||||
| 		GetWindowTextU(hDeviceList, tmp, ARRAYSIZE(tmp)); | 		GetWindowTextU(hDeviceList, tmp, ARRAYSIZE(tmp)); | ||||||
|  |  | ||||||
|  | @ -81,9 +81,12 @@ | ||||||
| #define STATUS_MSG_TIMEOUT          3500		// How long should cheat mode messages appear for on the status bar
 | #define STATUS_MSG_TIMEOUT          3500		// How long should cheat mode messages appear for on the status bar
 | ||||||
| #define WRITE_RETRIES               4 | #define WRITE_RETRIES               4 | ||||||
| #define WRITE_TIMEOUT               5000		// How long we should wait between write retries (in ms)
 | #define WRITE_TIMEOUT               5000		// How long we should wait between write retries (in ms)
 | ||||||
|  | #if defined(_DEBUG) | ||||||
|  | #define SEARCH_PROCESS_TIMEOUT      60000 | ||||||
|  | #else | ||||||
| #define SEARCH_PROCESS_TIMEOUT      10000		// How long we should search for conflicting processes before giving up (in ms)
 | #define SEARCH_PROCESS_TIMEOUT      10000		// How long we should search for conflicting processes before giving up (in ms)
 | ||||||
|  | #endif | ||||||
| #define NET_SESSION_TIMEOUT         3500		// How long we should wait to connect, send or receive internet data
 | #define NET_SESSION_TIMEOUT         3500		// How long we should wait to connect, send or receive internet data
 | ||||||
| #define CHECK_DRIVE_TIMEOUT         2000 |  | ||||||
| #define MARQUEE_TIMER_REFRESH       10			// Time between progress bar marquee refreshes, in ms
 | #define MARQUEE_TIMER_REFRESH       10			// Time between progress bar marquee refreshes, in ms
 | ||||||
| #define FS_DEFAULT                  FS_FAT32 | #define FS_DEFAULT                  FS_FAT32 | ||||||
| #define SINGLE_CLUSTERSIZE_DEFAULT  0x00000100 | #define SINGLE_CLUSTERSIZE_DEFAULT  0x00000100 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 232, 326 | IDD_DIALOG DIALOGEX 12, 12, 232, 326 | ||||||
| STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | ||||||
| EXSTYLE WS_EX_ACCEPTFILES | EXSTYLE WS_EX_ACCEPTFILES | ||||||
| CAPTION "Rufus 3.12.1696" | CAPTION "Rufus 3.12.1697" | ||||||
| FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | FONT 9, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP |     LTEXT           "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP | ||||||
|  | @ -395,8 +395,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 3,12,1696,0 |  FILEVERSION 3,12,1697,0 | ||||||
|  PRODUCTVERSION 3,12,1696,0 |  PRODUCTVERSION 3,12,1697,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -414,13 +414,13 @@ BEGIN | ||||||
|             VALUE "Comments", "https://rufus.ie" |             VALUE "Comments", "https://rufus.ie" | ||||||
|             VALUE "CompanyName", "Akeo Consulting" |             VALUE "CompanyName", "Akeo Consulting" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "3.12.1696" |             VALUE "FileVersion", "3.12.1697" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" |             VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html" | ||||||
|             VALUE "OriginalFilename", "rufus-3.12.exe" |             VALUE "OriginalFilename", "rufus-3.12.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "3.12.1696" |             VALUE "ProductVersion", "3.12.1697" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/stdfn.c
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/stdfn.c
									
										
									
									
									
								
							|  | @ -37,16 +37,6 @@ int  nWindowsVersion = WINDOWS_UNDEFINED; | ||||||
| int  nWindowsBuildNumber = -1; | int  nWindowsBuildNumber = -1; | ||||||
| char WindowsVersionStr[128] = "Windows "; | char WindowsVersionStr[128] = "Windows "; | ||||||
| 
 | 
 | ||||||
| // __popcnt16, __popcnt, __popcnt64 are not available for ARM :(
 |  | ||||||
| uint8_t popcnt8(uint8_t val) |  | ||||||
| { |  | ||||||
| 	static const uint8_t nibble_lookup[16] = { |  | ||||||
| 		0, 1, 1, 2, 1, 2, 2, 3, |  | ||||||
| 		1, 2, 2, 3, 2, 3, 3, 4 |  | ||||||
| 	}; |  | ||||||
| 	return nibble_lookup[val & 0x0F] + nibble_lookup[val >> 4]; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /*
 | /*
 | ||||||
|  * Hash table functions - modified From glibc 2.3.2: |  * Hash table functions - modified From glibc 2.3.2: | ||||||
|  * [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986 |  * [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue