diff --git a/src/context.h b/src/context.h index e220a1c..8178738 100644 --- a/src/context.h +++ b/src/context.h @@ -94,6 +94,8 @@ typedef struct nwipe_context_t_ char device_name_without_path[100]; char gui_device_name[100]; unsigned long long device_size; // The device size in bytes. + unsigned long long bytes_erased; // Irrespective of pass, this how much of the drive has been erased, CANNOT be + // greater than device_size. char* device_size_text; // The device size in a more (human)readable format. char device_size_txt[NWIPE_DEVICE_SIZE_TXT_LENGTH]; // The device size in a more (human)readable format. char* device_model; // The model of the device. @@ -128,6 +130,7 @@ typedef struct nwipe_context_t_ short sync_status; // A flag to indicate when the method is syncing. pthread_t thread; // The ID of the thread. u64 throughput; // Average throughput in bytes per second. + char throughput_txt[13]; // Human readable throughput. u64 verify_errors; // The number of verification errors across all passes. char temp1_path[MAX_HWMON_PATH_LENGTH]; // path to temperature variables /sys/class/hwmon/hwmonX/ etc. int temp1_crit; // Critical high drive temperature, 1000000=unitialised, millidegree celsius. diff --git a/src/create_pdf.c b/src/create_pdf.c index b9af734..23f53c7 100644 --- a/src/create_pdf.c +++ b/src/create_pdf.c @@ -54,6 +54,7 @@ int create_pdf( nwipe_context_t* ptr ) char prng_type[20] = ""; /* type of prng, twister, isaac, isaac64 */ char start_time_text[50] = ""; char end_time_text[50] = ""; + char bytes_erased[50] = ""; char HPA_pre_erase[50] = ""; char HPA_post_erase[50] = ""; char DCO_pre_erase[50] = ""; @@ -306,9 +307,21 @@ int create_pdf( nwipe_context_t* ptr ) pdf_set_font( pdf, "Helvetica" ); /* bytes erased */ - pdf_add_text( pdf, NULL, "Bytes Erased:", 12, 60, 210, PDF_GRAY ); + pdf_add_text( pdf, NULL, "*Bytes Erased:", 12, 60, 210, PDF_GRAY ); + snprintf( bytes_erased, + sizeof( bytes_erased ), + "%lli %.1i%%", + c->bytes_erased, + (int) ( c->bytes_erased / c->device_size ) * 100 ); pdf_set_font( pdf, "Helvetica-Bold" ); - pdf_add_text( pdf, NULL, "", 12, 60, 210, PDF_BLACK ); + if( c->bytes_erased == c->device_size ) + { + pdf_add_text( pdf, NULL, bytes_erased, 12, 145, 210, PDF_DARK_GREEN ); + } + else + { + pdf_add_text( pdf, NULL, bytes_erased, 12, 145, 210, PDF_RED ); + } pdf_set_font( pdf, "Helvetica" ); /* rounds */ @@ -327,7 +340,19 @@ int create_pdf( nwipe_context_t* ptr ) pdf_set_font( pdf, "Helvetica-Bold" ); pdf_add_text( pdf, NULL, DCO_post_erase, 12, 397, 190, PDF_BLACK ); pdf_set_font( pdf, "Helvetica" ); + + /* Throughput */ + pdf_add_text( pdf, NULL, "Throughput:", 12, 300, 170, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( pdf, NULL, c->throughput_txt, 12, 370, 170, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); + + /* Information */ pdf_add_text( pdf, NULL, "Information:", 12, 60, 170, PDF_GRAY ); + pdf_set_font( pdf, "Helvetica-Bold" ); + pdf_add_text( + pdf, NULL, "* bytes erased: The amount of drive that's been erased at least once", 12, 60, 130, PDF_BLACK ); + pdf_set_font( pdf, "Helvetica" ); /* ---------------------- */ /* Technician/Operator ID */ diff --git a/src/logging.c b/src/logging.c index 749d836..631134f 100644 --- a/src/logging.c +++ b/src/logging.c @@ -825,6 +825,9 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected ) /* Determine the size of throughput so that the correct nomenclature can be used */ Determine_C_B_nomenclature( c[i]->throughput, throughput, 13 ); + /* write the duration string to the drive context for later use by create_pdf() */ + snprintf( c[i]->throughput_txt, sizeof( c[i]->throughput_txt ), "%s", throughput ); + /* Add this devices throughput to the total throughput */ total_throughput += c[i]->throughput; diff --git a/src/nwipe.c b/src/nwipe.c index 6a6c897..a953be0 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -346,6 +346,9 @@ int main( int argc, char** argv ) /* Initialise the wipe result value */ c1[i]->result = 0; + + /* Initialise the variable that tracks how much of the drive has been erased */ + c1[i]->bytes_erased = 0; } /* Pass the number selected to the struct for other threads */ diff --git a/src/pass.c b/src/pass.c index 3f6487a..af52e09 100644 --- a/src/pass.c +++ b/src/pass.c @@ -338,6 +338,10 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) if( idx == 0 ) { nwipe_log( NWIPE_LOG_FATAL, "ERROR, prng wrote nothing to the buffer" ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } } @@ -350,6 +354,10 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) { nwipe_perror( errno, __FUNCTION__, "write" ); nwipe_log( NWIPE_LOG_FATAL, "Unable to read from '%s'.", c->device_name ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } @@ -374,18 +382,15 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) nwipe_perror( errno, __FUNCTION__, "lseek" ); nwipe_log( NWIPE_LOG_ERROR, "Unable to bump the '%s' file offset after a partial write.", c->device_name ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } } /* partial write */ - /* Decrement the bytes remaining in this pass. */ - z -= r; - - /* Increment the total progress counters. */ - c->pass_done += r; - c->round_done += r; - /* Perodic Sync */ if( syncRate > 0 ) { @@ -409,6 +414,10 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) nwipe_log( NWIPE_LOG_WARNING, "Wrote %llu bytes on '%s'.", c->pass_done, c->device_name ); c->fsyncdata_errors++; free( b ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } @@ -418,6 +427,13 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) pthread_testcancel(); + /* Decrement the bytes remaining in this pass. */ + z -= r; + + /* Increment the total progress counters. */ + c->pass_done += r; + c->round_done += r; + } /* remaining bytes */ /* Release the output buffer. */ @@ -438,6 +454,16 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE ) nwipe_perror( errno, __FUNCTION__, "fdatasync" ); nwipe_log( NWIPE_LOG_WARNING, "Buffer flush failure on '%s'.", c->device_name ); c->fsyncdata_errors++; + if( c->bytes_erased < ( c->device_size - z - blocksize ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z - blocksize; + } + return -1; + } + + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; } /* We're done. */ @@ -761,6 +787,10 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) { nwipe_perror( errno, __FUNCTION__, "write" ); nwipe_log( NWIPE_LOG_FATAL, "Unable to write to '%s'.", c->device_name ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } @@ -785,6 +815,10 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) nwipe_perror( errno, __FUNCTION__, "lseek" ); nwipe_log( NWIPE_LOG_ERROR, "Unable to bump the '%s' file offset after a partial write.", c->device_name ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } @@ -799,13 +833,6 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) * then ( w == 0 ) always. */ - /* Decrement the bytes remaining in this pass. */ - z -= r; - - /* Increment the total progress counterr. */ - c->pass_done += r; - c->round_done += r; - /* Perodic Sync */ if( syncRate > 0 ) { @@ -829,6 +856,10 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) nwipe_log( NWIPE_LOG_WARNING, "Wrote %llu bytes on '%s'.", c->pass_done, c->device_name ); c->fsyncdata_errors++; free( b ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } return -1; } @@ -838,6 +869,13 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) pthread_testcancel(); + /* Decrement the bytes remaining in this pass. */ + z -= r; + + /* Increment the total progress counterr. */ + c->pass_done += r; + c->round_done += r; + } /* remaining bytes */ /* Tell our parent that we are syncing the device. */ @@ -851,15 +889,24 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern ) if( r != 0 ) { - /* FIXME: Is there a better way to handle this? */ nwipe_perror( errno, __FUNCTION__, "fdatasync" ); nwipe_log( NWIPE_LOG_WARNING, "Buffer flush failure on '%s'.", c->device_name ); c->fsyncdata_errors++; + if( c->bytes_erased < ( c->device_size - z - blocksize ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z - blocksize; + } + return -1; } /* Release the output buffer. */ free( b ); + if( c->bytes_erased < ( c->device_size - z ) ) // How much of the device has been erased? + { + c->bytes_erased = c->device_size - z; + } + /* We're done. */ return 0;