partfmt.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. partfmt.h
  5. Abstract:
  6. This header contains definitions for the various partition formats
  7. supported by UEFI.
  8. Author:
  9. Evan Green 19-Mar-2014
  10. --*/
  11. //
  12. // ------------------------------------------------------------------- Includes
  13. //
  14. //
  15. // ---------------------------------------------------------------- Definitions
  16. //
  17. //
  18. // GPT partition definitions
  19. //
  20. #define EFI_PARTITION_TYPE_UNUSED_GUID \
  21. { \
  22. 0x00000000, 0x0000, 0x0000, \
  23. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
  24. }
  25. #define EFI_PARTITION_TYPE_EFI_SYSTEM_GUID \
  26. { \
  27. 0xC12A7328, 0xF81F, 0x11D2, \
  28. {0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B} \
  29. }
  30. #define EFI_PARTITION_TYPE_LEGACY_MBR_GUID \
  31. { \
  32. 0x024DEE41, 0x33E7, 0x11D3, \
  33. {0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F} \
  34. }
  35. //
  36. // The primary GPT header must be at LBA 1 (the second logical block).
  37. //
  38. #define EFI_PRIMARY_PARTITION_HEADER_LBA 1
  39. //
  40. // Define the EFI GPT header signature, "EFI PART".
  41. //
  42. #define EFI_GPT_HEADER_SIGNATURE 0x5452415020494645ULL
  43. #define EFI_GPT_ATTRIBUTE_OS_SPECIFIC (1 << 1)
  44. //
  45. // El Torito definitions
  46. //
  47. #define EFI_CD_BLOCK_SIZE 2048
  48. #define EFI_CD_VOLUME_RECORD_LBA 16
  49. #define EFI_CD_VOLUME_TYPE_STANDARD 0x0
  50. #define EFI_CD_VOLUME_TYPE_CODED 0x1
  51. #define EFI_CD_VOLUME_TYPE_END 0xFF
  52. #define EFI_CD_VOLUME_ID "CD001"
  53. #define EFI_CD_VOLUME_ELTORITO_ID "EL TORITO SPECIFICATION"
  54. //
  55. // Indicator types
  56. //
  57. #define EFI_ELTORITO_ID_CATALOG 0x01
  58. #define EFI_ELTORITO_ID_SECTION_BOOTABLE 0x88
  59. #define EFI_ELTORITO_ID_SECTION_NOT_BOOTABLE 0x00
  60. #define EFI_ELTORITO_ID_SECTION_HEADER 0x90
  61. #define EFI_ELTORITO_ID_SECTION_HEADER_FINAL 0x91
  62. //
  63. // Boot media types.
  64. //
  65. #define EFI_ELTORITO_NO_EMULATION 0x00
  66. #define EFI_ELTORITO_12_DISKETTE 0x01
  67. #define EFI_ELTORITO_14_DISKETTE 0x02
  68. #define EFI_ELTORITO_28_DISKETTE 0x03
  69. #define EFI_ELTORITO_HARD_DISK 0x04
  70. //
  71. // MBR partition definitions
  72. //
  73. #define EFI_MBR_SIGNATURE 0xAA55
  74. #define EFI_EXTENDED_DOS_PARTITION 0x05
  75. #define EFI_EXTENDED_WINDOWS_PARTITION 0x0F
  76. #define EFI_PROTECTIVE_MBR_PARTITION 0xEE
  77. #define EFI_PARTITION 0xEF
  78. #define EFI_MAX_MBR_PARTITIONS 4
  79. #define EFI_MBR_SIZE 512
  80. //
  81. // ------------------------------------------------------ Data Type Definitions
  82. //
  83. //
  84. // GPT partition structures
  85. //
  86. /*++
  87. Structure Description:
  88. This structure defines a GPT partition table header.
  89. Members:
  90. Header - Stores the common header portion of any EFI table.
  91. MyLba - Stores the LBA that contains this structure.
  92. AlternateLba - Stores the LBA of the other copy of this structure.
  93. FirstUsableLba - Stores the LBA of the first usable block that may be used
  94. by a partition described in a partition entry.
  95. LastUsableLba - Stores the last usable block that may be used by a
  96. partition described in a partition entry.
  97. DiskGuid - Stores a GUID that can be used to uniquely identify the disk.
  98. PartitionEntryLba - Stores the starting LBA of the partition entry array.
  99. NumberOfPartitionEntries - Stores the number of entries in the partition
  100. entry array.
  101. SizeOfPartitionEntry - Stores the size in bytes of each GUID partition
  102. entry structure. This must be a multiple of 128.
  103. PartitionEntryArrayCrc32 - Stores the CRC32 of the partition entry array.
  104. This starts at the partition entry LBA and is computed over a length
  105. of the number of partition entries times the size of a partition
  106. entry.
  107. --*/
  108. typedef struct _EFI_PARTITION_TABLE_HEADER {
  109. EFI_TABLE_HEADER Header;
  110. EFI_LBA MyLba;
  111. EFI_LBA AlternateLba;
  112. EFI_LBA FirstUsableLba;
  113. EFI_LBA LastUsableLba;
  114. EFI_GUID DiskGuid;
  115. EFI_LBA PartitionEntryLba;
  116. UINT32 NumberOfPartitionEntries;
  117. UINT32 SizeOfPartitionEntry;
  118. UINT32 PartitionEntryArrayCrc32;
  119. } PACKED EFI_PARTITION_TABLE_HEADER, *PEFI_PARTITION_TABLE_HEADER;
  120. /*++
  121. Structure Description:
  122. This structure defines a GPT partition entry.
  123. Members:
  124. PartitionTypeGuid - Stores a unique ID that identifies the purpose and type
  125. of this partition. A valid of zero indicates the partition entry is
  126. not being used.
  127. UniquePartitionGuid - Stores a unique identifier for each partition entry.
  128. Every partition ever created will have a unique ID. This GUID is
  129. assigned when the partition entry is created.
  130. StartingLba - Stores the starting LBA of the partition.
  131. EndingLba - Stores the ending LBA of the partition, inclusive.
  132. Attributes - Stores attribute bits.
  133. PartitionName - Stores a null-terminated human readable name for the
  134. partition.
  135. --*/
  136. typedef struct _EFI_PARTITION_ENTRY {
  137. EFI_GUID PartitionTypeGuid;
  138. EFI_GUID UniquePartitionGuid;
  139. EFI_LBA StartingLba;
  140. EFI_LBA EndingLba;
  141. UINT64 Attributes;
  142. CHAR16 PartitionName[36];
  143. } PACKED EFI_PARTITION_ENTRY, *PEFI_PARTITION_ENTRY;
  144. //
  145. // El Torito data structures
  146. //
  147. /*++
  148. Structure Description:
  149. This structure defines the boot record volume descriptor, defined in the
  150. "El Torito" specification. What a great name, El Torrrrrrrito!
  151. Members:
  152. Type - Stores the value zero for this type.
  153. Id - Stores the ASCII string "CD001".
  154. Version - Stores the constant one.
  155. SystemId - Stores the ASCII string "EL TORITO SPECIFICATION".
  156. Unused - Stores unused bytes that should be zero.
  157. Catalog - Stores the absolute first sector of the Boot Catalog.
  158. Unused2 - Stores more unused bytes that should be zero.
  159. --*/
  160. typedef struct _EFI_CDROM_BOOT_VOLUME_DESCRIPTOR {
  161. UINT8 Type;
  162. CHAR8 Id[5];
  163. UINT8 Version;
  164. CHAR8 SystemId[32];
  165. CHAR8 Unused[32];
  166. UINT8 Catalog[4];
  167. CHAR8 Unused2[13];
  168. } PACKED EFI_CDROM_BOOT_VOLUME_DESCRIPTOR, *PEFI_CDROM_BOOT_VOLUME_DESCRIPTOR;
  169. /*++
  170. Structure Description:
  171. This structure defines the primary volume descriptor, defined in ISO 9660,
  172. a much more boring name.
  173. Members:
  174. Type - Stores the volume type.
  175. Id - Stores the ASCII string "CD001".
  176. Unused - Stores an unused value that should be zero.
  177. SystemId - Stores the system ID string.
  178. VolumeId - Stores the volume ID string.
  179. Unused2 - Stores more bytes that should be zero.
  180. VolumeSize - Stores the number of logical blocks in the volume.
  181. --*/
  182. typedef struct _EFI_CDROM_PRIMARY_VOLUME_DESCRIPTOR {
  183. UINT8 Type;
  184. CHAR8 Id[5];
  185. UINT8 Version;
  186. UINT8 Unused;
  187. CHAR8 SystemId[32];
  188. CHAR8 VolumeId[32];
  189. UINT8 Unused2[8];
  190. UINT32 VolumeSize[2];
  191. } PACKED EFI_CDROM_PRIMARY_VOLUME_DESCRIPTOR,
  192. *PEFI_CDROM_PRIMARY_VOLUME_DESCRIPTOR;
  193. /*++
  194. Structure Description:
  195. This union defines the format of a CD-ROM volume descriptor.
  196. Members:
  197. BootRecordVolume - Stores the boot record volume.
  198. PrimaryVolume - Stores the primary volume record.
  199. --*/
  200. typedef union _EFI_CDROM_VOLUME_DESCRIPTOR {
  201. EFI_CDROM_BOOT_VOLUME_DESCRIPTOR BootRecordVolume;
  202. EFI_CDROM_PRIMARY_VOLUME_DESCRIPTOR PrimaryVolume;
  203. } EFI_CDROM_VOLUME_DESCRIPTOR, *PEFI_CDROM_VOLUME_DESCRIPTOR;
  204. /*++
  205. Structure Description:
  206. This structure defines the El Torito catalog validation entry.
  207. Members:
  208. Type - Stores the constant one.
  209. PlatformId - Stores a platform identifier byte.
  210. Reserved - Stores an unused value.
  211. ManufacturerId - Stores the string identifier of the manufacturer.
  212. Checksum - Stores the checksum of the catalog.
  213. Id55AA - Stores the constant values 0x55 and 0xAA.
  214. --*/
  215. typedef struct _EFI_ELTORITO_CATALOG_DATA {
  216. UINT8 Indicator;
  217. UINT8 PlatformId;
  218. UINT16 Reserved;
  219. CHAR8 ManufacturerId[24];
  220. UINT16 Checksum;
  221. UINT16 Id55AA;
  222. } PACKED EFI_ELTORITO_CATALOG_DATA, *PEFI_ELTORITO_CATALOG_DATA;
  223. /*++
  224. Structure Description:
  225. This structure defines the El Torito initial/default entry.
  226. Members:
  227. Indicator - Stores the value 0x88 for a bootable volume, or 0 for a
  228. non-bootable volume.
  229. MediaType - Stores the media type.
  230. LoadSegment - Stores the load segment.
  231. SystemType - Stores the system type.
  232. Reserved2 - Stores a reserved value that must be zero.
  233. Lba - Stores the LBA of the boot data.
  234. --*/
  235. typedef struct _EFI_ELTORITO_BOOT_DATA {
  236. UINT8 Indicator;
  237. UINT8 MediaType;
  238. UINT16 LoadSegment;
  239. UINT8 SystemType;
  240. UINT8 Reserved2;
  241. UINT16 SectorCount;
  242. UINT32 Lba;
  243. } PACKED EFI_ELTORITO_BOOT_DATA, *PEFI_ELTORITO_BOOT_DATA;
  244. /*++
  245. Structure Description:
  246. This structure defines the El Torito section header entry.
  247. Members:
  248. Indicator - Stores 0x90 for a header where more data follows, or 0x91 for
  249. the final header.
  250. PlatformId - Stores the platform ID byte.
  251. SectionEntries - Stores the number of section entries following this header.
  252. Id - Stores the identifier string of this section.
  253. --*/
  254. typedef struct _EFI_ELTORITO_SECTION {
  255. UINT8 Indicator;
  256. UINT8 PlatformId;
  257. UINT16 SectionEntries;
  258. CHAR8 Id[28];
  259. } PACKED EFI_ELTORITO_SECTION, *PEFI_ELTORITO_SECTION;
  260. /*++
  261. Structure Description:
  262. This union defines an El Torito catalog entry.
  263. Members:
  264. Catalog - Stores the catalog validation entry (catalog header).
  265. Boot - Stores the initial/default entry.
  266. Section - Stores the section header entry.
  267. --*/
  268. typedef union _EFI_ELTORITO_CATALOG {
  269. EFI_ELTORITO_CATALOG_DATA Catalog;
  270. EFI_ELTORITO_BOOT_DATA Boot;
  271. EFI_ELTORITO_SECTION Section;
  272. } EFI_ELTORITO_CATALOG, *PEFI_ELTORITO_CATALOG;
  273. //
  274. // MBR data structures
  275. //
  276. /*++
  277. Structure Description:
  278. This structure defines the format of an MBR partition table entry.
  279. Members:
  280. BootIndicator - Stores 0x00 for an inactive entry or 0x80 for an active
  281. entry.
  282. StartHead - Stores the starting head number of the partition.
  283. StartSector - Stores the starting sector number of the partition.
  284. StartTrack - Stores the starting track number of the partition.
  285. OsIndicator - Stores a wild west byte that tries to define the OS and/or
  286. file system on the partition.
  287. EndHead - Stores the ending head of the partition, inclusive.
  288. EndSector - Stores the ending sector of the partition, inclusive.
  289. EndTrack - Stores the ending track of the partition, inclusive.
  290. StartingLba - Stores the starting logical block address of the partition.
  291. SizeInLba - Stores the number of logical block in the partition.
  292. --*/
  293. typedef struct _EFI_MBR_PARTITION_RECORD {
  294. UINT8 BootIndicator;
  295. UINT8 StartHead;
  296. UINT8 StartSector;
  297. UINT8 StartTrack;
  298. UINT8 OsIndicator;
  299. UINT8 EndHead;
  300. UINT8 EndSector;
  301. UINT8 EndTrack;
  302. UINT8 StartingLba[4];
  303. UINT8 SizeInLba[4];
  304. } PACKED EFI_MBR_PARTITION_RECORD, *PEFI_MBR_PARTITION_RECORD;
  305. /*++
  306. Structure Description:
  307. This structure defines the first 512 bytes of an MBR partitioned disk. GPT
  308. disks also follow this format.
  309. Members:
  310. BootStrapCode - Stores 440 bytes of undefined data, usually x86 bootstrap
  311. code.
  312. UniqueMbrSignature - Stores the signature word of the MBR.
  313. Unknown - Stores two undefined bytes.
  314. Partition - Stores the partition records.
  315. Signature - Stores the constant 0xAA55.
  316. --*/
  317. typedef struct _EFI_MASTER_BOOT_RECORD {
  318. UINT8 BootStrapCode[440];
  319. UINT8 UniqueMbrSignature[4];
  320. UINT8 Unknown[2];
  321. EFI_MBR_PARTITION_RECORD Partition[EFI_MAX_MBR_PARTITIONS];
  322. UINT16 Signature;
  323. } PACKED EFI_MASTER_BOOT_RECORD, *PEFI_MASTER_BOOT_RECORD;
  324. //
  325. // -------------------------------------------------------------------- Globals
  326. //
  327. //
  328. // -------------------------------------------------------- Function Prototypes
  329. //