Skip to content

Commit c837e94

Browse files
Merge pull request martijnvanbrummelen#606 from PartialVolume/Add_new_search_location_for_hdparm_and_smartctl
Add a new search location when looking for hdparm and smartctl.
2 parents 5338328 + 5506c76 commit c837e94

File tree

4 files changed

+67
-28
lines changed

4 files changed

+67
-28
lines changed

src/create_pdf.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ int nwipe_get_smart_data( nwipe_context_t* c )
829829
char smartctl_command[] = "smartctl -a %s";
830830
char smartctl_command2[] = "/sbin/smartctl -a %s";
831831
char smartctl_command3[] = "/usr/bin/smartctl -a %s";
832+
char smartctl_command4[] = "/usr/sbin/smartctl -a %s";
832833
char final_cmd_smartctl[sizeof( smartctl_command3 ) + 256];
833834
char result[512];
834835
char smartctl_labels_to_anonymize[][18] = {
@@ -850,7 +851,14 @@ int nwipe_get_smart_data( nwipe_context_t* c )
850851
{
851852
if( system( "which /usr/bin/smartctl > /dev/null 2>&1" ) )
852853
{
853-
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
854+
if( system( "which /usr/sbin/smartctl > /dev/null 2>&1" ) )
855+
{
856+
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
857+
}
858+
else
859+
{
860+
sprintf( final_cmd_smartctl, smartctl_command4, c->device_name );
861+
}
854862
}
855863
else
856864
{

src/device.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, i
526526
char smartctl_command[] = "smartctl -i %s";
527527
char smartctl_command2[] = "/sbin/smartctl -i %s";
528528
char smartctl_command3[] = "/usr/bin/smartctl -i %s";
529+
char smartctl_command4[] = "/usr/sbin/smartctl -i %s";
529530
char device_shortform[50];
530531
char result[512];
531532
char final_cmd_readlink[sizeof( readlink_command ) + sizeof( device_shortform )];
@@ -706,7 +707,14 @@ int nwipe_get_device_bus_type_and_serialno( char* device, nwipe_device_t* bus, i
706707
{
707708
if( system( "which /usr/bin/smartctl > /dev/null 2>&1" ) )
708709
{
709-
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
710+
if( system( "which /usr/sbin/smartctl > /dev/null 2>&1" ) )
711+
{
712+
nwipe_log( NWIPE_LOG_WARNING, "Command not found. Install smartmontools !" );
713+
}
714+
else
715+
{
716+
sprintf( final_cmd_smartctl, smartctl_command4, device );
717+
}
710718
}
711719
else
712720
{

src/hpa_dco.c

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ int hpa_dco_status( nwipe_context_t* ptr )
5959
int dco_line_found;
6060

6161
FILE* fp;
62-
char path_hdparm_cmd1_get_hpa[] = "hdparm --verbose -N";
63-
char path_hdparm_cmd2_get_hpa[] = "/sbin/hdparm --verbose -N";
64-
char path_hdparm_cmd3_get_hpa[] = "/usr/bin/hdparm --verbose -N";
62+
char path_hdparm_cmd10_get_hpa[] = "hdparm --verbose -N";
63+
char path_hdparm_cmd20_get_hpa[] = "/sbin/hdparm --verbose -N";
64+
char path_hdparm_cmd30_get_hpa[] = "/usr/bin/hdparm --verbose -N";
65+
char path_hdparm_cmd31_get_hpa[] = "/usr/sbin/hdparm --verbose -N";
6566

66-
char path_hdparm_cmd4_get_dco[] = "hdparm --verbose --dco-identify";
67-
char path_hdparm_cmd5_get_dco[] = "/sbin/hdparm --verbose --dco-identify";
68-
char path_hdparm_cmd6_get_dco[] = "/usr/bin/hdparm --verbose --dco-identify";
67+
char path_hdparm_cmd40_get_dco[] = "hdparm --verbose --dco-identify";
68+
char path_hdparm_cmd50_get_dco[] = "/sbin/hdparm --verbose --dco-identify";
69+
char path_hdparm_cmd60_get_dco[] = "/usr/bin/hdparm --verbose --dco-identify";
70+
char path_hdparm_cmd61_get_dco[] = "/usr/sbin/hdparm --verbose --dco-identify";
6971

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

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

8486
/* Initialise return value */
8587
set_return_value = 0;
@@ -96,25 +98,43 @@ int hpa_dco_status( nwipe_context_t* ptr )
9698
{
9799
if( system( "which /usr/bin/hdparm > /dev/null 2>&1" ) )
98100
{
99-
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
100-
nwipe_log( NWIPE_LOG_WARNING,
101-
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
102-
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
103-
cleanup();
104-
exit( 1 );
101+
if( system( "which /usr/sbin/hdparm > /dev/null 2>&1" ) )
102+
{
103+
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
104+
nwipe_log( NWIPE_LOG_WARNING,
105+
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
106+
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
107+
cleanup();
108+
exit( 1 );
109+
}
110+
else
111+
{
112+
snprintf( hdparm_cmd_get_hpa,
113+
sizeof( hdparm_cmd_get_hpa ),
114+
"%s %s %s\n",
115+
path_hdparm_cmd31_get_hpa,
116+
c->device_name,
117+
pipe_std_err );
118+
snprintf( hdparm_cmd_get_dco,
119+
sizeof( hdparm_cmd_get_dco ),
120+
"%s %s %s\n",
121+
path_hdparm_cmd61_get_dco,
122+
c->device_name,
123+
pipe_std_err );
124+
}
105125
}
106126
else
107127
{
108128
snprintf( hdparm_cmd_get_hpa,
109129
sizeof( hdparm_cmd_get_hpa ),
110130
"%s %s %s\n",
111-
path_hdparm_cmd3_get_hpa,
131+
path_hdparm_cmd30_get_hpa,
112132
c->device_name,
113133
pipe_std_err );
114134
snprintf( hdparm_cmd_get_dco,
115135
sizeof( hdparm_cmd_get_dco ),
116136
"%s %s %s\n",
117-
path_hdparm_cmd6_get_dco,
137+
path_hdparm_cmd60_get_dco,
118138
c->device_name,
119139
pipe_std_err );
120140
}
@@ -124,13 +144,13 @@ int hpa_dco_status( nwipe_context_t* ptr )
124144
snprintf( hdparm_cmd_get_hpa,
125145
sizeof( hdparm_cmd_get_hpa ),
126146
"%s %s %s\n",
127-
path_hdparm_cmd2_get_hpa,
147+
path_hdparm_cmd20_get_hpa,
128148
c->device_name,
129149
pipe_std_err );
130150
snprintf( hdparm_cmd_get_dco,
131151
sizeof( hdparm_cmd_get_dco ),
132152
"%s %s %s\n",
133-
path_hdparm_cmd5_get_dco,
153+
path_hdparm_cmd50_get_dco,
134154
c->device_name,
135155
pipe_std_err );
136156
}
@@ -140,13 +160,13 @@ int hpa_dco_status( nwipe_context_t* ptr )
140160
snprintf( hdparm_cmd_get_hpa,
141161
sizeof( hdparm_cmd_get_hpa ),
142162
"%s %s %s\n",
143-
path_hdparm_cmd1_get_hpa,
163+
path_hdparm_cmd10_get_hpa,
144164
c->device_name,
145165
pipe_std_err );
146166
snprintf( hdparm_cmd_get_dco,
147167
sizeof( hdparm_cmd_get_dco ),
148168
"%s %s %s\n",
149-
path_hdparm_cmd4_get_dco,
169+
path_hdparm_cmd40_get_dco,
150170
c->device_name,
151171
pipe_std_err );
152172
}

src/nwipe.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,15 @@ int main( int argc, char** argv )
171171
{
172172
if( system( "which /usr/bin/hdparm > /dev/null 2>&1" ) )
173173
{
174-
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
175-
nwipe_log( NWIPE_LOG_WARNING,
176-
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
177-
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
178-
cleanup();
179-
exit( 1 );
174+
if( system( "which /usr/sbin/hdparm > /dev/null 2>&1" ) )
175+
{
176+
nwipe_log( NWIPE_LOG_WARNING, "hdparm command not found." );
177+
nwipe_log( NWIPE_LOG_WARNING,
178+
"Required by nwipe for HPA/DCO detection & correction and ATA secure erase." );
179+
nwipe_log( NWIPE_LOG_WARNING, "** Please install hdparm **\n" );
180+
cleanup();
181+
exit( 1 );
182+
}
180183
}
181184
}
182185
}

0 commit comments

Comments
 (0)