Project

General

Profile

Bug #2372 » 0001-CHROMIUM-block-partitions-efi-Add-support-for-IGNORE.patch

Megver83, 2020-01-16 05:36 PM

View differences:

block/partitions/efi.c
330 330
 * @lba: logical block address of the GPT header to test
331 331
 * @gpt: GPT header ptr, filled on return.
332 332
 * @ptes: PTEs ptr, filled on return.
333
 * @ignored is filled on return with 1 if this is an IGNOREME GPT,
334
 *     0 otherwise. May be NULL.
333 335
 *
334 336
 * Description: returns 1 if valid,  0 on error.
335 337
 * If valid, returns pointers to newly allocated GPT header and PTEs.
336 338
 */
337 339
static int is_gpt_valid(struct parsed_partitions *state, u64 lba,
338
			gpt_header **gpt, gpt_entry **ptes)
340
			gpt_header **gpt, gpt_entry **ptes, int *ignored)
339 341
{
340 342
	u32 crc, origcrc;
341 343
	u64 lastlba, pt_size;
342 344

  
345
	if (ignored)
346
		*ignored = 0;
343 347
	if (!ptes)
344 348
		return 0;
345 349
	if (!(*gpt = alloc_read_gpt_header(state, lba)))
346 350
		return 0;
347 351

  
348 352
	/* Check the GUID Partition Table signature */
349
	if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
353
	if (le64_to_cpu((*gpt)->signature) == GPT_HEADER_SIGNATURE_IGNORED) {
354
		pr_debug("GUID Partition Table at LBA %llu marked IGNOREME\n",
355
			 lba);
356
		if (ignored)
357
			*ignored = 1;
358
		goto fail;
359
	} else if (le64_to_cpu((*gpt)->signature) != GPT_HEADER_SIGNATURE) {
350 360
		pr_debug("GUID Partition Table Header signature is wrong:"
351 361
			 "%lld != %lld\n",
352 362
			 (unsigned long long)le64_to_cpu((*gpt)->signature),
......
583 593
static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt,
584 594
			  gpt_entry **ptes)
585 595
{
586
	int good_pgpt = 0, good_agpt = 0, good_pmbr = 0;
596
	int good_pgpt = 0, good_agpt = 0, good_pmbr = 0, pgpt_ignored = 0;
587 597
	gpt_header *pgpt = NULL, *agpt = NULL;
588 598
	gpt_entry *pptes = NULL, *aptes = NULL;
589 599
	legacy_mbr *legacymbr;
......
613 623
	}
614 624

  
615 625
	good_pgpt = is_gpt_valid(state, GPT_PRIMARY_PARTITION_TABLE_LBA,
616
				 &pgpt, &pptes);
626
				 &pgpt, &pptes, &pgpt_ignored);
617 627
        if (good_pgpt)
618 628
		good_agpt = is_gpt_valid(state,
619 629
					 le64_to_cpu(pgpt->alternate_lba),
620
					 &agpt, &aptes);
621
        if (!good_agpt && force_gpt)
622
                good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes);
630
					 &agpt, &aptes, NULL);
631

  
632
	if (!good_agpt && (force_gpt || pgpt_ignored))
633
		good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes, NULL);
623 634

  
624 635
        /* The obviously unsuccessful case */
625 636
        if (!good_pgpt && !good_agpt)
626 637
                goto fail;
627 638

  
628
        compare_gpts(pgpt, agpt, lastlba);
639
	if (!pgpt_ignored)
640
		compare_gpts(pgpt, agpt, lastlba);
629 641

  
630 642
        /* The good cases */
631 643
        if (good_pgpt) {
......
642 654
                *ptes = aptes;
643 655
                kfree(pgpt);
644 656
                kfree(pptes);
645
		pr_warn("Primary GPT is invalid, using alternate GPT.\n");
657
		pr_warn("Primary GPT is %s, using alternate GPT.\n",
658
			pgpt_ignored ? "being ignored" : "invalid");
646 659
                return 1;
647 660
        }
648 661

  
block/partitions/efi.h
27 27
#define GPT_MBR_PROTECTIVE  1
28 28
#define GPT_MBR_HYBRID      2
29 29

  
30
#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
30
#define GPT_HEADER_SIGNATURE		0x5452415020494645ULL	/* 'EFI PART' */
31
#define GPT_HEADER_SIGNATURE_IGNORED	0x454d45524f4e4749ULL	/* 'IGNOREME' */
31 32
#define GPT_HEADER_REVISION_V1 0x00010000
32 33
#define GPT_PRIMARY_PARTITION_TABLE_LBA 1
33 34

  
34
- 
(6-6/7)