1 |
robbat2 08/03/01 21:06:48 |
2 |
|
3 |
Added: 600_all_grub-0.97-gpt-partition-table.patch |
4 |
Log: |
5 |
Add GPT support per bug #178586. |
6 |
|
7 |
Revision Changes Path |
8 |
1.1 src/patchsets/grub/0.97/600_all_grub-0.97-gpt-partition-table.patch |
9 |
|
10 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/grub/0.97/600_all_grub-0.97-gpt-partition-table.patch?rev=1.1&view=markup |
11 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/src/patchsets/grub/0.97/600_all_grub-0.97-gpt-partition-table.patch?rev=1.1&content-type=text/plain |
12 |
|
13 |
Index: 600_all_grub-0.97-gpt-partition-table.patch |
14 |
=================================================================== |
15 |
Gentoo bug #178586 - Add support for a GPT partition table. |
16 |
|
17 |
This was originally posted at http://www.mail-archive.com/bug-grub@×××.org/msg10632.html |
18 |
but it contained a couple of misplaced braces after where statements, causing |
19 |
the intended bodies of the while statements to never execute. |
20 |
|
21 |
diff -Nuar --exclude '*.orig' grub-0.97.orig/stage2/builtins.c grub-0.97/stage2/builtins.c |
22 |
--- grub-0.97.orig/stage2/builtins.c 2008-02-29 18:14:44.646824000 -0800 |
23 |
+++ grub-0.97/stage2/builtins.c 2008-02-29 18:18:49.442695487 -0800 |
24 |
@@ -1400,14 +1400,15 @@ |
25 |
for (drive = 0x80; drive < 0x88; drive++) |
26 |
{ |
27 |
unsigned long part = 0xFFFFFF; |
28 |
- unsigned long start, len, offset, ext_offset; |
29 |
- int type, entry; |
30 |
+ unsigned long start, len, offset, ext_offset, gpt_offset; |
31 |
+ int type, entry, gpt_count, gpt_size; |
32 |
char buf[SECTOR_SIZE]; |
33 |
|
34 |
current_drive = drive; |
35 |
while (next_partition (drive, 0xFFFFFF, &part, &type, |
36 |
&start, &len, &offset, &entry, |
37 |
- &ext_offset, buf)) |
38 |
+ &ext_offset, &gpt_offset, |
39 |
+ &gpt_count, &gpt_size, buf)) |
40 |
{ |
41 |
if (type != PC_SLICE_TYPE_NONE |
42 |
&& ! IS_PC_SLICE_TYPE_BSD (type) |
43 |
@@ -3004,8 +3005,8 @@ |
44 |
{ |
45 |
int new_type; |
46 |
unsigned long part = 0xFFFFFF; |
47 |
- unsigned long start, len, offset, ext_offset; |
48 |
- int entry, type; |
49 |
+ unsigned long start, len, offset, ext_offset, gpt_offset; |
50 |
+ int entry, type, gpt_count, gpt_size; |
51 |
char mbr[512]; |
52 |
|
53 |
/* Get the drive and the partition. */ |
54 |
@@ -3042,8 +3043,15 @@ |
55 |
/* Look for the partition. */ |
56 |
while (next_partition (current_drive, 0xFFFFFF, &part, &type, |
57 |
&start, &len, &offset, &entry, |
58 |
- &ext_offset, mbr)) |
59 |
+ &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr)) |
60 |
{ |
61 |
+ /* The partition may not be a GPT partition. */ |
62 |
+ if (gpt_offset != 0) |
63 |
+ { |
64 |
+ errnum = ERR_BAD_ARGUMENT; |
65 |
+ return 1; |
66 |
+ } |
67 |
+ |
68 |
if (part == current_partition) |
69 |
{ |
70 |
/* Found. */ |
71 |
diff -Nuar --exclude '*.orig' grub-0.97.orig/stage2/disk_io.c grub-0.97/stage2/disk_io.c |
72 |
--- grub-0.97.orig/stage2/disk_io.c 2008-02-29 18:14:44.773490000 -0800 |
73 |
+++ grub-0.97/stage2/disk_io.c 2008-02-29 18:17:40.303271859 -0800 |
74 |
@@ -21,6 +21,7 @@ |
75 |
|
76 |
#include <shared.h> |
77 |
#include <filesys.h> |
78 |
+#include <gpt.h> |
79 |
|
80 |
#ifdef SUPPORT_NETBOOT |
81 |
# define GRUB 1 |
82 |
@@ -502,8 +503,8 @@ |
83 |
set_partition_hidden_flag (int hidden) |
84 |
{ |
85 |
unsigned long part = 0xFFFFFF; |
86 |
- unsigned long start, len, offset, ext_offset; |
87 |
- int entry, type; |
88 |
+ unsigned long start, len, offset, ext_offset, gpt_offset; |
89 |
+ int entry, type, gpt_count, gpt_size; |
90 |
char mbr[512]; |
91 |
|
92 |
/* The drive must be a hard disk. */ |
93 |
@@ -524,8 +525,15 @@ |
94 |
/* Look for the partition. */ |
95 |
while (next_partition (current_drive, 0xFFFFFF, &part, &type, |
96 |
&start, &len, &offset, &entry, |
97 |
- &ext_offset, mbr)) |
98 |
+ &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr)) |
99 |
{ |
100 |
+ /* The partition may not be a GPT partition. */ |
101 |
+ if (gpt_offset != 0) |
102 |
+ { |
103 |
+ errnum = ERR_BAD_ARGUMENT; |
104 |
+ return 1; |
105 |
+ } |
106 |
+ |
107 |
if (part == current_partition) |
108 |
{ |
109 |
/* Found. */ |
110 |
@@ -577,11 +585,14 @@ |
111 |
unsigned long *partition, int *type, |
112 |
unsigned long *start, unsigned long *len, |
113 |
unsigned long *offset, int *entry, |
114 |
- unsigned long *ext_offset, char *buf) |
115 |
+ unsigned long *ext_offset, |
116 |
+ unsigned long *gpt_offset, int *gpt_count, |
117 |
+ int *gpt_size, char *buf) |
118 |
{ |
119 |
/* Forward declarations. */ |
120 |
auto int next_bsd_partition (void); |
121 |
auto int next_pc_slice (void); |
122 |
+ auto int next_gpt_slice(void); |
123 |
|
124 |
/* Get next BSD partition in current PC slice. */ |
125 |
int next_bsd_partition (void) |
126 |
@@ -666,6 +677,40 @@ |
127 |
return 0; |
128 |
} |
129 |
|
130 |
+ /* If this is a GPT partition table, read it as such. */ |
131 |
+ if (*entry == -1 && *offset == 0 && PC_SLICE_TYPE (buf, 0) == PC_SLICE_TYPE_GPT) |
132 |
+ { |
133 |
+ struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf; |
134 |
+ |
135 |
+ /* Read in the GPT Partition table header. */ |
136 |
+ if (! rawread (drive, 1, 0, SECTOR_SIZE, buf)) |
137 |
+ return 0; |
138 |
+ |
139 |
+ if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000) |
140 |
+ { |
141 |
+ /* Let gpt_offset point to the first entry in the GPT |
142 |
+ partition table. This can also be used by callers of |
143 |
+ next_partition to determine if a entry comes from a |
144 |
+ GPT partition table or not. */ |
145 |
+ *gpt_offset = hdr->partitions; |
146 |
+ *gpt_count = hdr->maxpart; |
147 |
+ *gpt_size = hdr->partentry_size; |
148 |
+ |
149 |
+ return next_gpt_slice(); |
150 |
+ } |
151 |
+ else |
152 |
+ { |
153 |
+ /* This is not a valid header for a GPT partition table. |
154 |
+ Re-read the MBR or the boot sector of the extended |
155 |
+ partition. */ |
156 |
+ if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf)) |
157 |
+ return 0; |
158 |
+ } |
159 |
+ } |
160 |
+ |
161 |
+ /* Not a GPT partition. */ |
162 |
+ *gpt_offset = 0; |
163 |
+ |
164 |
/* Increase the entry number. */ |
165 |
(*entry)++; |
166 |
|
167 |
@@ -710,6 +755,43 @@ |
168 |
return 1; |
169 |
} |
170 |
|
171 |
+ /* Get the next GPT slice. */ |
172 |
+ int next_gpt_slice (void) |
173 |
+ { |
174 |
+ struct grub_gpt_partentry *gptentry = (struct grub_gpt_partentry *) buf; |
175 |
+ /* Make GPT partitions show up as PC slices. */ |
176 |
+ int pc_slice_no = (*partition & 0xFF0000) >> 16; |
177 |
+ |
178 |
+ /* If this is the first time... */ |
179 |
+ if (pc_slice_no == 0xFF) |
180 |
+ { |
181 |
+ pc_slice_no = -1; |
182 |
+ *entry = -1; |
183 |
+ } |
184 |
+ |
185 |
+ do { |
186 |
+ (*entry)++; |
187 |
+ |
188 |
+ if (*entry >= *gpt_count) |
189 |
+ { |
190 |
+ errnum = ERR_NO_PART; |
191 |
+ return 0; |
192 |
+ } |
193 |
+ /* Read in the GPT Partition table entry. */ |
194 |
+ if (! rawread (drive, (*gpt_offset) + GPT_ENTRY_SECTOR (*gpt_size, *entry), GPT_ENTRY_INDEX (*gpt_size, *entry), *gpt_size, buf)) |
195 |
+ return 0; |
196 |
+ } while (! (gptentry->type1 && gptentry->type2)); |
197 |
+ |
198 |
+ pc_slice_no++; |
199 |
+ *start = gptentry->start; |
200 |
+ *len = gptentry->end - gptentry->start + 1; |
201 |
+ *type = PC_SLICE_TYPE_EXT2FS; |
202 |
+ *entry = pc_slice_no; |
203 |
+ *partition = (*entry << 16) | 0xFFFF; |
204 |
+ |
205 |
+ return 1; |
206 |
+ } |
207 |
+ |
208 |
/* Start the body of this function. */ |
209 |
|
210 |
#ifndef STAGE1_5 |
211 |
@@ -717,6 +799,9 @@ |
212 |
return 0; |
213 |
#endif |
214 |
|
215 |
+ if (*partition != 0xFFFFFF && *gpt_offset != 0) |
216 |
+ return next_gpt_slice (); |
217 |
+ |
218 |
/* If previous partition is a BSD partition or a PC slice which |
219 |
contains BSD partitions... */ |
220 |
if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff)) |
221 |
@@ -755,6 +840,9 @@ |
222 |
unsigned long dest_partition = current_partition; |
223 |
unsigned long part_offset; |
224 |
unsigned long ext_offset; |
225 |
+ unsigned long gpt_offset; |
226 |
+ int gpt_count; |
227 |
+ int gpt_size; |
228 |
int entry; |
229 |
char buf[SECTOR_SIZE]; |
230 |
int bsd_part, pc_slice; |
231 |
@@ -766,7 +854,8 @@ |
232 |
int ret = next_partition (current_drive, dest_partition, |
233 |
¤t_partition, ¤t_slice, |
234 |
&part_start, &part_length, |
235 |
- &part_offset, &entry, &ext_offset, buf); |
236 |
+ &part_offset, &entry, &ext_offset, |
237 |
+ &gpt_offset, &gpt_count, &gpt_size, buf); |
238 |
bsd_part = (current_partition >> 8) & 0xFF; |
239 |
pc_slice = current_partition >> 16; |
240 |
return ret; |
241 |
diff -Nuar --exclude '*.orig' grub-0.97.orig/stage2/gpt.h grub-0.97/stage2/gpt.h |
242 |
--- grub-0.97.orig/stage2/gpt.h 1969-12-31 16:00:00.000000000 -0800 |
243 |
+++ grub-0.97/stage2/gpt.h 2008-02-29 18:15:31.659319242 -0800 |
244 |
@@ -0,0 +1,68 @@ |
245 |
+/* |
246 |
+ * GRUB -- GRand Unified Bootloader |
247 |
+ * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc. |
248 |
+ * |
249 |
+ * This program is free software; you can redistribute it and/or modify |
250 |
+ * it under the terms of the GNU General Public License as published by |
251 |
+ * the Free Software Foundation; either version 2 of the License, or |
252 |
+ * (at your option) any later version. |
253 |
+ * |
254 |
+ * This program is distributed in the hope that it will be useful, |
255 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
256 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
257 |
+ * GNU General Public License for more details. |
258 |
+ * |
259 |
+ * You should have received a copy of the GNU General Public License |
260 |
+ * along with this program; if not, write to the Free Software |
261 |
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
262 |
+ */ |
263 |
+ |
264 |
+#ifndef _GPT_H |
265 |
+#define _GPT_H |
266 |
+ |
267 |
+typedef signed char grub_int8_t; |
268 |
+typedef signed short grub_int16_t; |
269 |
+typedef signed int grub_int32_t; |
270 |
+typedef signed long long int grub_int64_t; |
271 |
+typedef unsigned char grub_uint8_t; |
272 |
+typedef unsigned short grub_uint16_t; |
273 |
+typedef unsigned int grub_uint32_t; |
274 |
+typedef unsigned long long int grub_uint64_t; |
275 |
+ |
276 |
+struct grub_gpt_header |
277 |
+{ |
278 |
+ grub_uint64_t magic; |
279 |
+ grub_uint32_t version; |
280 |
+ grub_uint32_t headersize; |
281 |
+ grub_uint32_t crc32; |
282 |
+ grub_uint32_t unused1; |
283 |
+ grub_uint64_t primary; |
284 |
+ grub_uint64_t backup; |
285 |
+ grub_uint64_t start; |
286 |
+ grub_uint64_t end; |
287 |
+ grub_uint8_t guid[16]; |
288 |
+ grub_uint64_t partitions; |
289 |
+ grub_uint32_t maxpart; |
290 |
+ grub_uint32_t partentry_size; |
291 |
+ grub_uint32_t partentry_crc32; |
292 |
+} __attribute__ ((packed)); |
293 |
+ |
294 |
+struct grub_gpt_partentry |
295 |
+{ |
296 |
+ grub_uint64_t type1; |
297 |
+ grub_uint64_t type2; |
298 |
+ grub_uint8_t guid[16]; |
299 |
+ grub_uint64_t start; |
300 |
+ grub_uint64_t end; |
301 |
+ grub_uint8_t attrib; |
302 |
+ char name[72]; |
303 |
+} __attribute__ ((packed)); |
304 |
+ |
305 |
+#define GPT_HEADER_MAGIC 0x5452415020494645UL |
306 |
+ |
307 |
+#define GPT_ENTRY_SECTOR(size,entry) \ |
308 |
+ ((((entry) * (size) + 1) & ~(SECTOR_SIZE - 1)) >> SECTOR_BITS) |
309 |
+#define GPT_ENTRY_INDEX(size,entry) \ |
310 |
+ ((((entry) * (size) + 1) & (SECTOR_SIZE - 1)) - 1) |
311 |
+ |
312 |
+#endif /* _GPT_H */ |
313 |
diff -Nuar --exclude '*.orig' grub-0.97.orig/stage2/pc_slice.h grub-0.97/stage2/pc_slice.h |
314 |
--- grub-0.97.orig/stage2/pc_slice.h 2003-07-09 04:45:53.000000000 -0700 |
315 |
+++ grub-0.97/stage2/pc_slice.h 2008-02-29 18:15:31.659319242 -0800 |
316 |
@@ -115,6 +115,7 @@ |
317 |
#define PC_SLICE_TYPE_LINUX_EXTENDED 0x85 |
318 |
#define PC_SLICE_TYPE_VSTAFS 0x9e |
319 |
#define PC_SLICE_TYPE_DELL_UTIL 0xde |
320 |
+#define PC_SLICE_TYPE_GPT 0xee |
321 |
#define PC_SLICE_TYPE_LINUX_RAID 0xfd |
322 |
|
323 |
|
324 |
diff -Nuar --exclude '*.orig' grub-0.97.orig/stage2/shared.h grub-0.97/stage2/shared.h |
325 |
--- grub-0.97.orig/stage2/shared.h 2008-02-29 18:14:44.646824000 -0800 |
326 |
+++ grub-0.97/stage2/shared.h 2008-02-29 18:15:31.659319242 -0800 |
327 |
@@ -935,7 +935,9 @@ |
328 |
unsigned long *partition, int *type, |
329 |
unsigned long *start, unsigned long *len, |
330 |
unsigned long *offset, int *entry, |
331 |
- unsigned long *ext_offset, char *buf); |
332 |
+ unsigned long *ext_offset, |
333 |
+ unsigned long *gpt_offset, int *gpt_count, |
334 |
+ int *gpt_size, char *buf); |
335 |
|
336 |
/* Sets device to the one represented by the SAVED_* parameters. */ |
337 |
int make_saved_active (void); |
338 |
|
339 |
|
340 |
|
341 |
-- |
342 |
gentoo-commits@l.g.o mailing list |