]> code.delx.au - refind/blobdiff - gptsync/gptsync.c
Significant reworking of Makefile structure. Added Apple Core Storage
[refind] / gptsync / gptsync.c
index 5d442c54119b68bd569f0f257e220c0f4f5887f5..c711186c97fc02115f44bee4fd50a8ccafea291c 100644 (file)
@@ -38,6 +38,7 @@
 #include "gptsync.h"
 
 #include "syslinux_mbr.h"
+#define memcpy(a, b, c) CopyMem(a, b, c)
 
 //
 // MBR functions
@@ -268,7 +269,7 @@ static VOID generate_hybrid_mbr(VOID) {
     i = 0;
     do {
         if ((gpt_parts[i].start_lba > 0) && (gpt_parts[i].end_lba > 0) &&
-            (gpt_parts[i].end_lba <= MAX_MBR_LBA) &&
+            (gpt_parts[i].end_lba <= MAX_MBR_LBA) &&                    /* Within MBR limits */
             (gpt_parts[i].gpt_parttype->kind == GPT_KIND_BASIC_DATA) && /* MS Basic Data GPT type code */
             (gpt_parts[i].mbr_type != 0x83)) {                          /* Not containing Linux filesystem */
            copy_gpt_to_new_mbr(i, new_mbr_part_count);
@@ -282,9 +283,10 @@ static VOID generate_hybrid_mbr(VOID) {
 
     // Second, do Linux partitions. Note that we start from the END of the
     // partition list, so as to maximize the space covered by the 0xEE
-    // partition if there are several Linux partitions.
+    // partition if there are several Linux partitions before other hybridized
+    // partitions.
     i = gpt_part_count - 1; // Note that gpt_part_count can't be 0; filtered by check_gpt()
-    while (i >= 0 && new_mbr_part_count <= 3) {
+    while (i < gpt_part_count && new_mbr_part_count <= 3) { // if too few GPT partitions, i loops around to a huge value
         if ((gpt_parts[i].start_lba > 0) && (gpt_parts[i].end_lba > 0) &&
             (gpt_parts[i].end_lba <= MAX_MBR_LBA) &&
             ((gpt_parts[i].gpt_parttype->kind == GPT_KIND_DATA) || (gpt_parts[i].gpt_parttype->kind == GPT_KIND_BASIC_DATA)) &&
@@ -352,9 +354,9 @@ static VOID generate_hybrid_mbr(VOID) {
         // set active on the first matching partition
         if (count_active == 0) {
             for (i = 0; i < new_mbr_part_count; i++) {
-                if ((iter >= 0 && (new_mbr_parts[i].mbr_type == 0x07 ||    // NTFS
-                                   new_mbr_parts[i].mbr_type == 0x0b ||    // FAT32
-                                   new_mbr_parts[i].mbr_type == 0x0c)) ||  // FAT32 (LBA)
+                if (((new_mbr_parts[i].mbr_type == 0x07 ||    // NTFS
+                      new_mbr_parts[i].mbr_type == 0x0b ||    // FAT32
+                      new_mbr_parts[i].mbr_type == 0x0c)) ||  // FAT32 (LBA)
                     (iter >= 1 && (new_mbr_parts[i].mbr_type == 0x83)) ||  // Linux
                     (iter >= 2 && i > 0)) {
                     new_mbr_parts[i].active = TRUE;
@@ -377,7 +379,7 @@ static VOID generate_hybrid_mbr(VOID) {
                     count_active++;
                 }
         }
-    }
+    } // for
 } // VOID generate_hybrid_mbr()
 
 // Examine partitions and decide whether a rewrite is in order.
@@ -492,7 +494,7 @@ UINTN gptsync(VOID)
     UINTN   status_gpt, status_mbr;
     BOOLEAN proceed = FALSE;
 
-    Print(L"gptsync version %s\ncopyright (c) 2006-2007 Christoph Pfisterer & 2013 Roderick W. Smith\n", VERSION);
+    Print(L"gptsync version %s\ncopyright (c) 2006-2007 Christoph Pfisterer & 2013 Roderick W. Smith\n", REFIND_VERSION);
 
     // get full information from disk
     status_gpt = read_gpt();