]> glassweightruler.freedombox.rocks Git - Ventoy.git/blobdiff - Ventoy2Disk/Ventoy2Disk/Utility.c
1.0.53 release
[Ventoy.git] / Ventoy2Disk / Ventoy2Disk / Utility.c
index cf86fef4924dc78dbc29c8321f77218a0ba352bb..6b4416076ace18a21b78293f7aae38bba3d03168 100644 (file)
@@ -592,6 +592,7 @@ int VentoyFillWholeGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)
 int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)\r
 {\r
     INT64 ReservedValue = 0;\r
+    UINT64 ModSectorCount = 0;\r
     UINT64 ReservedSector = 33;\r
     UINT64 Part1SectorCount = 0;\r
     UINT64 DiskSectorCount = DiskSizeBytes / 512;\r
@@ -609,18 +610,28 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)
         ReservedSector += ReservedValue * 2048;\r
     }\r
 \r
+    Part1SectorCount = DiskSectorCount - ReservedSector - (VENTOY_EFI_PART_SIZE / 512) - 2048;\r
+\r
+    ModSectorCount = (Part1SectorCount % 8);\r
+    if (ModSectorCount)\r
+    {\r
+        Log("Part1SectorCount:%llu is not aligned by 4KB (%llu)", (ULONGLONG)Part1SectorCount, (ULONGLONG)ModSectorCount);\r
+    }\r
+\r
     // check aligned with 4KB\r
     if (IsPartNeed4KBAlign())\r
     {\r
-        if (DiskSectorCount % 8)\r
+        if (ModSectorCount)\r
         {\r
-            Log("Disk need to align with 4KB %u", (UINT32)(DiskSectorCount % 8));\r
-            ReservedSector += (DiskSectorCount % 8);\r
+            Log("Disk need to align with 4KB %u", (UINT32)ModSectorCount);\r
+            Part1SectorCount -= ModSectorCount;\r
+        }\r
+        else\r
+        {\r
+            Log("no need to align with 4KB");\r
         }\r
     }\r
 \r
-    Part1SectorCount = DiskSectorCount - ReservedSector - (VENTOY_EFI_PART_SIZE / 512) - 2048;\r
-\r
     memcpy(Head->Signature, "EFI PART", 8);\r
     Head->Version[2] = 0x01;\r
     Head->Length = 92;\r
@@ -648,7 +659,7 @@ int VentoyFillGpt(UINT64 DiskSizeBytes, VTOY_GPT_INFO *pInfo)
     CoCreateGuid(&(Table[1].PartGuid));\r
     Table[1].StartLBA = Table[0].LastLBA + 1;\r
     Table[1].LastLBA = Table[1].StartLBA + VENTOY_EFI_PART_SIZE / 512 - 1;\r
-    Table[1].Attr = 0x8000000000000001ULL;\r
+    Table[1].Attr = 0xC000000000000001ULL;\r
     memcpy(Table[1].Name, L"VTOYEFI", 7 * 2);\r
 \r
 #if 0\r