1 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/builtins.c grub-0.96-patched/stage2/builtins.c
2 --- grub-0.96/stage2/builtins.c 2004-06-20 09:33:04.000000000 -0400
3 +++ grub-0.96-patched/stage2/builtins.c 2007-01-04 13:56:06.000000000 -0500
4 @@ -1229,14 +1229,15 @@
5 for (drive = 0x80; drive < 0x88; drive++)
7 unsigned long part = 0xFFFFFF;
8 - unsigned long start, len, offset, ext_offset;
10 + unsigned long start, len, offset, ext_offset, gpt_offset;
11 + int type, entry, gpt_count, gpt_size;
12 char buf[SECTOR_SIZE];
14 current_drive = drive;
15 while (next_partition (drive, 0xFFFFFF, &part, &type,
16 &start, &len, &offset, &entry,
18 + &ext_offset, &gpt_offset,
19 + &gpt_count, &gpt_size, buf))
21 if (type != PC_SLICE_TYPE_NONE
22 && ! IS_PC_SLICE_TYPE_BSD (type)
26 unsigned long part = 0xFFFFFF;
27 - unsigned long start, len, offset, ext_offset;
29 + unsigned long start, len, offset, ext_offset, gpt_offset;
30 + int entry, type, gpt_count, gpt_size;
33 /* Get the drive and the partition. */
34 @@ -2844,7 +2845,14 @@
35 /* Look for the partition. */
36 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
37 &start, &len, &offset, &entry,
39 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
40 + /* The partition may not be a GPT partition. */
41 + if (gpt_offset != 0)
43 + errnum = ERR_BAD_ARGUMENT;
48 if (part == current_partition)
50 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/disk_io.c grub-0.96-patched/stage2/disk_io.c
51 --- grub-0.96/stage2/disk_io.c 2004-05-23 12:35:24.000000000 -0400
52 +++ grub-0.96-patched/stage2/disk_io.c 2007-01-04 14:01:08.000000000 -0500
59 #ifdef SUPPORT_NETBOOT
62 set_partition_hidden_flag (int hidden)
64 unsigned long part = 0xFFFFFF;
65 - unsigned long start, len, offset, ext_offset;
67 + unsigned long start, len, offset, ext_offset, gpt_offset;
68 + int entry, type, gpt_count, gpt_size;
71 /* The drive must be a hard disk. */
73 /* Look for the partition. */
74 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
75 &start, &len, &offset, &entry,
77 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
78 + /* The partition may not be a GPT partition. */
79 + if (gpt_offset != 0)
81 + errnum = ERR_BAD_ARGUMENT;
86 if (part == current_partition)
89 unsigned long *partition, int *type,
90 unsigned long *start, unsigned long *len,
91 unsigned long *offset, int *entry,
92 - unsigned long *ext_offset, char *buf)
93 + unsigned long *ext_offset,
94 + unsigned long *gpt_offset, int *gpt_count,
95 + int *gpt_size, char *buf)
97 /* Forward declarations. */
98 auto int next_bsd_partition (void);
99 auto int next_pc_slice (void);
100 + auto int next_gpt_slice(void);
102 /* Get next BSD partition in current PC slice. */
103 int next_bsd_partition (void)
108 + /* If this is a GPT partition table, read it as such. */
109 + if (*entry == -1 && *offset == 0 && PC_SLICE_TYPE (buf, 0) == PC_SLICE_TYPE_GPT)
111 + struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf;
113 + /* Read in the GPT Partition table header. */
114 + if (! rawread (drive, 1, 0, SECTOR_SIZE, buf))
117 + if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000)
119 + /* Let gpt_offset point to the first entry in the GPT
120 + partition table. This can also be used by callers of
121 + next_partition to determine if a entry comes from a
122 + GPT partition table or not. */
123 + *gpt_offset = hdr->partitions;
124 + *gpt_count = hdr->maxpart;
125 + *gpt_size = hdr->partentry_size;
127 + return next_gpt_slice();
131 + /* This is not a valid header for a GPT partition table.
132 + Re-read the MBR or the boot sector of the extended
134 + if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf))
139 + /* Not a GPT partition. */
142 /* Increase the entry number. */
149 + /* Get the next GPT slice. */
150 + int next_gpt_slice (void)
152 + struct grub_gpt_partentry *gptentry = (struct grub_gpt_partentry *) buf;
153 + /* Make GPT partitions show up as PC slices. */
154 + int pc_slice_no = (*partition & 0xFF0000) >> 16;
156 + /* If this is the first time... */
157 + if (pc_slice_no == 0xFF)
166 + if (*entry >= *gpt_count)
168 + errnum = ERR_NO_PART;
171 + /* Read in the GPT Partition table entry. */
172 + if (! rawread (drive, (*gpt_offset) + GPT_ENTRY_SECTOR (*gpt_size, *entry), GPT_ENTRY_INDEX (*gpt_size, *entry), *gpt_size, buf))
174 + } while (! (gptentry->type1 && gptentry->type2));
177 + *start = gptentry->start;
178 + *len = gptentry->end - gptentry->start + 1;
179 + *type = PC_SLICE_TYPE_EXT2FS;
180 + *entry = pc_slice_no;
181 + *partition = (*entry << 16) | 0xFFFF;
186 /* Start the body of this function. */
193 + if (*partition != 0xFFFFFF && *gpt_offset != 0)
194 + return next_gpt_slice ();
196 /* If previous partition is a BSD partition or a PC slice which
197 contains BSD partitions... */
198 if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff))
200 unsigned long dest_partition = current_partition;
201 unsigned long part_offset;
202 unsigned long ext_offset;
203 + unsigned long gpt_offset;
207 char buf[SECTOR_SIZE];
208 int bsd_part, pc_slice;
210 int ret = next_partition (current_drive, dest_partition,
211 ¤t_partition, ¤t_slice,
212 &part_start, &part_length,
213 - &part_offset, &entry, &ext_offset, buf);
214 + &part_offset, &entry, &ext_offset,
215 + &gpt_offset, &gpt_count, &gpt_size, buf);
216 bsd_part = (current_partition >> 8) & 0xFF;
217 pc_slice = current_partition >> 16;
219 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/gpt.h grub-0.96-patched/stage2/gpt.h
220 --- grub-0.96/stage2/gpt.h 1969-12-31 19:00:00.000000000 -0500
221 +++ grub-0.96-patched/stage2/gpt.h 2007-01-04 13:52:14.000000000 -0500
224 + * GRUB -- GRand Unified Bootloader
225 + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
227 + * This program is free software; you can redistribute it and/or modify
228 + * it under the terms of the GNU General Public License as published by
229 + * the Free Software Foundation; either version 2 of the License, or
230 + * (at your option) any later version.
232 + * This program is distributed in the hope that it will be useful,
233 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
234 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
235 + * GNU General Public License for more details.
237 + * You should have received a copy of the GNU General Public License
238 + * along with this program; if not, write to the Free Software
239 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
245 +typedef signed char grub_int8_t;
246 +typedef signed short grub_int16_t;
247 +typedef signed int grub_int32_t;
248 +typedef signed long long int grub_int64_t;
249 +typedef unsigned char grub_uint8_t;
250 +typedef unsigned short grub_uint16_t;
251 +typedef unsigned int grub_uint32_t;
252 +typedef unsigned long long int grub_uint64_t;
254 +struct grub_gpt_header
256 + grub_uint64_t magic;
257 + grub_uint32_t version;
258 + grub_uint32_t headersize;
259 + grub_uint32_t crc32;
260 + grub_uint32_t unused1;
261 + grub_uint64_t primary;
262 + grub_uint64_t backup;
263 + grub_uint64_t start;
265 + grub_uint8_t guid[16];
266 + grub_uint64_t partitions;
267 + grub_uint32_t maxpart;
268 + grub_uint32_t partentry_size;
269 + grub_uint32_t partentry_crc32;
270 +} __attribute__ ((packed));
272 +struct grub_gpt_partentry
274 + grub_uint64_t type1;
275 + grub_uint64_t type2;
276 + grub_uint8_t guid[16];
277 + grub_uint64_t start;
279 + grub_uint8_t attrib;
281 +} __attribute__ ((packed));
283 +#define GPT_HEADER_MAGIC 0x5452415020494645UL
285 +#define GPT_ENTRY_SECTOR(size,entry) \
286 + ((((entry) * (size) + 1) & ~(SECTOR_SIZE - 1)) >> SECTOR_BITS)
287 +#define GPT_ENTRY_INDEX(size,entry) \
288 + ((((entry) * (size) + 1) & (SECTOR_SIZE - 1)) - 1)
291 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/pc_slice.h grub-0.96-patched/stage2/pc_slice.h
292 --- grub-0.96/stage2/pc_slice.h 2003-07-09 07:45:53.000000000 -0400
293 +++ grub-0.96-patched/stage2/pc_slice.h 2007-01-04 13:52:14.000000000 -0500
295 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
296 #define PC_SLICE_TYPE_VSTAFS 0x9e
297 #define PC_SLICE_TYPE_DELL_UTIL 0xde
298 +#define PC_SLICE_TYPE_GPT 0xee
299 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
302 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/shared.h grub-0.96-patched/stage2/shared.h
303 --- grub-0.96/stage2/shared.h 2004-06-19 12:40:09.000000000 -0400
304 +++ grub-0.96-patched/stage2/shared.h 2007-01-04 13:52:15.000000000 -0500
306 unsigned long *partition, int *type,
307 unsigned long *start, unsigned long *len,
308 unsigned long *offset, int *entry,
309 - unsigned long *ext_offset, char *buf);
310 + unsigned long *ext_offset,
311 + unsigned long *gpt_offset, int *gpt_count,
312 + int *gpt_size, char *buf);
314 /* Sets device to the one represented by the SAVED_* parameters. */
315 int make_saved_active (void);