Gpt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /** @file
  2. Routines supporting partition discovery and
  3. logical device reading
  4. Copyright (c) 2019 Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <IndustryStandard/Mbr.h>
  8. #include <Uefi/UefiGpt.h>
  9. #include <Library/BaseLib.h>
  10. #include "FatLitePeim.h"
  11. //
  12. // Assumption: 'a' and 'blocksize' are all UINT32 or UINT64.
  13. // If 'a' and 'blocksize' are not the same type, should use DivU64xU32 to calculate.
  14. //
  15. #define EFI_SIZE_TO_BLOCKS(a, blocksize) (((a) / (blocksize)) + (((a) % (blocksize)) ? 1 : 0))
  16. //
  17. // GPT Partition Entry Status
  18. //
  19. typedef struct {
  20. BOOLEAN OutOfRange;
  21. BOOLEAN Overlap;
  22. BOOLEAN OsSpecific;
  23. } EFI_PARTITION_ENTRY_STATUS;
  24. /**
  25. Check if the CRC field in the Partition table header is valid.
  26. @param[in] PartHeader Partition table header structure
  27. @retval TRUE the CRC is valid
  28. @retval FALSE the CRC is invalid
  29. **/
  30. BOOLEAN
  31. PartitionCheckGptHeaderCRC (
  32. IN EFI_PARTITION_TABLE_HEADER *PartHeader
  33. )
  34. {
  35. UINT32 GptHdrCrc;
  36. UINT32 Crc;
  37. GptHdrCrc = PartHeader->Header.CRC32;
  38. //
  39. // Set CRC field to zero when doing calcuation
  40. //
  41. PartHeader->Header.CRC32 = 0;
  42. Crc = CalculateCrc32 (PartHeader, PartHeader->Header.HeaderSize);
  43. //
  44. // Restore Header CRC
  45. //
  46. PartHeader->Header.CRC32 = GptHdrCrc;
  47. return (GptHdrCrc == Crc);
  48. }
  49. /**
  50. Check if the CRC field in the Partition table header is valid
  51. for Partition entry array.
  52. @param[in] PartHeader Partition table header structure
  53. @param[in] PartEntry The partition entry array
  54. @retval TRUE the CRC is valid
  55. @retval FALSE the CRC is invalid
  56. **/
  57. BOOLEAN
  58. PartitionCheckGptEntryArrayCRC (
  59. IN EFI_PARTITION_TABLE_HEADER *PartHeader,
  60. IN EFI_PARTITION_ENTRY *PartEntry
  61. )
  62. {
  63. UINT32 Crc;
  64. UINTN Size;
  65. Size = (UINTN)MultU64x32(PartHeader->NumberOfPartitionEntries, PartHeader->SizeOfPartitionEntry);
  66. Crc = CalculateCrc32 (PartEntry, Size);
  67. return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);
  68. }
  69. /**
  70. The function is used for valid GPT table. Both for Primary and Backup GPT header.
  71. @param[in] PrivateData The global memory map
  72. @param[in] ParentBlockDevNo The parent block device
  73. @param[in] IsPrimaryHeader Indicate to which header will be checked.
  74. @param[in] PartHdr Stores the partition table that is read
  75. @retval TRUE The partition table is valid
  76. @retval FALSE The partition table is not valid
  77. **/
  78. BOOLEAN
  79. PartitionCheckGptHeader (
  80. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  81. IN UINTN ParentBlockDevNo,
  82. IN BOOLEAN IsPrimaryHeader,
  83. IN EFI_PARTITION_TABLE_HEADER *PartHdr
  84. )
  85. {
  86. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  87. EFI_PEI_LBA Lba;
  88. EFI_PEI_LBA AlternateLba;
  89. EFI_PEI_LBA EntryArrayLastLba;
  90. UINT64 PartitionEntryArraySize;
  91. UINT64 PartitionEntryBlockNumb;
  92. UINT32 EntryArraySizeRemainder;
  93. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  94. if (IsPrimaryHeader) {
  95. Lba = PRIMARY_PART_HEADER_LBA;
  96. AlternateLba = ParentBlockDev->LastBlock;
  97. } else {
  98. Lba = ParentBlockDev->LastBlock;
  99. AlternateLba = PRIMARY_PART_HEADER_LBA;
  100. }
  101. if ( (PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
  102. (PartHdr->Header.Revision != 0x00010000) ||
  103. (PartHdr->Header.HeaderSize < 92) ||
  104. (PartHdr->Header.HeaderSize > ParentBlockDev->BlockSize) ||
  105. (!PartitionCheckGptHeaderCRC (PartHdr)) ||
  106. (PartHdr->Header.Reserved != 0)
  107. ) {
  108. DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
  109. return FALSE;
  110. }
  111. //
  112. // | Block0 | Block1 |Block2 ~ FirstUsableLBA - 1|FirstUsableLBA, ... ,LastUsableLBA|LastUsableLBA+1 ~ LastBlock-1| LastBlock |
  113. // |Protective MBR|Primary Header|Entry Array(At Least 16384)| Partition | Entry Array(At Least 16384) |BackUp Header|
  114. //
  115. // 1. Protective MBR is fixed at Block 0.
  116. // 2. Primary Header is fixed at Block 1.
  117. // 3. Backup Header is fixed at LastBlock.
  118. // 4. Must be remain 128*128 bytes for primary entry array.
  119. // 5. Must be remain 128*128 bytes for backup entry array.
  120. // 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
  121. //
  122. if ( (PartHdr->MyLBA != Lba) ||
  123. (PartHdr->AlternateLBA != AlternateLba) ||
  124. (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
  125. (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
  126. (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
  127. (PartHdr->PartitionEntryLBA < 2) ||
  128. (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
  129. (PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA && PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA) ||
  130. (PartHdr->SizeOfPartitionEntry%128 != 0) ||
  131. (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
  132. ) {
  133. DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
  134. return FALSE;
  135. }
  136. //
  137. // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
  138. //
  139. if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) {
  140. DEBUG ((DEBUG_ERROR, "Memory overflow in GPT Entry Array\n"));
  141. return FALSE;
  142. }
  143. PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
  144. EntryArraySizeRemainder = 0;
  145. PartitionEntryBlockNumb = DivU64x32Remainder (PartitionEntryArraySize, ParentBlockDev->BlockSize, &EntryArraySizeRemainder);
  146. if (EntryArraySizeRemainder != 0) {
  147. PartitionEntryBlockNumb++;
  148. }
  149. if (IsPrimaryHeader) {
  150. EntryArrayLastLba = PartHdr->FirstUsableLBA;
  151. } else {
  152. EntryArrayLastLba = ParentBlockDev->LastBlock;
  153. }
  154. //
  155. // Make sure partition entry array not overlaps with partition area or the LastBlock.
  156. //
  157. if (PartHdr->PartitionEntryLBA + PartitionEntryBlockNumb > EntryArrayLastLba) {
  158. DEBUG ((DEBUG_ERROR, "GPT Partition Entry Array Error!\n"));
  159. DEBUG ((DEBUG_ERROR, "PartitionEntryArraySize = %lu.\n", PartitionEntryArraySize));
  160. DEBUG ((DEBUG_ERROR, "PartitionEntryLBA = %lu.\n", PartHdr->PartitionEntryLBA));
  161. DEBUG ((DEBUG_ERROR, "PartitionEntryBlockNumb = %lu.\n", PartitionEntryBlockNumb));
  162. DEBUG ((DEBUG_ERROR, "EntryArrayLastLba = %lu.\n", EntryArrayLastLba));
  163. return FALSE;
  164. }
  165. return TRUE;
  166. }
  167. /**
  168. This function is used to verify each partition in block device.
  169. @param[in] PrivateData The global memory map
  170. @param[in] ParentBlockDevNo The parent block device
  171. @param[in] PartHdr Stores the partition table that is read
  172. @retval TRUE The partition is valid
  173. @retval FALSE The partition is not valid
  174. **/
  175. BOOLEAN
  176. PartitionCheckGptEntryArray (
  177. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  178. IN UINTN ParentBlockDevNo,
  179. IN EFI_PARTITION_TABLE_HEADER *PartHdr
  180. )
  181. {
  182. EFI_STATUS Status;
  183. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  184. PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
  185. UINT64 PartitionEntryArraySize;
  186. UINT64 PartitionEntryBlockNumb;
  187. UINT32 EntryArraySizeRemainder;
  188. EFI_PARTITION_ENTRY *PartitionEntryBuffer;
  189. EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
  190. BOOLEAN Found;
  191. EFI_LBA StartingLBA;
  192. EFI_LBA EndingLBA;
  193. UINTN Index;
  194. UINTN Index1;
  195. UINTN Index2;
  196. EFI_PARTITION_ENTRY *Entry;
  197. PartitionEntryBuffer = NULL;
  198. PartitionEntryStatus = NULL;
  199. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  200. Found = FALSE;
  201. PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
  202. EntryArraySizeRemainder = 0;
  203. PartitionEntryBlockNumb = DivU64x32Remainder (PartitionEntryArraySize, ParentBlockDev->BlockSize, &EntryArraySizeRemainder);
  204. if (EntryArraySizeRemainder != 0) {
  205. PartitionEntryBlockNumb++;
  206. }
  207. PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
  208. PartitionEntryBuffer = (EFI_PARTITION_ENTRY *) AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
  209. if (PartitionEntryBuffer == NULL) {
  210. DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
  211. goto EXIT;
  212. }
  213. PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *) AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
  214. if (PartitionEntryStatus == NULL) {
  215. DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
  216. goto EXIT;
  217. }
  218. ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
  219. Status = FatReadBlock (
  220. PrivateData,
  221. ParentBlockDevNo,
  222. PartHdr->PartitionEntryLBA,
  223. (UINTN)PartitionEntryArraySize,
  224. PartitionEntryBuffer
  225. );
  226. if (EFI_ERROR (Status)) {
  227. DEBUG ((DEBUG_ERROR, "Read partition entry array error!\n"));
  228. goto EXIT;
  229. }
  230. if (!PartitionCheckGptEntryArrayCRC (PartHdr, PartitionEntryBuffer)) {
  231. DEBUG ((DEBUG_ERROR, "Partition entries CRC check fail\n"));
  232. goto EXIT;
  233. }
  234. for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
  235. Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
  236. if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
  237. continue;
  238. }
  239. StartingLBA = Entry->StartingLBA;
  240. EndingLBA = Entry->EndingLBA;
  241. if (StartingLBA > EndingLBA ||
  242. StartingLBA < PartHdr->FirstUsableLBA ||
  243. StartingLBA > PartHdr->LastUsableLBA ||
  244. EndingLBA < PartHdr->FirstUsableLBA ||
  245. EndingLBA > PartHdr->LastUsableLBA
  246. ) {
  247. PartitionEntryStatus[Index1].OutOfRange = TRUE;
  248. continue;
  249. }
  250. if ((Entry->Attributes & BIT1) != 0) {
  251. //
  252. // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
  253. //
  254. PartitionEntryStatus[Index1].OsSpecific = TRUE;
  255. }
  256. for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
  257. Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
  258. if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
  259. continue;
  260. }
  261. if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {
  262. //
  263. // This region overlaps with the Index1'th region
  264. //
  265. PartitionEntryStatus[Index1].Overlap = TRUE;
  266. PartitionEntryStatus[Index2].Overlap = TRUE;
  267. continue;
  268. }
  269. }
  270. }
  271. for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
  272. if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid)||
  273. PartitionEntryStatus[Index].OutOfRange ||
  274. PartitionEntryStatus[Index].Overlap ||
  275. PartitionEntryStatus[Index].OsSpecific) {
  276. //
  277. // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
  278. // partition Entries
  279. //
  280. continue;
  281. }
  282. if (PrivateData->BlockDeviceCount >= PEI_FAT_MAX_BLOCK_DEVICE) {
  283. break;
  284. }
  285. Found = TRUE;
  286. BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
  287. BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
  288. BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
  289. BlockDevPtr->IoAlign = ParentBlockDev->IoAlign;
  290. BlockDevPtr->Logical = TRUE;
  291. BlockDevPtr->PartitionChecked = FALSE;
  292. BlockDevPtr->StartingPos = MultU64x32 (
  293. PartitionEntryBuffer[Index].StartingLBA,
  294. ParentBlockDev->BlockSize
  295. );
  296. BlockDevPtr->ParentDevNo = ParentBlockDevNo;
  297. PrivateData->BlockDeviceCount++;
  298. DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA, BlockDevPtr->LastBlock));
  299. DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
  300. DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
  301. }
  302. EXIT:
  303. if (PartitionEntryBuffer != NULL) {
  304. FreePages (PartitionEntryBuffer, EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
  305. }
  306. if (PartitionEntryStatus != NULL) {
  307. FreePages (PartitionEntryStatus, EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
  308. }
  309. return Found;
  310. }
  311. /**
  312. The function is used to check GPT structure, include GPT header and GPT entry array.
  313. 1. Check GPT header.
  314. 2. Check partition entry array.
  315. 3. Check each partitions.
  316. @param[in] PrivateData The global memory map
  317. @param[in] ParentBlockDevNo The parent block device
  318. @param[in] IsPrimary Indicate primary or backup to be check
  319. @retval TRUE Primary or backup GPT structure is valid.
  320. @retval FALSE Both primary and backup are invalid.
  321. **/
  322. BOOLEAN
  323. PartitionCheckGptStructure (
  324. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  325. IN UINTN ParentBlockDevNo,
  326. IN BOOLEAN IsPrimary
  327. )
  328. {
  329. EFI_STATUS Status;
  330. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  331. EFI_PARTITION_TABLE_HEADER *PartHdr;
  332. EFI_PEI_LBA GptHeaderLBA;
  333. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  334. PartHdr = (EFI_PARTITION_TABLE_HEADER *) PrivateData->BlockData;
  335. if (IsPrimary) {
  336. GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
  337. } else {
  338. GptHeaderLBA = ParentBlockDev->LastBlock;
  339. }
  340. Status = FatReadBlock (
  341. PrivateData,
  342. ParentBlockDevNo,
  343. GptHeaderLBA,
  344. ParentBlockDev->BlockSize,
  345. PartHdr
  346. );
  347. if (EFI_ERROR (Status)) {
  348. return FALSE;
  349. }
  350. if (!PartitionCheckGptHeader (PrivateData, ParentBlockDevNo, IsPrimary, PartHdr)) {
  351. return FALSE;
  352. }
  353. if (!PartitionCheckGptEntryArray (PrivateData, ParentBlockDevNo, PartHdr)) {
  354. return FALSE;
  355. }
  356. return TRUE;
  357. }
  358. /**
  359. This function is used to check protective MBR structure before checking GPT.
  360. @param[in] PrivateData The global memory map
  361. @param[in] ParentBlockDevNo The parent block device
  362. @retval TRUE Valid protective MBR
  363. @retval FALSE Invalid MBR
  364. **/
  365. BOOLEAN
  366. PartitionCheckProtectiveMbr (
  367. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  368. IN UINTN ParentBlockDevNo
  369. )
  370. {
  371. EFI_STATUS Status;
  372. MASTER_BOOT_RECORD *ProtectiveMbr;
  373. MBR_PARTITION_RECORD *MbrPartition;
  374. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  375. UINTN Index;
  376. ProtectiveMbr = (MASTER_BOOT_RECORD *) PrivateData->BlockData;
  377. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  378. //
  379. // Read Protective MBR
  380. //
  381. Status = FatReadBlock (
  382. PrivateData,
  383. ParentBlockDevNo,
  384. 0,
  385. ParentBlockDev->BlockSize,
  386. ProtectiveMbr
  387. );
  388. if (EFI_ERROR (Status)) {
  389. DEBUG ((DEBUG_ERROR, "GPT Error When Read Protective Mbr From Partition!\n"));
  390. return FALSE;
  391. }
  392. if (ProtectiveMbr->Signature != MBR_SIGNATURE) {
  393. DEBUG ((DEBUG_ERROR, "Protective Mbr Signature is invalid!\n"));
  394. return FALSE;
  395. }
  396. //
  397. // The partition define in UEFI Spec Table 17.
  398. // Boot Code, Unique MBR Disk Signature, Unknown.
  399. // These parts will not be used by UEFI, so we skip to check them.
  400. //
  401. for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
  402. MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
  403. if (MbrPartition->BootIndicator == 0x00 &&
  404. MbrPartition->StartSector == 0x02 &&
  405. MbrPartition->OSIndicator == PMBR_GPT_PARTITION &&
  406. UNPACK_UINT32 (MbrPartition->StartingLBA) == 1
  407. ) {
  408. return TRUE;
  409. }
  410. }
  411. DEBUG ((DEBUG_ERROR, "Protective Mbr, All Partition Entry Are Empty!\n"));
  412. return FALSE;
  413. }
  414. /**
  415. This function is used for finding GPT partition on block device.
  416. As follow UEFI spec we should check protective MBR first and then
  417. try to check both primary/backup GPT structures.
  418. @param[in] PrivateData The global memory map
  419. @param[in] ParentBlockDevNo The parent block device
  420. @retval TRUE New partitions are detected and logical block devices
  421. are added to block device array
  422. @retval FALSE No new partitions are added
  423. **/
  424. BOOLEAN
  425. FatFindGptPartitions (
  426. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  427. IN UINTN ParentBlockDevNo
  428. )
  429. {
  430. BOOLEAN Found;
  431. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  432. if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
  433. return FALSE;
  434. }
  435. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  436. if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
  437. DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
  438. return FALSE;
  439. }
  440. if (!PartitionCheckProtectiveMbr (PrivateData, ParentBlockDevNo)) {
  441. return FALSE;
  442. }
  443. Found = PartitionCheckGptStructure (PrivateData, ParentBlockDevNo, TRUE);
  444. if (!Found) {
  445. DEBUG ((DEBUG_ERROR, "Primary GPT Header Error, Try to Check Backup GPT Header!\n"));
  446. Found = PartitionCheckGptStructure (PrivateData, ParentBlockDevNo, FALSE);
  447. }
  448. if (Found) {
  449. ParentBlockDev->PartitionChecked = TRUE;
  450. }
  451. return Found;
  452. }