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
@ -2546,28 +2546,39 @@ ipmi_ek_display_fru_header_detail( char * filename )
|
||||
static void
|
||||
ipmi_ek_display_chassis_info_area(FILE * input_file, long offset)
|
||||
{
|
||||
if ( input_file != NULL ){
|
||||
unsigned char data = 0;
|
||||
unsigned char ch_type = 0;
|
||||
unsigned int len;
|
||||
size_t file_offset;
|
||||
|
||||
if (input_file == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||
printf("Chassis Info Area\n");
|
||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||
|
||||
fseek(input_file, offset, SEEK_SET);
|
||||
if ( !feof(input_file) ){
|
||||
unsigned char data = 0;
|
||||
unsigned int len = 0;
|
||||
if (feof(input_file)) {
|
||||
lprintf(LOG_ERR, "Invalid Chassis Info Area!");
|
||||
return;
|
||||
}
|
||||
|
||||
fread(&data, 1, 1, input_file);
|
||||
printf("Format Version Number: %d\n", (data & 0x0f));
|
||||
if ( !feof(input_file) ){
|
||||
if (feof(input_file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
fread(&len, 1, 1, input_file);
|
||||
/* len is in factor of 8 bytes */
|
||||
len = len * 8;
|
||||
printf("Area Length: %d\n", len);
|
||||
len -= 2;
|
||||
if (feof(input_file)) {
|
||||
return;
|
||||
}
|
||||
if ( !feof(input_file) ){
|
||||
unsigned char ch_type = 0;
|
||||
size_t file_offset = ftell (input_file);
|
||||
/* Chassis Type*/
|
||||
fread(&ch_type, 1, 1, input_file);
|
||||
printf("Chassis Type: %d\n", ch_type);
|
||||
@ -2581,14 +2592,8 @@ ipmi_ek_display_chassis_info_area( FILE * input_file, long offset )
|
||||
"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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
lprintf(LOG_ERR, "Invalid Chassis Info Area!");
|
||||
}
|
||||
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||
"Custom", &len);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@ -2736,27 +2741,38 @@ ipmi_ek_display_board_info_area( FILE * input_file, char * board_type,
|
||||
static void
|
||||
ipmi_ek_display_product_info_area(FILE * input_file, long offset)
|
||||
{
|
||||
if ( input_file != NULL ){
|
||||
unsigned char data = 0;
|
||||
unsigned int len;
|
||||
size_t file_offset = ftell(input_file);
|
||||
|
||||
if (input_file == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||
printf("Product Info Area\n");
|
||||
printf("%s\n", EQUAL_LINE_LIMITER);
|
||||
|
||||
fseek(input_file, offset, SEEK_SET);
|
||||
if ( !feof(input_file) ){
|
||||
unsigned char data = 0;
|
||||
unsigned int len = 0;
|
||||
if (feof(input_file)) {
|
||||
lprintf(LOG_ERR, "Invalid Product Info Area!");
|
||||
return;
|
||||
}
|
||||
|
||||
fread(&data, 1, 1, input_file);
|
||||
printf("Format Version Number: %d\n", (data & 0x0f));
|
||||
if ( !feof(input_file) ){
|
||||
if (feof(input_file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
if ( !feof(input_file) ){
|
||||
size_t file_offset = ftell (input_file);
|
||||
|
||||
fread(&data, 1, 1, input_file);
|
||||
printf("Language Code: %d\n", data);
|
||||
@ -2786,18 +2802,12 @@ ipmi_ek_display_product_info_area( FILE * input_file, long offset )
|
||||
"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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
lprintf(LOG_ERR, "Invalid Product Info Area!");
|
||||
}
|
||||
file_offset = ipmi_ek_display_board_info_area(input_file,
|
||||
"Custom", &len);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
@ -3887,47 +3897,51 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
|
||||
{
|
||||
int return_status = ERROR_STATUS;
|
||||
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_status = ERROR_STATUS;
|
||||
return ERROR_STATUS;
|
||||
}
|
||||
else{
|
||||
long multi_offset = 0;
|
||||
|
||||
fseek(input_file, START_DATA_OFFSET, SEEK_SET);
|
||||
fread(&multi_offset, 1, 1, input_file);
|
||||
if ( multi_offset <= 0 ){
|
||||
if (multi_offset < 1) {
|
||||
lprintf(LOG_NOTICE, "There is no multi record in the file %s\n",
|
||||
filename);
|
||||
}
|
||||
else{
|
||||
int record_count = 0;
|
||||
|
||||
if ( verbose == LOG_DEBUG ){
|
||||
printf( "start multi offset = 0x%02lx\n", multi_offset );
|
||||
fclose(input_file);
|
||||
return OK_STATUS;
|
||||
}
|
||||
/* the offset value is in multiple of 8 bytes. */
|
||||
multi_offset = multi_offset * 8;
|
||||
if (verbose == LOG_DEBUG) {
|
||||
printf("start multi offset = 0x%02lx\n", multi_offset);
|
||||
}
|
||||
fseek(input_file, multi_offset, SEEK_SET);
|
||||
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 ){
|
||||
(*list_record)->data =
|
||||
malloc ((*list_record)->header.len);
|
||||
if ( (*list_record)->data == NULL ){
|
||||
lprintf(LOG_ERR, "Lack of memory");
|
||||
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;
|
||||
}
|
||||
else{
|
||||
unsigned char last_record = 0;
|
||||
|
||||
fread ( (*list_record)->data,
|
||||
((*list_record)->header.len), 1, input_file);
|
||||
if ( verbose > 0 )
|
||||
fread((*list_record)->data, ((*list_record)->header.len), 1,
|
||||
input_file);
|
||||
if (verbose > 0) {
|
||||
printf("Record %d has length = %02x\n", record_count,
|
||||
(*list_record)->header.len);
|
||||
}
|
||||
if (verbose > 1) {
|
||||
int i;
|
||||
printf("%02x\t", (*list_record)->header.type);
|
||||
@ -3942,14 +3956,8 @@ ipmi_ekanalyzer_fru_file2structure( char * filename,
|
||||
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