mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 05:32:14 +00:00
Formatting device module.
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -23,4 +23,4 @@ jobs:
|
|||||||
- name: verifying code style
|
- name: verifying code style
|
||||||
# TODO use check-format when all the code has been formatted.
|
# TODO use check-format when all the code has been formatted.
|
||||||
# run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format
|
# run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format
|
||||||
run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/context.h src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD
|
run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/context.h src/device.h src/device.c src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD
|
||||||
|
|||||||
2
.github/workflows/ci_ubuntu-16.04.yml
vendored
2
.github/workflows/ci_ubuntu-16.04.yml
vendored
@@ -23,4 +23,4 @@ jobs:
|
|||||||
- name: verifying code style
|
- name: verifying code style
|
||||||
# TODO use check-format when all the code has been formatted.
|
# TODO use check-format when all the code has been formatted.
|
||||||
# run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format
|
# run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format
|
||||||
run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/context.h src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD
|
run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/context.h src/device.h src/device.c src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD
|
||||||
|
|||||||
40
src/device.c
40
src/device.c
@@ -86,7 +86,8 @@ int nwipe_device_get( nwipe_context_t*** c, char **devnamelist, int ndevnames )
|
|||||||
int i;
|
int i;
|
||||||
int dcount = 0;
|
int dcount = 0;
|
||||||
|
|
||||||
for(i = 0; i < ndevnames; i++) {
|
for( i = 0; i < ndevnames; i++ )
|
||||||
|
{
|
||||||
|
|
||||||
dev = ped_device_get( devnamelist[i] );
|
dev = ped_device_get( devnamelist[i] );
|
||||||
if( !dev )
|
if( !dev )
|
||||||
@@ -152,24 +153,33 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount )
|
|||||||
next_device->device_size = dev->length * dev->sector_size;
|
next_device->device_size = dev->length * dev->sector_size;
|
||||||
next_device->device_size_text = ped_unit_format_byte( dev, dev->length * dev->sector_size );
|
next_device->device_size_text = ped_unit_format_byte( dev, dev->length * dev->sector_size );
|
||||||
next_device->result = -2;
|
next_device->result = -2;
|
||||||
|
|
||||||
/* Attempt to get serial number of device. */
|
/* Attempt to get serial number of device. */
|
||||||
if( ( fd = open( next_device->device_name = dev->path, O_RDONLY ) ) == ERR )
|
if( ( fd = open( next_device->device_name = dev->path, O_RDONLY ) ) == ERR )
|
||||||
{
|
{
|
||||||
nwipe_log( NWIPE_LOG_WARNING, "Unable to open device %s to obtain serial number", next_device->device_name );
|
nwipe_log( NWIPE_LOG_WARNING, "Unable to open device %s to obtain serial number", next_device->device_name );
|
||||||
}
|
}
|
||||||
/* We don't check the ioctl return status because there are plenty of situations where a serial number may not be
|
|
||||||
|
/*
|
||||||
|
* We don't check the ioctl return status because there are plenty of situations where a serial number may not be
|
||||||
* returned by ioctl such as USB drives, logical volumes, encryted volumes, so the log file would have multiple
|
* returned by ioctl such as USB drives, logical volumes, encryted volumes, so the log file would have multiple
|
||||||
* benign ioctl errors reported which isn't necessarily a problem.
|
* benign ioctl errors reported which isn't necessarily a problem.
|
||||||
*/
|
*/
|
||||||
ioctl( fd, HDIO_GET_IDENTITY, &next_device->identity );
|
ioctl( fd, HDIO_GET_IDENTITY, &next_device->identity );
|
||||||
close( fd );
|
close( fd );
|
||||||
|
|
||||||
for (idx=0; idx<20; idx++) next_device->serial_no[idx]=next_device->identity.serial_no[idx];
|
for( idx = 0; idx < 20; idx++ )
|
||||||
|
next_device->serial_no[idx] = next_device->identity.serial_no[idx];
|
||||||
|
|
||||||
next_device->serial_no[20] = 0; /* terminate the string */
|
next_device->serial_no[20] = 0; /* terminate the string */
|
||||||
trim( (char*) next_device->serial_no ); /* Remove leading/training whitespace from serial number and left justify */
|
trim( (char*) next_device->serial_no ); /* Remove leading/training whitespace from serial number and left justify */
|
||||||
|
|
||||||
nwipe_log( NWIPE_LOG_INFO,"Found drive model=\"%s\", device path=\"%s\", size=\"%s\", serial number=\"%s\"", next_device->label, next_device->device_name, next_device->device_size_text, next_device->serial_no);
|
nwipe_log( NWIPE_LOG_INFO,
|
||||||
|
"Found drive model=\"%s\", device path=\"%s\", size=\"%s\", serial number=\"%s\"",
|
||||||
|
next_device->label,
|
||||||
|
next_device->device_name,
|
||||||
|
next_device->device_size_text,
|
||||||
|
next_device->serial_no );
|
||||||
|
|
||||||
( *c )[dcount] = next_device;
|
( *c )[dcount] = next_device;
|
||||||
return 1;
|
return 1;
|
||||||
@@ -193,29 +203,37 @@ char *trim(char *str)
|
|||||||
len = strlen( str );
|
len = strlen( str );
|
||||||
endp = str + len;
|
endp = str + len;
|
||||||
|
|
||||||
/* Move the front and back pointers to address the first non-whitespace
|
/*
|
||||||
|
* Move the front and back pointers to address the first non-whitespace
|
||||||
* characters from each end.
|
* characters from each end.
|
||||||
*/
|
*/
|
||||||
while( isspace((unsigned char) *frontp) ) { ++frontp; }
|
while( isspace( (unsigned char) *frontp ) )
|
||||||
|
{
|
||||||
|
++frontp;
|
||||||
|
}
|
||||||
if( endp != frontp )
|
if( endp != frontp )
|
||||||
{
|
{
|
||||||
while( isspace((unsigned char) *(--endp)) && endp != frontp ) {}
|
while( isspace( (unsigned char) *( --endp ) ) && endp != frontp )
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if( str + len - 1 != endp )
|
if( str + len - 1 != endp )
|
||||||
*( endp + 1 ) = '\0';
|
*( endp + 1 ) = '\0';
|
||||||
else if( frontp != str && endp == frontp )
|
else if( frontp != str && endp == frontp )
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
/* Shift the string so that it starts at str so that if it's dynamically
|
/*
|
||||||
|
* Shift the string so that it starts at str so that if it's dynamically
|
||||||
* allocated, we can still free it on the returned pointer. Note the reuse
|
* allocated, we can still free it on the returned pointer. Note the reuse
|
||||||
* of endp to mean the front of the string buffer now.
|
* of endp to mean the front of the string buffer now.
|
||||||
*/
|
*/
|
||||||
endp = str;
|
endp = str;
|
||||||
if( frontp != str )
|
if( frontp != str )
|
||||||
{
|
{
|
||||||
while( *frontp ) { *endp++ = *frontp++; }
|
while( *frontp )
|
||||||
|
{
|
||||||
|
*endp++ = *frontp++;
|
||||||
|
}
|
||||||
*endp = '\0';
|
*endp = '\0';
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eof */
|
|
||||||
|
|||||||
@@ -20,14 +20,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef DEVICE_H_
|
#ifndef DEVICE_H_
|
||||||
#define DEVICE_H_
|
#define DEVICE_H_
|
||||||
|
|
||||||
void nwipe_device_identify( nwipe_context_t* c ); /* Get hardware information about the device. */
|
void nwipe_device_identify( nwipe_context_t* c ); // Get hardware information about the device.
|
||||||
int nwipe_device_scan( nwipe_context_t*** c ); /* Find devices that we can wipe. */
|
int nwipe_device_scan( nwipe_context_t*** c ); // Find devices that we can wipe.
|
||||||
int nwipe_device_get( nwipe_context_t*** c, char **devnamelist, int ndevnames ); /* Get info about devices to wipe */
|
int nwipe_device_get( nwipe_context_t*** c, char** devnamelist, int ndevnames ); // Get info about devices to wipe.
|
||||||
|
|
||||||
#endif /* DEVICE_H_ */
|
#endif /* DEVICE_H_ */
|
||||||
|
|
||||||
/* eof */
|
|
||||||
|
|||||||
Reference in New Issue
Block a user