[core] fix default listing of large SanDisk SSD devices

* 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
This commit is contained in:
Pete Batard 2023-02-13 13:31:40 +00:00
parent 3281f6b97e
commit b163b3dfe2
No known key found for this signature in database
GPG key ID: 38E0CF5E69EDD671
6 changed files with 51 additions and 25 deletions

View file

@ -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) {
@ -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;
}
}
@ -475,14 +487,17 @@ 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;
}
}
@ -490,11 +505,19 @@ int IsHDD(DWORD DriveIndex, uint16_t vid, uint16_t pid, const char* strid)
// 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;
}