Commit c2ebdc24 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Linus Torvalds

partitions/efi: use lba-aware partition records

The kernel's GPT implementation currently uses the generic 'struct
partition' type for dealing with legacy MBR partition records.  While this
is is useful for disklabels that we designed for CHS addressing, such as
msdos, it doesn't adapt well to newer standards that use LBA instead, such
as GUID partition tables.  Furthermore, these generic partition structures
do not have all the required fields to properly follow the UEFI specs.

While a CHS address can be translated to LBA, it's much simpler and
cleaner to just replace the partition type.  This patch adds a new
'gpt_record' type that is fully compliant with EFI and will allow, in the
next patches, to add more checks to properly verify a protective MBR,
which is paramount to probing a device that makes use of GPT.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarDavidlohr Bueso <davidlohr@hp.com>
Reviewed-by: default avatarKarel Zak <kzak@redhat.com>
Acked-by: default avatarMatt Fleming <matt.fleming@intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6f79d332
...@@ -149,12 +149,11 @@ static u64 last_lba(struct block_device *bdev) ...@@ -149,12 +149,11 @@ static u64 last_lba(struct block_device *bdev)
bdev_logical_block_size(bdev)) - 1ULL; bdev_logical_block_size(bdev)) - 1ULL;
} }
static inline int static inline int pmbr_part_valid(gpt_mbr_record *part)
pmbr_part_valid(struct partition *part)
{ {
if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT && if (part->os_type == EFI_PMBR_OSTYPE_EFI_GPT &&
le32_to_cpu(part->start_sect) == 1UL) le32_to_cpu(part->start_sector) == 1UL)
return 1; return 1;
return 0; return 0;
} }
......
...@@ -101,11 +101,25 @@ typedef struct _gpt_entry { ...@@ -101,11 +101,25 @@ typedef struct _gpt_entry {
efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; efi_char16_t partition_name[72 / sizeof (efi_char16_t)];
} __attribute__ ((packed)) gpt_entry; } __attribute__ ((packed)) gpt_entry;
typedef struct _gpt_mbr_record {
u8 boot_indicator; /* unused by EFI, set to 0x80 for bootable */
u8 start_head; /* unused by EFI, pt start in CHS */
u8 start_sector; /* unused by EFI, pt start in CHS */
u8 start_track;
u8 os_type; /* EFI and legacy non-EFI OS types */
u8 end_head; /* unused by EFI, pt end in CHS */
u8 end_sector; /* unused by EFI, pt end in CHS */
u8 end_track; /* unused by EFI, pt end in CHS */
__le32 starting_lba; /* used by EFI - start addr of the on disk pt */
__le32 size_in_lba; /* used by EFI - size of pt in LBA */
} __packed gpt_mbr_record;
typedef struct _legacy_mbr { typedef struct _legacy_mbr {
u8 boot_code[440]; u8 boot_code[440];
__le32 unique_mbr_signature; __le32 unique_mbr_signature;
__le16 unknown; __le16 unknown;
struct partition partition_record[4]; gpt_mbr_record partition_record[4];
__le16 signature; __le16 signature;
} __attribute__ ((packed)) legacy_mbr; } __attribute__ ((packed)) legacy_mbr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment