Gpt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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 calculation
  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. {
  109. DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
  110. return FALSE;
  111. }
  112. //
  113. // | Block0 | Block1 |Block2 ~ FirstUsableLBA - 1|FirstUsableLBA, ... ,LastUsableLBA|LastUsableLBA+1 ~ LastBlock-1| LastBlock |
  114. // |Protective MBR|Primary Header|Entry Array(At Least 16384)| Partition | Entry Array(At Least 16384) |BackUp Header|
  115. //
  116. // 1. Protective MBR is fixed at Block 0.
  117. // 2. Primary Header is fixed at Block 1.
  118. // 3. Backup Header is fixed at LastBlock.
  119. // 4. Must be remain 128*128 bytes for primary entry array.
  120. // 5. Must be remain 128*128 bytes for backup entry array.
  121. // 6. SizeOfPartitionEntry must be equals to 128 * 2^n.
  122. //
  123. if ((PartHdr->MyLBA != Lba) ||
  124. (PartHdr->AlternateLBA != AlternateLba) ||
  125. (PartHdr->FirstUsableLBA < 2 + EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
  126. (PartHdr->LastUsableLBA > ParentBlockDev->LastBlock - 1 - EFI_SIZE_TO_BLOCKS (EFI_GPT_PART_ENTRY_MIN_SIZE, ParentBlockDev->BlockSize)) ||
  127. (PartHdr->FirstUsableLBA > PartHdr->LastUsableLBA) ||
  128. (PartHdr->PartitionEntryLBA < 2) ||
  129. (PartHdr->PartitionEntryLBA > ParentBlockDev->LastBlock - 1) ||
  130. ((PartHdr->PartitionEntryLBA >= PartHdr->FirstUsableLBA) && (PartHdr->PartitionEntryLBA <= PartHdr->LastUsableLBA)) ||
  131. (PartHdr->SizeOfPartitionEntry%128 != 0) ||
  132. (PartHdr->SizeOfPartitionEntry != sizeof (EFI_PARTITION_ENTRY))
  133. )
  134. {
  135. DEBUG ((DEBUG_ERROR, "Invalid efi partition table header\n"));
  136. return FALSE;
  137. }
  138. //
  139. // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
  140. //
  141. if (PartHdr->NumberOfPartitionEntries > DivU64x32 (MAX_UINTN, PartHdr->SizeOfPartitionEntry)) {
  142. DEBUG ((DEBUG_ERROR, "Memory overflow in GPT Entry Array\n"));
  143. return FALSE;
  144. }
  145. PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
  146. EntryArraySizeRemainder = 0;
  147. PartitionEntryBlockNumb = DivU64x32Remainder (PartitionEntryArraySize, ParentBlockDev->BlockSize, &EntryArraySizeRemainder);
  148. if (EntryArraySizeRemainder != 0) {
  149. PartitionEntryBlockNumb++;
  150. }
  151. if (IsPrimaryHeader) {
  152. EntryArrayLastLba = PartHdr->FirstUsableLBA;
  153. } else {
  154. EntryArrayLastLba = ParentBlockDev->LastBlock;
  155. }
  156. //
  157. // Make sure partition entry array not overlaps with partition area or the LastBlock.
  158. //
  159. if (PartHdr->PartitionEntryLBA + PartitionEntryBlockNumb > EntryArrayLastLba) {
  160. DEBUG ((DEBUG_ERROR, "GPT Partition Entry Array Error!\n"));
  161. DEBUG ((DEBUG_ERROR, "PartitionEntryArraySize = %lu.\n", PartitionEntryArraySize));
  162. DEBUG ((DEBUG_ERROR, "PartitionEntryLBA = %lu.\n", PartHdr->PartitionEntryLBA));
  163. DEBUG ((DEBUG_ERROR, "PartitionEntryBlockNumb = %lu.\n", PartitionEntryBlockNumb));
  164. DEBUG ((DEBUG_ERROR, "EntryArrayLastLba = %lu.\n", EntryArrayLastLba));
  165. return FALSE;
  166. }
  167. return TRUE;
  168. }
  169. /**
  170. This function is used to verify each partition in block device.
  171. @param[in] PrivateData The global memory map
  172. @param[in] ParentBlockDevNo The parent block device
  173. @param[in] PartHdr Stores the partition table that is read
  174. @retval TRUE The partition is valid
  175. @retval FALSE The partition is not valid
  176. **/
  177. BOOLEAN
  178. PartitionCheckGptEntryArray (
  179. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  180. IN UINTN ParentBlockDevNo,
  181. IN EFI_PARTITION_TABLE_HEADER *PartHdr
  182. )
  183. {
  184. EFI_STATUS Status;
  185. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  186. PEI_FAT_BLOCK_DEVICE *BlockDevPtr;
  187. UINT64 PartitionEntryArraySize;
  188. UINT64 PartitionEntryBlockNumb;
  189. UINT32 EntryArraySizeRemainder;
  190. EFI_PARTITION_ENTRY *PartitionEntryBuffer;
  191. EFI_PARTITION_ENTRY_STATUS *PartitionEntryStatus;
  192. BOOLEAN Found;
  193. EFI_LBA StartingLBA;
  194. EFI_LBA EndingLBA;
  195. UINTN Index;
  196. UINTN Index1;
  197. UINTN Index2;
  198. EFI_PARTITION_ENTRY *Entry;
  199. PartitionEntryBuffer = NULL;
  200. PartitionEntryStatus = NULL;
  201. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  202. Found = FALSE;
  203. PartitionEntryArraySize = MultU64x32 (PartHdr->NumberOfPartitionEntries, PartHdr->SizeOfPartitionEntry);
  204. EntryArraySizeRemainder = 0;
  205. PartitionEntryBlockNumb = DivU64x32Remainder (PartitionEntryArraySize, ParentBlockDev->BlockSize, &EntryArraySizeRemainder);
  206. if (EntryArraySizeRemainder != 0) {
  207. PartitionEntryBlockNumb++;
  208. }
  209. PartitionEntryArraySize = MultU64x32 (PartitionEntryBlockNumb, ParentBlockDev->BlockSize);
  210. PartitionEntryBuffer = (EFI_PARTITION_ENTRY *)AllocatePages (EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
  211. if (PartitionEntryBuffer == NULL) {
  212. DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
  213. goto EXIT;
  214. }
  215. PartitionEntryStatus = (EFI_PARTITION_ENTRY_STATUS *)AllocatePages (EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
  216. if (PartitionEntryStatus == NULL) {
  217. DEBUG ((DEBUG_ERROR, "Allocate memory error!\n"));
  218. goto EXIT;
  219. }
  220. ZeroMem (PartitionEntryStatus, PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));
  221. Status = FatReadBlock (
  222. PrivateData,
  223. ParentBlockDevNo,
  224. PartHdr->PartitionEntryLBA,
  225. (UINTN)PartitionEntryArraySize,
  226. PartitionEntryBuffer
  227. );
  228. if (EFI_ERROR (Status)) {
  229. DEBUG ((DEBUG_ERROR, "Read partition entry array error!\n"));
  230. goto EXIT;
  231. }
  232. if (!PartitionCheckGptEntryArrayCRC (PartHdr, PartitionEntryBuffer)) {
  233. DEBUG ((DEBUG_ERROR, "Partition entries CRC check fail\n"));
  234. goto EXIT;
  235. }
  236. for (Index1 = 0; Index1 < PartHdr->NumberOfPartitionEntries; Index1++) {
  237. Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index1 * PartHdr->SizeOfPartitionEntry);
  238. if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
  239. continue;
  240. }
  241. StartingLBA = Entry->StartingLBA;
  242. EndingLBA = Entry->EndingLBA;
  243. if ((StartingLBA > EndingLBA) ||
  244. (StartingLBA < PartHdr->FirstUsableLBA) ||
  245. (StartingLBA > PartHdr->LastUsableLBA) ||
  246. (EndingLBA < PartHdr->FirstUsableLBA) ||
  247. (EndingLBA > PartHdr->LastUsableLBA)
  248. )
  249. {
  250. PartitionEntryStatus[Index1].OutOfRange = TRUE;
  251. continue;
  252. }
  253. if ((Entry->Attributes & BIT1) != 0) {
  254. //
  255. // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
  256. //
  257. PartitionEntryStatus[Index1].OsSpecific = TRUE;
  258. }
  259. for (Index2 = Index1 + 1; Index2 < PartHdr->NumberOfPartitionEntries; Index2++) {
  260. Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartitionEntryBuffer + Index2 * PartHdr->SizeOfPartitionEntry);
  261. if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {
  262. continue;
  263. }
  264. if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {
  265. //
  266. // This region overlaps with the Index1'th region
  267. //
  268. PartitionEntryStatus[Index1].Overlap = TRUE;
  269. PartitionEntryStatus[Index2].Overlap = TRUE;
  270. continue;
  271. }
  272. }
  273. }
  274. for (Index = 0; Index < PartHdr->NumberOfPartitionEntries; Index++) {
  275. if (CompareGuid (&PartitionEntryBuffer[Index].PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||
  276. PartitionEntryStatus[Index].OutOfRange ||
  277. PartitionEntryStatus[Index].Overlap ||
  278. PartitionEntryStatus[Index].OsSpecific)
  279. {
  280. //
  281. // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
  282. // partition Entries
  283. //
  284. continue;
  285. }
  286. if (PrivateData->BlockDeviceCount >= PEI_FAT_MAX_BLOCK_DEVICE) {
  287. break;
  288. }
  289. Found = TRUE;
  290. BlockDevPtr = &(PrivateData->BlockDevice[PrivateData->BlockDeviceCount]);
  291. BlockDevPtr->BlockSize = ParentBlockDev->BlockSize;
  292. BlockDevPtr->LastBlock = PartitionEntryBuffer[Index].EndingLBA;
  293. BlockDevPtr->IoAlign = ParentBlockDev->IoAlign;
  294. BlockDevPtr->Logical = TRUE;
  295. BlockDevPtr->PartitionChecked = FALSE;
  296. BlockDevPtr->StartingPos = MultU64x32 (
  297. PartitionEntryBuffer[Index].StartingLBA,
  298. ParentBlockDev->BlockSize
  299. );
  300. BlockDevPtr->ParentDevNo = ParentBlockDevNo;
  301. PrivateData->BlockDeviceCount++;
  302. DEBUG ((DEBUG_INFO, "Find GPT Partition [0x%lx", PartitionEntryBuffer[Index].StartingLBA));
  303. DEBUG ((DEBUG_INFO, ", 0x%lx]\n", BlockDevPtr->LastBlock));
  304. DEBUG ((DEBUG_INFO, " BlockSize %x\n", BlockDevPtr->BlockSize));
  305. }
  306. EXIT:
  307. if (PartitionEntryBuffer != NULL) {
  308. FreePages (PartitionEntryBuffer, EFI_SIZE_TO_PAGES ((UINTN)PartitionEntryArraySize));
  309. }
  310. if (PartitionEntryStatus != NULL) {
  311. FreePages (PartitionEntryStatus, EFI_SIZE_TO_PAGES (PartHdr->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS)));
  312. }
  313. return Found;
  314. }
  315. /**
  316. The function is used to check GPT structure, include GPT header and GPT entry array.
  317. 1. Check GPT header.
  318. 2. Check partition entry array.
  319. 3. Check each partitions.
  320. @param[in] PrivateData The global memory map
  321. @param[in] ParentBlockDevNo The parent block device
  322. @param[in] IsPrimary Indicate primary or backup to be check
  323. @retval TRUE Primary or backup GPT structure is valid.
  324. @retval FALSE Both primary and backup are invalid.
  325. **/
  326. BOOLEAN
  327. PartitionCheckGptStructure (
  328. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  329. IN UINTN ParentBlockDevNo,
  330. IN BOOLEAN IsPrimary
  331. )
  332. {
  333. EFI_STATUS Status;
  334. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  335. EFI_PARTITION_TABLE_HEADER *PartHdr;
  336. EFI_PEI_LBA GptHeaderLBA;
  337. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  338. PartHdr = (EFI_PARTITION_TABLE_HEADER *)PrivateData->BlockData;
  339. if (IsPrimary) {
  340. GptHeaderLBA = PRIMARY_PART_HEADER_LBA;
  341. } else {
  342. GptHeaderLBA = ParentBlockDev->LastBlock;
  343. }
  344. Status = FatReadBlock (
  345. PrivateData,
  346. ParentBlockDevNo,
  347. GptHeaderLBA,
  348. ParentBlockDev->BlockSize,
  349. PartHdr
  350. );
  351. if (EFI_ERROR (Status)) {
  352. return FALSE;
  353. }
  354. if (!PartitionCheckGptHeader (PrivateData, ParentBlockDevNo, IsPrimary, PartHdr)) {
  355. return FALSE;
  356. }
  357. if (!PartitionCheckGptEntryArray (PrivateData, ParentBlockDevNo, PartHdr)) {
  358. return FALSE;
  359. }
  360. return TRUE;
  361. }
  362. /**
  363. This function is used to check protective MBR structure before checking GPT.
  364. @param[in] PrivateData The global memory map
  365. @param[in] ParentBlockDevNo The parent block device
  366. @retval TRUE Valid protective MBR
  367. @retval FALSE Invalid MBR
  368. **/
  369. BOOLEAN
  370. PartitionCheckProtectiveMbr (
  371. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  372. IN UINTN ParentBlockDevNo
  373. )
  374. {
  375. EFI_STATUS Status;
  376. MASTER_BOOT_RECORD *ProtectiveMbr;
  377. MBR_PARTITION_RECORD *MbrPartition;
  378. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  379. UINTN Index;
  380. ProtectiveMbr = (MASTER_BOOT_RECORD *)PrivateData->BlockData;
  381. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  382. //
  383. // Read Protective MBR
  384. //
  385. Status = FatReadBlock (
  386. PrivateData,
  387. ParentBlockDevNo,
  388. 0,
  389. ParentBlockDev->BlockSize,
  390. ProtectiveMbr
  391. );
  392. if (EFI_ERROR (Status)) {
  393. DEBUG ((DEBUG_ERROR, "GPT Error When Read Protective Mbr From Partition!\n"));
  394. return FALSE;
  395. }
  396. if (ProtectiveMbr->Signature != MBR_SIGNATURE) {
  397. DEBUG ((DEBUG_ERROR, "Protective Mbr Signature is invalid!\n"));
  398. return FALSE;
  399. }
  400. //
  401. // The partition define in UEFI Spec Table 17.
  402. // Boot Code, Unique MBR Disk Signature, Unknown.
  403. // These parts will not be used by UEFI, so we skip to check them.
  404. //
  405. for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
  406. MbrPartition = (MBR_PARTITION_RECORD *)&ProtectiveMbr->Partition[Index];
  407. if ((MbrPartition->BootIndicator == 0x00) &&
  408. (MbrPartition->StartSector == 0x02) &&
  409. (MbrPartition->OSIndicator == PMBR_GPT_PARTITION) &&
  410. (UNPACK_UINT32 (MbrPartition->StartingLBA) == 1)
  411. )
  412. {
  413. return TRUE;
  414. }
  415. }
  416. DEBUG ((DEBUG_ERROR, "Protective Mbr, All Partition Entry Are Empty!\n"));
  417. return FALSE;
  418. }
  419. /**
  420. This function is used for finding GPT partition on block device.
  421. As follow UEFI spec we should check protective MBR first and then
  422. try to check both primary/backup GPT structures.
  423. @param[in] PrivateData The global memory map
  424. @param[in] ParentBlockDevNo The parent block device
  425. @retval TRUE New partitions are detected and logical block devices
  426. are added to block device array
  427. @retval FALSE No new partitions are added
  428. **/
  429. BOOLEAN
  430. FatFindGptPartitions (
  431. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  432. IN UINTN ParentBlockDevNo
  433. )
  434. {
  435. BOOLEAN Found;
  436. PEI_FAT_BLOCK_DEVICE *ParentBlockDev;
  437. if (ParentBlockDevNo > PEI_FAT_MAX_BLOCK_DEVICE - 1) {
  438. return FALSE;
  439. }
  440. ParentBlockDev = &(PrivateData->BlockDevice[ParentBlockDevNo]);
  441. if (ParentBlockDev->BlockSize > PEI_FAT_MAX_BLOCK_SIZE) {
  442. DEBUG ((DEBUG_ERROR, "Device BlockSize %x exceed FAT_MAX_BLOCK_SIZE\n", ParentBlockDev->BlockSize));
  443. return FALSE;
  444. }
  445. if (!PartitionCheckProtectiveMbr (PrivateData, ParentBlockDevNo)) {
  446. return FALSE;
  447. }
  448. Found = PartitionCheckGptStructure (PrivateData, ParentBlockDevNo, TRUE);
  449. if (!Found) {
  450. DEBUG ((DEBUG_ERROR, "Primary GPT Header Error, Try to Check Backup GPT Header!\n"));
  451. Found = PartitionCheckGptStructure (PrivateData, ParentBlockDevNo, FALSE);
  452. }
  453. if (Found) {
  454. ParentBlockDev->PartitionChecked = TRUE;
  455. }
  456. return Found;
  457. }