mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 13:42:14 +00:00
sort the device list
This commit is contained in:
@@ -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.
|
||||
*
|
||||
*/
|
||||
|
||||
22
src/nwipe.c
22
src/nwipe.c
@@ -28,6 +28,9 @@
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user