^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * EFI GUID Partition Table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Per Intel EFI Specification v1.02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * http://developer.intel.com/technology/efi/efi.htm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * By Matt Domsch <Matt_Domsch@dell.com> Fri Sep 22 22:15:56 CDT 2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright 2000,2001 Dell Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) ************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #ifndef FS_PART_EFI_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define FS_PART_EFI_H_INCLUDED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/genhd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/major.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define MSDOS_MBR_SIGNATURE 0xaa55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define EFI_PMBR_OSTYPE_EFI 0xEF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define GPT_MBR_PROTECTIVE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define GPT_MBR_HYBRID 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define GPT_HEADER_REVISION_V1 0x00010000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define PARTITION_SYSTEM_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) EFI_GUID( 0xC12A7328, 0xF81F, 0x11d2, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define LEGACY_MBR_PARTITION_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) EFI_GUID( 0x024DEE41, 0x33E7, 0x11d3, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define PARTITION_MSFT_RESERVED_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) EFI_GUID( 0xE3C9E316, 0x0B5C, 0x4DB8, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define PARTITION_BASIC_DATA_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) EFI_GUID( 0xEBD0A0A2, 0xB9E5, 0x4433, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define PARTITION_LINUX_RAID_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) EFI_GUID( 0xa19d880f, 0x05fc, 0x4d3b, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define PARTITION_LINUX_SWAP_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) EFI_GUID( 0x0657fd6d, 0xa4ab, 0x43c4, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define PARTITION_LINUX_LVM_GUID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) typedef struct _gpt_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) __le64 signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) __le32 revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) __le32 header_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) __le32 header_crc32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) __le32 reserved1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) __le64 my_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) __le64 alternate_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) __le64 first_usable_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __le64 last_usable_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) efi_guid_t disk_guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) __le64 partition_entry_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __le32 num_partition_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __le32 sizeof_partition_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __le32 partition_entry_array_crc32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* The rest of the logical block is reserved by UEFI and must be zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * EFI standard handles this by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * uint8_t reserved2[ BlockSize - 92 ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) } __packed gpt_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) typedef struct _gpt_entry_attributes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u64 required_to_function:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u64 reserved:47;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u64 type_guid_specific:16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) } __packed gpt_entry_attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) typedef struct _gpt_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) efi_guid_t partition_type_guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) efi_guid_t unique_partition_guid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) __le64 starting_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) __le64 ending_lba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) gpt_entry_attributes attributes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) __le16 partition_name[72/sizeof(__le16)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) } __packed gpt_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) typedef struct _gpt_mbr_record {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) u8 boot_indicator; /* unused by EFI, set to 0x80 for bootable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) u8 start_head; /* unused by EFI, pt start in CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) u8 start_sector; /* unused by EFI, pt start in CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u8 start_track;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u8 os_type; /* EFI and legacy non-EFI OS types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u8 end_head; /* unused by EFI, pt end in CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u8 end_sector; /* unused by EFI, pt end in CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u8 end_track; /* unused by EFI, pt end in CHS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) __le32 starting_lba; /* used by EFI - start addr of the on disk pt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) __le32 size_in_lba; /* used by EFI - size of pt in LBA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) } __packed gpt_mbr_record;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) typedef struct _legacy_mbr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 boot_code[440];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) __le32 unique_mbr_signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) __le16 unknown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) gpt_mbr_record partition_record[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __le16 signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) } __packed legacy_mbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #endif