partfmt.h 12 KB

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