Skip to content

Commit

Permalink
[core] fix default listing of large SanDisk SSD devices
Browse files Browse the repository at this point in the history
* Closes #2164
* Also add breakdown of score computation when device enumeration debug is active
* Also fix a minor Code Analysis warning in msapi_utf8.h
  • Loading branch information
pbatard committed Feb 13, 2023
1 parent 3281f6b commit 637f833
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 0x048D
#define FORCED_PID 0x4030
#define FORCED_NAME "HP iLO Internal SD-CARD USB Device"
#define FORCED_VID 0x0781
#define FORCED_PID 0x55AE
#define FORCED_NAME "SanDisk Extreme 55AE SCSI Disk Device"
#endif

void ClearDrives(void)
Expand Down
2 changes: 2 additions & 0 deletions src/hdd_vs_ufd.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ static str_score_t str_adjust[] = {
{ "Flash", -10 },
{ "SD-CARD", -10 },
{ "HDD", +20 },
{ "SATA", +20 },
{ "SCSI", +20 },
{ "SSD", +20 }
};

Expand Down
5 changes: 3 additions & 2 deletions src/msapi_utf8.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* See also: https://utf8everywhere.org
*
* Copyright © 2010-2022 Pete Batard <pete@akeo.ie>
* Copyright © 2010-2023 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
Expand Down Expand Up @@ -359,7 +359,8 @@ static __inline int GetWindowTextU(HWND hWnd, char* lpString, int nMaxCount)
err = GetLastError();
}
wfree(lpString);
lpString[nMaxCount - 1] = 0;
if (lpString != NULL)
lpString[nMaxCount - 1] = 0;
SetLastError(err);
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/rufus.c
Original file line number Diff line number Diff line change
Expand Up @@ -3638,14 +3638,14 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
nWindowsVersion = forced_windows_version;

// ...and nothing of value was lost
// TODO: Set to <= for 3.22
// TODO: Set to <= for 3.23
if (nWindowsVersion < WINDOWS_7) {
// Load the translation before we print the error
get_loc_data_file(loc_file, selected_locale);
right_to_left_mode = ((selected_locale->ctrl_id) & LOC_RIGHT_TO_LEFT);
// Set MB_SYSTEMMODAL to prevent Far Manager from stealing focus...
MessageBoxExU(NULL,
lmprintf(MSG_294, (nWindowsVersion == WINDOWS_7) ? 3 : 2, (nWindowsVersion == WINDOWS_7) ? 21 : 18),
lmprintf(MSG_294, (nWindowsVersion == WINDOWS_7) ? 3 : 2, (nWindowsVersion == WINDOWS_7) ? 22 : 18),
lmprintf(MSG_293), MB_ICONSTOP | MB_IS_RTL | MB_SYSTEMMODAL, selected_langid);
goto out;
}
Expand Down
10 changes: 5 additions & 5 deletions src/rufus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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.22.1962"
CAPTION "Rufus 3.22.1963"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
Expand Down Expand Up @@ -392,8 +392,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,22,1962,0
PRODUCTVERSION 3,22,1962,0
FILEVERSION 3,22,1963,0
PRODUCTVERSION 3,22,1963,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -411,13 +411,13 @@ BEGIN
VALUE "Comments", "https://rufus.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.22.1962"
VALUE "FileVersion", "3.22.1963"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2023 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "https://www.gnu.org/licenses/gpl-3.0.html"
VALUE "OriginalFilename", "rufus-3.22.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.22.1962"
VALUE "ProductVersion", "3.22.1963"
END
END
BLOCK "VarFileInfo"
Expand Down
49 changes: 36 additions & 13 deletions src/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,32 @@ BOOL SmartGetVersion(HANDLE hdevice)
*/
int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
{
int score = 0;
int score = 0, score_list_size = 0;
size_t i, mlen, ilen;
BOOL wc;
uint64_t drive_size;
int8_t score_list[16];
char str[64] = { 0 };

// Boost the score if fixed, as these are *generally* HDDs
if (GetDriveTypeFromIndex(DriveIndex) == DRIVE_FIXED)
score += 3;
if (GetDriveTypeFromIndex(DriveIndex) == DRIVE_FIXED) {
score_list[score_list_size] = 3;
score += score_list[score_list_size++];
}

// Adjust the score depending on the size
drive_size = GetDriveSize(DriveIndex);
if (drive_size > 800 * GB)
score += 10;
else if (drive_size < 32 * GB)
score -= 10;
if (drive_size > 800 * GB) {
score_list[score_list_size] = 15;
score += score_list[score_list_size++];
if (drive_size > 1800 * GB) {
score_list[score_list_size] = 15;
score += score_list[score_list_size++];
}
} else if (drive_size < 32 * GB) {
score_list[score_list_size] = 15;
score += score_list[score_list_size++];
}

// Check the string against well known HDD identifiers
if (strid != NULL) {
Expand All @@ -466,7 +477,8 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
wc = (str_score[i].name[mlen-1] == '#');
if ( (_strnicmp(strid, str_score[i].name, mlen-((wc)?1:0)) == 0)
&& ((!wc) || ((strid[mlen] >= '0') && (strid[mlen] <= '9'))) ) {
score += str_score[i].score;
score_list[score_list_size] = str_score[i].score;
score += score_list[score_list_size++];
break;
}
}
Expand All @@ -475,26 +487,37 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
// Adjust for oddball devices
if (strid != NULL) {
for (i = 0; i < ARRAYSIZE(str_adjust); i++)
if (StrStrIA(strid, str_adjust[i].name) != NULL)
score += str_adjust[i].score;
if (StrStrIA(strid, str_adjust[i].name) != NULL) {
score_list[score_list_size] = str_adjust[i].score;
score += score_list[score_list_size++];
}
}

// Check against known VIDs
for (i = 0; i < ARRAYSIZE(vid_score); i++) {
if (vid == vid_score[i].vid) {
score += vid_score[i].score;
score_list[score_list_size] = vid_score[i].score;
score += score_list[score_list_size++];
break;
}
}

// Check against known VID:PIDs
for (i = 0; i < ARRAYSIZE(vidpid_score); i++) {
if ((vid == vidpid_score[i].vid) && (pid == vidpid_score[i].pid)) {
score += vidpid_score[i].score;
score_list[score_list_size] = vidpid_score[i].score;
score += score_list[score_list_size++];
break;
}
}

duprintf(" Score: %d\n", score);
// Print a breakdown of the device score if requested
if (usb_debug) {
static_strcat(str, "Device score: ");
for (i = 0; i < score_list_size; i++)
static_sprintf(&str[strlen(str)], "%+d", score_list[i]);
uprintf("%s=%+d → Detected as %s", str, score, (score > 0) ? "HDD" : "UFD");
}

return score;
}

0 comments on commit 637f833

Please sign in to comment.