mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-10 18:47:22 +00:00
ID: 3608765 - 'lib/ipmi_ekanalyzer.c' - reverse checks to reduce indentation
Rewrote ipmi_ek_display_chassis_info_area, ipmi_ek_display_product_info_area, and ipmi_ekanalyzer_fru_file2structure to reverse the checks of error conditions to reduce the amount of indentation required. Commit for Dan Gora
This commit is contained in:
parent
184994586e
commit
4299cfa385
@ -2544,51 +2544,56 @@ ipmi_ek_display_fru_header_detail( char * filename )
|
|||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static void
|
||||||
ipmi_ek_display_chassis_info_area( FILE * input_file, long offset )
|
ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
|
||||||
{
|
{
|
||||||
if ( input_file != NULL ){
|
unsigned char data = 0;
|
||||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
unsigned char ch_type = 0;
|
||||||
printf("Chassis Info Area\n");
|
unsigned int len;
|
||||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
size_t file_offset;
|
||||||
|
|
||||||
fseek (input_file, offset, SEEK_SET);
|
if (input_file == NULL) {
|
||||||
if ( !feof(input_file) ){
|
return;
|
||||||
unsigned char data = 0;
|
}
|
||||||
unsigned int len = 0;
|
|
||||||
|
|
||||||
fread (&data, 1, 1, input_file);
|
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||||
printf("Format Version Number: %d\n", (data & 0x0f) );
|
printf("Chassis Info Area\n");
|
||||||
if ( !feof(input_file) ){
|
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||||
fread (&len, 1, 1, input_file);
|
|
||||||
/* len is in factor of 8 bytes */
|
fseek(input_file, offset, SEEK_SET);
|
||||||
len = len * 8;
|
if (feof(input_file)) {
|
||||||
printf("Area Length: %d\n", len);
|
lprintf(LOG_ERR, "Invalid Chassis Info Area!");
|
||||||
len -= 2;
|
return;
|
||||||
}
|
}
|
||||||
if ( !feof(input_file) ){
|
|
||||||
unsigned char ch_type = 0;
|
fread(&data, 1, 1, input_file);
|
||||||
size_t file_offset = ftell (input_file);
|
printf("Format Version Number: %d\n", (data & 0x0f));
|
||||||
/* Chassis Type*/
|
if (feof(input_file)) {
|
||||||
fread (&ch_type, 1, 1, input_file);
|
return;
|
||||||
printf("Chassis Type: %d\n", ch_type);
|
}
|
||||||
len --;
|
|
||||||
/* Chassis Part Number*/
|
fread(&len, 1, 1, input_file);
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
/* len is in factor of 8 bytes */
|
||||||
"Chassis Part Number", &len);
|
len = len * 8;
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
printf("Area Length: %d\n", len);
|
||||||
/* Chassis Serial */
|
len -= 2;
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
if (feof(input_file)) {
|
||||||
"Chassis Serial Number", &len);
|
return;
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
}
|
||||||
/* Custom product info area */
|
/* Chassis Type*/
|
||||||
file_offset = ipmi_ek_display_board_info_area (
|
fread(&ch_type, 1, 1, input_file);
|
||||||
input_file, "Custom", &len);
|
printf("Chassis Type: %d\n", ch_type);
|
||||||
}
|
len--;
|
||||||
}
|
/* Chassis Part Number*/
|
||||||
}
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
else{
|
"Chassis Part Number", &len);
|
||||||
lprintf(LOG_ERR, "Invalid Chassis Info Area!");
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
}
|
/* Chassis Serial */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"Chassis Serial Number", &len);
|
||||||
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
|
/* Custom product info area */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"Custom", &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@ -2734,70 +2739,75 @@ ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
|
|||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static void
|
||||||
ipmi_ek_display_product_info_area( FILE * input_file, long offset )
|
ipmi_ek_display_product_info_area(FILE * input_file, long offset)
|
||||||
{
|
{
|
||||||
if ( input_file != NULL ){
|
unsigned char data = 0;
|
||||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
unsigned int len;
|
||||||
printf("Product Info Area\n");
|
size_t file_offset = ftell(input_file);
|
||||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
|
||||||
|
|
||||||
fseek (input_file, offset, SEEK_SET);
|
if (input_file == NULL) {
|
||||||
if ( !feof(input_file) ){
|
return;
|
||||||
unsigned char data = 0;
|
}
|
||||||
unsigned int len = 0;
|
|
||||||
|
|
||||||
fread (&data, 1, 1, input_file);
|
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||||
printf("Format Version Number: %d\n", (data & 0x0f) );
|
printf("Product Info Area\n");
|
||||||
if ( !feof(input_file) ){
|
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||||
fread (&len, 1, 1, input_file);
|
|
||||||
/* length is in factor of 8 bytes */
|
|
||||||
len = len * 8;
|
|
||||||
printf("Area Length: %d\n", len);
|
|
||||||
len -= 2; /* -1 byte of format version and -1 byte itself */
|
|
||||||
}
|
|
||||||
if ( !feof(input_file) ){
|
|
||||||
size_t file_offset = ftell (input_file);
|
|
||||||
|
|
||||||
fread (&data, 1, 1, input_file);
|
fseek(input_file, offset, SEEK_SET);
|
||||||
printf("Language Code: %d\n", data);
|
if (feof(input_file)) {
|
||||||
len --;
|
lprintf(LOG_ERR, "Invalid Product Info Area!");
|
||||||
/* Product Mfg */
|
return;
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
}
|
||||||
"Product Manufacture Data", &len);
|
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
fread(&data, 1, 1, input_file);
|
||||||
/* Product Name */
|
printf("Format Version Number: %d\n", (data & 0x0f));
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
if (feof(input_file)) {
|
||||||
"Product Name", &len);
|
return;
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
}
|
||||||
/* Product Part */
|
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
fread(&len, 1, 1, input_file);
|
||||||
"Product Part/Model Number", &len);
|
/* length is in factor of 8 bytes */
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
len = len * 8;
|
||||||
/* Product Version */
|
printf("Area Length: %d\n", len);
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
len -= 2; /* -1 byte of format version and -1 byte itself */
|
||||||
"Product Version", &len);
|
if (feof(input_file)) {
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
return;
|
||||||
/* Product Serial */
|
}
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
|
||||||
"Product Serial Number", &len);
|
fread(&data, 1, 1, input_file);
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
printf("Language Code: %d\n", data);
|
||||||
/* Product Asset Tag */
|
len--;
|
||||||
file_offset = ipmi_ek_display_board_info_area ( input_file,
|
/* Product Mfg */
|
||||||
"Asset Tag", &len);
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
"Product Manufacture Data", &len);
|
||||||
/* FRU file ID */
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
file_offset = ipmi_ek_display_board_info_area (
|
/* Product Name */
|
||||||
input_file, "FRU File ID", &len);
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
fseek (input_file, file_offset, SEEK_SET);
|
"Product Name", &len);
|
||||||
/* Custom product info area */
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
file_offset = ipmi_ek_display_board_info_area (
|
/* Product Part */
|
||||||
input_file, "Custom", &len);
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
}
|
"Product Part/Model Number", &len);
|
||||||
}
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
}
|
/* Product Version */
|
||||||
else{
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
lprintf(LOG_ERR, "Invalid Product Info Area!");
|
"Product Version", &len);
|
||||||
}
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
|
/* Product Serial */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"Product Serial Number", &len);
|
||||||
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
|
/* Product Asset Tag */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"Asset Tag", &len);
|
||||||
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
|
/* FRU file ID */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"FRU File ID", &len);
|
||||||
|
fseek(input_file, file_offset, SEEK_SET);
|
||||||
|
/* Custom product info area */
|
||||||
|
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||||
|
"Custom", &len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
@ -3880,77 +3890,75 @@ ipmi_ek_display_clock_config_record( struct ipmi_ek_multi_header * record )
|
|||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static int
|
static int
|
||||||
ipmi_ekanalyzer_fru_file2structure( char * filename,
|
ipmi_ekanalyzer_fru_file2structure(char * filename,
|
||||||
struct ipmi_ek_multi_header ** list_head,
|
struct ipmi_ek_multi_header ** list_head,
|
||||||
struct ipmi_ek_multi_header ** list_record,
|
struct ipmi_ek_multi_header ** list_record,
|
||||||
struct ipmi_ek_multi_header ** list_last )
|
struct ipmi_ek_multi_header ** list_last)
|
||||||
{
|
{
|
||||||
int return_status = ERROR_STATUS;
|
int return_status = ERROR_STATUS;
|
||||||
FILE * input_file;
|
FILE * input_file;
|
||||||
|
unsigned char last_record = 0;
|
||||||
|
long multi_offset = 0;
|
||||||
|
int record_count = 0;
|
||||||
|
|
||||||
|
input_file = fopen(filename, "r");
|
||||||
|
if (input_file == NULL) {
|
||||||
|
lprintf(LOG_ERR, "File: '%s' is not found", filename);
|
||||||
|
return ERROR_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
input_file = fopen ( filename, "r");
|
fseek(input_file, START_DATA_OFFSET, SEEK_SET);
|
||||||
if ( input_file == NULL ){
|
fread(&multi_offset, 1, 1, input_file);
|
||||||
lprintf(LOG_ERR, "File: '%s' is not found", filename);
|
if (multi_offset < 1) {
|
||||||
return_status = ERROR_STATUS;
|
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
|
||||||
}
|
filename);
|
||||||
else{
|
fclose(input_file);
|
||||||
long multi_offset = 0;
|
return OK_STATUS;
|
||||||
fseek ( input_file, START_DATA_OFFSET, SEEK_SET );
|
}
|
||||||
fread ( &multi_offset, 1, 1, input_file );
|
/* the offset value is in multiple of 8 bytes. */
|
||||||
if ( multi_offset <= 0 ){
|
multi_offset = multi_offset * 8;
|
||||||
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
|
if (verbose == LOG_DEBUG) {
|
||||||
filename);
|
printf("start multi offset = 0x%02lx\n", multi_offset);
|
||||||
}
|
}
|
||||||
else{
|
fseek(input_file, multi_offset, SEEK_SET);
|
||||||
int record_count = 0;
|
while (!feof(input_file)) {
|
||||||
|
*list_record = malloc(sizeof(struct ipmi_ek_multi_header));
|
||||||
|
fread(&(*list_record)->header, START_DATA_OFFSET, 1, input_file);
|
||||||
|
if ((*list_record)->header.len == 0) {
|
||||||
|
record_count++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
(*list_record)->data = malloc((*list_record)->header.len);
|
||||||
|
if ((*list_record)->data == NULL) {
|
||||||
|
lprintf(LOG_ERR, "Failed to allocation memory size %d\n",
|
||||||
|
(*list_record)->header.len);
|
||||||
|
record_count++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( verbose == LOG_DEBUG ){
|
fread((*list_record)->data, ((*list_record)->header.len), 1,
|
||||||
printf( "start multi offset = 0x%02lx\n", multi_offset );
|
input_file);
|
||||||
}
|
if (verbose > 0) {
|
||||||
/*the offset value is in multiple of 8 bytes.*/
|
printf("Record %d has length = %02x\n", record_count,
|
||||||
multi_offset = multi_offset * 8;
|
(*list_record)->header.len);
|
||||||
fseek ( input_file, multi_offset, SEEK_SET );
|
}
|
||||||
while ( !feof( input_file ) ){
|
if (verbose > 1) {
|
||||||
*list_record = malloc ( sizeof (struct ipmi_ek_multi_header) );
|
int i;
|
||||||
fread ( &(*list_record)->header, START_DATA_OFFSET, 1, input_file);
|
printf("%02x\t", (*list_record)->header.type);
|
||||||
if ( (*list_record)->header.len > 0 ){
|
for (i = 0; i < ((*list_record)->header.len); i++) {
|
||||||
(*list_record)->data =
|
printf("%02x\t", (*list_record)->data[i]);
|
||||||
malloc ((*list_record)->header.len);
|
}
|
||||||
if ( (*list_record)->data == NULL ){
|
printf("\n");
|
||||||
lprintf(LOG_ERR, "Lack of memory");
|
}
|
||||||
}
|
ipmi_ek_add_record2list(list_record, list_head, list_last);
|
||||||
else{
|
/* mask the 8th bits to see if it is the last record */
|
||||||
unsigned char last_record = 0;
|
last_record = ((*list_record)->header.format) & 0x80;
|
||||||
|
if (last_record) {
|
||||||
fread ( (*list_record)->data,
|
break;
|
||||||
((*list_record)->header.len), 1, input_file);
|
}
|
||||||
if ( verbose > 0 )
|
record_count++;
|
||||||
printf("Record %d has length = %02x\n", record_count,
|
}
|
||||||
(*list_record)->header.len);
|
return return_status;
|
||||||
if ( verbose > 1 ){
|
|
||||||
int i;
|
|
||||||
printf("%02x\t", (*list_record)->header.type);
|
|
||||||
for ( i = 0; i < ( (*list_record)->header.len ); i++ ){
|
|
||||||
printf("%02x\t", (*list_record)->data[i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
ipmi_ek_add_record2list ( list_record, list_head, list_last );
|
|
||||||
/*mask the 8th bits to see if it is the last record*/
|
|
||||||
last_record = ((*list_record)->header.format) & 0x80;
|
|
||||||
if ( last_record ){
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
record_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose( input_file );
|
|
||||||
return_status = OK_STATUS;
|
|
||||||
}
|
|
||||||
return return_status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user