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

[dev] improve FIXED vs REMOVABLE detection for drives with unmounted partitions

* And add an exception for a reported flash drive
* Also fix a couple warnings in msapi_utf8.h and net.c
This commit is contained in:
Pete Batard 2020-04-10 13:16:57 +01:00
parent 1e6e38b180
commit 2442aaf76f
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
7 changed files with 39 additions and 20 deletions

View file

@ -418,9 +418,9 @@ BOOL GetOpticalMedia(IMG_SAVE* img_save)
/* For debugging user reports of HDDs vs UFDs */
//#define FORCED_DEVICE
#ifdef FORCED_DEVICE
#define FORCED_VID 0x05AC
#define FORCED_PID 0x8406
#define FORCED_NAME "APPLE SD Card Reader USB Device"
#define FORCED_VID 0x6557
#define FORCED_PID 0x0021
#define FORCED_NAME "USB DISK 2.0 USB Device"
#endif
/*

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* Drive access function calls
* Copyright © 2011-2019 Pete Batard <pete@akeo.ie>
* Copyright © 2011-2020 Pete Batard <pete@akeo.ie>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -797,11 +797,13 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
{
DWORD size;
BOOL r = FALSE;
HANDLE hDrive = INVALID_HANDLE_VALUE;
HANDLE hDrive = INVALID_HANDLE_VALUE, hPhysical = INVALID_HANDLE_VALUE;
UINT _drive_type;
IO_STATUS_BLOCK io_status_block;
FILE_FS_DEVICE_INFORMATION file_fs_device_info;
int i = 0, drive_number;
BYTE geometry[256] = { 0 };
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)(void*)geometry;
int i = 0, drives_found = 0, drive_number;
char *drive, drives[26*4 + 1]; /* "D:\", "E:\", etc., plus one NUL */
char logical_drive[] = "\\\\.\\#:";
@ -831,7 +833,7 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
}
r = TRUE; // Required to detect drives that don't have volumes assigned
for (drive = drives ;*drive; drive += safe_strlen(drive)+1) {
for (drive = drives ;*drive; drive += safe_strlen(drive) + 1) {
if (!isalpha(*drive))
continue;
*drive = (char)toupper((int)*drive);
@ -865,6 +867,7 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
safe_closehandle(hDrive);
if (drive_number == DriveIndex) {
r = TRUE;
drives_found++;
if (drive_letters != NULL)
drive_letters[i++] = *drive;
// The drive type should be the same for all volumes, so we can overwrite
@ -873,6 +876,21 @@ static BOOL _GetDriveLettersAndType(DWORD DriveIndex, char* drive_letters, UINT*
}
}
// Devices that don't have mounted partitions require special
// handling to determine if they are fixed or removable.
if ((drives_found == 0) && (drive_type != NULL)) {
hPhysical = GetPhysicalHandle(DriveIndex + DRIVE_INDEX_MIN, FALSE, FALSE, FALSE);
r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, geometry, sizeof(geometry), &size, NULL);
safe_closehandle(hPhysical);
if (r && size > 0) {
if (DiskGeometry->Geometry.MediaType == FixedMedia)
*drive_type = DRIVE_FIXED;
else if (DiskGeometry->Geometry.MediaType == RemovableMedia)
*drive_type = DRIVE_REMOVABLE;
}
}
out:
if (drive_letters != NULL)
drive_letters[i] = 0;

View file

@ -1,7 +1,7 @@
/*
* Rufus: The Reliable USB Formatting Utility
* SMART HDD vs Flash detection - isHDD() tables
* Copyright © 2013-2019 Pete Batard <pete@akeo.ie>
* Copyright © 2013-2020 Pete Batard <pete@akeo.ie>
*
* Based in part on drivedb.h from Smartmontools:
* http://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools/drivedb.h
@ -261,6 +261,8 @@ static vidpid_score_t vidpid_score[] = {
{ 0x05ac, 0x8405, -20},
{ 0x05ac, 0x8406, -20},
{ 0x05ac, 0x8407, -20},
// No idea who these guys are. They don't exist in usb.ids.
{ 0x6557, 0x0021, -5},
// Prolific exceptions
{ 0x067b, 0x2506, -20 }, // 8 GB Micro Hard Drive
{ 0x067b, 0x2517, -20 }, // 1 GB UFD

View file

@ -3,7 +3,7 @@
* Compensating for what Microsoft should have done a long long time ago.
* Also see https://utf8everywhere.org
*
* Copyright © 2010-2019 Pete Batard <pete@akeo.ie>
* Copyright © 2010-2020 Pete Batard <pete@akeo.ie>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -439,7 +439,7 @@ static __inline int ComboBox_GetLBTextU(HWND hCtrl, int index, char* lpString)
size = (int)SendMessageW(hCtrl, CB_GETLBTEXTLEN, (WPARAM)index, (LPARAM)0);
if (size < 0)
return size;
wlpString = (wchar_t*)calloc(size+1, sizeof(wchar_t));
wlpString = (wchar_t*)calloc((size_t)size + 1, sizeof(wchar_t));
size = (int)SendMessageW(hCtrl, CB_GETLBTEXT, (WPARAM)index, (LPARAM)wlpString);
err = GetLastError();
if (size > 0)

View file

@ -865,7 +865,7 @@ BOOL CheckForUpdates(BOOL force)
static DWORD WINAPI DownloadISOThread(LPVOID param)
{
char locale_str[1024], cmdline[sizeof(locale_str) + 512], pipe[MAX_GUID_STRING_LENGTH + 16] = "\\\\.\\pipe\\";
char powershell_path[MAX_PATH], icon_path[MAX_PATH] = "", script_path[MAX_PATH] = "";
char powershell_path[MAX_PATH], icon_path[MAX_PATH] = { 0 }, script_path[MAX_PATH] = { 0 };
char *url = NULL, sig_url[128];
uint64_t uncompressed_size;
int64_t size = -1;

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.10.1634"
CAPTION "Rufus 3.10.1635"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -395,8 +395,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,10,1634,0
PRODUCTVERSION 3,10,1634,0
FILEVERSION 3,10,1635,0
PRODUCTVERSION 3,10,1635,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -414,13 +414,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.10.1634"
VALUE "FileVersion", "3.10.1635"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2020 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.10.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.10.1634"
VALUE "ProductVersion", "3.10.1635"
END
END
BLOCK "VarFileInfo"

View file

@ -1,11 +1,11 @@
/*
* Rufus: The Reliable USB Formatting Utility
* SMART HDD vs Flash detection (using ATA over USB, S.M.A.R.T., etc.)
* Copyright © 2013-2016 Pete Batard <pete@akeo.ie>
* Copyright © 2013-2020 Pete Batard <pete@akeo.ie>
*
* Based in part on scsiata.cpp from Smartmontools: http://smartmontools.sourceforge.net
* Copyright © 2006-12 Douglas Gilbert <dgilbert@interlog.com>
* Copyright © 2009-13 Christian Franke <smartmontools-support@lists.sourceforge.net>
* Copyright © 2006-2012 Douglas Gilbert <dgilbert@interlog.com>
* Copyright © 2009-2013 Christian Franke <smartmontools-support@lists.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -446,7 +446,6 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
uint64_t drive_size;
// Boost the score if fixed, as these are *generally* HDDs
// NB: Due to a Windows API limitation, drives with no mounted partition will never have DRIVE_FIXED
if (GetDriveTypeFromIndex(DriveIndex) == DRIVE_FIXED)
score += 3;