Skip to content

Commit

Permalink
Merge pull request martijnvanbrummelen#630 from PartialVolume/Add_two…
Browse files Browse the repository at this point in the history
…_new_models_to_endian_switching

Fix endian for various model names on some older USB adapters
  • Loading branch information
PartialVolume authored Dec 3, 2024
2 parents 5bdd87f + e3dfa55 commit a9e3dd2
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions src/miscellaneous.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,17 +629,70 @@ void fix_endian_model_names( char* model )
int idx2 = 0;
unsigned int length = 0;
char* tmp_string;
char* model_lower_case;
int swap_endian_flag = 0;

length = strlen( model );
length = strlen( model ) + 1;
nwipe_log( NWIPE_LOG_INFO, " length = %i", length );

tmp_string = calloc( length, 1 );
model_lower_case = calloc( length, 1 );

strncpy( model_lower_case, model, length + 1 );
model_lower_case[length + 1] = 0; /* makesure it's terminated */
strlower( model_lower_case ); /* convert to lower case for comparison */

/* "ASSMNU G" = "SAMSUNG ", tested against model Samsung HM160HC so that
* "ASSMNU G MH61H0 C" becomes "SAMSUNG HM160HC ")
*/
if( !( strncmp( model, "ASSMNU G", 8 ) ) )
if( !( strncmp( model_lower_case, "assmnu g", 8 ) ) )
{
swap_endian_flag = 1;
}
else
{
/* Hitachi */
if( !( strncmp( model_lower_case, "ihathc i", 8 ) ) )
{
swap_endian_flag = 1;
}
else
{
/* Toshiba */
if( !( strncmp( model_lower_case, "othsbi a", 8 ) ) )
{
swap_endian_flag = 1;
}
else
{
/* WDC (Western Digital Corporation) */
if( !( strncmp( model_lower_case, "dw c", 4 ) ) )
{
swap_endian_flag = 1;
}
else
{
/* Seagate */
if( !( strncmp( model_lower_case, "esgata e", 8 ) ) )
{
swap_endian_flag = 1;
}
else
{
/* Seagate models starting ST */
if( !( strncmp( model_lower_case, "ts", 2 ) ) )
{
swap_endian_flag = 1;
}
}
}
}
}
}

if( swap_endian_flag == 1 )
{
while( model[idx] != 0 )
while( model[idx] != 0 && idx < length )
{
tmp_string[idx2 + 1] = model[idx];
if( model[idx + 1] != 0 )
Expand All @@ -663,4 +716,6 @@ void fix_endian_model_names( char* model )
tmp_string[idx2 + 1] = 0;
strcpy( model, tmp_string );
}
free( tmp_string );
free( model_lower_case );
}

0 comments on commit a9e3dd2

Please sign in to comment.