diff --git a/src/device.c b/src/device.c index 5fda944..08543be 100644 --- a/src/device.c +++ b/src/device.c @@ -58,7 +58,7 @@ int nwipe_device_scan( nwipe_context_t*** c ) * Scans the filesystem for storage device names. * * @parameter device_names A reference to a null array pointer. - * @modifies device_names Populates device_names with an array of nwipe_contect_t + * @modifies device_names Populates device_names with an array of nwipe_context_t * @returns The number of strings in the device_names array. * */ diff --git a/src/nwipe.c b/src/nwipe.c index aa063f5..b19b2fc 100644 --- a/src/nwipe.c +++ b/src/nwipe.c @@ -28,6 +28,9 @@ #endif #include +#include +#include +#include #include #include #include @@ -61,6 +64,16 @@ int terminate_signal; int user_abort; int global_wipe_status; +/* helper function for sorting */ +int devnamecmp( const void* a, const void* b ) +{ + // nwipe_log( NWIPE_LOG_DEBUG, "a: %s, b: %s", ( *( nwipe_context_t** ) a)->device_name, ( *( nwipe_context_t** ) + // b)->device_name ); + + int ret = strcmp( ( *(nwipe_context_t**) a )->device_name, ( *(nwipe_context_t**) b )->device_name ); + return ( ret ); +} + int main( int argc, char** argv ) { int nwipe_optind; // The result of nwipe_options(). @@ -207,6 +220,9 @@ int main( int argc, char** argv ) } } + /* sort list of devices here */ + qsort( (void*) c1, (size_t) nwipe_enumerated, sizeof( nwipe_context_t* ), devnamecmp ); + if( terminate_signal == 1 ) { cleanup(); @@ -218,6 +234,12 @@ int main( int argc, char** argv ) /* The array of pointers to contexts that will actually be wiped. */ nwipe_context_t** c2 = (nwipe_context_t**) malloc( nwipe_enumerated * sizeof( nwipe_context_t* ) ); + if( c2 == NULL ) + { + nwipe_log( NWIPE_LOG_ERROR, "memory allocation for c2 failed" ); + cleanup(); + exit( 1 ); + } /* Open the entropy source. */ nwipe_entropy = open( NWIPE_KNOB_ENTROPY, O_RDONLY );