Changed how often fdatasyncs occur.

Changed what the sync option does.
Stopped nwipe from changing the disk blocksize.
Added periodic fdatasyncs within the write loops in pass.c
This commit is contained in:
Legogizmo
2019-10-21 11:16:19 -05:00
committed by GitHub
parent 721c8de743
commit a75c29f973
5 changed files with 88 additions and 18 deletions

View File

@@ -111,6 +111,7 @@ typedef struct nwipe_context_t_
int signal; /* Set when the child is killed by a signal. */
nwipe_speedring_t speedring; /* Ring buffer for computing the rolling throughput average. */
short sync_status; /* A flag to indicate when the method is syncing. */
int sync_rate;
pthread_t thread; /* The ID of the thread. */
u64 throughput; /* Average throughput in bytes per second. */
u64 verify_errors; /* The number of verification errors across all passes. */

View File

@@ -309,19 +309,8 @@ int main( int argc, char** argv )
if( ioctl( c2[i]->device_fd, BLKBSZGET, &c2[i]->block_size ) == 0 )
{
if( c2[i]->block_size != c2[i]->sector_size )
{
nwipe_log( NWIPE_LOG_WARNING, "Changing '%s' block size from %i to %i.", c2[i]->device_name, c2[i]->block_size, c2[i]->sector_size );
if( ioctl( c2[i]->device_fd, BLKBSZSET, &c2[i]->sector_size ) == 0 )
{
c2[i]->block_size = c2[i]->sector_size;
}
else
{
nwipe_log( NWIPE_LOG_WARNING, "Device '%s' failed BLKBSZSET ioctl.", c2[i]->device_name );
}
}
nwipe_log( NWIPE_LOG_INFO, "Device '%s' has block size %i.", c2[i]->device_name, c2[i]->block_size );
}
else
{

View File

@@ -93,7 +93,7 @@ int nwipe_options_parse( int argc, char** argv )
{ "nogui", no_argument, 0, 0 },
/* A flag to indicate whether the devices whould be opened in sync mode. */
{ "sync", no_argument, 0, 0 },
{ "sync", required_argument, 0, 0 },
/* Verify that wipe patterns are being written to the device. */
{ "verify", required_argument, 0, 0 },
@@ -171,7 +171,13 @@ int nwipe_options_parse( int argc, char** argv )
if( strcmp( nwipe_options_long[i].name, "sync" ) == 0 )
{
nwipe_options.sync = 1;
if( sscanf( optarg, " %i", &nwipe_options.sync ) != 1 \
|| nwipe_options.sync < 1
)
{
fprintf( stderr, "Error: The sync argument must be a positive integer.\n" );
exit( EINVAL );
}
break;
}
@@ -433,7 +439,10 @@ display_help()
puts(" --autonuke If no devices have been specified on the command line, starts wiping all");
puts(" devices immediately. If devices have been specified, starts wiping only");
puts(" those specified devices immediately.");
puts(" --sync Open devices in sync mode");
puts(" --sync=NUM Will preform a sync after NUM writes (default: 0)");
puts(" 0 - fdatasync after the disk is completely written");
puts(" 1 - fdatasync after every write");
puts(" 1000000 - fdatasync after 1000000 writes ect.");
puts(" --verify=TYPE Whether to perform verification of erasure (default: last)");
puts(" off - Do not verify");
puts(" last - Verify after the last pass");

View File

@@ -60,7 +60,7 @@ typedef struct /* nwipe_options_t */
char exclude[MAX_NUMBER_EXCLUDED_DRIVES][MAX_DRIVE_PATH_LENGTH]; /* Drives excluded from the search */
nwipe_prng_t* prng; /* The pseudo random number generator implementation. */
int rounds; /* The number of times that the wipe method should be called. */
int sync; /* A flag to indicate whether writes should be sync'd. */
int sync; /* A flag to indicate whether and how often writes should be sync'd. */
nwipe_verify_t verify; /* A flag to indicate whether writes should be verified. */
} nwipe_options_t;

View File

@@ -236,7 +236,12 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
/* The number of bytes remaining in the pass. */
u64 z = c->device_size;
/* Number of writes to do before a fdatasync. */
int syncRate = nwipe_options.sync;
/* Counter to track when to do a fdatasync. */
int i = 0;
if( c->prng_seed.s == NULL )
{
@@ -349,6 +354,36 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
/* Increment the total progress counters. */
c->pass_done += r;
c->round_done += r;
/* Perodic Sync */
if( syncRate > 0 )
{
i++;
if( i >= syncRate )
{
/* Tell our parent that we are syncing the device. */
c->sync_status = 1;
/* Sync the device. */
r = fdatasync( c->device_fd );
/* Tell our parent that we have finished syncing the device. */
c->sync_status = 0;
if( r != 0 )
{
nwipe_perror( errno, __FUNCTION__, "fdatasync" );
nwipe_log( NWIPE_LOG_WARNING, "Buffer flush failure on '%s'.", c->device_name );
nwipe_log( NWIPE_LOG_WARNING, "Wrote %llu bytes on '%s'.", c->pass_done, c->device_name);
free(b);
return -1;
}
i = 0;
}
}
pthread_testcancel();
@@ -610,6 +645,12 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern )
/* The number of bytes remaining in the pass. */
u64 z = c->device_size;
/* Number of writes to do before a fdatasync. */
int syncRate = nwipe_options.sync;
/* Counter to track when to do a fdatasync. */
int i = 0;
if( pattern == NULL )
{
@@ -732,6 +773,36 @@ int nwipe_static_pass( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* pattern )
/* Increment the total progress counterr. */
c->pass_done += r;
c->round_done += r;
/* Perodic Sync */
if( syncRate > 0 )
{
i++;
if( i >= syncRate )
{
/* Tell our parent that we are syncing the device. */
c->sync_status = 1;
/* Sync the device. */
r = fdatasync( c->device_fd );
/* Tell our parent that we have finished syncing the device. */
c->sync_status = 0;
if( r != 0 )
{
nwipe_perror( errno, __FUNCTION__, "fdatasync" );
nwipe_log( NWIPE_LOG_WARNING, "Buffer flush failure on '%s'.", c->device_name );
nwipe_log( NWIPE_LOG_WARNING, "Wrote %llu bytes on '%s'.", c->pass_done, c->device_name);
free(b);
return -1;
}
i = 0;
}
}
pthread_testcancel();