Re: [PATCH 1/8] partitions/efi: use lba-aware partition records
On Mon, 2013-09-02 at 12:10 +0200, Karel Zak wrote: > On Mon, Aug 05, 2013 at 10:21:09PM -0700, Davidlohr Bueso wrote: > > > > +typedef struct _gpt_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 */ > > +} __attribute__ ((packed)) gpt_record; > > + > > Maybe it would be better to rename this struct to "gpt_mbr_record" to > make it more obvious. Yes, good idea. I've added the patch below. 8<-- From: Davidlohr Bueso Subject: [PATCH] partitions/efi: rename gpt_record structure Since the gpt_record structure is an MBR-specific type, rename it to gpt_mbr_record for obvious reading. Suggested-by: Karel Zak Signed-off-by: Davidlohr Bueso --- block/partitions/efi.c | 2 +- block/partitions/efi.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 8e6d77e..9a4eba7 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -152,7 +152,7 @@ static u64 last_lba(struct block_device *bdev) bdev_logical_block_size(bdev)) - 1ULL; } -static inline int pmbr_part_valid(gpt_record *part) +static inline int pmbr_part_valid(gpt_mbr_record *part) { if (part->os_type != EFI_PMBR_OSTYPE_EFI_GPT) goto invalid; diff --git a/block/partitions/efi.h b/block/partitions/efi.h index 9ab8ee9..54b2687 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -104,7 +104,7 @@ typedef struct _gpt_entry { efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; } __attribute__ ((packed)) gpt_entry; -typedef struct _gpt_record { +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 */ @@ -115,14 +115,14 @@ typedef struct _gpt_record { 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 */ -} __attribute__ ((packed)) gpt_record; +} __attribute__ ((packed)) gpt_mbr_record; typedef struct _legacy_mbr { u8 boot_code[440]; __le32 unique_mbr_signature; __le16 unknown; - gpt_record partition_record[4]; + gpt_mbr_record partition_record[4]; __le16 signature; } __attribute__ ((packed)) legacy_mbr; -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/8] partitions/efi: use lba-aware partition records
On Mon, Aug 05, 2013 at 10:21:09PM -0700, Davidlohr Bueso wrote: > > +typedef struct _gpt_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 */ > +} __attribute__ ((packed)) gpt_record; > + Maybe it would be better to rename this struct to "gpt_mbr_record" to make it more obvious. Karel -- Karel Zak http://karelzak.blogspot.com -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/8] partitions/efi: use lba-aware partition records
On Mon, Aug 05, 2013 at 10:21:09PM -0700, Davidlohr Bueso wrote: +typedef struct _gpt_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 */ +} __attribute__ ((packed)) gpt_record; + Maybe it would be better to rename this struct to gpt_mbr_record to make it more obvious. Karel -- Karel Zak k...@redhat.com http://karelzak.blogspot.com -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 1/8] partitions/efi: use lba-aware partition records
On Mon, 2013-09-02 at 12:10 +0200, Karel Zak wrote: On Mon, Aug 05, 2013 at 10:21:09PM -0700, Davidlohr Bueso wrote: +typedef struct _gpt_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 */ +} __attribute__ ((packed)) gpt_record; + Maybe it would be better to rename this struct to gpt_mbr_record to make it more obvious. Yes, good idea. I've added the patch below. 8-- From: Davidlohr Bueso davidl...@hp.com Subject: [PATCH] partitions/efi: rename gpt_record structure Since the gpt_record structure is an MBR-specific type, rename it to gpt_mbr_record for obvious reading. Suggested-by: Karel Zak k...@redhat.com Signed-off-by: Davidlohr Bueso davidl...@hp.com --- block/partitions/efi.c | 2 +- block/partitions/efi.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 8e6d77e..9a4eba7 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -152,7 +152,7 @@ static u64 last_lba(struct block_device *bdev) bdev_logical_block_size(bdev)) - 1ULL; } -static inline int pmbr_part_valid(gpt_record *part) +static inline int pmbr_part_valid(gpt_mbr_record *part) { if (part-os_type != EFI_PMBR_OSTYPE_EFI_GPT) goto invalid; diff --git a/block/partitions/efi.h b/block/partitions/efi.h index 9ab8ee9..54b2687 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -104,7 +104,7 @@ typedef struct _gpt_entry { efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; } __attribute__ ((packed)) gpt_entry; -typedef struct _gpt_record { +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 */ @@ -115,14 +115,14 @@ typedef struct _gpt_record { 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 */ -} __attribute__ ((packed)) gpt_record; +} __attribute__ ((packed)) gpt_mbr_record; typedef struct _legacy_mbr { u8 boot_code[440]; __le32 unique_mbr_signature; __le16 unknown; - gpt_record partition_record[4]; + gpt_mbr_record partition_record[4]; __le16 signature; } __attribute__ ((packed)) legacy_mbr; -- 1.7.11.7 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/8] 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. Signed-off-by: Davidlohr Bueso --- block/partitions/efi.c | 7 +++ block/partitions/efi.h | 16 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index c85fc89..3ebd3d8 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -149,11 +149,10 @@ static u64 last_lba(struct block_device *bdev) bdev_logical_block_size(bdev)) - 1ULL; } -static inline int -pmbr_part_valid(struct partition *part) +static inline int pmbr_part_valid(gpt_record *part) { -if (part->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT && -le32_to_cpu(part->start_sect) == 1UL) +if (part->os_type == EFI_PMBR_OSTYPE_EFI_GPT && +le32_to_cpu(part->start_sector) == 1UL) return 1; return 0; } diff --git a/block/partitions/efi.h b/block/partitions/efi.h index b69ab72..46cf1a4 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -101,11 +101,25 @@ typedef struct _gpt_entry { efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; } __attribute__ ((packed)) gpt_entry; +typedef struct _gpt_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 */ +} __attribute__ ((packed)) gpt_record; + + typedef struct _legacy_mbr { u8 boot_code[440]; __le32 unique_mbr_signature; __le16 unknown; - struct partition partition_record[4]; + gpt_record partition_record[4]; __le16 signature; } __attribute__ ((packed)) legacy_mbr; -- 1.7.11.7 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 1/8] 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. Signed-off-by: Davidlohr Bueso davidl...@hp.com --- block/partitions/efi.c | 7 +++ block/partitions/efi.h | 16 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index c85fc89..3ebd3d8 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -149,11 +149,10 @@ static u64 last_lba(struct block_device *bdev) bdev_logical_block_size(bdev)) - 1ULL; } -static inline int -pmbr_part_valid(struct partition *part) +static inline int pmbr_part_valid(gpt_record *part) { -if (part-sys_ind == EFI_PMBR_OSTYPE_EFI_GPT -le32_to_cpu(part-start_sect) == 1UL) +if (part-os_type == EFI_PMBR_OSTYPE_EFI_GPT +le32_to_cpu(part-start_sector) == 1UL) return 1; return 0; } diff --git a/block/partitions/efi.h b/block/partitions/efi.h index b69ab72..46cf1a4 100644 --- a/block/partitions/efi.h +++ b/block/partitions/efi.h @@ -101,11 +101,25 @@ typedef struct _gpt_entry { efi_char16_t partition_name[72 / sizeof (efi_char16_t)]; } __attribute__ ((packed)) gpt_entry; +typedef struct _gpt_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 */ +} __attribute__ ((packed)) gpt_record; + + typedef struct _legacy_mbr { u8 boot_code[440]; __le32 unique_mbr_signature; __le16 unknown; - struct partition partition_record[4]; + gpt_record partition_record[4]; __le16 signature; } __attribute__ ((packed)) legacy_mbr; -- 1.7.11.7 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/