Skip to content

Commit

Permalink
Merge pull request martijnvanbrummelen#606 from PartialVolume/Add_new…
Browse files Browse the repository at this point in the history
…_search_location_for_hdparm_and_smartctl

Add a new search location when looking for hdparm and smartctl.
  • Loading branch information
PartialVolume authored Sep 13, 2024
2 parents 5338328 + 5506c76 commit c837e94
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
10 changes: 9 additions & 1 deletion src/create_pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ int nwipe_get_smart_data( nwipe_context_t* c )
char smartctl_command[] = "smartctl -a %s";
char smartctl_command2[] = "/sbin/smartctl -a %s";
char smartctl_command3[] = "/usr/bin/smartctl -a %s";
char smartctl_command4[] = "/usr/sbin/smartctl -a %s";
char final_cmd_smartctl[sizeof( smartctl_command3 ) + 256];
char result[512];
char smartctl_labels_to_anonymize[][18] = {
Expand All @@ -850,7 +851,14 @@ int nwipe_get_smart_data( nwipe_context_t* c )
{
if( system( "which /usr/bin/smartctl > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
if( system( "which /usr/sbin/smartctl > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
}
else
{
sprintf( final_cmd_smartctl, smartctl_command4, c->device_name );
}
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, i
char smartctl_command[] = "smartctl -i %s";
char smartctl_command2[] = "/sbin/smartctl -i %s";
char smartctl_command3[] = "/usr/bin/smartctl -i %s";
char smartctl_command4[] = "/usr/sbin/smartctl -i %s";
char device_shortform[50];
char result[512];
char final_cmd_readlink[sizeof( readlink_command ) + sizeof( device_shortform )];
Expand Down Expand Up @@ -706,7 +707,14 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, i
{
if( system( "which /usr/bin/smartctl > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
if( system( "which /usr/sbin/smartctl > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
}
else
{
sprintf( final_cmd_smartctl, smartctl_command4, device );
}
}
else
{
Expand Down
60 changes: 40 additions & 20 deletions src/hpa_dco.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ int hpa_dco_status( nwipe_context_t* ptr )
int dco_line_found;

FILE* fp;
char path_hdparm_cmd1_get_hpa[] = "hdparm --verbose -N";
char path_hdparm_cmd2_get_hpa[] = "/sbin/hdparm --verbose -N";
char path_hdparm_cmd3_get_hpa[] = "/usr/bin/hdparm --verbose -N";
char path_hdparm_cmd10_get_hpa[] = "hdparm --verbose -N";
char path_hdparm_cmd20_get_hpa[] = "/sbin/hdparm --verbose -N";
char path_hdparm_cmd30_get_hpa[] = "/usr/bin/hdparm --verbose -N";
char path_hdparm_cmd31_get_hpa[] = "/usr/sbin/hdparm --verbose -N";

char path_hdparm_cmd4_get_dco[] = "hdparm --verbose --dco-identify";
char path_hdparm_cmd5_get_dco[] = "/sbin/hdparm --verbose --dco-identify";
char path_hdparm_cmd6_get_dco[] = "/usr/bin/hdparm --verbose --dco-identify";
char path_hdparm_cmd40_get_dco[] = "hdparm --verbose --dco-identify";
char path_hdparm_cmd50_get_dco[] = "/sbin/hdparm --verbose --dco-identify";
char path_hdparm_cmd60_get_dco[] = "/usr/bin/hdparm --verbose --dco-identify";
char path_hdparm_cmd61_get_dco[] = "/usr/sbin/hdparm --verbose --dco-identify";

char pipe_std_err[] = "2>&1";

Expand All @@ -78,8 +80,8 @@ int hpa_dco_status( nwipe_context_t* ptr )
/* Use the longest of the 'path_hdparm_cmd.....' strings above to
*determine size in the strings below
*/
char hdparm_cmd_get_hpa[sizeof( path_hdparm_cmd3_get_hpa ) + sizeof( c->device_name ) + sizeof( pipe_std_err )];
char hdparm_cmd_get_dco[sizeof( path_hdparm_cmd6_get_dco ) + sizeof( c->device_name ) + sizeof( pipe_std_err )];
char hdparm_cmd_get_hpa[sizeof( path_hdparm_cmd30_get_hpa ) + sizeof( c->device_name ) + sizeof( pipe_std_err )];
char hdparm_cmd_get_dco[sizeof( path_hdparm_cmd60_get_dco ) + sizeof( c->device_name ) + sizeof( pipe_std_err )];

/* Initialise return value */
set_return_value = 0;
Expand All @@ -96,25 +98,43 @@ int hpa_dco_status( nwipe_context_t* ptr )
{
if( system( "which /usr/bin/hdparm > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
nwipe_log( NWIPE_LOG_WARNING,
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
cleanup();
exit( 1 );
if( system( "which /usr/sbin/hdparm > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
nwipe_log( NWIPE_LOG_WARNING,
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
cleanup();
exit( 1 );
}
else
{
snprintf( hdparm_cmd_get_hpa,
sizeof( hdparm_cmd_get_hpa ),
"%s %s %s\n",
path_hdparm_cmd31_get_hpa,
c->device_name,
pipe_std_err );
snprintf( hdparm_cmd_get_dco,
sizeof( hdparm_cmd_get_dco ),
"%s %s %s\n",
path_hdparm_cmd61_get_dco,
c->device_name,
pipe_std_err );
}
}
else
{
snprintf( hdparm_cmd_get_hpa,
sizeof( hdparm_cmd_get_hpa ),
"%s %s %s\n",
path_hdparm_cmd3_get_hpa,
path_hdparm_cmd30_get_hpa,
c->device_name,
pipe_std_err );
snprintf( hdparm_cmd_get_dco,
sizeof( hdparm_cmd_get_dco ),
"%s %s %s\n",
path_hdparm_cmd6_get_dco,
path_hdparm_cmd60_get_dco,
c->device_name,
pipe_std_err );
}
Expand All @@ -124,13 +144,13 @@ int hpa_dco_status( nwipe_context_t* ptr )
snprintf( hdparm_cmd_get_hpa,
sizeof( hdparm_cmd_get_hpa ),
"%s %s %s\n",
path_hdparm_cmd2_get_hpa,
path_hdparm_cmd20_get_hpa,
c->device_name,
pipe_std_err );
snprintf( hdparm_cmd_get_dco,
sizeof( hdparm_cmd_get_dco ),
"%s %s %s\n",
path_hdparm_cmd5_get_dco,
path_hdparm_cmd50_get_dco,
c->device_name,
pipe_std_err );
}
Expand All @@ -140,13 +160,13 @@ int hpa_dco_status( nwipe_context_t* ptr )
snprintf( hdparm_cmd_get_hpa,
sizeof( hdparm_cmd_get_hpa ),
"%s %s %s\n",
path_hdparm_cmd1_get_hpa,
path_hdparm_cmd10_get_hpa,
c->device_name,
pipe_std_err );
snprintf( hdparm_cmd_get_dco,
sizeof( hdparm_cmd_get_dco ),
"%s %s %s\n",
path_hdparm_cmd4_get_dco,
path_hdparm_cmd40_get_dco,
c->device_name,
pipe_std_err );
}
Expand Down
15 changes: 9 additions & 6 deletions src/nwipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ int main( int argc, char** argv )
{
if( system( "which /usr/bin/hdparm > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
nwipe_log( NWIPE_LOG_WARNING,
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
cleanup();
exit( 1 );
if( system( "which /usr/sbin/hdparm > /dev/null 2>&1" ) )
{
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
nwipe_log( NWIPE_LOG_WARNING,
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
cleanup();
exit( 1 );
}
}
}
}
Expand Down

0 comments on commit c837e94

Please sign in to comment.