mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[core] alter the drive letter we use when Windows has already remounted it
* Our code should be flexible enough to do just that and this will also alleviate requiring end users to retry an operation.
This commit is contained in:
parent
7a04f52f6c
commit
06b33f94e4
3 changed files with 27 additions and 28 deletions
39
src/drive.c
39
src/drive.c
|
@ -1119,44 +1119,42 @@ BOOL UnmountVolume(HANDLE hDrive)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mount the volume identified by drive_guid to mountpoint drive_name
|
* Mount the volume identified by drive_guid to mountpoint drive_name.
|
||||||
|
* If drive_guid is already mounted, but with a different letter than the
|
||||||
|
* one requested, drive_name is updated to use that letter.
|
||||||
*/
|
*/
|
||||||
BOOL MountVolume(char* drive_name, char *drive_guid)
|
BOOL MountVolume(char* drive_name, char *drive_guid)
|
||||||
{
|
{
|
||||||
char mounted_guid[52]; // You need at least 51 characters on XP
|
char mounted_guid[52];
|
||||||
char mounted_letter[16] = {0};
|
char mounted_letter[27] = { 0 };
|
||||||
DWORD size;
|
DWORD size;
|
||||||
|
|
||||||
if (drive_name[0] == '?')
|
if (drive_name[0] == '?')
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// For fixed disks, Windows may already have remounted the volume, but with a different letter
|
// Windows may already have the volume mounted but under a different letter.
|
||||||
// than the one we want. If that's the case, we need to unmount first.
|
// If that is the case, update drive_name to that letter.
|
||||||
if ( (GetVolumePathNamesForVolumeNameA(drive_guid, mounted_letter, sizeof(mounted_letter), &size))
|
if ( (GetVolumePathNamesForVolumeNameA(drive_guid, mounted_letter, sizeof(mounted_letter), &size))
|
||||||
&& (size > 1) && (mounted_letter[0] != drive_name[0]) ) {
|
&& (size > 1) && (mounted_letter[0] != drive_name[0]) ) {
|
||||||
uprintf("Volume is already mounted, but as %c: instead of %c: - Unmounting...", mounted_letter[0], drive_name[0]);
|
uprintf("%s is already mounted as %C: instead of %C: - Will now use this target instead...", mounted_letter[0], drive_name[0]);
|
||||||
if (!DeleteVolumeMountPointA(mounted_letter))
|
drive_name[0] = mounted_letter[0];
|
||||||
uprintf("Failed to unmount volume: %s", WindowsErrorString());
|
return TRUE;
|
||||||
// Also delete the destination mountpoint if needed (Don't care about errors)
|
|
||||||
DeleteVolumeMountPointA(drive_name);
|
|
||||||
Sleep(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetVolumeMountPointA(drive_name, drive_guid)) {
|
if (!SetVolumeMountPointA(drive_name, drive_guid)) {
|
||||||
// If the OS was faster than us at remounting the drive, this operation can fail
|
// If we get ERROR_DIR_NOT_EMPTY, check that mountpoints match...
|
||||||
// with ERROR_DIR_NOT_EMPTY. If that's the case, just check that mountpoints match
|
|
||||||
if (GetLastError() == ERROR_DIR_NOT_EMPTY) {
|
if (GetLastError() == ERROR_DIR_NOT_EMPTY) {
|
||||||
if (!GetVolumeNameForVolumeMountPointA(drive_name, mounted_guid, sizeof(mounted_guid))) {
|
if (!GetVolumeNameForVolumeMountPointA(drive_name, mounted_guid, sizeof(mounted_guid))) {
|
||||||
uprintf("%s already mounted, but volume GUID could not be checked: %s",
|
uprintf("%s is already mounted, but volume GUID could not be checked: %s",
|
||||||
drive_name, WindowsErrorString());
|
drive_name, WindowsErrorString());
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (safe_strcmp(drive_guid, mounted_guid) != 0) {
|
if (safe_strcmp(drive_guid, mounted_guid) != 0) {
|
||||||
uprintf("%s already mounted, but volume GUID doesn't match:\r\n expected %s, got %s",
|
uprintf("%s is mounted, but volume GUID doesn't match:\r\n expected %s, got %s",
|
||||||
drive_name, drive_guid, mounted_guid);
|
drive_name, drive_guid, mounted_guid);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
uprintf("%s was already mounted as %s", drive_guid, drive_name);
|
uprintf("%s is already mounted as %C:", drive_guid, drive_name[0]);
|
||||||
} else {
|
} else {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1263,7 +1261,8 @@ BOOL AltUnmountVolume(const char* drive_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Issue a complete remount of the volume
|
* Issue a complete remount of the volume.
|
||||||
|
* Note that drive_name *may* be altered when the volume gets remounted.
|
||||||
*/
|
*/
|
||||||
BOOL RemountVolume(char* drive_name)
|
BOOL RemountVolume(char* drive_name)
|
||||||
{
|
{
|
||||||
|
@ -1275,15 +1274,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 %C:", drive_guid, drive_name[0]);
|
uprintf("Successfully remounted %s as %C:", drive_guid, drive_name[0]);
|
||||||
} else {
|
} else {
|
||||||
uprintf("Failed to remount %s on %C:", drive_guid, drive_name[0]);
|
uprintf("Failed to remount %s as %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 %C: %s", drive_name[0], WindowsErrorString());
|
uprintf("Could not remount %s as %C: %s", drive_guid, drive_name[0], WindowsErrorString());
|
||||||
// Try to continue regardless
|
// Try to continue regardless
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1969,7 +1969,7 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
if (GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_type, sizeof(fs_type), TRUE)) {
|
if (GetDrivePartitionData(SelectedDrive.DeviceNumber, fs_type, sizeof(fs_type), TRUE)) {
|
||||||
guid_volume = GetLogicalName(DriveIndex, TRUE, TRUE);
|
guid_volume = GetLogicalName(DriveIndex, TRUE, TRUE);
|
||||||
if ((guid_volume != NULL) && (MountVolume(drive_name, guid_volume)))
|
if ((guid_volume != NULL) && (MountVolume(drive_name, guid_volume)))
|
||||||
uprintf("Remounted %s on %s\n", guid_volume, drive_name);
|
uprintf("Remounted %s as %C:\n", guid_volume, drive_name[0]);
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -2034,7 +2034,7 @@ DWORD WINAPI FormatThread(void* param)
|
||||||
uprintf("Found volume GUID %s\n", guid_volume);
|
uprintf("Found volume GUID %s\n", guid_volume);
|
||||||
|
|
||||||
if (!MountVolume(drive_name, guid_volume)) {
|
if (!MountVolume(drive_name, guid_volume)) {
|
||||||
uprintf("Could not remount %s on %s: %s\n", guid_volume, drive_name, WindowsErrorString());
|
uprintf("Could not remount %s as %C: %s\n", guid_volume, drive_name[0], WindowsErrorString());
|
||||||
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_MOUNT_VOLUME);
|
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|APPERR(ERROR_CANT_MOUNT_VOLUME);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -2199,7 +2199,7 @@ out:
|
||||||
guid_volume = GetLogicalName(DriveIndex, TRUE, FALSE);
|
guid_volume = GetLogicalName(DriveIndex, TRUE, FALSE);
|
||||||
if (guid_volume != NULL) {
|
if (guid_volume != NULL) {
|
||||||
if (MountVolume(drive_name, guid_volume))
|
if (MountVolume(drive_name, guid_volume))
|
||||||
uprintf("Re-mounted volume as '%c:' after error\n", drive_name[0]);
|
uprintf("Re-mounted volume as %C: after error\n", drive_name[0]);
|
||||||
free(guid_volume);
|
free(guid_volume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
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.6.1512"
|
CAPTION "Rufus 3.6.1513"
|
||||||
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
|
||||||
|
@ -394,8 +394,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 3,6,1512,0
|
FILEVERSION 3,6,1513,0
|
||||||
PRODUCTVERSION 3,6,1512,0
|
PRODUCTVERSION 3,6,1513,0
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -413,13 +413,13 @@ BEGIN
|
||||||
VALUE "Comments", "https://akeo.ie"
|
VALUE "Comments", "https://akeo.ie"
|
||||||
VALUE "CompanyName", "Akeo Consulting"
|
VALUE "CompanyName", "Akeo Consulting"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "3.6.1512"
|
VALUE "FileVersion", "3.6.1513"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011-2019 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus-3.6.exe"
|
VALUE "OriginalFilename", "rufus-3.6.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "3.6.1512"
|
VALUE "ProductVersion", "3.6.1513"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Reference in a new issue