From fb6b47d12a6f62046ec7b543d0dafbd180d96277 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Wed, 17 Nov 2021 09:59:20 +0000 Subject: [PATCH] Fix summary table - Control-C If you used control-c during a wipe, the summary table would report FAILED rather than UABORTED, even though no errors had occured and no errors were reported in the error summary table. The correct message on control-c abort should be UABORTED if no errors on that drive had so far been detected or FAILED if errors had been detected. nwipe reported correctly when letting the wipe continue to it's natural completion. This patch fixes that issue. --- src/logging.c | 36 ++++++++++++------------------------ src/method.c | 2 -- src/nwipe.c | 41 ++++++++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/logging.c b/src/logging.c index f60936d..e47ebf2 100644 --- a/src/logging.c +++ b/src/logging.c @@ -758,7 +758,7 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected ) /* Any errors ? if so set the exclamation_flag and fail message, * All status messages should be eight characters EXACTLY ! */ - if( c[i]->result < 0 ) + if( c[i]->pass_errors != 0 || c[i]->verify_errors != 0 || c[i]->fsyncdata_errors != 0 ) { strncpy( exclamation_flag, "!", 1 ); exclamation_flag[1] = 0; @@ -768,44 +768,32 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected ) } else { - - if( c[i]->pass_errors != 0 || c[i]->verify_errors != 0 ) + if( c[i]->wipe_status == 0 ) { - strncpy( exclamation_flag, "!", 1 ); + strncpy( exclamation_flag, " ", 1 ); exclamation_flag[1] = 0; - strncpy( status, "-FAILED-", 8 ); + strncpy( status, " Erased ", 8 ); status[8] = 0; } else { - if( c[i]->wipe_status == 0 ) + if( user_abort == 1 ) { - strncpy( exclamation_flag, " ", 1 ); + strncpy( exclamation_flag, "!", 1 ); exclamation_flag[1] = 0; - strncpy( status, " Erased ", 8 ); + strncpy( status, "UABORTED", 8 ); status[8] = 0; } else { - if( user_abort == 1 ) - { - strncpy( exclamation_flag, "!", 1 ); - exclamation_flag[1] = 0; + /* If this ever happens, there is a bug ! */ + strncpy( exclamation_flag, " ", 1 ); + exclamation_flag[1] = 0; - strncpy( status, "UABORTED", 8 ); - status[8] = 0; - } - else - { - /* If this ever happens, there is a bug ! */ - strncpy( exclamation_flag, " ", 1 ); - exclamation_flag[1] = 0; - - strncpy( status, "INSANITY", 8 ); - status[8] = 0; - } + strncpy( status, "INSANITY", 8 ); + status[8] = 0; } } } diff --git a/src/method.c b/src/method.c index b7e2b69..b620d5b 100644 --- a/src/method.c +++ b/src/method.c @@ -804,8 +804,6 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) /* For the selected method, calculate the correct round_size value (for correct percentage calculation) */ calculate_round_size( c ); - c->result = c->round_size; - /* If only verifying then the round size is the device size */ if( nwipe_options.method == &nwipe_verify_zero || nwipe_options.method == &nwipe_verify_one ) { diff --git a/src/nwipe.c b/src/nwipe.c index 426d51e..905c176 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -291,6 +291,9 @@ int main( int argc, char** argv ) { nwipe_selected += 1; } + + /* Initialise the wipe result value */ + c1[i]->result = 0; } /* Pass the number selected to the struct for other threads */ @@ -598,6 +601,19 @@ int main( int argc, char** argv ) close( c2[i]->device_fd ); } } + if( nwipe_options.verbose ) + { + for( i = 0; i < nwipe_selected; i++ ) + { + nwipe_log( NWIPE_LOG_DEBUG, + "Status: %s, result=%d, pass_errors=%llu, verify_errors=%llu, fsync_errors=%llu", + c2[i]->device_name, + c2[i]->result, + c2[i]->pass_errors, + c2[i]->verify_errors, + c2[i]->fsyncdata_errors ); + } + } /* if no wipe threads started then zero each selected drive result flag, * as we don't need to report fatal/non fatal errors if no wipes were ever started ! */ @@ -613,24 +629,23 @@ int main( int argc, char** argv ) for( i = 0; i < nwipe_selected; i++ ) { /* Check for non-fatal errors. */ - if( c2[i]->result > 0 ) + if( c2[i]->result != 0 || c2[i]->pass_errors != 0 || c2[i]->verify_errors != 0 + || c2[i]->fsyncdata_errors != 0 ) { - nwipe_log( NWIPE_LOG_FATAL, "Nwipe exited with non fatal errors on device = %s\n", c2[i]->device_name ); + nwipe_log( NWIPE_LOG_FATAL, + "Nwipe exited with errors on device = %s, see log for specific error\n", + c2[i]->device_name ); + nwipe_log( NWIPE_LOG_DEBUG, + "Status: %s, result=%d, pass_errors=%llu, verify_errors=%llu, fsync_errors=%llu", + c2[i]->device_name, + c2[i]->result, + c2[i]->pass_errors, + c2[i]->verify_errors, + c2[i]->fsyncdata_errors ); non_fatal_errors_flag = 1; return_status = 1; } } - - for( i = 0; i < nwipe_selected; i++ ) - { - /* Check for fatal errors. */ - if( c2[i]->result < 0 ) - { - nwipe_log( NWIPE_LOG_ERROR, "Nwipe exited with fatal errors on device = %s\n", c2[i]->device_name ); - fatal_errors_flag = 1; - return_status = -1; - } - } } /* Generate and send the drive status summary to the log */