1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # T2 SDE: package/.../grub/grub-0.96-gpt.patch
5 # Copyright (C) 2008 The T2 SDE Project
7 # More information can be found in the files COPYING and README.
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
15 # --- T2-COPYRIGHT-NOTE-END ---
17 http://files.bitleap.com/software/grub/grub-0.96-gpt_partition_support.patch
18 http://www.bitleap.com/blog/2007/01/22/reissued-gpt-patch-for-grub-096/
20 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/builtins.c grub-0.96-patched/stage2/builtins.c
21 --- grub-0.96/stage2/builtins.c 2004-06-20 09:33:04.000000000 -0400
22 +++ grub-0.96-patched/stage2/builtins.c 2007-01-04 13:56:06.000000000 -0500
23 @@ -1229,14 +1229,15 @@
24 for (drive = 0x80; drive < 0x88; drive++)
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 type, entry, gpt_count, gpt_size;
31 char buf[SECTOR_SIZE];
33 current_drive = drive;
34 while (next_partition (drive, 0xFFFFFF, &part, &type,
35 &start, &len, &offset, &entry,
37 + &ext_offset, &gpt_offset,
38 + &gpt_count, &gpt_size, buf))
40 if (type != PC_SLICE_TYPE_NONE
41 && ! IS_PC_SLICE_TYPE_BSD (type)
45 unsigned long part = 0xFFFFFF;
46 - unsigned long start, len, offset, ext_offset;
48 + unsigned long start, len, offset, ext_offset, gpt_offset;
49 + int entry, type, gpt_count, gpt_size;
52 /* Get the drive and the partition. */
53 @@ -2844,7 +2845,14 @@
54 /* Look for the partition. */
55 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
56 &start, &len, &offset, &entry,
58 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
59 + /* The partition may not be a GPT partition. */
60 + if (gpt_offset != 0)
62 + errnum = ERR_BAD_ARGUMENT;
67 if (part == current_partition)
69 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/disk_io.c grub-0.96-patched/stage2/disk_io.c
70 --- grub-0.96/stage2/disk_io.c 2004-05-23 12:35:24.000000000 -0400
71 +++ grub-0.96-patched/stage2/disk_io.c 2007-01-04 14:01:08.000000000 -0500
78 #ifdef SUPPORT_NETBOOT
81 set_partition_hidden_flag (int hidden)
83 unsigned long part = 0xFFFFFF;
84 - unsigned long start, len, offset, ext_offset;
86 + unsigned long start, len, offset, ext_offset, gpt_offset;
87 + int entry, type, gpt_count, gpt_size;
90 /* The drive must be a hard disk. */
92 /* Look for the partition. */
93 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
94 &start, &len, &offset, &entry,
96 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
97 + /* The partition may not be a GPT partition. */
98 + if (gpt_offset != 0)
100 + errnum = ERR_BAD_ARGUMENT;
105 if (part == current_partition)
107 @@ -577,11 +585,14 @@
108 unsigned long *partition, int *type,
109 unsigned long *start, unsigned long *len,
110 unsigned long *offset, int *entry,
111 - unsigned long *ext_offset, char *buf)
112 + unsigned long *ext_offset,
113 + unsigned long *gpt_offset, int *gpt_count,
114 + int *gpt_size, char *buf)
116 /* Forward declarations. */
117 auto int next_bsd_partition (void);
118 auto int next_pc_slice (void);
119 + auto int next_gpt_slice(void);
121 /* Get next BSD partition in current PC slice. */
122 int next_bsd_partition (void)
127 + /* If this is a GPT partition table, read it as such. */
128 + if (*entry == -1 && *offset == 0 && PC_SLICE_TYPE (buf, 0) == PC_SLICE_TYPE_GPT)
130 + struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf;
132 + /* Read in the GPT Partition table header. */
133 + if (! rawread (drive, 1, 0, SECTOR_SIZE, buf))
136 + if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000)
138 + /* Let gpt_offset point to the first entry in the GPT
139 + partition table. This can also be used by callers of
140 + next_partition to determine if a entry comes from a
141 + GPT partition table or not. */
142 + *gpt_offset = hdr->partitions;
143 + *gpt_count = hdr->maxpart;
144 + *gpt_size = hdr->partentry_size;
146 + return next_gpt_slice();
150 + /* This is not a valid header for a GPT partition table.
151 + Re-read the MBR or the boot sector of the extended
153 + if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf))
158 + /* Not a GPT partition. */
161 /* Increase the entry number. */
168 + /* Get the next GPT slice. */
169 + int next_gpt_slice (void)
171 + struct grub_gpt_partentry *gptentry = (struct grub_gpt_partentry *) buf;
172 + /* Make GPT partitions show up as PC slices. */
173 + int pc_slice_no = (*partition & 0xFF0000) >> 16;
175 + /* If this is the first time... */
176 + if (pc_slice_no == 0xFF)
185 + if (*entry >= *gpt_count)
187 + errnum = ERR_NO_PART;
190 + /* Read in the GPT Partition table entry. */
191 + if (! rawread (drive, (*gpt_offset) + GPT_ENTRY_SECTOR (*gpt_size, *entry), GPT_ENTRY_INDEX (*gpt_size, *entry), *gpt_size, buf))
193 + } while (! (gptentry->type1 && gptentry->type2));
196 + *start = gptentry->start;
197 + *len = gptentry->end - gptentry->start + 1;
198 + *type = PC_SLICE_TYPE_EXT2FS;
199 + *entry = pc_slice_no;
200 + *partition = (*entry << 16) | 0xFFFF;
205 /* Start the body of this function. */
212 + if (*partition != 0xFFFFFF && *gpt_offset != 0)
213 + return next_gpt_slice ();
215 /* If previous partition is a BSD partition or a PC slice which
216 contains BSD partitions... */
217 if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff))
219 unsigned long dest_partition = current_partition;
220 unsigned long part_offset;
221 unsigned long ext_offset;
222 + unsigned long gpt_offset;
226 char buf[SECTOR_SIZE];
227 int bsd_part, pc_slice;
229 int ret = next_partition (current_drive, dest_partition,
230 ¤t_partition, ¤t_slice,
231 &part_start, &part_length,
232 - &part_offset, &entry, &ext_offset, buf);
233 + &part_offset, &entry, &ext_offset,
234 + &gpt_offset, &gpt_count, &gpt_size, buf);
235 bsd_part = (current_partition >> 8) & 0xFF;
236 pc_slice = current_partition >> 16;
238 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/gpt.h grub-0.96-patched/stage2/gpt.h
239 --- grub-0.96/stage2/gpt.h 1969-12-31 19:00:00.000000000 -0500
240 +++ grub-0.96-patched/stage2/gpt.h 2007-01-04 13:52:14.000000000 -0500
243 + * GRUB -- GRand Unified Bootloader
244 + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
246 + * This program is free software; you can redistribute it and/or modify
247 + * it under the terms of the GNU General Public License as published by
248 + * the Free Software Foundation; either version 2 of the License, or
249 + * (at your option) any later version.
251 + * This program is distributed in the hope that it will be useful,
252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
254 + * GNU General Public License for more details.
256 + * You should have received a copy of the GNU General Public License
257 + * along with this program; if not, write to the Free Software
258 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
264 +typedef signed char grub_int8_t;
265 +typedef signed short grub_int16_t;
266 +typedef signed int grub_int32_t;
267 +typedef signed long long int grub_int64_t;
268 +typedef unsigned char grub_uint8_t;
269 +typedef unsigned short grub_uint16_t;
270 +typedef unsigned int grub_uint32_t;
271 +typedef unsigned long long int grub_uint64_t;
273 +struct grub_gpt_header
275 + grub_uint64_t magic;
276 + grub_uint32_t version;
277 + grub_uint32_t headersize;
278 + grub_uint32_t crc32;
279 + grub_uint32_t unused1;
280 + grub_uint64_t primary;
281 + grub_uint64_t backup;
282 + grub_uint64_t start;
284 + grub_uint8_t guid[16];
285 + grub_uint64_t partitions;
286 + grub_uint32_t maxpart;
287 + grub_uint32_t partentry_size;
288 + grub_uint32_t partentry_crc32;
289 +} __attribute__ ((packed));
291 +struct grub_gpt_partentry
293 + grub_uint64_t type1;
294 + grub_uint64_t type2;
295 + grub_uint8_t guid[16];
296 + grub_uint64_t start;
298 + grub_uint8_t attrib;
300 +} __attribute__ ((packed));
302 +#define GPT_HEADER_MAGIC 0x5452415020494645UL
304 +#define GPT_ENTRY_SECTOR(size,entry) \
305 + ((((entry) * (size) + 1) & ~(SECTOR_SIZE - 1)) >> SECTOR_BITS)
306 +#define GPT_ENTRY_INDEX(size,entry) \
307 + ((((entry) * (size) + 1) & (SECTOR_SIZE - 1)) - 1)
310 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/pc_slice.h grub-0.96-patched/stage2/pc_slice.h
311 --- grub-0.96/stage2/pc_slice.h 2003-07-09 07:45:53.000000000 -0400
312 +++ grub-0.96-patched/stage2/pc_slice.h 2007-01-04 13:52:14.000000000 -0500
314 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
315 #define PC_SLICE_TYPE_VSTAFS 0x9e
316 #define PC_SLICE_TYPE_DELL_UTIL 0xde
317 +#define PC_SLICE_TYPE_GPT 0xee
318 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
321 diff -ruBbd --unidirectional-new-file grub-0.96/stage2/shared.h grub-0.96-patched/stage2/shared.h
322 --- grub-0.96/stage2/shared.h 2004-06-19 12:40:09.000000000 -0400
323 +++ grub-0.96-patched/stage2/shared.h 2007-01-04 13:52:15.000000000 -0500
325 unsigned long *partition, int *type,
326 unsigned long *start, unsigned long *len,
327 unsigned long *offset, int *entry,
328 - unsigned long *ext_offset, char *buf);
329 + unsigned long *ext_offset,
330 + unsigned long *gpt_offset, int *gpt_count,
331 + int *gpt_size, char *buf);
333 /* Sets device to the one represented by the SAVED_* parameters. */
334 int make_saved_active (void);