wok-current annotate grub/stuff/gpt.diff @ rev 25124

updated apache-mod-perl (2.0.8 -> 2.0.11)
author Hans-G?nter Theisgen
date Tue Jun 28 16:23:55 2022 +0100 (2022-06-28)
parents
children
rev   line source
pascal@24987 1 --- grub-0.97/stage2/builtins.c
pascal@24987 2 +++ grub-0.97/stage2/builtins.c
pascal@24987 3 @@ -1233,14 +1233,15 @@ find_func (char *arg, int flags)
pascal@24987 4 for (drive = 0x80; drive < 0x88; drive++)
pascal@24987 5 {
pascal@24987 6 unsigned long part = 0xFFFFFF;
pascal@24987 7 - unsigned long start, len, offset, ext_offset;
pascal@24987 8 - int type, entry;
pascal@24987 9 + unsigned long start, len, offset, ext_offset, gpt_offset;
pascal@24987 10 + int type, entry, gpt_count, gpt_size;
pascal@24987 11 char buf[SECTOR_SIZE];
pascal@24987 12
pascal@24987 13 current_drive = drive;
pascal@24987 14 while (next_partition (drive, 0xFFFFFF, &part, &type,
pascal@24987 15 &start, &len, &offset, &entry,
pascal@24987 16 - &ext_offset, buf))
pascal@24987 17 + &ext_offset, &gpt_offset,
pascal@24987 18 + &gpt_count, &gpt_size, buf))
pascal@24987 19 {
pascal@24987 20 if (type != PC_SLICE_TYPE_NONE
pascal@24987 21 && ! IS_PC_SLICE_TYPE_BSD (type)
pascal@24987 22 @@ -2815,8 +2816,8 @@ parttype_func (char *arg, int flags)
pascal@24987 23 {
pascal@24987 24 int new_type;
pascal@24987 25 unsigned long part = 0xFFFFFF;
pascal@24987 26 - unsigned long start, len, offset, ext_offset;
pascal@24987 27 - int entry, type;
pascal@24987 28 + unsigned long start, len, offset, ext_offset, gpt_offset;
pascal@24987 29 + int entry, type, gpt_count, gpt_size;
pascal@24987 30 char mbr[512];
pascal@24987 31
pascal@24987 32 /* Get the drive and the partition. */
pascal@24987 33 @@ -2853,7 +2854,14 @@ parttype_func (char *arg, int flags)
pascal@24987 34 /* Look for the partition. */
pascal@24987 35 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
pascal@24987 36 &start, &len, &offset, &entry,
pascal@24987 37 - &ext_offset, mbr))
pascal@24987 38 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
pascal@24987 39 + /* The partition may not be a GPT partition. */
pascal@24987 40 + if (gpt_offset != 0)
pascal@24987 41 + {
pascal@24987 42 + errnum = ERR_BAD_ARGUMENT;
pascal@24987 43 + return 1;
pascal@24987 44 + }
pascal@24987 45 +
pascal@24987 46 {
pascal@24987 47 if (part == current_partition)
pascal@24987 48 {
pascal@24987 49 --- grub-0.97/stage2/disk_io.c
pascal@24987 50 +++ grub-0.97/stage2/disk_io.c
pascal@24987 51 @@ -21,6 +21,7 @@
pascal@24987 52
pascal@24987 53 #include <shared.h>
pascal@24987 54 #include <filesys.h>
pascal@24987 55 +#include <gpt.h>
pascal@24987 56
pascal@24987 57 #ifdef SUPPORT_NETBOOT
pascal@24987 58 # define GRUB 1
pascal@24987 59 @@ -502,8 +503,8 @@ int
pascal@24987 60 set_partition_hidden_flag (int hidden)
pascal@24987 61 {
pascal@24987 62 unsigned long part = 0xFFFFFF;
pascal@24987 63 - unsigned long start, len, offset, ext_offset;
pascal@24987 64 - int entry, type;
pascal@24987 65 + unsigned long start, len, offset, ext_offset, gpt_offset;
pascal@24987 66 + int entry, type, gpt_count, gpt_size;
pascal@24987 67 char mbr[512];
pascal@24987 68
pascal@24987 69 /* The drive must be a hard disk. */
pascal@24987 70 @@ -524,7 +525,14 @@ set_partition_hidden_flag (int hidden)
pascal@24987 71 /* Look for the partition. */
pascal@24987 72 while (next_partition (current_drive, 0xFFFFFF, &part, &type,
pascal@24987 73 &start, &len, &offset, &entry,
pascal@24987 74 - &ext_offset, mbr))
pascal@24987 75 + &ext_offset, &gpt_offset, &gpt_count, &gpt_size, mbr))
pascal@24987 76 + /* The partition may not be a GPT partition. */
pascal@24987 77 + if (gpt_offset != 0)
pascal@24987 78 + {
pascal@24987 79 + errnum = ERR_BAD_ARGUMENT;
pascal@24987 80 + return 1;
pascal@24987 81 + }
pascal@24987 82 +
pascal@24987 83 {
pascal@24987 84 if (part == current_partition)
pascal@24987 85 {
pascal@24987 86 @@ -577,11 +585,14 @@ next_partition (unsigned long drive, uns
pascal@24987 87 unsigned long *partition, int *type,
pascal@24987 88 unsigned long *start, unsigned long *len,
pascal@24987 89 unsigned long *offset, int *entry,
pascal@24987 90 - unsigned long *ext_offset, char *buf)
pascal@24987 91 + unsigned long *ext_offset,
pascal@24987 92 + unsigned long *gpt_offset, int *gpt_count,
pascal@24987 93 + int *gpt_size, char *buf)
pascal@24987 94 {
pascal@24987 95 /* Forward declarations. */
pascal@24987 96 auto int next_bsd_partition (void);
pascal@24987 97 auto int next_pc_slice (void);
pascal@24987 98 + auto int next_gpt_slice(void);
pascal@24987 99
pascal@24987 100 /* Get next BSD partition in current PC slice. */
pascal@24987 101 int next_bsd_partition (void)
pascal@24987 102 @@ -666,6 +677,40 @@ next_partition (unsigned long drive, uns
pascal@24987 103 return 0;
pascal@24987 104 }
pascal@24987 105
pascal@24987 106 + /* If this is a GPT partition table, read it as such. */
pascal@24987 107 + if (*entry == -1 && *offset == 0 && PC_SLICE_TYPE (buf, 0) == PC_SLICE_TYPE_GPT)
pascal@24987 108 + {
pascal@24987 109 + struct grub_gpt_header *hdr = (struct grub_gpt_header *) buf;
pascal@24987 110 +
pascal@24987 111 + /* Read in the GPT Partition table header. */
pascal@24987 112 + if (! rawread (drive, 1, 0, SECTOR_SIZE, buf))
pascal@24987 113 + return 0;
pascal@24987 114 +
pascal@24987 115 + if (hdr->magic == GPT_HEADER_MAGIC && hdr->version == 0x10000)
pascal@24987 116 + {
pascal@24987 117 + /* Let gpt_offset point to the first entry in the GPT
pascal@24987 118 + partition table. This can also be used by callers of
pascal@24987 119 + next_partition to determine if a entry comes from a
pascal@24987 120 + GPT partition table or not. */
pascal@24987 121 + *gpt_offset = hdr->partitions;
pascal@24987 122 + *gpt_count = hdr->maxpart;
pascal@24987 123 + *gpt_size = hdr->partentry_size;
pascal@24987 124 +
pascal@24987 125 + return next_gpt_slice();
pascal@24987 126 + }
pascal@24987 127 + else
pascal@24987 128 + {
pascal@24987 129 + /* This is not a valid header for a GPT partition table.
pascal@24987 130 + Re-read the MBR or the boot sector of the extended
pascal@24987 131 + partition. */
pascal@24987 132 + if (! rawread (drive, *offset, 0, SECTOR_SIZE, buf))
pascal@24987 133 + return 0;
pascal@24987 134 + }
pascal@24987 135 + }
pascal@24987 136 +
pascal@24987 137 + /* Not a GPT partition. */
pascal@24987 138 + *gpt_offset = 0;
pascal@24987 139 +
pascal@24987 140 /* Increase the entry number. */
pascal@24987 141 (*entry)++;
pascal@24987 142
pascal@24987 143 @@ -710,6 +755,43 @@ next_partition (unsigned long drive, uns
pascal@24987 144 return 1;
pascal@24987 145 }
pascal@24987 146
pascal@24987 147 + /* Get the next GPT slice. */
pascal@24987 148 + int next_gpt_slice (void)
pascal@24987 149 + {
pascal@24987 150 + struct grub_gpt_partentry *gptentry = (struct grub_gpt_partentry *) buf;
pascal@24987 151 + /* Make GPT partitions show up as PC slices. */
pascal@24987 152 + int pc_slice_no = (*partition & 0xFF0000) >> 16;
pascal@24987 153 +
pascal@24987 154 + /* If this is the first time... */
pascal@24987 155 + if (pc_slice_no == 0xFF)
pascal@24987 156 + {
pascal@24987 157 + pc_slice_no = -1;
pascal@24987 158 + *entry = -1;
pascal@24987 159 + }
pascal@24987 160 +
pascal@24987 161 + do {
pascal@24987 162 + (*entry)++;
pascal@24987 163 +
pascal@24987 164 + if (*entry >= *gpt_count)
pascal@24987 165 + {
pascal@24987 166 + errnum = ERR_NO_PART;
pascal@24987 167 + return 0;
pascal@24987 168 + }
pascal@24987 169 + /* Read in the GPT Partition table entry. */
pascal@24987 170 + if (! rawread (drive, (*gpt_offset) + GPT_ENTRY_SECTOR (*gpt_size, *entry), GPT_ENTRY_INDEX (*gpt_size, *entry), *gpt_size, buf))
pascal@24987 171 + return 0;
pascal@24987 172 + } while (! (gptentry->type1 && gptentry->type2));
pascal@24987 173 +
pascal@24987 174 + pc_slice_no++;
pascal@24987 175 + *start = gptentry->start;
pascal@24987 176 + *len = gptentry->end - gptentry->start + 1;
pascal@24987 177 + *type = PC_SLICE_TYPE_EXT2FS;
pascal@24987 178 + *entry = pc_slice_no;
pascal@24987 179 + *partition = (*entry << 16) | 0xFFFF;
pascal@24987 180 +
pascal@24987 181 + return 1;
pascal@24987 182 + }
pascal@24987 183 +
pascal@24987 184 /* Start the body of this function. */
pascal@24987 185
pascal@24987 186 #ifndef STAGE1_5
pascal@24987 187 @@ -717,6 +799,9 @@ next_partition (unsigned long drive, uns
pascal@24987 188 return 0;
pascal@24987 189 #endif
pascal@24987 190
pascal@24987 191 + if (*partition != 0xFFFFFF && *gpt_offset != 0)
pascal@24987 192 + return next_gpt_slice ();
pascal@24987 193 +
pascal@24987 194 /* If previous partition is a BSD partition or a PC slice which
pascal@24987 195 contains BSD partitions... */
pascal@24987 196 if ((*partition != 0xFFFFFF && IS_PC_SLICE_TYPE_BSD (*type & 0xff))
pascal@24987 197 @@ -755,6 +840,9 @@ real_open_partition (int flags)
pascal@24987 198 unsigned long dest_partition = current_partition;
pascal@24987 199 unsigned long part_offset;
pascal@24987 200 unsigned long ext_offset;
pascal@24987 201 + unsigned long gpt_offset;
pascal@24987 202 + int gpt_count;
pascal@24987 203 + int gpt_size;
pascal@24987 204 int entry;
pascal@24987 205 char buf[SECTOR_SIZE];
pascal@24987 206 int bsd_part, pc_slice;
pascal@24987 207 @@ -766,7 +854,8 @@ real_open_partition (int flags)
pascal@24987 208 int ret = next_partition (current_drive, dest_partition,
pascal@24987 209 &current_partition, &current_slice,
pascal@24987 210 &part_start, &part_length,
pascal@24987 211 - &part_offset, &entry, &ext_offset, buf);
pascal@24987 212 + &part_offset, &entry, &ext_offset,
pascal@24987 213 + &gpt_offset, &gpt_count, &gpt_size, buf);
pascal@24987 214 bsd_part = (current_partition >> 8) & 0xFF;
pascal@24987 215 pc_slice = current_partition >> 16;
pascal@24987 216 return ret;
pascal@24987 217 --- grub-0.97/stage2/gpt.h
pascal@24987 218 +++ grub-0.97/stage2/gpt.h
pascal@24987 219 @@ -0,0 +1,68 @@
pascal@24987 220 +/*
pascal@24987 221 + * GRUB -- GRand Unified Bootloader
pascal@24987 222 + * Copyright (C) 2002,2005,2006 Free Software Foundation, Inc.
pascal@24987 223 + *
pascal@24987 224 + * This program is free software; you can redistribute it and/or modify
pascal@24987 225 + * it under the terms of the GNU General Public License as published by
pascal@24987 226 + * the Free Software Foundation; either version 2 of the License, or
pascal@24987 227 + * (at your option) any later version.
pascal@24987 228 + *
pascal@24987 229 + * This program is distributed in the hope that it will be useful,
pascal@24987 230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
pascal@24987 231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
pascal@24987 232 + * GNU General Public License for more details.
pascal@24987 233 + *
pascal@24987 234 + * You should have received a copy of the GNU General Public License
pascal@24987 235 + * along with this program; if not, write to the Free Software
pascal@24987 236 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
pascal@24987 237 + */
pascal@24987 238 +
pascal@24987 239 +#ifndef _GPT_H
pascal@24987 240 +#define _GPT_H
pascal@24987 241 +
pascal@24987 242 +typedef signed char grub_int8_t;
pascal@24987 243 +typedef signed short grub_int16_t;
pascal@24987 244 +typedef signed int grub_int32_t;
pascal@24987 245 +typedef signed long long int grub_int64_t;
pascal@24987 246 +typedef unsigned char grub_uint8_t;
pascal@24987 247 +typedef unsigned short grub_uint16_t;
pascal@24987 248 +typedef unsigned int grub_uint32_t;
pascal@24987 249 +typedef unsigned long long int grub_uint64_t;
pascal@24987 250 +
pascal@24987 251 +struct grub_gpt_header
pascal@24987 252 +{
pascal@24987 253 + grub_uint64_t magic;
pascal@24987 254 + grub_uint32_t version;
pascal@24987 255 + grub_uint32_t headersize;
pascal@24987 256 + grub_uint32_t crc32;
pascal@24987 257 + grub_uint32_t unused1;
pascal@24987 258 + grub_uint64_t primary;
pascal@24987 259 + grub_uint64_t backup;
pascal@24987 260 + grub_uint64_t start;
pascal@24987 261 + grub_uint64_t end;
pascal@24987 262 + grub_uint8_t guid[16];
pascal@24987 263 + grub_uint64_t partitions;
pascal@24987 264 + grub_uint32_t maxpart;
pascal@24987 265 + grub_uint32_t partentry_size;
pascal@24987 266 + grub_uint32_t partentry_crc32;
pascal@24987 267 +} __attribute__ ((packed));
pascal@24987 268 +
pascal@24987 269 +struct grub_gpt_partentry
pascal@24987 270 +{
pascal@24987 271 + grub_uint64_t type1;
pascal@24987 272 + grub_uint64_t type2;
pascal@24987 273 + grub_uint8_t guid[16];
pascal@24987 274 + grub_uint64_t start;
pascal@24987 275 + grub_uint64_t end;
pascal@24987 276 + grub_uint8_t attrib;
pascal@24987 277 + char name[72];
pascal@24987 278 +} __attribute__ ((packed));
pascal@24987 279 +
pascal@24987 280 +#define GPT_HEADER_MAGIC 0x5452415020494645UL
pascal@24987 281 +
pascal@24987 282 +#define GPT_ENTRY_SECTOR(size,entry) \
pascal@24987 283 + ((((entry) * (size) + 1) & ~(SECTOR_SIZE - 1)) >> SECTOR_BITS)
pascal@24987 284 +#define GPT_ENTRY_INDEX(size,entry) \
pascal@24987 285 + ((((entry) * (size) + 1) & (SECTOR_SIZE - 1)) - 1)
pascal@24987 286 +
pascal@24987 287 +#endif /* _GPT_H */
pascal@24987 288 --- grub-0.97/stage2/pc_slice.h
pascal@24987 289 +++ grub-0.97/stage2/pc_slice.h
pascal@24987 290 @@ -115,6 +115,7 @@
pascal@24987 291 #define PC_SLICE_TYPE_LINUX_EXTENDED 0x85
pascal@24987 292 #define PC_SLICE_TYPE_VSTAFS 0x9e
pascal@24987 293 #define PC_SLICE_TYPE_DELL_UTIL 0xde
pascal@24987 294 +#define PC_SLICE_TYPE_GPT 0xee
pascal@24987 295 #define PC_SLICE_TYPE_LINUX_RAID 0xfd
pascal@24987 296
pascal@24987 297
pascal@24987 298 --- grub-0.97/stage2/shared.h
pascal@24987 299 +++ grub-0.97/stage2/shared.h
pascal@24987 300 @@ -934,7 +934,9 @@ int next_partition (unsigned long drive,
pascal@24987 301 unsigned long *partition, int *type,
pascal@24987 302 unsigned long *start, unsigned long *len,
pascal@24987 303 unsigned long *offset, int *entry,
pascal@24987 304 - unsigned long *ext_offset, char *buf);
pascal@24987 305 + unsigned long *ext_offset,
pascal@24987 306 + unsigned long *gpt_offset, int *gpt_count,
pascal@24987 307 + int *gpt_size, char *buf);
pascal@24987 308
pascal@24987 309 /* Sets device to the one represented by the SAVED_* parameters. */
pascal@24987 310 int make_saved_active (void);