add-support-for-IGNOREME-GPT-signature.patch 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. diff --git a/block/partitions/efi.c b/block/partitions/efi.c
  2. index 4bf0f97..b33671d 100644
  3. --- a/block/partitions/efi.c
  4. +++ b/block/partitions/efi.c
  5. @@ -348,23 +348,32 @@
  6. * @lba is the logical block address of the GPT header to test
  7. * @gpt is a GPT header ptr, filled on return.
  8. * @ptes is a PTEs ptr, filled on return.
  9. + * @ignored is filled on return with 1 if this is an IGNOREME GPT,
  10. + * 0 otherwise. May be NULL.
  11. *
  12. * Description: returns 1 if valid, 0 on error.
  13. * If valid, returns pointers to newly allocated GPT header and PTEs.
  14. */
  15. static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
  16. - gpt_header **gpt, gpt_entry **ptes)
  17. + gpt_header **gpt, gpt_entry **ptes, int *ignored)
  18. {
  19. u32 crc, origcrc;
  20. u64 lastlba;
  21. + if (ignored)
  22. + *ignored = 0;
  23. if (!ptes)
  24. return 0;
  25. if (!(*gpt = alloc_read_gpt_header(state, lba)))
  26. return 0;
  27. /* Check the GUID Partition Table signature */
  28. - if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  29. + if (le64_to_cpu((*gpt)->signature) == GPT_HEADER_SIGNATURE_IGNORED) {
  30. + pr_debug("GUID Partition Table at LBA %llu marked IGNOREME\n");
  31. + if (ignored)
  32. + *ignored = 1;
  33. + goto fail;
  34. + } else if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
  35. pr_debug("GUID Partition Table Header signature is wrong:"
  36. "%lld != %lld\n",
  37. (unsigned long long)le64_to_cpu((*gpt)->signature),
  38. @@ -592,7 +601,7 @@
  39. static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
  40. gpt_entry **ptes)
  41. {
  42. - int good_pgpt = 0, good_agpt = 0, good_pmbr = 0;
  43. + int good_pgpt = 0, good_agpt = 0, good_pmbr = 0, pgpt_ignored = 0;
  44. gpt_header *pgpt = NULL, *agpt = NULL;
  45. gpt_entry *pptes = NULL, *aptes = NULL;
  46. legacy_mbr *legacymbr;
  47. @@ -622,19 +631,20 @@
  48. }
  49. good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
  50. - &pgpt, &pptes);
  51. + &pgpt, &pptes, &pgpt_ignored);
  52. if (good_pgpt)
  53. good_agpt = is_gpt_valid(state,
  54. le64_to_cpu(pgpt->alternate_lba),
  55. - &agpt, &aptes);
  56. - if (!good_agpt && force_gpt)
  57. - good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
  58. + &agpt, &aptes, NULL);
  59. + if (!good_agpt && (force_gpt || pgpt_ignored))
  60. + good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes, NULL);
  61. /* The obviously unsuccessful case */
  62. if (!good_pgpt && !good_agpt)
  63. goto fail;
  64. - compare_gpts(pgpt, agpt, lastlba);
  65. + if (!pgpt_ignored)
  66. + compare_gpts(pgpt, agpt, lastlba);
  67. /* The good cases */
  68. if (good_pgpt) {
  69. @@ -651,7 +661,8 @@
  70. *ptes = aptes;
  71. kfree(pgpt);
  72. kfree(pptes);
  73. - pr_warn("Primary GPT is invalid, using alternate GPT.\n");
  74. + pr_warn("Primary GPT is %s, using alternate GPT.\n",
  75. + pgpt_ignored ? "being ignored" : "invalid");
  76. return 1;
  77. }
  78. diff --git a/block/partitions/efi.h b/block/partitions/efi.h
  79. index 4efcafb..3a13ef9 100644
  80. --- a/block/partitions/efi.h
  81. +++ b/block/partitions/efi.h
  82. @@ -40,7 +40,8 @@
  83. #define GPT_MBR_PROTECTIVE 1
  84. #define GPT_MBR_HYBRID 2
  85. -#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
  86. +#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL /* 'EFI PART' */
  87. +#define GPT_HEADER_SIGNATURE_IGNORED 0x454d45524f4e4749ULL /* 'IGNOREME' */
  88. #define GPT_HEADER_REVISION_V1 0x00010000
  89. #define GPT_PRIMARY_PARTITION_TABLE_LBA 1