1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[core] relax the FILE_SHARE_WRITE rules during enumeration

* Should allow enumeration of drives, that other process have open
  with RW access, back again (looking at you, Paragon!!!)
This commit is contained in:
Pete Batard 2017-05-02 00:56:07 +01:00
parent 3b4b742772
commit 23390bf911
5 changed files with 18 additions and 19 deletions

View file

@ -654,8 +654,8 @@ BOOL GetDevices(DWORD devnum)
continue;
}
hDrive = CreateFileA(devint_detail_data->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
hDrive = CreateFileA(devint_detail_data->DevicePath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hDrive == INVALID_HANDLE_VALUE) {
uprintf("Could not open '%s': %s\n", devint_detail_data->DevicePath, WindowsErrorString());
continue;

View file

@ -138,7 +138,7 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
// We keep FILE_SHARE_READ though, as this shouldn't hurt us any, and is
// required for enumeration.
hDrive = CreateFileA(Path, GENERIC_READ|(bWriteAccess?GENERIC_WRITE:0),
FILE_SHARE_READ|((bWriteAccess && bWriteShare)?FILE_SHARE_WRITE:0),
FILE_SHARE_READ|(bWriteShare?FILE_SHARE_WRITE:0),
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDrive != INVALID_HANDLE_VALUE)
break;
@ -146,11 +146,10 @@ static HANDLE GetHandle(char* Path, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWr
break;
if (i == 0) {
uprintf("Waiting for access...");
} else if (bWriteAccess && !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,
// try to enable FILE_SHARE_WRITE...
uprintf("Warning: Could not obtain exclusive rights. Retrying with write sharing enabled...");
SearchProcess(DevPath, TRUE, TRUE);
bWriteShare = TRUE;
}
Sleep(DRIVE_ACCESS_TIMEOUT / DRIVE_ACCESS_RETRIES);
@ -207,11 +206,11 @@ out:
/*
* Return a handle to the physical drive identified by DriveIndex
*/
HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess)
HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare)
{
HANDLE hPhysical = INVALID_HANDLE_VALUE;
char* PhysicalPath = GetPhysicalName(DriveIndex);
hPhysical = GetHandle(PhysicalPath, bLockDrive, bWriteAccess, FALSE);
hPhysical = GetHandle(PhysicalPath, bLockDrive, bWriteAccess, bWriteShare);
safe_free(PhysicalPath);
return hPhysical;
}
@ -537,7 +536,7 @@ BOOL GetDriveLabel(DWORD DriveIndex, char* letters, char** label)
// Try to read an extended label from autorun first. Fallback to regular label if not found.
// In the case of card readers with no card, users can get an annoying popup asking them
// to insert media. Use IOCTL_STORAGE_CHECK_VERIFY to prevent this
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE, TRUE);
if (DeviceIoControl(hPhysical, IOCTL_STORAGE_CHECK_VERIFY, NULL, 0, NULL, 0, &size, NULL))
AutorunLabel = get_token_data_file("label", AutorunPath);
else if (GetLastError() == ERROR_NOT_READY)
@ -570,7 +569,7 @@ uint64_t GetDriveSize(DWORD DriveIndex)
BYTE geometry[256];
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE, TRUE);
if (hPhysical == INVALID_HANDLE_VALUE)
return FALSE;
@ -592,7 +591,7 @@ BOOL IsMediaPresent(DWORD DriveIndex)
DWORD size;
BYTE geometry[128];
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE, TRUE);
r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, geometry, sizeof(geometry), &size, NULL) && (size > 0);
safe_closehandle(hPhysical);
@ -711,7 +710,7 @@ BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSys
}
safe_free(volume_name);
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE, TRUE);
if (hPhysical == INVALID_HANDLE_VALUE)
return 0;

View file

@ -79,7 +79,7 @@ extern RUFUS_DRIVE_INFO SelectedDrive;
BOOL SetAutoMount(BOOL enable);
BOOL GetAutoMount(BOOL* enabled);
char* GetPhysicalName(DWORD DriveIndex);
HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess);
HANDLE GetPhysicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare);
char* GetLogicalName(DWORD DriveIndex, BOOL bKeepTrailingBackslash, BOOL bSilent);
BOOL WaitForLogical(DWORD DriveIndex);
HANDLE GetLogicalHandle(DWORD DriveIndex, BOOL bLockDrive, BOOL bWriteAccess, BOOL bWriteShare);

View file

@ -1663,7 +1663,7 @@ DWORD WINAPI FormatThread(void* param)
extra_partitions = XP_COMPAT;
PrintInfoDebug(0, MSG_225);
hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE);
hPhysicalDrive = GetPhysicalHandle(DriveIndex, lock_drive, TRUE, FALSE);
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_OPEN_FAILED;
goto out;
@ -2096,7 +2096,7 @@ DWORD WINAPI SaveImageThread(void* param)
LastRefresh = 0;
switch (img_save->Type) {
case IMG_SAVE_TYPE_VHD:
hPhysicalDrive = GetPhysicalHandle(img_save->DeviceNum, TRUE, FALSE);
hPhysicalDrive = GetPhysicalHandle(img_save->DeviceNum, TRUE, FALSE, FALSE);
break;
case IMG_SAVE_TYPE_ISO:
hPhysicalDrive = CreateFileA(img_save->DevicePath, GENERIC_READ, FILE_SHARE_READ,

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 242, 376
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 2.15.1103"
CAPTION "Rufus 2.15.1104"
FONT 8, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Device",IDS_DEVICE_TXT,9,6,200,8
@ -334,8 +334,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 2,15,1103,0
PRODUCTVERSION 2,15,1103,0
FILEVERSION 2,15,1104,0
PRODUCTVERSION 2,15,1104,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -352,13 +352,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "2.15.1103"
VALUE "FileVersion", "2.15.1104"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2017 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "2.15.1103"
VALUE "ProductVersion", "2.15.1104"
END
END
BLOCK "VarFileInfo"