mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 13:42:14 +00:00
Merge pull request #442 from PartialVolume/HPA_DCO_002
HPA_DCO_002 - Add HPA, DCO capability
This commit is contained in:
@@ -157,13 +157,13 @@ typedef struct nwipe_context_t_
|
||||
time_t end_time; // End time of wipe
|
||||
u64 fsyncdata_errors; // The number of fsyncdata errors across all passes.
|
||||
char PDF_filename[256]; // The filename of the PDF certificate/report.
|
||||
int HPA_pre_erase_status; // 0 = No HPA found/disabled, 1 = HPA detected, 2 = Unknown, unable to checked
|
||||
int HPA_post_erase_status; // 0 = No HPA found/disabled, 1 = HPA detected, 2 = Unknown, unable to checked
|
||||
int HPA_status; // 0 = No HPA found/disabled, 1 = HPA detected, 2 = Unknown, unable to checked
|
||||
u64 HPA_reported_set; // the 'HPA set' value reported hdparm -N, i.e the first value of n/n
|
||||
u64 HPA_reported_real; // the 'HPA real' value reported hdparm -N, i.e the second value of n/n
|
||||
int DCO_pre_erase_status; // 0 = No DCO found, 1 = DCO detected, 2 = Unknown, unable to checked
|
||||
int DCO_post_erase_status; // 0 = No DCO found, 1 = DCO detected, 2 = Unknown, unable to checked
|
||||
int DCO_status; // 0 = No DCO found, 1 = DCO detected, 2 = Unknown, unable to checked
|
||||
u64 DCO_reported_real_max_sectors; // real max sectors as reported by hdparm --dco-identify
|
||||
u64 HPA_size; // The size of the host protected area in sectors
|
||||
char HPA_size_text[NWIPE_DEVICE_SIZE_TXT_LENGTH]; // Human readable size bytes, KB, MB, GB ..
|
||||
|
||||
/*
|
||||
* Identity contains the raw serial number of the drive
|
||||
|
||||
156
src/create_pdf.c
156
src/create_pdf.c
@@ -35,6 +35,8 @@
|
||||
#include "logging.h"
|
||||
#include "options.h"
|
||||
#include "prng.h"
|
||||
#include "hpa_dco.h"
|
||||
#include "miscellaneous.h"
|
||||
|
||||
int create_pdf( nwipe_context_t* ptr )
|
||||
{
|
||||
@@ -57,12 +59,14 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
char end_time_text[50] = "";
|
||||
char bytes_erased[50] = "";
|
||||
char HPA_pre_erase[50] = "";
|
||||
char HPA_post_erase[50] = "";
|
||||
char DCO_pre_erase[50] = "";
|
||||
char DCO_post_erase[50] = "";
|
||||
char HPA_status_text[50] = "";
|
||||
char HPA_size_text[50] = "";
|
||||
char errors[50] = "";
|
||||
char throughput_txt[50] = "";
|
||||
|
||||
float height;
|
||||
float page_width;
|
||||
|
||||
struct pdf_info info = { .creator = "https://github.com/PartialVolume/shredos.x86_64",
|
||||
.producer = "https://github.com/martijnvanbrummelen/nwipe",
|
||||
.title = "PDF Disk Erasure Certificate",
|
||||
@@ -80,16 +84,18 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
struct pdf_doc* pdf = pdf_create( PDF_A4_WIDTH, PDF_A4_HEIGHT, &info );
|
||||
|
||||
/* Create footer text string and append the version */
|
||||
strcpy( pdf_footer, "Disc Erasure by NWIPE version " );
|
||||
strcat( pdf_footer, version_string );
|
||||
snprintf( pdf_footer, sizeof( pdf_footer ), "Disc Erasure by NWIPE version %s", version_string );
|
||||
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
pdf_append_page( pdf );
|
||||
struct pdf_object* page_1 = pdf_append_page( pdf );
|
||||
|
||||
/* Obtain page page_width */
|
||||
page_width = pdf_page_width( page_1 );
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
/* Create header and footer, with the exception of the green */
|
||||
/* tick/red icon which is set from the 'status' section below */
|
||||
pdf_add_text( pdf, NULL, pdf_footer, 12, 200, 30, PDF_BLACK );
|
||||
pdf_add_text_wrap( pdf, NULL, pdf_footer, 12, 0, 30, PDF_BLACK, page_width, PDF_ALIGN_CENTER, &height );
|
||||
pdf_add_line( pdf, NULL, 50, 50, 550, 50, 3, PDF_BLACK );
|
||||
pdf_add_line( pdf, NULL, 50, 650, 550, 650, 3, PDF_BLACK );
|
||||
pdf_add_image_data( pdf, NULL, 45, 665, 100, 100, bin2c_shred_db_jpg, 27063 );
|
||||
@@ -157,23 +163,6 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
pdf_add_text( pdf, NULL, "Health:", 12, 60, 370, PDF_GRAY );
|
||||
pdf_add_text( pdf, NULL, "Remapped Sectors:", 12, 300, 370, PDF_GRAY );
|
||||
|
||||
/* HPA, DCO, pre-erase */
|
||||
if( !strcmp( c->device_type_str, "NVME" ) )
|
||||
{
|
||||
snprintf( HPA_pre_erase, sizeof( HPA_pre_erase ), "Not applicable to NVME" );
|
||||
snprintf( HPA_post_erase, sizeof( HPA_post_erase ), "Not applicable to NVME" );
|
||||
snprintf( DCO_pre_erase, sizeof( DCO_pre_erase ), "Not applicable to NVME" );
|
||||
snprintf( DCO_post_erase, sizeof( DCO_post_erase ), "Not applicable to NVME" );
|
||||
}
|
||||
pdf_add_text( pdf, NULL, "HPA(pre-erase):", 12, 60, 350, PDF_GRAY );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_pre_erase, 12, 150, 350, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
pdf_add_text( pdf, NULL, "DCO(pre-erase):", 12, 300, 350, PDF_GRAY );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, DCO_pre_erase, 12, 393, 350, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* --------------- */
|
||||
/* Erasure Details */
|
||||
pdf_add_text( pdf, NULL, "Disk Erasure Details", 12, 50, 310, PDF_BLUE );
|
||||
@@ -350,24 +339,96 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
}
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* HPA, DCO, post erase */
|
||||
pdf_add_text( pdf, NULL, "HPA(post-erase):", 12, 60, 190, PDF_GRAY );
|
||||
/*******************************
|
||||
* HPA, DCO, post erase - LABELS
|
||||
*/
|
||||
pdf_add_text( pdf, NULL, "HPA:", 12, 60, 190, PDF_GRAY );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_post_erase, 12, 155, 190, PDF_BLACK );
|
||||
pdf_add_text( pdf, NULL, HPA_status_text, 12, 155, 190, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
pdf_add_text( pdf, NULL, "DCO(post-erase):", 12, 300, 190, PDF_GRAY );
|
||||
pdf_add_text( pdf, NULL, "HPA Size:", 12, 300, 190, PDF_GRAY );
|
||||
|
||||
/*******************
|
||||
* Populate HPA size
|
||||
*/
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, DCO_post_erase, 12, 397, 190, PDF_BLACK );
|
||||
if( c->HPA_status == HPA_ENABLED )
|
||||
{
|
||||
snprintf( HPA_size_text, sizeof( HPA_size_text ), "%lli sectors", c->HPA_size );
|
||||
pdf_add_text( pdf, NULL, HPA_size_text, 12, 360, 190, PDF_RED );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_status == HPA_DISABLED )
|
||||
{
|
||||
snprintf( HPA_size_text, sizeof( HPA_size_text ), "Zero sectors" );
|
||||
pdf_add_text( pdf, NULL, HPA_size_text, 12, 360, 190, PDF_DARK_GREEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_status == HPA_UNKNOWN )
|
||||
{
|
||||
snprintf( HPA_size_text, sizeof( HPA_size_text ), "UNKNOWN" );
|
||||
pdf_add_text( pdf, NULL, HPA_size_text, 12, 360, 190, PDF_RED );
|
||||
}
|
||||
}
|
||||
}
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* Throughput */
|
||||
/*********************
|
||||
* Populate HPA status
|
||||
*/
|
||||
if( !strcmp( c->device_type_str, "NVME" ) )
|
||||
{
|
||||
snprintf( HPA_status_text, sizeof( HPA_status_text ), "Not applicable to NVME" );
|
||||
snprintf( HPA_size_text, sizeof( HPA_size_text ), "Not applicable to NVME" );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_status_text, 12, 95, 190, PDF_DARK_GREEN );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_status == HPA_ENABLED )
|
||||
{
|
||||
snprintf( HPA_status_text, sizeof( HPA_status_text ), "ENABLED" );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_status_text, 12, 95, 190, PDF_RED );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_status == HPA_DISABLED )
|
||||
{
|
||||
snprintf( HPA_status_text, sizeof( HPA_status_text ), "DISABLED" );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_status_text, 12, 95, 190, PDF_DARK_GREEN );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_status == HPA_UNKNOWN )
|
||||
{
|
||||
snprintf( HPA_status_text, sizeof( HPA_status_text ), "UNKNOWN" );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, HPA_status_text, 12, 95, 190, PDF_RED );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************
|
||||
* Throughput
|
||||
*/
|
||||
pdf_add_text( pdf, NULL, "Throughput:", 12, 300, 170, PDF_GRAY );
|
||||
snprintf( throughput_txt, sizeof( throughput_txt ), "%s/sec", c->throughput_txt );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text( pdf, NULL, throughput_txt, 12, 370, 170, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* Errors */
|
||||
/********
|
||||
* Errors
|
||||
*/
|
||||
pdf_add_text( pdf, NULL, "Errors(pass/sync/verify):", 12, 60, 170, PDF_GRAY );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
snprintf( errors, sizeof( errors ), "%llu/%llu/%llu", c->pass_errors, c->fsyncdata_errors, c->verify_errors );
|
||||
@@ -381,27 +442,30 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
}
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* Information */
|
||||
/*************
|
||||
* Information
|
||||
*/
|
||||
pdf_add_text( pdf, NULL, "Information:", 12, 60, 150, PDF_GRAY );
|
||||
pdf_set_font( pdf, "Helvetica-Bold" );
|
||||
pdf_add_text(
|
||||
pdf, NULL, "* bytes erased: The amount of drive that's been erased at least once", 12, 60, 130, PDF_BLACK );
|
||||
pdf_set_font( pdf, "Helvetica" );
|
||||
|
||||
/* ---------------------- */
|
||||
/* Technician/Operator ID */
|
||||
/************************
|
||||
* Technician/Operator ID
|
||||
*/
|
||||
pdf_add_line( pdf, NULL, 50, 120, 550, 120, 1, PDF_GRAY );
|
||||
pdf_add_text( pdf, NULL, "Technician/Operator ID", 12, 50, 100, PDF_BLUE );
|
||||
pdf_add_text( pdf, NULL, "Name/ID:", 12, 60, 80, PDF_GRAY );
|
||||
pdf_add_text( pdf, NULL, "Signature:", 12, 300, 100, PDF_BLUE );
|
||||
pdf_add_line( pdf, NULL, 360, 65, 550, 66, 1, PDF_GRAY );
|
||||
|
||||
/* --------------------------- */
|
||||
/* Create the reports filename */
|
||||
|
||||
/* Sanitize the strings that we are going to use to create the report filename
|
||||
* by converting any non alphanumeric characters to an underscore or hyphon */
|
||||
|
||||
/*****************************
|
||||
* Create the reports filename
|
||||
*
|
||||
* Sanitize the strings that we are going to use to create the report filename
|
||||
* by converting any non alphanumeric characters to an underscore or hyphon
|
||||
*/
|
||||
replace_non_alphanumeric( end_time_text, '-' );
|
||||
replace_non_alphanumeric( c->device_model, '_' );
|
||||
replace_non_alphanumeric( c->device_serial_no, '_' );
|
||||
@@ -416,15 +480,3 @@ int create_pdf( nwipe_context_t* ptr )
|
||||
pdf_destroy( pdf );
|
||||
return 0;
|
||||
}
|
||||
void replace_non_alphanumeric( char* str, char replacement_char )
|
||||
{
|
||||
int i = 0;
|
||||
while( str[i] != 0 )
|
||||
{
|
||||
if( str[i] < '0' || ( str[i] > '9' && str[i] < 'A' ) || ( str[i] > 'Z' && str[i] < 'a' ) || str[i] > 'z' )
|
||||
{
|
||||
str[i] = replacement_char;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#ifndef CREATE_PDF_H_
|
||||
#define CREATE_PDF_H_
|
||||
|
||||
#define MAX_PDF_FOOTER_TEXT_LENGTH 50
|
||||
#define MAX_PDF_FOOTER_TEXT_LENGTH 100
|
||||
|
||||
/* Additional colors that supplement the standard colors in pdfgen.h
|
||||
*/
|
||||
@@ -38,17 +38,4 @@
|
||||
*/
|
||||
int create_pdf( nwipe_context_t* ptr );
|
||||
|
||||
/**
|
||||
* Scan a string and replace any characters that are not alpha-numeric with
|
||||
* the character_char.
|
||||
* Example:
|
||||
* char str[] = 18:21:56;
|
||||
* calling the function replace_non_alphanumeric( &str, '_' )
|
||||
* would result in str changing from 18:21:56 to 18_21_56
|
||||
* @param character pointer to the string to be processed
|
||||
* @param replacement_char the character used to replace non alpha-numeric characters
|
||||
* @return void
|
||||
*/
|
||||
void replace_non_alphanumeric( char* str, char replacement_char );
|
||||
|
||||
#endif /* CREATE_PDF_H_ */
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include "hpa_dco.h"
|
||||
#include "miscellaneous.h"
|
||||
|
||||
#include <parted/parted.h>
|
||||
#include <parted/debug.h>
|
||||
@@ -342,7 +343,7 @@ int check_device( nwipe_context_t*** c, PedDevice* dev, int dcount )
|
||||
}
|
||||
if( check_HPA == 1 )
|
||||
{
|
||||
hpa_dco_status( next_device, PRE_WIPE_HPA_CHECK );
|
||||
hpa_dco_status( next_device );
|
||||
}
|
||||
|
||||
if( strlen( (const char*) next_device->device_serial_no ) )
|
||||
|
||||
13
src/gui.c
13
src/gui.c
@@ -43,6 +43,7 @@
|
||||
#include "logging.h"
|
||||
#include "version.h"
|
||||
#include "temperature.h"
|
||||
#include "miscellaneous.h"
|
||||
|
||||
#define NWIPE_GUI_PANE 8
|
||||
|
||||
@@ -580,18 +581,6 @@ void nwipe_gui_create_all_windows_on_terminal_resize( int force_creation, const
|
||||
|
||||
void nwipe_gui_select( int count, nwipe_context_t** c )
|
||||
{
|
||||
/**
|
||||
* The primary user interface. Allows the user to
|
||||
* change options and specify the devices to be wiped.
|
||||
*
|
||||
* @parameter count The number of contexts in the array.
|
||||
* @parameter c An array of device contexts.
|
||||
*
|
||||
* @modifies c[].select Sets the select flag according to user input.
|
||||
* @modifies options Sets program options according to to user input.
|
||||
*
|
||||
*/
|
||||
|
||||
extern int terminate_signal;
|
||||
|
||||
/* Widget labels. */
|
||||
|
||||
12
src/gui.h
12
src/gui.h
@@ -33,6 +33,18 @@ void nwipe_gui_create_stats_window( void ); // Create the stats window
|
||||
void nwipe_gui_create_all_windows_on_terminal_resize(
|
||||
int force_creation,
|
||||
const char* footer_text ); // If terminal is resized recreate all windows
|
||||
|
||||
/**
|
||||
* The primary user interface. Allows the user to
|
||||
* change options and specify the devices to be wiped.
|
||||
*
|
||||
* @parameter count The number of contexts in the array.
|
||||
* @parameter c An array of device contexts.
|
||||
*
|
||||
* @modifies c[].select Sets the select flag according to user input.
|
||||
* @modifies options Sets program options according to to user input.
|
||||
*
|
||||
*/
|
||||
void nwipe_gui_select( int count, nwipe_context_t** c ); // Select devices to wipe.
|
||||
void* nwipe_gui_status( void* ptr ); // Update operation progress.
|
||||
void nwipe_gui_method( void ); // Change the method option.
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
* ahead and submit a pull request to https://github.com/martijnvanbrummelen/nwipe
|
||||
*/
|
||||
|
||||
int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
int hpa_dco_status( nwipe_context_t* ptr )
|
||||
{
|
||||
nwipe_context_t* c;
|
||||
c = ptr;
|
||||
@@ -164,14 +164,8 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
*/
|
||||
if( strstr( result, "hpa is disabled" ) != 0 )
|
||||
{
|
||||
if( pre_or_post == PRE_WIPE_HPA_CHECK )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
c->HPA_post_erase_status = HPA_DISABLED;
|
||||
}
|
||||
c->HPA_status = HPA_DISABLED;
|
||||
|
||||
nwipe_log( NWIPE_LOG_INFO, "[GOOD] The host protected area is disabled on %s", c->device_name );
|
||||
hpa_line_found = 1;
|
||||
break;
|
||||
@@ -180,7 +174,7 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
{
|
||||
if( strstr( result, "hpa is enabled" ) != 0 )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_ENABLED;
|
||||
c->HPA_status = HPA_ENABLED;
|
||||
nwipe_log(
|
||||
NWIPE_LOG_WARNING, "[BAD] The host protected area is enabled on %s", c->device_name );
|
||||
hpa_line_found = 1;
|
||||
@@ -190,7 +184,7 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
{
|
||||
if( strstr( result, "invalid" ) != 0 )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_ENABLED;
|
||||
c->HPA_status = HPA_ENABLED;
|
||||
nwipe_log( NWIPE_LOG_WARNING,
|
||||
"[UNSURE] hdparm reports invalid output, buggy drive firmware on %s?",
|
||||
c->device_name );
|
||||
@@ -237,7 +231,7 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
}
|
||||
else
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_UNKNOWN;
|
||||
c->HPA_status = HPA_UNKNOWN;
|
||||
nwipe_log( NWIPE_LOG_WARNING,
|
||||
"[UNKNOWN] We can't find the HPA line, has hdparm ouput changed? %s",
|
||||
c->device_name );
|
||||
@@ -379,37 +373,37 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
/* If all three values match then there is no hidden disc area. HPA is disabled. */
|
||||
if( ( c->HPA_reported_set == c->HPA_reported_real ) && c->DCO_reported_real_max_sectors == c->HPA_reported_set )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_DISABLED;
|
||||
c->HPA_status = HPA_DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If HPA set and DCO max sectors are equal it can also be considered that HPA is disabled */
|
||||
if( c->HPA_reported_set == c->DCO_reported_real_max_sectors )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_DISABLED;
|
||||
c->HPA_status = HPA_DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_reported_set != c->DCO_reported_real_max_sectors )
|
||||
{
|
||||
c->HPA_pre_erase_status = HPA_ENABLED;
|
||||
c->HPA_status = HPA_ENABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( c->HPA_pre_erase_status == HPA_DISABLED )
|
||||
if( c->HPA_status == HPA_DISABLED )
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_INFO, "[GOOD] HPA is disabled on %s", c->device_name );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_pre_erase_status == HPA_ENABLED )
|
||||
if( c->HPA_status == HPA_ENABLED )
|
||||
{
|
||||
nwipe_log( NWIPE_LOG_WARNING, "[BAD] HPA is enabled on %s", c->device_name );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( c->HPA_pre_erase_status == HPA_UNKNOWN )
|
||||
if( c->HPA_status == HPA_UNKNOWN )
|
||||
{
|
||||
nwipe_log(
|
||||
NWIPE_LOG_WARNING, "[UNKNOWN] We can't seem to determine the HPA status on %s", c->device_name );
|
||||
@@ -417,11 +411,20 @@ int hpa_dco_status( nwipe_context_t* ptr, int pre_or_post )
|
||||
}
|
||||
}
|
||||
|
||||
/* Determine the size of the HPA and store the results in the
|
||||
* context.
|
||||
*/
|
||||
/* Determine the size of the HPA if it's enabled and store the results in the context.*/
|
||||
if( c->HPA_status == HPA_ENABLED )
|
||||
{
|
||||
c->HPA_size = c->DCO_reported_real_max_sectors - c->HPA_reported_set;
|
||||
|
||||
// WARNING Add code here
|
||||
/* Convert the size to a human readable format and save in context */
|
||||
Determine_C_B_nomenclature( c->HPA_size, c->HPA_size_text, NWIPE_DEVICE_SIZE_TXT_LENGTH );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* HPA not enabled so initialise these values */
|
||||
c->HPA_size = 0;
|
||||
c->HPA_size_text[0] = 0;
|
||||
}
|
||||
|
||||
return set_return_value;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@
|
||||
#define HPA_ENABLED 1
|
||||
#define HPA_UNKNOWN 2
|
||||
|
||||
#define PRE_WIPE_HPA_CHECK 0
|
||||
#define POST_WIPE_HPA_CHECK 1
|
||||
|
||||
int hpa_dco_status( nwipe_context_t*, int );
|
||||
int hpa_dco_status( nwipe_context_t* );
|
||||
|
||||
#endif /* HPA_DCO_H_ */
|
||||
|
||||
103
src/logging.c
103
src/logging.c
@@ -37,6 +37,7 @@
|
||||
#include "options.h"
|
||||
#include "logging.h"
|
||||
#include "create_pdf.h"
|
||||
#include "miscellaneous.h"
|
||||
|
||||
/* Global array to hold log values to print when logging to STDOUT */
|
||||
char** log_lines;
|
||||
@@ -929,105 +930,3 @@ void nwipe_log_summary( nwipe_context_t** ptr, int nwipe_selected )
|
||||
"********************************************************************************" );
|
||||
nwipe_log( NWIPE_LOG_NOTIMESTAMP, "" );
|
||||
}
|
||||
|
||||
void Determine_C_B_nomenclature( u64 speed, char* result, int result_array_size )
|
||||
{
|
||||
|
||||
/* C_B ? Determine Capacity or Bandwidth nomenclature
|
||||
*
|
||||
* A pointer to a result character string with a minimum of 13 characters in length
|
||||
* should be provided.
|
||||
*
|
||||
* Outputs a string of the form xxxTB/s, xxxGB/s, xxxMB/s, xxxKB/s B/s depending on the value of 'speed'
|
||||
*/
|
||||
|
||||
/* Initialise the output array */
|
||||
int idx = 0;
|
||||
|
||||
while( idx < result_array_size )
|
||||
{
|
||||
result[idx++] = 0;
|
||||
}
|
||||
|
||||
/* Determine the size of throughput so that the correct nomenclature can be used */
|
||||
if( speed >= INT64_C( 1000000000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu TB", speed / INT64_C( 1000000000000 ) );
|
||||
}
|
||||
else if( speed >= INT64_C( 1000000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu GB", speed / INT64_C( 1000000000 ) );
|
||||
}
|
||||
else if( speed >= INT64_C( 1000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu MB", speed / INT64_C( 1000000 ) );
|
||||
}
|
||||
else if( speed >= INT64_C( 1000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu KB", speed / INT64_C( 1000 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu B", speed / INT64_C( 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
void convert_seconds_to_hours_minutes_seconds( u64 total_seconds, int* hours, int* minutes, int* seconds )
|
||||
{
|
||||
/* Convert binary seconds into binary hours, minutes and seconds */
|
||||
|
||||
if( total_seconds % 60 )
|
||||
{
|
||||
*minutes = total_seconds / 60;
|
||||
|
||||
*seconds = total_seconds - ( *minutes * 60 );
|
||||
}
|
||||
else
|
||||
{
|
||||
*minutes = total_seconds / 60;
|
||||
|
||||
*seconds = 0;
|
||||
}
|
||||
if( *minutes > 59 )
|
||||
{
|
||||
*hours = *minutes / 60;
|
||||
if( *minutes % 60 )
|
||||
{
|
||||
*minutes = *minutes - ( *hours * 60 );
|
||||
}
|
||||
else
|
||||
{
|
||||
*minutes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int nwipe_strip_path( char* output, char* input )
|
||||
{
|
||||
/* Take the input string, say "/dev/sda" and remove the "/dev/", prefix the result
|
||||
* with 'length' spaces. So if length=8 and input=/dev/sda, output will
|
||||
* be " sda", a string 8 characters long right justified with spaces.
|
||||
*/
|
||||
int idx_dest;
|
||||
int idx_src;
|
||||
idx_dest = 8;
|
||||
// idx_dest = length;
|
||||
output[idx_dest--] = 0;
|
||||
idx_src = strlen( input );
|
||||
idx_src--;
|
||||
|
||||
while( idx_dest >= 0 )
|
||||
{
|
||||
/* if the device name contains a / start prefixing spaces */
|
||||
if( input[idx_src] == '/' )
|
||||
{
|
||||
output[idx_dest--] = ' ';
|
||||
continue;
|
||||
}
|
||||
if( idx_src >= 0 )
|
||||
{
|
||||
output[idx_dest--] = input[idx_src--];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,8 +60,5 @@ void nwipe_perror( int nwipe_errno, const char* f, const char* s );
|
||||
void nwipe_log_OSinfo();
|
||||
int nwipe_log_sysinfo();
|
||||
void nwipe_log_summary( nwipe_context_t**, int ); // This produces the wipe status table on exit
|
||||
void Determine_C_B_nomenclature( u64, char*, int );
|
||||
void convert_seconds_to_hours_minutes_seconds( u64, int*, int*, int* );
|
||||
int nwipe_strip_path( char*, char* );
|
||||
|
||||
#endif /* LOGGING_H_ */
|
||||
|
||||
@@ -111,3 +111,118 @@ u64 str_ascii_number_to_ll( char* str )
|
||||
}
|
||||
return -2; /* no number found */
|
||||
}
|
||||
|
||||
void Determine_C_B_nomenclature( u64 qty, char* result, int result_array_size )
|
||||
{
|
||||
|
||||
/* C_B ? Determine Capacity or Bandwidth nomenclature
|
||||
*
|
||||
* A pointer to a result character string with a minimum of 13 characters in length
|
||||
* should be provided.
|
||||
*
|
||||
* Outputs a string of the form xxxTB, xxxGB, xxxMB, xxxKB B depending on the value of 'qty'
|
||||
*/
|
||||
|
||||
/* Initialise the output array */
|
||||
int idx = 0;
|
||||
|
||||
while( idx < result_array_size )
|
||||
{
|
||||
result[idx++] = 0;
|
||||
}
|
||||
|
||||
/* Determine the size of throughput so that the correct nomenclature can be used */
|
||||
if( qty >= INT64_C( 1000000000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu TB", qty / INT64_C( 1000000000000 ) );
|
||||
}
|
||||
else if( qty >= INT64_C( 1000000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu GB", qty / INT64_C( 1000000000 ) );
|
||||
}
|
||||
else if( qty >= INT64_C( 1000000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu MB", qty / INT64_C( 1000000 ) );
|
||||
}
|
||||
else if( qty >= INT64_C( 1000 ) )
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu KB", qty / INT64_C( 1000 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( result, result_array_size, "%3llu B", qty / INT64_C( 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
void convert_seconds_to_hours_minutes_seconds( u64 total_seconds, int* hours, int* minutes, int* seconds )
|
||||
{
|
||||
/* Convert binary seconds into binary hours, minutes and seconds */
|
||||
|
||||
if( total_seconds % 60 )
|
||||
{
|
||||
*minutes = total_seconds / 60;
|
||||
|
||||
*seconds = total_seconds - ( *minutes * 60 );
|
||||
}
|
||||
else
|
||||
{
|
||||
*minutes = total_seconds / 60;
|
||||
|
||||
*seconds = 0;
|
||||
}
|
||||
if( *minutes > 59 )
|
||||
{
|
||||
*hours = *minutes / 60;
|
||||
if( *minutes % 60 )
|
||||
{
|
||||
*minutes = *minutes - ( *hours * 60 );
|
||||
}
|
||||
else
|
||||
{
|
||||
*minutes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int nwipe_strip_path( char* output, char* input )
|
||||
{
|
||||
/* Take the input string, say "/dev/sda" and remove the "/dev/", prefix the result
|
||||
* with 'length' spaces. So if length=8 and input=/dev/sda, output will
|
||||
* be " sda", a string 8 characters long right justified with spaces.
|
||||
*/
|
||||
int idx_dest;
|
||||
int idx_src;
|
||||
idx_dest = 8;
|
||||
// idx_dest = length;
|
||||
output[idx_dest--] = 0;
|
||||
idx_src = strlen( input );
|
||||
idx_src--;
|
||||
|
||||
while( idx_dest >= 0 )
|
||||
{
|
||||
/* if the device name contains a / start prefixing spaces */
|
||||
if( input[idx_src] == '/' )
|
||||
{
|
||||
output[idx_dest--] = ' ';
|
||||
continue;
|
||||
}
|
||||
if( idx_src >= 0 )
|
||||
{
|
||||
output[idx_dest--] = input[idx_src--];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void replace_non_alphanumeric( char* str, char replacement_char )
|
||||
{
|
||||
int i = 0;
|
||||
while( str[i] != 0 )
|
||||
{
|
||||
if( str[i] < '0' || ( str[i] > '9' && str[i] < 'A' ) || ( str[i] > 'Z' && str[i] < 'a' ) || str[i] > 'z' )
|
||||
{
|
||||
str[i] = replacement_char;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,21 @@ void strlower( char* str );
|
||||
*/
|
||||
u64 str_ascii_number_to_ll( char* );
|
||||
|
||||
void Determine_C_B_nomenclature( u64, char*, int );
|
||||
void convert_seconds_to_hours_minutes_seconds( u64, int*, int*, int* );
|
||||
int nwipe_strip_path( char*, char* );
|
||||
|
||||
/**
|
||||
* Scan a string and replace any characters that are not alpha-numeric with
|
||||
* the character_char.
|
||||
* Example:
|
||||
* char str[] = 18:21:56;
|
||||
* calling the function replace_non_alphanumeric( &str, '_' )
|
||||
* would result in str changing from 18:21:56 to 18_21_56
|
||||
* @param character pointer to the string to be processed
|
||||
* @param replacement_char the character used to replace non alpha-numeric characters
|
||||
* @return void
|
||||
*/
|
||||
void replace_non_alphanumeric( char* str, char replacement_char );
|
||||
|
||||
#endif /* HPA_DCO_H_ */
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "logging.h"
|
||||
#include "gui.h"
|
||||
#include "temperature.h"
|
||||
#include "miscellaneous.h"
|
||||
|
||||
#include <sys/ioctl.h> /* FIXME: Twice Included */
|
||||
#include <sys/shm.h>
|
||||
|
||||
BIN
src/redcross.jpg
Normal file
BIN
src/redcross.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
BIN
src/te.jpg
Normal file
BIN
src/te.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Reference in New Issue
Block a user