@@ -476,57 +476,53 @@ int main(int argc, char *argv[])
476476 fatal ("Failed to open file: %s" , strerror (errno ));
477477 }
478478
479- char common_header [8 ];
480- safe_read (fd , common_header , 8 );
481-
482- // Common Header Format Version = common_header[0]
483- // Internal Use Area Starting Offset = common_header[1]
484- uint16_t chassis_start_offset = 8 * common_header [2 ];
485- uint16_t board_start_offset = 8 * common_header [3 ];
486- uint16_t product_start_offset = 8 * common_header [4 ];
487- // MultiRecord Area Starting Offset = 8 * common_header[5]
488- // Padding = common_header[6] = 0
489- // Checksum = common_header[7]
490-
491- // For the above offsets, an offset of 0 is valid and implies
492- // that the field is not present.
493-
494- bool data_has_chassis = chassis_start_offset != 0 ;
495- bool data_has_board = board_start_offset != 0 ;
496- bool data_has_product = product_start_offset != 0 ;
497-
498- if (data_has_chassis ) {
499- lseek (fd , chassis_start_offset , SEEK_SET );
500- fru_chassis_area_t * chassis_raw =
501- read_fru_chassis_area (fd );
502- bool success = fru_decode_chassis_info (
503- chassis_raw , & chassis );
504- if (!success )
505- fatal ("Failed to decode chassis!" );
506- free (chassis_raw );
507-
479+ fru_t * raw_fru = read_fru_header (fd );
480+ if (!raw_fru )
481+ fatal ("Failed to read fru header" );
482+
483+ if (raw_fru -> chassis != 0 ) {
484+ if (lseek (fd , 8 * raw_fru -> chassis , SEEK_SET ) < 0 )
485+ fatal ("Failed to seek" );
486+
487+ fru_chassis_area_t * chassis_raw =
488+ read_fru_chassis_area (fd );
489+ bool success = fru_decode_chassis_info (
490+ chassis_raw , & chassis );
491+ if (!success )
492+ fatal ("Failed to decode chassis" );
493+
494+ free (chassis_raw );
508495 has_chassis = true;
509496 }
510- if (data_has_board ) {
511- lseek (fd , board_start_offset , SEEK_SET );
497+ if (raw_fru -> board != 0 ) {
498+ if (lseek (fd , 8 * raw_fru -> board , SEEK_SET ) < 0 )
499+ fatal ("Failed to seek" );
512500
513501 fru_board_area_t * board_raw = read_fru_board_area (fd );
514502 bool success = fru_decode_board_info (board_raw , & board );
503+ if (!success )
504+ fatal ("Failed to decode board" );
515505
506+ free (board_raw );
516507 has_board = true;
517508 has_bdate = true;
518509 }
519- if (data_has_product ) {
520- lseek (fd , product_start_offset , SEEK_SET );
510+ if (raw_fru -> product != 0 ) {
511+ if (lseek (fd , 8 * raw_fru -> product , SEEK_SET ) < 0 )
512+ fatal ("Failed to seek" );
521513
522514 fru_product_area_t * product_raw =
523515 read_fru_product_area (fd );
524516 bool success =
525517 fru_decode_product_info (product_raw , & product );
518+ if (!success )
519+ fatal ("Failed to decode product" );
526520
521+ free (product_raw );
527522 has_product = true;
528523 }
529524
525+ free (raw_fru );
530526 close (fd );
531527 }
532528 else {
0 commit comments