mirror of
				https://github.com/pbatard/rufus.git
				synced 2024-08-14 23:57:05 +00:00 
			
		
		
		
	[misc] expand lock cheat mode to also apply to write sharing
* Also improve log messages
This commit is contained in:
		
							parent
							
								
									ea940114ee
								
							
						
					
					
						commit
						867177c5cd
					
				
					 4 changed files with 25 additions and 21 deletions
				
			
		
							
								
								
									
										24
									
								
								src/drive.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/drive.c
									
										
									
									
									
								
							|  | @ -120,6 +120,7 @@ BOOL GetAutoMount(BOOL* enabled) | ||||||
| static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare) | static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare) | ||||||
| { | { | ||||||
| 	int i; | 	int i; | ||||||
|  | 	BOOL bSearchProcess = FALSE; | ||||||
| 	DWORD size; | 	DWORD size; | ||||||
| 	HANDLE hDrive = INVALID_HANDLE_VALUE; | 	HANDLE hDrive = INVALID_HANDLE_VALUE; | ||||||
| 	char DevPath[MAX_PATH]; | 	char DevPath[MAX_PATH]; | ||||||
|  | @ -145,22 +146,24 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr | ||||||
| 		if ((GetLastError() != ERROR_SHARING_VIOLATION) && (GetLastError() != ERROR_ACCESS_DENIED)) | 		if ((GetLastError() != ERROR_SHARING_VIOLATION) && (GetLastError() != ERROR_ACCESS_DENIED)) | ||||||
| 			break; | 			break; | ||||||
| 		if (i == 0) { | 		if (i == 0) { | ||||||
| 			uprintf("Waiting for access..."); | 			uprintf("Waiting for access on %s [%s]...", Path, DevPath); | ||||||
| 		} else if (!bWriteShare && (i > DRIVE_ACCESS_RETRIES/3)) { | 		} else if (!bWriteShare && (i > DRIVE_ACCESS_RETRIES/3)) { | ||||||
| 			// If we can't seem to get a hold of the drive for some time,
 | 			// If we can't seem to get a hold of the drive for some time, try to enable FILE_SHARE_WRITE...
 | ||||||
| 			// try to enable FILE_SHARE_WRITE...
 |  | ||||||
| 			uprintf("Warning: Could not obtain exclusive rights. Retrying with write sharing enabled..."); | 			uprintf("Warning: Could not obtain exclusive rights. Retrying with write sharing enabled..."); | ||||||
| 			bWriteShare = TRUE; | 			bWriteShare = TRUE; | ||||||
|  | 			// Try to report the process that is locking the drive
 | ||||||
|  | 			SearchProcess(DevPath, TRUE, TRUE); | ||||||
|  | 			bSearchProcess = TRUE; | ||||||
| 		} | 		} | ||||||
| 		Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES); | 		Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES); | ||||||
| 	} | 	} | ||||||
| 	if (hDrive == INVALID_HANDLE_VALUE) { | 	if (hDrive == INVALID_HANDLE_VALUE) { | ||||||
| 		uprintf("Could not open %s [%s]: %s\n", Path, DevPath, WindowsErrorString()); | 		uprintf("Could not open %s: %s\n", Path, WindowsErrorString()); | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (bWriteAccess) { | 	if (bWriteAccess) { | ||||||
| 		uprintf("Opened %s [%s] for write access", Path, DevPath); | 		uprintf("Opened %s for %s write access", Path, bWriteShare?"shared":"exclusive"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if (bLockDrive) { | 	if (bLockDrive) { | ||||||
|  | @ -168,6 +171,7 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr | ||||||
| 			uprintf("I/O boundary checks disabled\n"); | 			uprintf("I/O boundary checks disabled\n"); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		uprintf("Requesting lock..."); | ||||||
| 		for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) { | 		for (i = 0; i < DRIVE_ACCESS_RETRIES; i++) { | ||||||
| 			if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL)) | 			if (DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &size, NULL)) | ||||||
| 				goto out; | 				goto out; | ||||||
|  | @ -176,9 +180,9 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr | ||||||
| 			Sleep(DRIVE_ACCESS_TIMEOUT/DRIVE_ACCESS_RETRIES); | 			Sleep(DRIVE_ACCESS_TIMEOUT/DRIVE_ACCESS_RETRIES); | ||||||
| 		} | 		} | ||||||
| 		// If we reached this section, either we didn't manage to get a lock or the user cancelled
 | 		// If we reached this section, either we didn't manage to get a lock or the user cancelled
 | ||||||
| 		uprintf("Could not get exclusive access to %s: %s", Path, WindowsErrorString()); | 		uprintf("Could not lock access to %s: %s", Path, WindowsErrorString()); | ||||||
| 		// See if we can tell the user what processes are accessing the drive
 | 		// See if we can tell the user what processes are accessing the drive
 | ||||||
| 		if (!IS_ERROR(FormatStatus)) | 		if (!IS_ERROR(FormatStatus) && !bSearchProcess) | ||||||
| 			SearchProcess(DevPath, TRUE, TRUE); | 			SearchProcess(DevPath, TRUE, TRUE); | ||||||
| 		safe_closehandle(hDrive); | 		safe_closehandle(hDrive); | ||||||
| 	} | 	} | ||||||
|  | @ -1036,15 +1040,15 @@ BOOL RemountVolume(char* drive_name) | ||||||
| 		if (DeleteVolumeMountPointA(drive_name)) { | 		if (DeleteVolumeMountPointA(drive_name)) { | ||||||
| 			Sleep(200); | 			Sleep(200); | ||||||
| 			if (MountVolume(drive_name, drive_guid)) { | 			if (MountVolume(drive_name, drive_guid)) { | ||||||
| 				uprintf("Successfully remounted %s on %s\n", &drive_guid[4], drive_name); | 				uprintf("Successfully remounted %s on %C:", drive_guid, drive_name[0]); | ||||||
| 			} else { | 			} else { | ||||||
| 				uprintf("Failed to remount %s on %s\n", &drive_guid[4], drive_name); | 				uprintf("Failed to remount %s on %C:", drive_guid, drive_name[0]); | ||||||
| 				// This will leave the drive inaccessible and must be flagged as an error
 | 				// This will leave the drive inaccessible and must be flagged as an error
 | ||||||
| 				FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_REMOUNT_VOLUME); | 				FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_REMOUNT_VOLUME); | ||||||
| 				return FALSE; | 				return FALSE; | ||||||
| 			} | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			uprintf("Could not remount %s %s\n", drive_name, WindowsErrorString()); | 			uprintf("Could not remount %C: %s", drive_name[0], WindowsErrorString()); | ||||||
| 			// Try to continue regardless
 | 			// Try to continue regardless
 | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1663,13 +1663,13 @@ DWORD WINAPI FormatThread(void* param) | ||||||
| 		extra_partitions = XP_COMPAT; | 		extra_partitions = XP_COMPAT; | ||||||
| 
 | 
 | ||||||
| 	PrintInfoDebug(0, MSG_225); | 	PrintInfoDebug(0, MSG_225); | ||||||
| 	hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE, FALSE); | 	hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE, !lock_drive); | ||||||
| 	if (hPhysicalDrive == INVALID_HANDLE_VALUE) { | 	if (hPhysicalDrive == INVALID_HANDLE_VALUE) { | ||||||
| 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; | 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; | ||||||
| 		goto out; | 		goto out; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// At this stage with have both a handle and a lock to the physical drive...
 | 	// At this stage we should have both a handle and a lock to the physical drive...
 | ||||||
| 	if (!GetDriveLetters(DriveIndex, drive_letters)) { | 	if (!GetDriveLetters(DriveIndex, drive_letters)) { | ||||||
| 		uprintf("Failed to get a drive letter\n"); | 		uprintf("Failed to get a drive letter\n"); | ||||||
| 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_ASSIGN_LETTER); | 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_ASSIGN_LETTER); | ||||||
|  | @ -1705,7 +1705,7 @@ DWORD WINAPI FormatThread(void* param) | ||||||
| 	uprintf("Will use '%c:' as volume mountpoint\n", drive_name[0]); | 	uprintf("Will use '%c:' as volume mountpoint\n", drive_name[0]); | ||||||
| 
 | 
 | ||||||
| 	// ...but we need a lock to the logical drive to be able to write anything to it
 | 	// ...but we need a lock to the logical drive to be able to write anything to it
 | ||||||
| 	hLogicalVolume = GetLogicalHandle(DriveIndex, TRUE, FALSE, FALSE); | 	hLogicalVolume = GetLogicalHandle(DriveIndex, TRUE, FALSE, !lock_drive); | ||||||
| 	if (hLogicalVolume == INVALID_HANDLE_VALUE) { | 	if (hLogicalVolume == INVALID_HANDLE_VALUE) { | ||||||
| 		uprintf("Could not lock volume\n"); | 		uprintf("Could not lock volume\n"); | ||||||
| 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; | 		FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED; | ||||||
|  |  | ||||||
|  | @ -433,7 +433,7 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | ||||||
| 
 | 
 | ||||||
| 			// If we're switching process and found a match, print it
 | 			// If we're switching process and found a match, print it
 | ||||||
| 			if (bFound) { | 			if (bFound) { | ||||||
| 				uprintf("o '%s' (pid: %ld, access: %s)", exe_path, pid[cur_pid], access_rights_str[access_rights & 0x3]); | 				uprintf("‣ '%s' (pid: %ld, access: %s)", exe_path, pid[cur_pid], access_rights_str[access_rights & 0x3]); | ||||||
| 				bFound = FALSE; | 				bFound = FALSE; | ||||||
| 				access_rights = 0; | 				access_rights = 0; | ||||||
| 			} | 			} | ||||||
|  | @ -533,7 +533,7 @@ BOOL SearchProcess(char* HandleName, BOOL bPartialMatch, BOOL bIgnoreSelf) | ||||||
| 
 | 
 | ||||||
| 		// If this is the very first process we find, print a header
 | 		// If this is the very first process we find, print a header
 | ||||||
| 		if (exe_path[0] == 0) | 		if (exe_path[0] == 0) | ||||||
| 			uprintf("\r\nNOTE: The following process(es) or service(s) are accessing %s:", HandleName); | 			uprintf("NOTE: The following process(es) or service(s) are accessing %s:", HandleName); | ||||||
| 
 | 
 | ||||||
| 		if (!GetModuleFileNameExU(processHandle, 0, exe_path, MAX_PATH - 1)) | 		if (!GetModuleFileNameExU(processHandle, 0, exe_path, MAX_PATH - 1)) | ||||||
| 			safe_sprintf(exe_path, MAX_PATH, "Unknown_Process_%" PRIu64, | 			safe_sprintf(exe_path, MAX_PATH, "Unknown_Process_%" PRIu64, | ||||||
|  | @ -544,7 +544,7 @@ out: | ||||||
| 	if (exe_path[0] != 0) | 	if (exe_path[0] != 0) | ||||||
| 		uprintf("You should try to close these applications before attempting to reformat the drive."); | 		uprintf("You should try to close these applications before attempting to reformat the drive."); | ||||||
| 	else | 	else | ||||||
| 		uprintf(APPLICATION_NAME " was unable to identify the process(es) or service(s) preventing access to %s", HandleName); | 		uprintf("NOTE: Could not identify the process(es) or service(s) accessing %s", HandleName); | ||||||
| 
 | 
 | ||||||
| 	free(wHandleName); | 	free(wHandleName); | ||||||
| 	PhFree(buffer); | 	PhFree(buffer); | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								src/rufus.rc
									
										
									
									
									
								
							|  | @ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL | ||||||
| IDD_DIALOG DIALOGEX 12, 12, 242, 376 | IDD_DIALOG DIALOGEX 12, 12, 242, 376 | ||||||
| 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 2.15.1105" | CAPTION "Rufus 2.15.1106" | ||||||
| FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | FONT 8, "Segoe UI Symbol", 400, 0, 0x0 | ||||||
| BEGIN | BEGIN | ||||||
|     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 |     LTEXT           "Device",IDS_DEVICE_TXT,9,6,200,8 | ||||||
|  | @ -334,8 +334,8 @@ END | ||||||
| // | // | ||||||
| 
 | 
 | ||||||
| VS_VERSION_INFO VERSIONINFO | VS_VERSION_INFO VERSIONINFO | ||||||
|  FILEVERSION 2,15,1105,0 |  FILEVERSION 2,15,1106,0 | ||||||
|  PRODUCTVERSION 2,15,1105,0 |  PRODUCTVERSION 2,15,1106,0 | ||||||
|  FILEFLAGSMASK 0x3fL |  FILEFLAGSMASK 0x3fL | ||||||
| #ifdef _DEBUG | #ifdef _DEBUG | ||||||
|  FILEFLAGS 0x1L |  FILEFLAGS 0x1L | ||||||
|  | @ -352,13 +352,13 @@ BEGIN | ||||||
|         BEGIN |         BEGIN | ||||||
|             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" |             VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" | ||||||
|             VALUE "FileDescription", "Rufus" |             VALUE "FileDescription", "Rufus" | ||||||
|             VALUE "FileVersion", "2.15.1105" |             VALUE "FileVersion", "2.15.1106" | ||||||
|             VALUE "InternalName", "Rufus" |             VALUE "InternalName", "Rufus" | ||||||
|             VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" |             VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)" | ||||||
|             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" |             VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" | ||||||
|             VALUE "OriginalFilename", "rufus.exe" |             VALUE "OriginalFilename", "rufus.exe" | ||||||
|             VALUE "ProductName", "Rufus" |             VALUE "ProductName", "Rufus" | ||||||
|             VALUE "ProductVersion", "2.15.1105" |             VALUE "ProductVersion", "2.15.1106" | ||||||
|         END |         END | ||||||
|     END |     END | ||||||
|     BLOCK "VarFileInfo" |     BLOCK "VarFileInfo" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue