cgpt/cgpt_common.c
/*  Update CRC value if necessary.  */
Update CRC value if necessary.
Update CRC value if necessary .
void UpdateCrc(GptData *gpt) {
  GptHeader *primary_header, *secondary_header;
  primary_header = (GptHeader*)gpt->primary_header;
  secondary_header = (GptHeader*)gpt->secondary_header;
  if (gpt->modified & GPT_MODIFIED_ENTRIES1 &&
      memcmp(primary_header, GPT_HEADER_SIGNATURE2,
             GPT_HEADER_SIGNATURE_SIZE)) {
    size_t entries_size = primary_header->size_of_entry *
        primary_header->number_of_entries;
    primary_header->entries_crc32 =
        Crc32(gpt->primary_entries, entries_size);
  }
  if (gpt->modified & GPT_MODIFIED_ENTRIES2) {
    size_t entries_size = secondary_header->size_of_entry *
        secondary_header->number_of_entries;
    secondary_header->entries_crc32 =
        Crc32(gpt->secondary_entries, entries_size);
  }
  if (gpt->modified & GPT_MODIFIED_HEADER1) {
    primary_header->header_crc32 = 0;
    primary_header->header_crc32 = Crc32(
        (const uint8_t *)primary_header, sizeof(GptHeader));
  }
  if (gpt->modified & GPT_MODIFIED_HEADER2) {
    secondary_header->header_crc32 = 0;
    secondary_header->header_crc32 = Crc32(
        (const uint8_t *)secondary_header, sizeof(GptHeader));
  }
}
void UpdateCrc ( GptData * gpt ) { GptHeader * primary_header , * secondary_header ; primary_header = ( GptHeader * ) gpt -> primary_header ; secondary_header = ( GptHeader * ) gpt -> secondary_header ; if ( gpt -> modified & GPT_MODIFIED_ENTRIES1 && memcmp ( primary_header , GPT_HEADER_SIGNATURE2 , GPT_HEADER_SIGNATURE_SIZE ) ) { size_t entries_size = primary_header -> size_of_entry * primary_header -> number_of_entries ; primary_header -> entries_crc32 = Crc32 ( gpt -> primary_entries , entries_size ) ; } if ( gpt -> modified & GPT_MODIFIED_ENTRIES2 ) { size_t entries_size = secondary_header -> size_of_entry * secondary_header -> number_of_entries ; secondary_header -> entries_crc32 = Crc32 ( gpt -> secondary_entries , entries_size ) ; } if ( gpt -> modified & GPT_MODIFIED_HEADER1 ) { primary_header -> header_crc32 = 0 ; primary_header -> header_crc32 = Crc32 ( ( const uint8_t * ) primary_header , sizeof ( GptHeader ) ) ; } if ( gpt -> modified & GPT_MODIFIED_HEADER2 ) { secondary_header -> header_crc32 = 0 ; secondary_header -> header_crc32 = Crc32 ( ( const uint8_t * ) secondary_header , sizeof ( GptHeader ) ) ; } }
Update CRC value if necessary.
Update CRC value if necessary .