Skip to content

Commit

Permalink
Merge pull request martijnvanbrummelen#505 from ggruber/master
Browse files Browse the repository at this point in the history
sort the device list
  • Loading branch information
PartialVolume authored Oct 21, 2023
2 parents 7fb2a77 + 539a023 commit 603716e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
*/
Expand Down
22 changes: 22 additions & 0 deletions src/nwipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -208,6 +221,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();
Expand All @@ -219,6 +235,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 );
Expand Down

0 comments on commit 603716e

Please sign in to comment.