Part.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /** @file
  2. Routines supporting partition discovery and
  3. logical device reading
  4. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include "FatLitePeim.h"
  8. /**
  9. This function finds Eltorito partitions. Main algorithm
  10. is ported from DXE partition driver.
  11. @param[in] PrivateData The global memory map
  12. @param[in] ParentBlockDevNo The parent block device
  13. @retval TRUE New partitions are detected and logical block devices
  14. are added to block device array
  15. @retval FALSE No new partitions are added
  16. **/
  17. BOOLEAN
  18. FatFindEltoritoPartitions (
  19. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  20. IN UINTN ParentBlockDevNo
  21. );
  22. /**
  23. This function finds Mbr partitions. Main algorithm
  24. is ported from DXE partition driver.
  25. @param[in] PrivateData The global memory map
  26. @param[in] ParentBlockDevNo The parent block device
  27. @retval TRUE New partitions are detected and logical block devices
  28. are added to block device array
  29. @retval FALSE No new partitions are added
  30. **/
  31. BOOLEAN
  32. FatFindMbrPartitions (
  33. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  34. IN UINTN ParentBlockDevNo
  35. );
  36. /**
  37. This function is used for finding GPT partition on block device.
  38. As follow UEFI spec we should check protective MBR first and then
  39. try to check both primary/backup GPT structures.
  40. @param[in] PrivateData The global memory map
  41. @param[in] ParentBlockDevNo The parent block device
  42. @retval TRUE New partitions are detected and logical block devices
  43. are added to block device array
  44. @retval FALSE No new partitions are added
  45. **/
  46. BOOLEAN
  47. FatFindGptPartitions (
  48. IN PEI_FAT_PRIVATE_DATA *PrivateData,
  49. IN UINTN ParentBlockDevNo
  50. );
  51. /**
  52. This function finds partitions (logical devices) in physical block devices.
  53. @param PrivateData Global memory map for accessing global variables.
  54. **/
  55. VOID
  56. FatFindPartitions (
  57. IN PEI_FAT_PRIVATE_DATA *PrivateData
  58. )
  59. {
  60. BOOLEAN Found;
  61. UINTN Index;
  62. do {
  63. Found = FALSE;
  64. for (Index = 0; Index < PrivateData->BlockDeviceCount; Index++) {
  65. if (!PrivateData->BlockDevice[Index].PartitionChecked) {
  66. if (FatFindGptPartitions (PrivateData, Index)) {
  67. Found = TRUE;
  68. continue;
  69. }
  70. if (FatFindMbrPartitions (PrivateData, Index)) {
  71. Found = TRUE;
  72. continue;
  73. }
  74. if (FatFindEltoritoPartitions (PrivateData, Index)) {
  75. Found = TRUE;
  76. continue;
  77. }
  78. }
  79. }
  80. } while (Found && PrivateData->BlockDeviceCount <= PEI_FAT_MAX_BLOCK_DEVICE);
  81. }