| 1 | |
| 2 | |
| 3 | * fs/partitions/msdos.c
|
| 4 | *
|
| 5 | * Code extracted from drivers/block/genhd.c
|
| 6 | * Copyright (C) 1991-1998 Linus Torvalds
|
| 7 | *
|
| 8 | * Thanks to Branko Lankester, [email protected], who found a bug
|
| 9 | * in the early extended-partition checks and added DM partitions
|
| 10 | *
|
| 11 | * Support for DiskManager v6.0x added by Mark Lord,
|
| 12 | * with information provided by OnTrack. This now works for linux fdisk
|
| 13 | * and LILO, as well as loadlin and bootln. Note that disks other than
|
| 14 | * /dev/hda *must* have a "DOS" type 0x51 partition in the first slot (hda1).
|
| 15 | *
|
| 16 | * More flexible handling of extended partitions - aeb, 950831
|
| 17 | *
|
| 18 | * Check partition table on IDE disks for common CHS translations
|
| 19 | *
|
| 20 | * Re-organised Feb 1998 Russell King
|
| 21 | *
|
| 22 | * BSD disklabel support by Yossi Gottlieb <[email protected]>
|
| 23 | * updated by Marc Espie <[email protected]>
|
| 24 | *
|
| 25 | * Unixware slices support by Andrzej Krzysztofowicz <[email protected]>
|
| 26 | * and Krzysztof G. Baranowski <[email protected]>
|
| 27 |
|
| 28 | #include <linux/msdos_fs.h>
|
| 29 | #include <linux/msdos_partition.h>
|
| 30 |
|
| 31 | #include "check.h"
|
| 32 | #include "efi.h"
|
| 33 |
|
| 34 | |
| 35 | * Many architectures don't like unaligned accesses, while
|
| 36 | * the nr_sects and start_sect partition table entries are
|
| 37 | * at a 2 (mod 4) address.
|
| 38 |
|
| 39 | #include <linux/unaligned.h>
|
| 40 |
|
| 41 | static inline sector_t nr_sects(struct msdos_partition *p)
|
| 42 | {
|
| 43 | return (sector_t)get_unaligned_le32(&p->nr_sects);
|
| 44 | }
|
| 45 |
|
| 46 | static inline sector_t start_sect(struct msdos_partition *p)
|
| 47 | {
|
| 48 | return (sector_t)get_unaligned_le32(&p->start_sect);
|
| 49 | }
|
| 50 |
|
| 51 | static inline int is_extended_partition(struct msdos_partition *p)
|
| 52 | {
|
| 53 | return (p->sys_ind == DOS_EXTENDED_PARTITION ||
|
| 54 | p->sys_ind == WIN98_EXTENDED_PARTITION ||
|
| 55 | p->sys_ind == LINUX_EXTENDED_PARTITION);
|
| 56 | }
|
| 57 |
|
| 58 | #define MSDOS_LABEL_MAGIC1 0x55
|
| 59 | #define MSDOS_LABEL_MAGIC2 0xAA
|
| 60 |
|
| 61 | static inline int
|
| 62 | msdos_magic_present(unsigned char *p)
|
| 63 | {
|
| 64 | return (p[0] == MSDOS_LABEL_MAGIC1 && p[1] == MSDOS_LABEL_MAGIC2);
|
| 65 | }
|
| 66 |
|
| 67 |
|
| 68 | #define AIX_LABEL_MAGIC1 0xC9
|
| 69 | #define AIX_LABEL_MAGIC2 0xC2
|
| 70 | #define AIX_LABEL_MAGIC3 0xD4
|
| 71 | #define AIX_LABEL_MAGIC4 0xC1
|
| 72 | static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
|
| 73 | {
|
| 74 | struct msdos_partition *pt = (struct msdos_partition *) (p + 0x1be);
|
| 75 | Sector sect;
|
| 76 | unsigned char *d;
|
| 77 | int slot, ret = 0;
|
| 78 |
|
| 79 | if (!(p[0] == AIX_LABEL_MAGIC1 &&
|
| 80 | p[1] == AIX_LABEL_MAGIC2 &&
|
| 81 | p[2] == AIX_LABEL_MAGIC3 &&
|
| 82 | p[3] == AIX_LABEL_MAGIC4))
|
| 83 | return 0;
|
| 84 |
|
| 85 | |
| 86 | * Assume the partition table is valid if Linux partitions exists.
|
| 87 | * Note that old Solaris/x86 partitions use the same indicator as
|
| 88 | * Linux swap partitions, so we consider that a Linux partition as
|
| 89 | * well.
|
| 90 |
|
| 91 | for (slot = 1; slot <= 4; slot++, pt++) {
|
| 92 | if (pt->sys_ind == SOLARIS_X86_PARTITION ||
|
| 93 | pt->sys_ind == LINUX_RAID_PARTITION ||
|
| 94 | pt->sys_ind == LINUX_DATA_PARTITION ||
|
| 95 | pt->sys_ind == LINUX_LVM_PARTITION ||
|
| 96 | is_extended_partition(pt))
|
| 97 | return 0;
|
| 98 | }
|
| 99 | d = read_part_sector(state, 7, §);
|
| 100 | if (d) {
|
| 101 | if (d[0] == '_' && d[1] == 'L' && d[2] == 'V' && d[3] == 'M')
|
| 102 | ret = 1;
|
| 103 | put_dev_sector(sect);
|
| 104 | }
|
| 105 | return ret;
|
| 106 | }
|
| 107 |
|
| 108 | static void set_info(struct parsed_partitions *state, int slot,
|
| 109 | u32 disksig)
|
| 110 | {
|
| 111 | struct partition_meta_info *info = &state->parts[slot].info;
|
| 112 |
|
| 113 | snprintf(info->uuid, sizeof(info->uuid), "%08x-%02x", disksig,
|
| 114 | slot);
|
| 115 | info->volname[0] = 0;
|
| 116 | state->parts[slot].has_info = true;
|
| 117 | }
|
| 118 |
|
| 119 | |
| 120 | * Create devices for each logical partition in an extended partition.
|
| 121 | * The logical partitions form a linked list, with each entry being
|
| 122 | * a partition table with two entries. The first entry
|
| 123 | * is the real data partition (with a start relative to the partition
|
| 124 | * table start). The second is a pointer to the next logical partition
|
| 125 | * (with a start relative to the entire extended partition).
|
| 126 | * We do not create a Linux partition for the partition tables, but
|
| 127 | * only for the actual data partitions.
|
| 128 |
|
| 129 |
|
| 130 | static void parse_extended(struct parsed_partitions *state,
|
| 131 | sector_t first_sector, sector_t first_size,
|
| 132 | u32 disksig)
|
| 133 | {
|
| 134 | struct msdos_partition *p;
|
| 135 | Sector sect;
|
| 136 | unsigned char *data;
|
| 137 | sector_t this_sector, this_size;
|
| 138 | sector_t sector_size;
|
| 139 | int loopct = 0; |
| 140 | without finding a data partition
|
| 141 | int i;
|
| 142 |
|
| 143 | sector_size = queue_logical_block_size(state->disk->queue) / 512;
|
| 144 | this_sector = first_sector;
|
| 145 | this_size = first_size;
|
| 146 |
|
| 147 | while (1) {
|
| 148 | if (++loopct > 100)
|
| 149 | return;
|
| 150 | if (state->next == state->limit)
|
| 151 | return;
|
| 152 | data = read_part_sector(state, this_sector, §);
|
| 153 | if (!data)
|
| 154 | return;
|
| 155 |
|
| 156 | if (!msdos_magic_present(data + 510))
|
| 157 | goto done;
|
| 158 |
|
| 159 | p = (struct msdos_partition *) (data + 0x1be);
|
| 160 |
|
| 161 | |
| 162 | * Usually, the first entry is the real data partition,
|
| 163 | * the 2nd entry is the next extended partition, or empty,
|
| 164 | * and the 3rd and 4th entries are unused.
|
| 165 | * However, DRDOS sometimes has the extended partition as
|
| 166 | * the first entry (when the data partition is empty),
|
| 167 | * and OS/2 seems to use all four entries.
|
| 168 |
|
| 169 |
|
| 170 | |
| 171 | * First process the data partition(s)
|
| 172 |
|
| 173 | for (i = 0; i < 4; i++, p++) {
|
| 174 | sector_t offs, size, next;
|
| 175 |
|
| 176 | if (!nr_sects(p) || is_extended_partition(p))
|
| 177 | continue;
|
| 178 |
|
| 179 | |
| 180 | these sometimes contain random garbage
|
| 181 | offs = start_sect(p)*sector_size;
|
| 182 | size = nr_sects(p)*sector_size;
|
| 183 | next = this_sector + offs;
|
| 184 | if (i >= 2) {
|
| 185 | if (offs + size > this_size)
|
| 186 | continue;
|
| 187 | if (next < first_sector)
|
| 188 | continue;
|
| 189 | if (next + size > first_sector + first_size)
|
| 190 | continue;
|
| 191 | }
|
| 192 |
|
| 193 | put_partition(state, state->next, next, size);
|
| 194 | set_info(state, state->next, disksig);
|
| 195 | if (p->sys_ind == LINUX_RAID_PARTITION)
|
| 196 | state->parts[state->next].flags = ADDPART_FLAG_RAID;
|
| 197 | loopct = 0;
|
| 198 | if (++state->next == state->limit)
|
| 199 | goto done;
|
| 200 | }
|
| 201 | |
| 202 | * Next, process the (first) extended partition, if present.
|
| 203 | * (So far, there seems to be no reason to make
|
| 204 | * parse_extended() recursive and allow a tree
|
| 205 | * of extended partitions.)
|
| 206 | * It should be a link to the next logical partition.
|
| 207 |
|
| 208 | p -= 4;
|
| 209 | for (i = 0; i < 4; i++, p++)
|
| 210 | if (nr_sects(p) && is_extended_partition(p))
|
| 211 | break;
|
| 212 | if (i == 4)
|
| 213 | goto done;
|
| 214 |
|
| 215 | this_sector = first_sector + start_sect(p) * sector_size;
|
| 216 | this_size = nr_sects(p) * sector_size;
|
| 217 | put_dev_sector(sect);
|
| 218 | }
|
| 219 | done:
|
| 220 | put_dev_sector(sect);
|
| 221 | }
|
| 222 |
|
| 223 | #define SOLARIS_X86_NUMSLICE 16
|
| 224 | #define SOLARIS_X86_VTOC_SANE (0x600DDEEEUL)
|
| 225 |
|
| 226 | struct solaris_x86_slice {
|
| 227 | __le16 s_tag;
|
| 228 | __le16 s_flag;
|
| 229 | __le32 s_start;
|
| 230 | __le32 s_size;
|
| 231 | };
|
| 232 |
|
| 233 | struct solaris_x86_vtoc {
|
| 234 | unsigned int v_bootinfo[3];
|
| 235 | __le32 v_sanity;
|
| 236 | __le32 v_version;
|
| 237 | char v_volume[8];
|
| 238 | __le16 v_sectorsz;
|
| 239 | __le16 v_nparts;
|
| 240 | unsigned int v_reserved[10];
|
| 241 | struct solaris_x86_slice
|
| 242 | v_slice[SOLARIS_X86_NUMSLICE];
|
| 243 | unsigned int timestamp[SOLARIS_X86_NUMSLICE];
|
| 244 | char v_asciilabel[128];
|
| 245 | };
|
| 246 |
|
| 247 | |
| 248 | indicates linux swap. Be careful before believing this is Solaris.
|
| 249 |
|
| 250 | static void parse_solaris_x86(struct parsed_partitions *state,
|
| 251 | sector_t offset, sector_t size, int origin)
|
| 252 | {
|
| 253 | #ifdef CONFIG_SOLARIS_X86_PARTITION
|
| 254 | Sector sect;
|
| 255 | struct solaris_x86_vtoc *v;
|
| 256 | int i;
|
| 257 | short max_nparts;
|
| 258 |
|
| 259 | v = read_part_sector(state, offset + 1, §);
|
| 260 | if (!v)
|
| 261 | return;
|
| 262 | if (le32_to_cpu(v->v_sanity) != SOLARIS_X86_VTOC_SANE) {
|
| 263 | put_dev_sector(sect);
|
| 264 | return;
|
| 265 | }
|
| 266 | seq_buf_printf(&state->pp_buf, " %s%d: <solaris:", state->name, origin);
|
| 267 | if (le32_to_cpu(v->v_version) != 1) {
|
| 268 | seq_buf_printf(&state->pp_buf,
|
| 269 | " cannot handle version %d vtoc>\n",
|
| 270 | le32_to_cpu(v->v_version));
|
| 271 | put_dev_sector(sect);
|
| 272 | return;
|
| 273 | }
|
| 274 |
|
| 275 | max_nparts = le16_to_cpu(v->v_nparts) > 8 ? SOLARIS_X86_NUMSLICE : 8;
|
| 276 | for (i = 0; i < max_nparts && state->next < state->limit; i++) {
|
| 277 | struct solaris_x86_slice *s = &v->v_slice[i];
|
| 278 |
|
| 279 | if (s->s_size == 0)
|
| 280 | continue;
|
| 281 | seq_buf_printf(&state->pp_buf, " [s%d]", i);
|
| 282 | |
| 283 | * one; must add the offset of the current partition
|
| 284 | put_partition(state, state->next++,
|
| 285 | le32_to_cpu(s->s_start)+offset,
|
| 286 | le32_to_cpu(s->s_size));
|
| 287 | }
|
| 288 | put_dev_sector(sect);
|
| 289 | seq_buf_puts(&state->pp_buf, " >\n");
|
| 290 | #endif
|
| 291 | }
|
| 292 |
|
| 293 |
|
| 294 | #define BSD_DISKMAGIC (0x82564557UL)
|
| 295 | #define BSD_MAXPARTITIONS 16
|
| 296 | #define OPENBSD_MAXPARTITIONS 16
|
| 297 | #define BSD_FS_UNUSED 0
|
| 298 | struct bsd_disklabel {
|
| 299 | __le32 d_magic;
|
| 300 | __s16 d_type;
|
| 301 | __s16 d_subtype;
|
| 302 | char d_typename[16];
|
| 303 | char d_packname[16];
|
| 304 | __u32 d_secsize;
|
| 305 | __u32 d_nsectors;
|
| 306 | __u32 d_ntracks;
|
| 307 | __u32 d_ncylinders;
|
| 308 | __u32 d_secpercyl;
|
| 309 | __u32 d_secperunit;
|
| 310 | __u16 d_sparespertrack;
|
| 311 | __u16 d_sparespercyl;
|
| 312 | __u32 d_acylinders;
|
| 313 | __u16 d_rpm;
|
| 314 | __u16 d_interleave;
|
| 315 | __u16 d_trackskew;
|
| 316 | __u16 d_cylskew;
|
| 317 | __u32 d_headswitch;
|
| 318 | __u32 d_trkseek;
|
| 319 | __u32 d_flags;
|
| 320 | #define NDDATA 5
|
| 321 | __u32 d_drivedata[NDDATA];
|
| 322 | #define NSPARE 5
|
| 323 | __u32 d_spare[NSPARE];
|
| 324 | __le32 d_magic2;
|
| 325 | __le16 d_checksum;
|
| 326 |
|
| 327 |
|
| 328 | __le16 d_npartitions;
|
| 329 | __le32 d_bbsize;
|
| 330 | __le32 d_sbsize;
|
| 331 | struct bsd_partition {
|
| 332 | __le32 p_size;
|
| 333 | __le32 p_offset;
|
| 334 | __le32 p_fsize;
|
| 335 | __u8 p_fstype;
|
| 336 | __u8 p_frag;
|
| 337 | __le16 p_cpg;
|
| 338 | } d_partitions[BSD_MAXPARTITIONS];
|
| 339 | };
|
| 340 |
|
| 341 | #if defined(CONFIG_BSD_DISKLABEL)
|
| 342 | |
| 343 | * Create devices for BSD partitions listed in a disklabel, under a
|
| 344 | * dos-like partition. See parse_extended() for more information.
|
| 345 |
|
| 346 | static void parse_bsd(struct parsed_partitions *state,
|
| 347 | sector_t offset, sector_t size, int origin, char *flavour,
|
| 348 | int max_partitions)
|
| 349 | {
|
| 350 | Sector sect;
|
| 351 | struct bsd_disklabel *l;
|
| 352 | struct bsd_partition *p;
|
| 353 |
|
| 354 | l = read_part_sector(state, offset + 1, §);
|
| 355 | if (!l)
|
| 356 | return;
|
| 357 | if (le32_to_cpu(l->d_magic) != BSD_DISKMAGIC) {
|
| 358 | put_dev_sector(sect);
|
| 359 | return;
|
| 360 | }
|
| 361 |
|
| 362 | seq_buf_printf(&state->pp_buf, " %s%d: <%s:", state->name, origin, flavour);
|
| 363 |
|
| 364 | if (le16_to_cpu(l->d_npartitions) < max_partitions)
|
| 365 | max_partitions = le16_to_cpu(l->d_npartitions);
|
| 366 | for (p = l->d_partitions; p - l->d_partitions < max_partitions; p++) {
|
| 367 | sector_t bsd_start, bsd_size;
|
| 368 |
|
| 369 | if (state->next == state->limit)
|
| 370 | break;
|
| 371 | if (p->p_fstype == BSD_FS_UNUSED)
|
| 372 | continue;
|
| 373 | bsd_start = le32_to_cpu(p->p_offset);
|
| 374 | bsd_size = le32_to_cpu(p->p_size);
|
| 375 |
|
| 376 | if (memcmp(flavour, "bsd\0", 4) == 0 &&
|
| 377 | le32_to_cpu(l->d_partitions[2].p_offset) == 0)
|
| 378 | bsd_start += offset;
|
| 379 | if (offset == bsd_start && size == bsd_size)
|
| 380 |
|
| 381 | continue;
|
| 382 | if (offset > bsd_start || offset+size < bsd_start+bsd_size) {
|
| 383 | seq_buf_puts(&state->pp_buf, "bad subpartition - ignored\n");
|
| 384 | continue;
|
| 385 | }
|
| 386 | put_partition(state, state->next++, bsd_start, bsd_size);
|
| 387 | }
|
| 388 | put_dev_sector(sect);
|
| 389 | if (le16_to_cpu(l->d_npartitions) > max_partitions)
|
| 390 | seq_buf_printf(&state->pp_buf, " (ignored %d more)",
|
| 391 | le16_to_cpu(l->d_npartitions) - max_partitions);
|
| 392 | seq_buf_puts(&state->pp_buf, " >\n");
|
| 393 | }
|
| 394 | #endif
|
| 395 |
|
| 396 | static void parse_freebsd(struct parsed_partitions *state,
|
| 397 | sector_t offset, sector_t size, int origin)
|
| 398 | {
|
| 399 | #ifdef CONFIG_BSD_DISKLABEL
|
| 400 | parse_bsd(state, offset, size, origin, "bsd", BSD_MAXPARTITIONS);
|
| 401 | #endif
|
| 402 | }
|
| 403 |
|
| 404 | static void parse_netbsd(struct parsed_partitions *state,
|
| 405 | sector_t offset, sector_t size, int origin)
|
| 406 | {
|
| 407 | #ifdef CONFIG_BSD_DISKLABEL
|
| 408 | parse_bsd(state, offset, size, origin, "netbsd", BSD_MAXPARTITIONS);
|
| 409 | #endif
|
| 410 | }
|
| 411 |
|
| 412 | static void parse_openbsd(struct parsed_partitions *state,
|
| 413 | sector_t offset, sector_t size, int origin)
|
| 414 | {
|
| 415 | #ifdef CONFIG_BSD_DISKLABEL
|
| 416 | parse_bsd(state, offset, size, origin, "openbsd",
|
| 417 | OPENBSD_MAXPARTITIONS);
|
| 418 | #endif
|
| 419 | }
|
| 420 |
|
| 421 | #define UNIXWARE_DISKMAGIC (0xCA5E600DUL)
|
| 422 | #define UNIXWARE_DISKMAGIC2 (0x600DDEEEUL)
|
| 423 | #define UNIXWARE_NUMSLICE 16
|
| 424 | #define UNIXWARE_FS_UNUSED 0
|
| 425 |
|
| 426 | struct unixware_slice {
|
| 427 | __le16 s_label;
|
| 428 | __le16 s_flags;
|
| 429 | __le32 start_sect;
|
| 430 | __le32 nr_sects;
|
| 431 | };
|
| 432 |
|
| 433 | struct unixware_disklabel {
|
| 434 | __le32 d_type;
|
| 435 | __le32 d_magic;
|
| 436 | __le32 d_version;
|
| 437 | char d_serial[12];
|
| 438 | __le32 d_ncylinders;
|
| 439 | __le32 d_ntracks;
|
| 440 | __le32 d_nsectors;
|
| 441 | __le32 d_secsize;
|
| 442 | __le32 d_part_start;
|
| 443 | __le32 d_unknown1[12];
|
| 444 | __le32 d_alt_tbl;
|
| 445 | __le32 d_alt_len;
|
| 446 | __le32 d_phys_cyl;
|
| 447 | __le32 d_phys_trk;
|
| 448 | __le32 d_phys_sec;
|
| 449 | __le32 d_phys_bytes;
|
| 450 | __le32 d_unknown2;
|
| 451 | __le32 d_unknown3;
|
| 452 | __le32 d_pad[8];
|
| 453 |
|
| 454 | struct unixware_vtoc {
|
| 455 | __le32 v_magic;
|
| 456 | __le32 v_version;
|
| 457 | char v_name[8];
|
| 458 | __le16 v_nslices;
|
| 459 | __le16 v_unknown1;
|
| 460 | __le32 v_reserved[10];
|
| 461 | struct unixware_slice
|
| 462 | v_slice[UNIXWARE_NUMSLICE];
|
| 463 | } vtoc;
|
| 464 | };
|
| 465 |
|
| 466 | |
| 467 | * Create devices for Unixware partitions listed in a disklabel, under a
|
| 468 | * dos-like partition. See parse_extended() for more information.
|
| 469 |
|
| 470 | static void parse_unixware(struct parsed_partitions *state,
|
| 471 | sector_t offset, sector_t size, int origin)
|
| 472 | {
|
| 473 | #ifdef CONFIG_UNIXWARE_DISKLABEL
|
| 474 | Sector sect;
|
| 475 | struct unixware_disklabel *l;
|
| 476 | struct unixware_slice *p;
|
| 477 |
|
| 478 | l = read_part_sector(state, offset + 29, §);
|
| 479 | if (!l)
|
| 480 | return;
|
| 481 | if (le32_to_cpu(l->d_magic) != UNIXWARE_DISKMAGIC ||
|
| 482 | le32_to_cpu(l->vtoc.v_magic) != UNIXWARE_DISKMAGIC2) {
|
| 483 | put_dev_sector(sect);
|
| 484 | return;
|
| 485 | }
|
| 486 | seq_buf_printf(&state->pp_buf, " %s%d: <unixware:", state->name, origin);
|
| 487 | p = &l->vtoc.v_slice[1];
|
| 488 |
|
| 489 | while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {
|
| 490 | if (state->next == state->limit)
|
| 491 | break;
|
| 492 |
|
| 493 | if (p->s_label != UNIXWARE_FS_UNUSED)
|
| 494 | put_partition(state, state->next++,
|
| 495 | le32_to_cpu(p->start_sect),
|
| 496 | le32_to_cpu(p->nr_sects));
|
| 497 | p++;
|
| 498 | }
|
| 499 | put_dev_sector(sect);
|
| 500 | seq_buf_puts(&state->pp_buf, " >\n");
|
| 501 | #endif
|
| 502 | }
|
| 503 |
|
| 504 | #define MINIX_NR_SUBPARTITIONS 4
|
| 505 |
|
| 506 | |
| 507 | * Minix 2.0.0/2.0.2 subpartition support.
|
| 508 | * Anand Krishnamurthy <[email protected]>
|
| 509 | * Rajeev V. Pillai <[email protected]>
|
| 510 |
|
| 511 | static void parse_minix(struct parsed_partitions *state,
|
| 512 | sector_t offset, sector_t size, int origin)
|
| 513 | {
|
| 514 | #ifdef CONFIG_MINIX_SUBPARTITION
|
| 515 | Sector sect;
|
| 516 | unsigned char *data;
|
| 517 | struct msdos_partition *p;
|
| 518 | int i;
|
| 519 |
|
| 520 | data = read_part_sector(state, offset, §);
|
| 521 | if (!data)
|
| 522 | return;
|
| 523 |
|
| 524 | p = (struct msdos_partition *)(data + 0x1be);
|
| 525 |
|
| 526 | |
| 527 | * a secondary MBR describing its subpartitions, or
|
| 528 | * the normal boot sector.
|
| 529 | if (msdos_magic_present(data + 510) &&
|
| 530 | p->sys_ind == MINIX_PARTITION) {
|
| 531 | seq_buf_printf(&state->pp_buf, " %s%d: <minix:", state->name, origin);
|
| 532 | for (i = 0; i < MINIX_NR_SUBPARTITIONS; i++, p++) {
|
| 533 | if (state->next == state->limit)
|
| 534 | break;
|
| 535 |
|
| 536 | if (p->sys_ind == MINIX_PARTITION)
|
| 537 | put_partition(state, state->next++,
|
| 538 | start_sect(p), nr_sects(p));
|
| 539 | }
|
| 540 | seq_buf_puts(&state->pp_buf, " >\n");
|
| 541 | }
|
| 542 | put_dev_sector(sect);
|
| 543 | #endif
|
| 544 | }
|
| 545 |
|
| 546 | static struct {
|
| 547 | unsigned char id;
|
| 548 | void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
|
| 549 | } subtypes[] = {
|
| 550 | {FREEBSD_PARTITION, parse_freebsd},
|
| 551 | {NETBSD_PARTITION, parse_netbsd},
|
| 552 | {OPENBSD_PARTITION, parse_openbsd},
|
| 553 | {MINIX_PARTITION, parse_minix},
|
| 554 | {UNIXWARE_PARTITION, parse_unixware},
|
| 555 | {SOLARIS_X86_PARTITION, parse_solaris_x86},
|
| 556 | {NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
|
| 557 | {0, NULL},
|
| 558 | };
|
| 559 |
|
| 560 | int msdos_partition(struct parsed_partitions *state)
|
| 561 | {
|
| 562 | sector_t sector_size;
|
| 563 | Sector sect;
|
| 564 | unsigned char *data;
|
| 565 | struct msdos_partition *p;
|
| 566 | struct fat_boot_sector *fb;
|
| 567 | int slot;
|
| 568 | u32 disksig;
|
| 569 |
|
| 570 | sector_size = queue_logical_block_size(state->disk->queue) / 512;
|
| 571 | data = read_part_sector(state, 0, §);
|
| 572 | if (!data)
|
| 573 | return -1;
|
| 574 |
|
| 575 | |
| 576 | * Note order! (some AIX disks, e.g. unbootable kind,
|
| 577 | * have no MSDOS 55aa)
|
| 578 |
|
| 579 | if (aix_magic_present(state, data)) {
|
| 580 | put_dev_sector(sect);
|
| 581 | #ifdef CONFIG_AIX_PARTITION
|
| 582 | return aix_partition(state);
|
| 583 | #else
|
| 584 | seq_buf_puts(&state->pp_buf, " [AIX]");
|
| 585 | return 0;
|
| 586 | #endif
|
| 587 | }
|
| 588 |
|
| 589 | if (!msdos_magic_present(data + 510)) {
|
| 590 | put_dev_sector(sect);
|
| 591 | return 0;
|
| 592 | }
|
| 593 |
|
| 594 | |
| 595 | * Now that the 55aa signature is present, this is probably
|
| 596 | * either the boot sector of a FAT filesystem or a DOS-type
|
| 597 | * partition table. Reject this in case the boot indicator
|
| 598 | * is not 0 or 0x80.
|
| 599 |
|
| 600 | p = (struct msdos_partition *) (data + 0x1be);
|
| 601 | for (slot = 1; slot <= 4; slot++, p++) {
|
| 602 | if (p->boot_ind != 0 && p->boot_ind != 0x80) {
|
| 603 | |
| 604 | * Even without a valid boot indicator value
|
| 605 | * its still possible this is valid FAT filesystem
|
| 606 | * without a partition table.
|
| 607 |
|
| 608 | fb = (struct fat_boot_sector *) data;
|
| 609 | if (slot == 1 && fb->reserved && fb->fats
|
| 610 | && fat_valid_media(fb->media)) {
|
| 611 | seq_buf_puts(&state->pp_buf, "\n");
|
| 612 | put_dev_sector(sect);
|
| 613 | return 1;
|
| 614 | } else {
|
| 615 | put_dev_sector(sect);
|
| 616 | return 0;
|
| 617 | }
|
| 618 | }
|
| 619 | }
|
| 620 |
|
| 621 | #ifdef CONFIG_EFI_PARTITION
|
| 622 | p = (struct msdos_partition *) (data + 0x1be);
|
| 623 | for (slot = 1 ; slot <= 4 ; slot++, p++) {
|
| 624 |
|
| 625 | if (p->sys_ind == EFI_PMBR_OSTYPE_EFI_GPT) {
|
| 626 | put_dev_sector(sect);
|
| 627 | return 0;
|
| 628 | }
|
| 629 | }
|
| 630 | #endif
|
| 631 | p = (struct msdos_partition *) (data + 0x1be);
|
| 632 |
|
| 633 | disksig = le32_to_cpup((__le32 *)(data + 0x1b8));
|
| 634 |
|
| 635 | |
| 636 | * Look for partitions in two passes:
|
| 637 | * First find the primary and DOS-type extended partitions.
|
| 638 | * On the second pass look inside *BSD, Unixware and Solaris partitions.
|
| 639 |
|
| 640 |
|
| 641 | state->next = 5;
|
| 642 | for (slot = 1 ; slot <= 4 ; slot++, p++) {
|
| 643 | sector_t start = start_sect(p)*sector_size;
|
| 644 | sector_t size = nr_sects(p)*sector_size;
|
| 645 |
|
| 646 | if (!size)
|
| 647 | continue;
|
| 648 | if (is_extended_partition(p)) {
|
| 649 | |
| 650 | * prevent someone doing mkfs or mkswap on an
|
| 651 | * extended partition, but leave room for LILO
|
| 652 | * FIXME: this uses one logical sector for > 512b
|
| 653 | * sector, although it may not be enough/proper.
|
| 654 |
|
| 655 | sector_t n = 2;
|
| 656 |
|
| 657 | n = min(size, max(sector_size, n));
|
| 658 | put_partition(state, slot, start, n);
|
| 659 |
|
| 660 | seq_buf_puts(&state->pp_buf, " <");
|
| 661 | parse_extended(state, start, size, disksig);
|
| 662 | seq_buf_puts(&state->pp_buf, " >");
|
| 663 | continue;
|
| 664 | }
|
| 665 | put_partition(state, slot, start, size);
|
| 666 | set_info(state, slot, disksig);
|
| 667 | if (p->sys_ind == LINUX_RAID_PARTITION)
|
| 668 | state->parts[slot].flags = ADDPART_FLAG_RAID;
|
| 669 | if (p->sys_ind == DM6_PARTITION)
|
| 670 | seq_buf_puts(&state->pp_buf, "[DM]");
|
| 671 | if (p->sys_ind == EZD_PARTITION)
|
| 672 | seq_buf_puts(&state->pp_buf, "[EZD]");
|
| 673 | }
|
| 674 |
|
| 675 | seq_buf_puts(&state->pp_buf, "\n");
|
| 676 |
|
| 677 |
|
| 678 | p = (struct msdos_partition *) (0x1be + data);
|
| 679 | for (slot = 1 ; slot <= 4 ; slot++, p++) {
|
| 680 | unsigned char id = p->sys_ind;
|
| 681 | int n;
|
| 682 |
|
| 683 | if (!nr_sects(p))
|
| 684 | continue;
|
| 685 |
|
| 686 | for (n = 0; subtypes[n].parse && id != subtypes[n].id; n++)
|
| 687 | ;
|
| 688 |
|
| 689 | if (!subtypes[n].parse)
|
| 690 | continue;
|
| 691 | subtypes[n].parse(state, start_sect(p) * sector_size,
|
| 692 | nr_sects(p) * sector_size, slot);
|
| 693 | }
|
| 694 | put_dev_sector(sect);
|
| 695 | return 1;
|
| 696 | }
|