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