gptsync/gptsync.c
static BOOLEAN should_rewrite(VOID) {
   BOOLEAN retval = TRUE, all_identical = TRUE, invalid;
   UINTN i, num_existing_hybrid = 0, num_new_hybrid = 0;

   // Check to see if the proposed table is identical to the current one;
   // if so, synchronizing is pointless....
   for (i = 0; i < 4; i++) {
      if ((new_mbr_parts[i].mbr_type != 0xEE) && (mbr_parts[i].mbr_type != 0xEE) &&
          ((new_mbr_parts[i].active != mbr_parts[i].active) ||
           (new_mbr_parts[i].start_lba != mbr_parts[i].start_lba) ||
           (new_mbr_parts[i].end_lba != mbr_parts[i].end_lba) ||
           (new_mbr_parts[i].mbr_type != mbr_parts[i].mbr_type)))
         all_identical = FALSE;

      // while we're looping, count the number of old & new hybrid partitions....
      if ((mbr_parts[i].mbr_type != 0x00) && (mbr_parts[i].mbr_type != 0xEE))
         num_existing_hybrid++;
      if ((new_mbr_parts[i].mbr_type != 0x00) && (new_mbr_parts[i].mbr_type != 0xEE))
         num_new_hybrid++;
   } // for

   if (all_identical) {
      Print(L"Tables are synchronized, no need to sync.\n");
      return FALSE;
   }

   // If there's nothing to hybridize, but an existing hybrid MBR exists, offer to replace
   // the hybrid MBR with a protective MBR.
   if ((num_new_hybrid == 0) && (num_existing_hybrid > 0)) {
      Print(L"Found no partitions that could be hybridized, but an existing hybrid MBR exists.\n");
      Print(L"If you proceed, a fresh protective MBR will be created. Do you want to create\n");
      invalid = input_boolean(STR("this new protective MBR, erasing the hybrid MBR? [y/N] "), &retval);
      if (invalid)
         retval = FALSE;
   } // if

   // If existing hybrid MBR that's NOT identical to the new one, ask the user
   // before overwriting the old one.
   if ((num_new_hybrid > 0) && (num_existing_hybrid > 0)) {
      Print(L"Existing hybrid MBR detected, but it's not identical to what this program\n");
      Print(L"would generate. Do you want to see the hybrid MBR that this program would\n");
      invalid = input_boolean(STR("generate? [y/N] "), &retval);
      if (invalid)
         retval = FALSE;
   } // if

   return retval;
}
// Examine partitions and decide whether a rewrite is in order.
// Note that this function MAY ask user for advice.
// Note that this function assumes the new hybrid MBR has already
// been computed and stored in new_mbr_parts[].
Examine partitions and decide whether a rewrite is in order.
Note that this function MAY ask user for advice.
Note that this function assumes the new hybrid MBR has already
been computed and stored in new_mbr_parts[].
Examine partitions and decide whether a rewrite is in order . Note that this function MAY ask user for advice . Note that this function assumes the new hybrid MBR has already been computed and stored in new_mbr_parts [] .
static BOOLEAN should_rewrite(VOID) {
   BOOLEAN retval = TRUE, all_identical = TRUE, invalid;
   UINTN i, num_existing_hybrid = 0, num_new_hybrid = 0;
   for (i = 0; i < 4; i++) {
      if ((new_mbr_parts[i].mbr_type != 0xEE) && (mbr_parts[i].mbr_type != 0xEE) &&
          ((new_mbr_parts[i].active != mbr_parts[i].active) ||
           (new_mbr_parts[i].start_lba != mbr_parts[i].start_lba) ||
           (new_mbr_parts[i].end_lba != mbr_parts[i].end_lba) ||
           (new_mbr_parts[i].mbr_type != mbr_parts[i].mbr_type)))
         all_identical = FALSE;
      if ((mbr_parts[i].mbr_type != 0x00) && (mbr_parts[i].mbr_type != 0xEE))
         num_existing_hybrid++;
      if ((new_mbr_parts[i].mbr_type != 0x00) && (new_mbr_parts[i].mbr_type != 0xEE))
         num_new_hybrid++;
   } 
   if (all_identical) {
      Print(L"Tables are synchronized, no need to sync.\n");
      return FALSE;
   }
   if ((num_new_hybrid == 0) && (num_existing_hybrid > 0)) {
      Print(L"Found no partitions that could be hybridized, but an existing hybrid MBR exists.\n");
      Print(L"If you proceed, a fresh protective MBR will be created. Do you want to create\n");
      invalid = input_boolean(STR("this new protective MBR, erasing the hybrid MBR? [y/N] "), &retval);
      if (invalid)
         retval = FALSE;
   } 
   if ((num_new_hybrid > 0) && (num_existing_hybrid > 0)) {
      Print(L"Existing hybrid MBR detected, but it's not identical to what this program\n");
      Print(L"would generate. Do you want to see the hybrid MBR that this program would\n");
      invalid = input_boolean(STR("generate? [y/N] "), &retval);
      if (invalid)
         retval = FALSE;
   } 
   return retval;
}
static BOOLEAN should_rewrite ( VOID ) { BOOLEAN retval = TRUE , all_identical = TRUE , invalid ; UINTN i , num_existing_hybrid = 0 , num_new_hybrid = 0 ; for ( i = 0 ; i < 4 ; i ++ ) { if ( ( new_mbr_parts [ i ] . mbr_type != 0xEE ) && ( mbr_parts [ i ] . mbr_type != 0xEE ) && ( ( new_mbr_parts [ i ] . active != mbr_parts [ i ] . active ) || ( new_mbr_parts [ i ] . start_lba != mbr_parts [ i ] . start_lba ) || ( new_mbr_parts [ i ] . end_lba != mbr_parts [ i ] . end_lba ) || ( new_mbr_parts [ i ] . mbr_type != mbr_parts [ i ] . mbr_type ) ) ) all_identical = FALSE ; if ( ( mbr_parts [ i ] . mbr_type != 0x00 ) && ( mbr_parts [ i ] . mbr_type != 0xEE ) ) num_existing_hybrid ++ ; if ( ( new_mbr_parts [ i ] . mbr_type != 0x00 ) && ( new_mbr_parts [ i ] . mbr_type != 0xEE ) ) num_new_hybrid ++ ; } if ( all_identical ) { Print ( L" \n " ) ; return FALSE ; } if ( ( num_new_hybrid == 0 ) && ( num_existing_hybrid > 0 ) ) { Print ( L" \n " ) ; Print ( L" \n " ) ; invalid = input_boolean ( STR ( " " ) , & retval ) ; if ( invalid ) retval = FALSE ; } if ( ( num_new_hybrid > 0 ) && ( num_existing_hybrid > 0 ) ) { Print ( L" \n " ) ; Print ( L" \n " ) ; invalid = input_boolean ( STR ( " " ) , & retval ) ; if ( invalid ) retval = FALSE ; } return retval ; }
Examine partitions and decide whether a rewrite is in order.
Examine partitions and decide whether a rewrite is in order .
// Check to see if the proposed table is identical to the current one; // if so, synchronizing is pointless.... // while we're looping, count the number of old & new hybrid partitions.... // for // If there's nothing to hybridize, but an existing hybrid MBR exists, offer to replace // the hybrid MBR with a protective MBR. // if // If existing hybrid MBR that's NOT identical to the new one, ask the user // before overwriting the old one. // if