Merge pull request #453 from PartialVolume/add_temperature_limits_to_log_info

Add temperature limits to nwipe log
This commit is contained in:
PartialVolume
2023-03-14 20:42:37 +00:00
committed by GitHub
4 changed files with 106 additions and 8 deletions

View File

@@ -818,13 +818,13 @@ void nwipe_gui_select( int count, nwipe_context_t** c )
case HPA_ENABLED:
wprintw( main_window, " " );
wattron( main_window, COLOR_PAIR( 9 ) );
wprintw( main_window, " HPA/DCO hidden area detected !! " );
wprintw( main_window, " HPA/DCO Hidden area detected !! " );
wattroff( main_window, COLOR_PAIR( 9 ) );
break;
case HPA_DISABLED:
wprintw( main_window, " " );
wprintw( main_window, " HPA/DCO Excellent NO hidden areas " );
wprintw( main_window, " HPA/DCO No hidden areas detected " );
break;
case HPA_UNKNOWN:

View File

@@ -317,6 +317,12 @@ int main( int argc, char** argv )
}
nwipe_update_temperature( c1[i] );
/* Log the temperature crtical, highest, lowest and lowest critical temperature
* limits to nwipes log file using the INFO catagory
*/
nwipe_log_drives_temperature_limits( c1[i] );
}
/* Check for initialization errors. */

View File

@@ -40,11 +40,7 @@
int nwipe_init_temperature( nwipe_context_t* c )
{
/* This function is called after each nwipe_context_t has been created.
* It initialises the temperature variables in each context and then
* constructs a path that is placed in the context that points to the
* appropriate /sys/class/hwmon/hwmonX directory that corresponds with
* the particular drive represented in the context structure.
/* See header definition for description of function
*/
DIR* dir;
DIR* dir2;
@@ -269,3 +265,80 @@ void nwipe_update_temperature( nwipe_context_t* c )
return;
}
void nwipe_log_drives_temperature_limits( nwipe_context_t* c )
{
/* See header for description of function
*/
char temperature_limits_txt[500];
int idx = 0;
/*
* Initialise the character string, as we are building it a few
* characters at a time and it's important there it is populated
* with all zeros as we are using strlen() as we build the line up.
*/
memset( &temperature_limits_txt, 0, sizeof( temperature_limits_txt ) );
if( c->temp1_crit != 1000000 )
{
snprintf( temperature_limits_txt,
sizeof( temperature_limits_txt ),
"Temperature limits for %s, critical=%ic, ",
c->device_name,
c->temp1_crit );
}
else
{
snprintf( temperature_limits_txt,
sizeof( temperature_limits_txt ),
"Temperature limits for %s, critical=N/A, ",
c->device_name );
}
idx = strlen( temperature_limits_txt );
if( c->temp1_highest != 1000000 )
{
snprintf( &temperature_limits_txt[idx],
( sizeof( temperature_limits_txt ) - idx ),
"highest=%ic, ",
c->temp1_highest );
}
else
{
snprintf( &temperature_limits_txt[idx], ( sizeof( temperature_limits_txt ) - idx ), "highest=N/A, " );
}
idx = strlen( temperature_limits_txt );
if( c->temp1_lowest != 1000000 )
{
snprintf(
&temperature_limits_txt[idx], ( sizeof( temperature_limits_txt ) - idx ), "lowest=%ic, ", c->temp1_lowest );
}
else
{
snprintf( &temperature_limits_txt[idx], ( sizeof( temperature_limits_txt ) - idx ), "lowest=N/A, " );
}
idx = strlen( temperature_limits_txt );
if( c->temp1_lcrit != 1000000 )
{
snprintf( &temperature_limits_txt[idx],
( sizeof( temperature_limits_txt ) - idx ),
"low critical=%ic.",
c->temp1_lcrit );
}
else
{
snprintf( &temperature_limits_txt[idx], ( sizeof( temperature_limits_txt ) - idx ), "low critical=N/A. " );
}
nwipe_log( NWIPE_LOG_INFO, "%s", temperature_limits_txt );
return;
}

View File

@@ -1,4 +1,4 @@
/*.
/*
* temperature.h: The header file for disk drive temperature sensing
*
* This program is free software; you can redistribute it and/or modify it under
@@ -22,9 +22,28 @@
#include <sys/types.h>
#include "context.h"
/**
* This function is called after each nwipe_context_t has been created.
* It initialises the temperature variables in each context and then
* constructs a path that is placed in the context that points to the
* appropriate /sys/class/hwmon/hwmonX directory that corresponds with
* the particular drive represented in the context structure.
* @param pointer to a drive context
* @return returns 0 on success < 1 on error
*/
int nwipe_init_temperature( nwipe_context_t* );
void nwipe_update_temperature( nwipe_context_t* );
/**
* This function is normally called only once. It's called after both the
* nwipe_init_temperature() function and nwipe_update_temperature()
* functions have been called. It logs the drives critical, highest, lowest
* and lowest critical temperatures. Not all drives report four temperatures.
* @param pointer to a drive context
*/
void nwipe_log_drives_temperature_limits( nwipe_context_t* );
#define NUMBER_OF_FILES 7
#endif /* TEMPERATURE_H_ */