xref: /spdk/include/spdk/gpt_spec.h (revision da6841e4509a8eec7972dfe154ea9f13d09d9be1)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2016 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 /**
7  * \file
8  * GUID Partition Table (GPT) specification definitions
9  */
10 
11 #ifndef SPDK_GPT_SPEC_H
12 #define SPDK_GPT_SPEC_H
13 
14 #include "spdk/stdinc.h"
15 
16 #include "spdk/assert.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #pragma pack(push, 1)
23 
24 #define SPDK_MBR_SIGNATURE 0xAA55
25 
26 #define SPDK_MBR_OS_TYPE_GPT_PROTECTIVE		0xEE
27 #define SPDK_MBR_OS_TYPE_EFI_SYSTEM_PARTITION	0xEF
28 
29 struct spdk_mbr_chs {
30 	uint8_t head;
31 	uint16_t sector : 6;
32 	uint16_t cylinder : 10;
33 };
34 SPDK_STATIC_ASSERT(sizeof(struct spdk_mbr_chs) == 3, "size incorrect");
35 
36 struct spdk_mbr_partition_entry {
37 	uint8_t reserved : 7;
38 	uint8_t bootable : 1;
39 
40 	struct spdk_mbr_chs start_chs;
41 
42 	uint8_t os_type;
43 
44 	struct spdk_mbr_chs end_chs;
45 
46 	uint32_t start_lba;
47 	uint32_t size_lba;
48 };
49 SPDK_STATIC_ASSERT(sizeof(struct spdk_mbr_partition_entry) == 16, "size incorrect");
50 
51 struct spdk_mbr {
52 	uint8_t boot_code[440];
53 	uint32_t disk_signature;
54 	uint16_t reserved_444;
55 	struct spdk_mbr_partition_entry partitions[4];
56 	uint16_t mbr_signature;
57 };
58 SPDK_STATIC_ASSERT(sizeof(struct spdk_mbr) == 512, "size incorrect");
59 
60 #define SPDK_GPT_SIGNATURE "EFI PART"
61 
62 #define SPDK_GPT_REVISION_1_0 0x00010000u
63 
64 struct spdk_gpt_guid {
65 	uint8_t raw[16];
66 };
67 SPDK_STATIC_ASSERT(sizeof(struct spdk_gpt_guid) == 16, "size incorrect");
68 
69 #define SPDK_GPT_GUID(a, b, c, d, e) \
70 	(struct spdk_gpt_guid){{ \
71 		(uint8_t)(a), (uint8_t)(((uint32_t)a) >> 8), \
72 		(uint8_t)(((uint32_t)a) >> 16), (uint8_t)(((uint32_t)a >> 24)), \
73 		(uint8_t)(b), (uint8_t)(((uint16_t)b) >> 8), \
74 		(uint8_t)(c), (uint8_t)(((uint16_t)c) >> 8), \
75 		(uint8_t)(((uint16_t)d) >> 8), (uint8_t)(d), \
76 		(uint8_t)(((uint64_t)e) >> 40), (uint8_t)(((uint64_t)e) >> 32), (uint8_t)(((uint64_t)e) >> 24), \
77 		(uint8_t)(((uint64_t)e) >> 16), (uint8_t)(((uint64_t)e) >> 8), (uint8_t)(e) \
78 	}}
79 
80 #define SPDK_GPT_PART_TYPE_UNUSED		SPDK_GPT_GUID(0x00000000, 0x0000, 0x0000, 0x0000, 0x000000000000)
81 #define SPDK_GPT_PART_TYPE_EFI_SYSTEM_PARTITION	SPDK_GPT_GUID(0xC12A7328, 0xF81F, 0x11D2, 0xBA4B, 0x00A0C93EC93B)
82 #define SPDK_GPT_PART_TYPE_LEGACY_MBR		SPDK_GPT_GUID(0x024DEE41, 0x33E7, 0x11D3, 0x9D69, 0x0008C781F39F)
83 
84 struct spdk_gpt_header {
85 	char gpt_signature[8];
86 	uint32_t revision;
87 	uint32_t header_size;
88 	uint32_t header_crc32;
89 	uint32_t reserved;
90 	uint64_t my_lba;
91 	uint64_t alternate_lba;
92 	uint64_t first_usable_lba;
93 	uint64_t last_usable_lba;
94 	struct spdk_gpt_guid disk_guid;
95 	uint64_t partition_entry_lba;
96 	uint32_t num_partition_entries;
97 	uint32_t size_of_partition_entry;
98 	uint32_t partition_entry_array_crc32;
99 };
100 SPDK_STATIC_ASSERT(sizeof(struct spdk_gpt_header) == 92, "size incorrect");
101 
102 struct spdk_gpt_partition_entry {
103 	struct spdk_gpt_guid part_type_guid;
104 	struct spdk_gpt_guid unique_partition_guid;
105 	uint64_t starting_lba;
106 	uint64_t ending_lba;
107 	struct {
108 		uint64_t required : 1;
109 		uint64_t no_block_io_proto : 1;
110 		uint64_t legacy_bios_bootable : 1;
111 		uint64_t reserved_uefi : 45;
112 		uint64_t guid_specific : 16;
113 	} attr;
114 	uint16_t partition_name[36];
115 };
116 SPDK_STATIC_ASSERT(sizeof(struct spdk_gpt_partition_entry) == 128, "size incorrect");
117 
118 #pragma pack(pop)
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
125