Magellan Linux

Contents of /trunk/grub/patches/grub-0.97-gpt.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1053 - (show annotations) (download)
Fri Jun 25 10:52:50 2010 UTC (13 years, 10 months ago) by niro
File size: 10682 byte(s)
more patches and fixed ext4 patch

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++)
6 {
7 unsigned long part = 0xFFFFFF;
8 - unsigned long start, len, offset, ext_offset;
9 - int type, entry;
10 + unsigned long start, len, offset, ext_offset, gpt_offset;
11 + int type, entry, gpt_count, gpt_size;
12 char buf[SECTOR_SIZE];
13
14 current_drive = drive;
15 while (next_partition (drive, 0xFFFFFF, &part, &type,
16 &start, &len, &offset, &entry,
17 - &ext_offset, buf))
18 + &ext_offset, &gpt_offset,
19 + &gpt_count, &gpt_size, buf))
20 {
21 if (type != PC_SLICE_TYPE_NONE
22 && ! IS_PC_SLICE_TYPE_BSD (type)
23 @@ -2806,8 +2807,8 @@
24 {
25 int new_type;
26 unsigned long part = 0xFFFFFF;
27 - unsigned long start, len, offset, ext_offset;
28 - int entry, type;
29 + unsigned long start, len, offset, ext_offset, gpt_offset;
30 + int entry, type, gpt_count, gpt_size;
31 char mbr[512];
32
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,
38 - &ext_offset, mbr))
39 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
40 + /* The partition may not be a GPT partition. */
41 + if (gpt_offset != 0)
42 + {
43 + errnum = ERR_BAD_ARGUMENT;
44 + return 1;
45 + }
46 +
47 {
48 if (part == current_partition)
49 {
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
53 @@ -21,6 +21,7 @@
54
55 #include <shared.h>
56 #include <filesys.h>
57 +#include <gpt.h>
58
59 #ifdef SUPPORT_NETBOOT
60 # define GRUB 1
61 @@ -502,8 +503,8 @@
62 set_partition_hidden_flag (int hidden)
63 {
64 unsigned long part = 0xFFFFFF;
65 - unsigned long start, len, offset, ext_offset;
66 - int entry, type;
67 + unsigned long start, len, offset, ext_offset, gpt_offset;
68 + int entry, type, gpt_count, gpt_size;
69 char mbr[512];
70
71 /* The drive must be a hard disk. */
72 @@ -524,7 +525,14 @@
73 /* Look for the partition. */
74 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
75 &start, &len, &offset, &entry,
76 - &ext_offset, mbr))
77 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
78 + /* The partition may not be a GPT partition. */
79 + if (gpt_offset != 0)
80 + {
81 + errnum = ERR_BAD_ARGUMENT;
82 + return 1;
83 + }
84 +
85 {
86 if (part == current_partition)
87 {
88 @@ -577,11 +585,14 @@
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)
96 {
97 /* Forward declarations. */
98 auto int next_bsd_partition (void);
99 auto int next_pc_slice (void);
100 + auto int next_gpt_slice(void);
101
102 /* Get next BSD partition in current PC slice. */
103 int next_bsd_partition (void)
104 @@ -666,6 +677,40 @@
105 return 0;
106 }
107
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)
110 + {
111 + struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf;
112 +
113 + /* Read in the GPT Partition table header. */
114 + if (! rawread (drive, 1, 0, SECTOR_SIZE, buf))
115 + return 0;
116 +
117 + if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000)
118 + {
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;
126 +
127 + return next_gpt_slice();
128 + }
129 + else
130 + {
131 + /* This is not a valid header for a GPT partition table.
132 + Re-read the MBR or the boot sector of the extended
133 + partition. */
134 + if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf))
135 + return 0;
136 + }
137 + }
138 +
139 + /* Not a GPT partition. */
140 + *gpt_offset = 0;
141 +
142 /* Increase the entry number. */
143 (*entry)++;
144
145 @@ -710,6 +755,43 @@
146 return 1;
147 }
148
149 + /* Get the next GPT slice. */
150 + int next_gpt_slice (void)
151 + {
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;
155 +
156 + /* If this is the first time... */
157 + if (pc_slice_no == 0xFF)
158 + {
159 + pc_slice_no = -1;
160 + *entry = -1;
161 + }
162 +
163 + do {
164 + (*entry)++;
165 +
166 + if (*entry >= *gpt_count)
167 + {
168 + errnum = ERR_NO_PART;
169 + return 0;
170 + }
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))
173 + return 0;
174 + } while (! (gptentry->type1 && gptentry->type2));
175 +
176 + pc_slice_no++;
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;
182 +
183 + return 1;
184 + }
185 +
186 /* Start the body of this function. */
187
188 #ifndef STAGE1_5
189 @@ -717,6 +799,9 @@
190 return 0;
191 #endif
192
193 + if (*partition != 0xFFFFFF && *gpt_offset != 0)
194 + return next_gpt_slice ();
195 +
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))
199 @@ -755,6 +840,9 @@
200 unsigned long dest_partition = current_partition;
201 unsigned long part_offset;
202 unsigned long ext_offset;
203 + unsigned long gpt_offset;
204 + int gpt_count;
205 + int gpt_size;
206 int entry;
207 char buf[SECTOR_SIZE];
208 int bsd_part, pc_slice;
209 @@ -766,7 +854,8 @@
210 int ret = next_partition (current_drive, dest_partition,
211 &current_partition, &current_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;
218 return ret;
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
222 @@ -0,0 +1,68 @@
223 +/*
224 + * GRUB -- GRand Unified Bootloader
225 + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
226 + *
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.
231 + *
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.
236 + *
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.
240 + */
241 +
242 +#ifndef _GPT_H
243 +#define _GPT_H
244 +
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;
253 +
254 +struct grub_gpt_header
255 +{
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;
264 + grub_uint64_t end;
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));
271 +
272 +struct grub_gpt_partentry
273 +{
274 + grub_uint64_t type1;
275 + grub_uint64_t type2;
276 + grub_uint8_t guid[16];
277 + grub_uint64_t start;
278 + grub_uint64_t end;
279 + grub_uint8_t attrib;
280 + char name[72];
281 +} __attribute__ ((packed));
282 +
283 +#define GPT_HEADER_MAGIC 0x5452415020494645UL
284 +
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)
289 +
290 +#endif /* _GPT_H */
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
294 @@ -115,6 +115,7 @@
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
300
301
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
305 @@ -934,7 +934,9 @@
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);
313
314 /* Sets device to the one represented by the SAVED_* parameters. */
315 int make_saved_active (void);