Merge pull request #105 from Legogizmo/SyncChanges

Sync changes
This commit is contained in:
PartialVolume
2019-11-08 13:21:31 +00:00
committed by GitHub
4 changed files with 88 additions and 19 deletions

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

@@ -91,7 +91,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},
@@ -111,7 +111,7 @@ int nwipe_options_parse( int argc, char** argv )
nwipe_options.nowait = 0;
nwipe_options.nosignals = 0;
nwipe_options.nogui = 0;
nwipe_options.sync = 0;
nwipe_options.sync = 100000;
nwipe_options.verify = NWIPE_VERIFY_LAST;
memset( nwipe_options.logfile, '\0', sizeof( nwipe_options.logfile ) );
@@ -170,7 +170,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;
}
@@ -424,7 +430,10 @@ void display_help()
puts(" starts wiping all devices immediately. If devices have");
puts(" been specified, starts wiping only those specified");
puts(" devices immediately.\n");
puts(" --sync Open devices in sync mode\n");
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");
puts(" (default: last)");
puts(" off - Do not verify");

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();