Imported Debian patch 0.5.3-1.1
[debian/efibootmgr] / src / include / gpt.h
1 /*
2     gpt.[ch]
3
4     Copyright (C) 2000-2001 Dell Computer Corporation <Matt_Domsch@dell.com> 
5
6     EFI GUID Partition Table handling
7     Per Intel EFI Specification v1.02
8     http://developer.intel.com/technology/efi/efi.htm
9
10     This program is free software; you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation; either version 2 of the License, or
13     (at your option) any later version.
14
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20     You should have received a copy of the GNU General Public License
21     along with this program; if not, write to the Free Software
22     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 */
24
25 #ifndef _GPT_H
26 #define _GPT_H
27
28
29 #include <inttypes.h>
30 #include "efi.h"
31
32 #define EFI_PMBR_OSTYPE_EFI 0xEF
33 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
34 #define MSDOS_MBR_SIGNATURE 0xaa55
35 #define GPT_BLOCK_SIZE 512
36
37
38 #define GPT_HEADER_SIGNATURE ((uint64_t)(0x5452415020494645LL))
39 #define GPT_HEADER_REVISION_V1_02 0x00010200
40 #define GPT_HEADER_REVISION_V1_00 0x00010000
41 #define GPT_HEADER_REVISION_V0_99 0x00009900
42 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
43
44 #define PARTITION_SYSTEM_GUID \
45     EFI_GUID( 0xC12A7328, 0xF81F, 0x11d2, \
46               0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B) 
47 #define LEGACY_MBR_PARTITION_GUID \
48     EFI_GUID( 0x024DEE41, 0x33E7, 0x11d3, \
49               0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F)
50 #define PARTITION_MSFT_RESERVED_GUID \
51     EFI_GUID( 0xE3C9E316, 0x0B5C, 0x4DB8, \
52               0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE)
53 #define PARTITION_BASIC_DATA_GUID \
54     EFI_GUID( 0xEBD0A0A2, 0xB9E5, 0x4433, \
55               0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7)
56 #define PARTITION_LINUX_RAID_GUID \
57     EFI_GUID( 0xa19d880f, 0x05fc, 0x4d3b, \
58               0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e)
59 #define PARTITION_LINUX_SWAP_GUID \
60     EFI_GUID( 0x0657fd6d, 0xa4ab, 0x43c4, \
61               0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f)
62 #define PARTITION_LINUX_LVM_GUID \
63     EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
64               0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
65
66 typedef struct _gpt_header {
67         uint64_t signature;
68         uint32_t revision;
69         uint32_t header_size;
70         uint32_t header_crc32;
71         uint32_t reserved1;
72         uint64_t my_lba;
73         uint64_t alternate_lba;
74         uint64_t first_usable_lba;
75         uint64_t last_usable_lba;
76         efi_guid_t disk_guid;
77         uint64_t partition_entry_lba;
78         uint32_t num_partition_entries;
79         uint32_t sizeof_partition_entry;
80         uint32_t partition_entry_array_crc32;
81         uint8_t reserved2[GPT_BLOCK_SIZE - 92];
82 } __attribute__ ((packed)) gpt_header;
83
84 typedef struct _gpt_entry_attributes {
85         uint64_t required_to_function:1;
86         uint64_t reserved:47;
87         uint64_t type_guid_specific:16;
88 } __attribute__ ((packed)) gpt_entry_attributes;
89
90 typedef struct _gpt_entry {
91         efi_guid_t partition_type_guid;
92         efi_guid_t unique_partition_guid;
93         uint64_t starting_lba;
94         uint64_t ending_lba;
95         gpt_entry_attributes attributes;
96         efi_char16_t partition_name[72 / sizeof(efi_char16_t)];
97 } __attribute__ ((packed)) gpt_entry;
98
99
100 /* 
101    These values are only defaults.  The actual on-disk structures
102    may define different sizes, so use those unless creating a new GPT disk!
103 */
104
105 #define GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE 16384
106 /* 
107    Number of actual partition entries should be calculated
108    as: 
109 */
110 #define GPT_DEFAULT_RESERVED_PARTITION_ENTRIES \
111         (GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE / \
112          sizeof(gpt_entry))
113
114
115 typedef struct _partition_record {
116         uint8_t boot_indicator; /* Not used by EFI firmware. Set to 0x80 to indicate that this
117                                    is the bootable legacy partition. */
118         uint8_t start_head;             /* Start of partition in CHS address, not used by EFI firmware. */
119         uint8_t start_sector;   /* Start of partition in CHS address, not used by EFI firmware. */
120         uint8_t start_track;    /* Start of partition in CHS address, not used by EFI firmware. */
121         uint8_t os_type;                /* OS type. A value of 0xEF defines an EFI system partition.
122                                    Other values are reserved for legacy operating systems, and
123                                    allocated independently of the EFI specification. */
124         uint8_t end_head;               /* End of partition in CHS address, not used by EFI firmware. */
125         uint8_t end_sector;             /* End of partition in CHS address, not used by EFI firmware. */
126         uint8_t end_track;              /* End of partition in CHS address, not used by EFI firmware. */
127         uint32_t starting_lba;  /* Starting LBA address of the partition on the disk. Used by
128                                    EFI firmware to define the start of the partition. */
129         uint32_t size_in_lba;   /* Size of partition in LBA. Used by EFI firmware to determine
130                                    the size of the partition. */
131 } __attribute__ ((packed)) partition_record;
132
133
134 /* Protected Master Boot Record  & Legacy MBR share same structure */
135 /* Needs to be packed because the u16s force misalignment. */
136
137 typedef struct _legacy_mbr {
138         uint8_t bootcode[440];
139         uint32_t unique_mbr_signature;
140         uint16_t unknown;
141         partition_record partition[4];
142         uint16_t signature;
143 } __attribute__ ((packed)) legacy_mbr;
144
145
146
147
148 #define EFI_GPT_PRIMARY_PARTITION_TABLE_LBA 1
149
150 /* Functions */
151 int gpt_disk_get_partition_info (int fd, 
152                                  uint32_t num,
153                                  uint64_t *start, uint64_t *size,
154                                  char *signature,
155                                  uint8_t *mbr_type, uint8_t *signature_type);
156
157
158 #endif
159
160 /*
161  * Overrides for Emacs so that we follow Linus's tabbing style.
162  * Emacs will notice this stuff at the end of the file and automatically
163  * adjust the settings for this buffer only.  This must remain at the end
164  * of the file.
165  * ---------------------------------------------------------------------------
166  * Local variables:
167  * c-indent-level: 4 
168  * c-brace-imaginary-offset: 0
169  * c-brace-offset: -4
170  * c-argdecl-indent: 4
171  * c-label-offset: -4
172  * c-continued-statement-offset: 4
173  * c-continued-brace-offset: 0
174  * indent-tabs-mode: nil
175  * tab-width: 8
176  * End:
177  */