Imported Upstream version 0.6.3
[platform/upstream/multipath-tools.git] / kpartx / 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, see <http://www.gnu.org/licenses/>.
22 */
23
24 #ifndef _GPT_H
25 #define _GPT_H
26
27
28 #include <inttypes.h>
29 #include "kpartx.h"
30 #include "dos.h"
31 #include "efi.h"
32
33 #define EFI_PMBR_OSTYPE_EFI 0xEF
34 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
35 #define MSDOS_MBR_SIGNATURE 0xaa55
36 #define GPT_BLOCK_SIZE 512
37
38 #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
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 typedef struct _gpt_header {
45         uint64_t signature;
46         uint32_t revision;
47         uint32_t header_size;
48         uint32_t header_crc32;
49         uint32_t reserved1;
50         uint64_t my_lba;
51         uint64_t alternate_lba;
52         uint64_t first_usable_lba;
53         uint64_t last_usable_lba;
54         efi_guid_t disk_guid;
55         uint64_t partition_entry_lba;
56         uint32_t num_partition_entries;
57         uint32_t sizeof_partition_entry;
58         uint32_t partition_entry_array_crc32;
59         uint8_t reserved2[GPT_BLOCK_SIZE - 92];
60 } __attribute__ ((packed)) gpt_header;
61
62 typedef struct _gpt_entry_attributes {
63         uint64_t required_to_function:1;
64         uint64_t reserved:47;
65         uint64_t type_guid_specific:16;
66 } __attribute__ ((packed)) gpt_entry_attributes;
67
68 typedef struct _gpt_entry {
69         efi_guid_t partition_type_guid;
70         efi_guid_t unique_partition_guid;
71         uint64_t starting_lba;
72         uint64_t ending_lba;
73         gpt_entry_attributes attributes;
74         efi_char16_t partition_name[72 / sizeof(efi_char16_t)];
75 } __attribute__ ((packed)) gpt_entry;
76
77
78 /*
79    These values are only defaults.  The actual on-disk structures
80    may define different sizes, so use those unless creating a new GPT disk!
81 */
82
83 #define GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE 16384
84 /*
85    Number of actual partition entries should be calculated
86    as:
87 */
88 #define GPT_DEFAULT_RESERVED_PARTITION_ENTRIES \
89         (GPT_DEFAULT_RESERVED_PARTITION_ENTRY_ARRAY_SIZE / \
90          sizeof(gpt_entry))
91
92
93 /* Protected Master Boot Record  & Legacy MBR share same structure */
94 /* Needs to be packed because the u16s force misalignment. */
95
96 typedef struct _legacy_mbr {
97         uint8_t bootcode[440];
98         uint32_t unique_mbr_signature;
99         uint16_t unknown;
100         struct partition partition[4];
101         uint16_t signature;
102 } __attribute__ ((packed)) legacy_mbr;
103
104
105 #define EFI_GPT_PRIMARY_PARTITION_TABLE_LBA 1
106
107 /* Functions */
108 int read_gpt_pt (int fd, struct slice all, struct slice *sp, int ns);
109
110
111 #endif
112
113 /*
114  * Overrides for Emacs so that we follow Linus's tabbing style.
115  * Emacs will notice this stuff at the end of the file and automatically
116  * adjust the settings for this buffer only.  This must remain at the end
117  * of the file.
118  * ---------------------------------------------------------------------------
119  * Local variables:
120  * c-indent-level: 4
121  * c-brace-imaginary-offset: 0
122  * c-brace-offset: -4
123  * c-argdecl-indent: 4
124  * c-label-offset: -4
125  * c-continued-statement-offset: 4
126  * c-continued-brace-offset: 0
127  * indent-tabs-mode: nil
128  * tab-width: 8
129  * End:
130  */