msdos.c 16.1 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
L
Linus Torvalds 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 *  fs/partitions/msdos.c
 *
 *  Code extracted from drivers/block/genhd.c
 *  Copyright (C) 1991-1998  Linus Torvalds
 *
 *  Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
 *  in the early extended-partition checks and added DM partitions
 *
 *  Support for DiskManager v6.0x added by Mark Lord,
 *  with information provided by OnTrack.  This now works for linux fdisk
 *  and LILO, as well as loadlin and bootln.  Note that disks other than
 *  /dev/hda *must* have a "DOS" type 0x51 partition in the first slot (hda1).
 *
 *  More flexible handling of extended partitions - aeb, 950831
 *
 *  Check partition table on IDE disks for common CHS translations
 *
 *  Re-organised Feb 1998 Russell King
 */
22
#include <linux/msdos_fs.h>
23
#include <linux/msdos_partition.h>
L
Linus Torvalds 已提交
24 25 26 27 28 29 30 31 32 33 34

#include "check.h"
#include "efi.h"

/*
 * Many architectures don't like unaligned accesses, while
 * the nr_sects and start_sect partition table entries are
 * at a 2 (mod 4) address.
 */
#include <asm/unaligned.h>

35
#define SYS_IND(p)	get_unaligned(&p->sys_ind)
L
Linus Torvalds 已提交
36

37
static inline sector_t nr_sects(struct msdos_partition *p)
38 39 40 41
{
	return (sector_t)get_unaligned_le32(&p->nr_sects);
}

42
static inline sector_t start_sect(struct msdos_partition *p)
43 44 45
{
	return (sector_t)get_unaligned_le32(&p->start_sect);
}
L
Linus Torvalds 已提交
46

47
static inline int is_extended_partition(struct msdos_partition *p)
L
Linus Torvalds 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
{
	return (SYS_IND(p) == DOS_EXTENDED_PARTITION ||
		SYS_IND(p) == WIN98_EXTENDED_PARTITION ||
		SYS_IND(p) == LINUX_EXTENDED_PARTITION);
}

#define MSDOS_LABEL_MAGIC1	0x55
#define MSDOS_LABEL_MAGIC2	0xAA

static inline int
msdos_magic_present(unsigned char *p)
{
	return (p[0] == MSDOS_LABEL_MAGIC1 && p[1] == MSDOS_LABEL_MAGIC2);
}

63 64 65 66 67
/* Value is EBCDIC 'IBMA' */
#define AIX_LABEL_MAGIC1	0xC9
#define AIX_LABEL_MAGIC2	0xC2
#define AIX_LABEL_MAGIC3	0xD4
#define AIX_LABEL_MAGIC4	0xC1
68
static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
69
{
70
	struct msdos_partition *pt = (struct msdos_partition *) (p + 0x1be);
71 72
	Sector sect;
	unsigned char *d;
73
	int slot, ret = 0;
74

75 76 77 78
	if (!(p[0] == AIX_LABEL_MAGIC1 &&
		p[1] == AIX_LABEL_MAGIC2 &&
		p[2] == AIX_LABEL_MAGIC3 &&
		p[3] == AIX_LABEL_MAGIC4))
79
		return 0;
80 81 82 83 84 85 86 87 88
	/* Assume the partition table is valid if Linux partitions exists */
	for (slot = 1; slot <= 4; slot++, pt++) {
		if (pt->sys_ind == LINUX_SWAP_PARTITION ||
			pt->sys_ind == LINUX_RAID_PARTITION ||
			pt->sys_ind == LINUX_DATA_PARTITION ||
			pt->sys_ind == LINUX_LVM_PARTITION ||
			is_extended_partition(pt))
			return 0;
	}
89
	d = read_part_sector(state, 7, &sect);
90 91 92 93
	if (d) {
		if (d[0] == '_' && d[1] == 'L' && d[2] == 'V' && d[3] == 'M')
			ret = 1;
		put_dev_sector(sect);
94
	}
95 96 97
	return ret;
}

98 99 100 101 102 103 104 105 106 107 108
static void set_info(struct parsed_partitions *state, int slot,
		     u32 disksig)
{
	struct partition_meta_info *info = &state->parts[slot].info;

	snprintf(info->uuid, sizeof(info->uuid), "%08x-%02x", disksig,
		 slot);
	info->volname[0] = 0;
	state->parts[slot].has_info = true;
}

L
Linus Torvalds 已提交
109 110 111 112 113 114 115 116 117 118 119
/*
 * Create devices for each logical partition in an extended partition.
 * The logical partitions form a linked list, with each entry being
 * a partition table with two entries.  The first entry
 * is the real data partition (with a start relative to the partition
 * table start).  The second is a pointer to the next logical partition
 * (with a start relative to the entire extended partition).
 * We do not create a Linux partition for the partition tables, but
 * only for the actual data partitions.
 */

120
static void parse_extended(struct parsed_partitions *state,
121 122
			   sector_t first_sector, sector_t first_size,
			   u32 disksig)
L
Linus Torvalds 已提交
123
{
124
	struct msdos_partition *p;
L
Linus Torvalds 已提交
125 126
	Sector sect;
	unsigned char *data;
127
	sector_t this_sector, this_size;
128
	sector_t sector_size = bdev_logical_block_size(state->bdev) / 512;
L
Linus Torvalds 已提交
129 130 131 132 133 134 135 136 137 138 139 140
	int loopct = 0;		/* number of links followed
				   without finding a data partition */
	int i;

	this_sector = first_sector;
	this_size = first_size;

	while (1) {
		if (++loopct > 100)
			return;
		if (state->next == state->limit)
			return;
141
		data = read_part_sector(state, this_sector, &sect);
L
Linus Torvalds 已提交
142 143 144 145
		if (!data)
			return;

		if (!msdos_magic_present(data + 510))
146
			goto done;
L
Linus Torvalds 已提交
147

148
		p = (struct msdos_partition *) (data + 0x1be);
L
Linus Torvalds 已提交
149 150 151 152 153 154 155 156 157 158

		/*
		 * Usually, the first entry is the real data partition,
		 * the 2nd entry is the next extended partition, or empty,
		 * and the 3rd and 4th entries are unused.
		 * However, DRDOS sometimes has the extended partition as
		 * the first entry (when the data partition is empty),
		 * and OS/2 seems to use all four entries.
		 */

159
		/*
L
Linus Torvalds 已提交
160 161
		 * First process the data partition(s)
		 */
162
		for (i = 0; i < 4; i++, p++) {
163
			sector_t offs, size, next;
164

165
			if (!nr_sects(p) || is_extended_partition(p))
L
Linus Torvalds 已提交
166 167 168 169
				continue;

			/* Check the 3rd and 4th entries -
			   these sometimes contain random garbage */
170 171
			offs = start_sect(p)*sector_size;
			size = nr_sects(p)*sector_size;
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182
			next = this_sector + offs;
			if (i >= 2) {
				if (offs + size > this_size)
					continue;
				if (next < first_sector)
					continue;
				if (next + size > first_sector + first_size)
					continue;
			}

			put_partition(state, state->next, next, size);
183
			set_info(state, state->next, disksig);
L
Linus Torvalds 已提交
184
			if (SYS_IND(p) == LINUX_RAID_PARTITION)
185
				state->parts[state->next].flags = ADDPART_FLAG_RAID;
L
Linus Torvalds 已提交
186 187 188 189 190 191 192 193 194 195 196 197
			loopct = 0;
			if (++state->next == state->limit)
				goto done;
		}
		/*
		 * Next, process the (first) extended partition, if present.
		 * (So far, there seems to be no reason to make
		 *  parse_extended()  recursive and allow a tree
		 *  of extended partitions.)
		 * It should be a link to the next logical partition.
		 */
		p -= 4;
198
		for (i = 0; i < 4; i++, p++)
199
			if (nr_sects(p) && is_extended_partition(p))
L
Linus Torvalds 已提交
200 201 202 203
				break;
		if (i == 4)
			goto done;	 /* nothing left to do */

204 205
		this_sector = first_sector + start_sect(p) * sector_size;
		this_size = nr_sects(p) * sector_size;
L
Linus Torvalds 已提交
206 207 208 209 210 211 212 213 214
		put_dev_sector(sect);
	}
done:
	put_dev_sector(sect);
}

/* james@bpgc.com: Solaris has a nasty indicator: 0x82 which also
   indicates linux swap.  Be careful before believing this is Solaris. */

215 216
static void parse_solaris_x86(struct parsed_partitions *state,
			      sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
217 218 219 220 221
{
#ifdef CONFIG_SOLARIS_X86_PARTITION
	Sector sect;
	struct solaris_x86_vtoc *v;
	int i;
222
	short max_nparts;
L
Linus Torvalds 已提交
223

224
	v = read_part_sector(state, offset + 1, &sect);
L
Linus Torvalds 已提交
225 226 227 228 229 230
	if (!v)
		return;
	if (le32_to_cpu(v->v_sanity) != SOLARIS_X86_VTOC_SANE) {
		put_dev_sector(sect);
		return;
	}
231 232 233 234 235 236
	{
		char tmp[1 + BDEVNAME_SIZE + 10 + 11 + 1];

		snprintf(tmp, sizeof(tmp), " %s%d: <solaris:", state->name, origin);
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
	}
L
Linus Torvalds 已提交
237
	if (le32_to_cpu(v->v_version) != 1) {
238 239 240 241 242
		char tmp[64];

		snprintf(tmp, sizeof(tmp), "  cannot handle version %d vtoc>\n",
			 le32_to_cpu(v->v_version));
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
L
Linus Torvalds 已提交
243 244 245
		put_dev_sector(sect);
		return;
	}
246
	/* Ensure we can handle previous case of VTOC with 8 entries gracefully */
247 248
	max_nparts = le16_to_cpu(v->v_nparts) > 8 ? SOLARIS_X86_NUMSLICE : 8;
	for (i = 0; i < max_nparts && state->next < state->limit; i++) {
L
Linus Torvalds 已提交
249
		struct solaris_x86_slice *s = &v->v_slice[i];
250 251
		char tmp[3 + 10 + 1 + 1];

L
Linus Torvalds 已提交
252 253
		if (s->s_size == 0)
			continue;
254 255
		snprintf(tmp, sizeof(tmp), " [s%d]", i);
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
L
Linus Torvalds 已提交
256 257 258 259 260 261 262
		/* solaris partitions are relative to current MS-DOS
		 * one; must add the offset of the current partition */
		put_partition(state, state->next++,
				 le32_to_cpu(s->s_start)+offset,
				 le32_to_cpu(s->s_size));
	}
	put_dev_sector(sect);
263
	strlcat(state->pp_buf, " >\n", PAGE_SIZE);
L
Linus Torvalds 已提交
264 265 266
#endif
}

267
#if defined(CONFIG_BSD_DISKLABEL)
268
/*
L
Linus Torvalds 已提交
269 270 271
 * Create devices for BSD partitions listed in a disklabel, under a
 * dos-like partition. See parse_extended() for more information.
 */
272 273 274
static void parse_bsd(struct parsed_partitions *state,
		      sector_t offset, sector_t size, int origin, char *flavour,
		      int max_partitions)
L
Linus Torvalds 已提交
275 276 277 278
{
	Sector sect;
	struct bsd_disklabel *l;
	struct bsd_partition *p;
279
	char tmp[64];
L
Linus Torvalds 已提交
280

281
	l = read_part_sector(state, offset + 1, &sect);
L
Linus Torvalds 已提交
282 283 284 285 286 287
	if (!l)
		return;
	if (le32_to_cpu(l->d_magic) != BSD_DISKMAGIC) {
		put_dev_sector(sect);
		return;
	}
288 289 290

	snprintf(tmp, sizeof(tmp), " %s%d: <%s:", state->name, origin, flavour);
	strlcat(state->pp_buf, tmp, PAGE_SIZE);
L
Linus Torvalds 已提交
291 292 293 294

	if (le16_to_cpu(l->d_npartitions) < max_partitions)
		max_partitions = le16_to_cpu(l->d_npartitions);
	for (p = l->d_partitions; p - l->d_partitions < max_partitions; p++) {
295
		sector_t bsd_start, bsd_size;
L
Linus Torvalds 已提交
296 297 298

		if (state->next == state->limit)
			break;
299
		if (p->p_fstype == BSD_FS_UNUSED)
L
Linus Torvalds 已提交
300 301 302
			continue;
		bsd_start = le32_to_cpu(p->p_offset);
		bsd_size = le32_to_cpu(p->p_size);
303 304 305
		/* FreeBSD has relative offset if C partition offset is zero */
		if (memcmp(flavour, "bsd\0", 4) == 0 &&
		    le32_to_cpu(l->d_partitions[2].p_offset) == 0)
306
			bsd_start += offset;
L
Linus Torvalds 已提交
307 308 309 310
		if (offset == bsd_start && size == bsd_size)
			/* full parent partition, we have it already */
			continue;
		if (offset > bsd_start || offset+size < bsd_start+bsd_size) {
311
			strlcat(state->pp_buf, "bad subpartition - ignored\n", PAGE_SIZE);
L
Linus Torvalds 已提交
312 313 314 315 316
			continue;
		}
		put_partition(state, state->next++, bsd_start, bsd_size);
	}
	put_dev_sector(sect);
317 318 319 320 321 322
	if (le16_to_cpu(l->d_npartitions) > max_partitions) {
		snprintf(tmp, sizeof(tmp), " (ignored %d more)",
			 le16_to_cpu(l->d_npartitions) - max_partitions);
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
	}
	strlcat(state->pp_buf, " >\n", PAGE_SIZE);
L
Linus Torvalds 已提交
323 324 325
}
#endif

326 327
static void parse_freebsd(struct parsed_partitions *state,
			  sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
328 329
{
#ifdef CONFIG_BSD_DISKLABEL
330
	parse_bsd(state, offset, size, origin, "bsd", BSD_MAXPARTITIONS);
L
Linus Torvalds 已提交
331 332 333
#endif
}

334 335
static void parse_netbsd(struct parsed_partitions *state,
			 sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
336 337
{
#ifdef CONFIG_BSD_DISKLABEL
338
	parse_bsd(state, offset, size, origin, "netbsd", BSD_MAXPARTITIONS);
L
Linus Torvalds 已提交
339 340 341
#endif
}

342 343
static void parse_openbsd(struct parsed_partitions *state,
			  sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
344 345
{
#ifdef CONFIG_BSD_DISKLABEL
346 347
	parse_bsd(state, offset, size, origin, "openbsd",
		  OPENBSD_MAXPARTITIONS);
L
Linus Torvalds 已提交
348 349 350 351 352 353 354
#endif
}

/*
 * Create devices for Unixware partitions listed in a disklabel, under a
 * dos-like partition. See parse_extended() for more information.
 */
355 356
static void parse_unixware(struct parsed_partitions *state,
			   sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
357 358 359 360 361 362
{
#ifdef CONFIG_UNIXWARE_DISKLABEL
	Sector sect;
	struct unixware_disklabel *l;
	struct unixware_slice *p;

363
	l = read_part_sector(state, offset + 29, &sect);
L
Linus Torvalds 已提交
364 365 366 367 368 369 370
	if (!l)
		return;
	if (le32_to_cpu(l->d_magic) != UNIXWARE_DISKMAGIC ||
	    le32_to_cpu(l->vtoc.v_magic) != UNIXWARE_DISKMAGIC2) {
		put_dev_sector(sect);
		return;
	}
371 372 373 374 375 376
	{
		char tmp[1 + BDEVNAME_SIZE + 10 + 12 + 1];

		snprintf(tmp, sizeof(tmp), " %s%d: <unixware:", state->name, origin);
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
	}
L
Linus Torvalds 已提交
377 378 379 380 381 382 383 384
	p = &l->vtoc.v_slice[1];
	/* I omit the 0th slice as it is the same as whole disk. */
	while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {
		if (state->next == state->limit)
			break;

		if (p->s_label != UNIXWARE_FS_UNUSED)
			put_partition(state, state->next++,
385 386
				      le32_to_cpu(p->start_sect),
				      le32_to_cpu(p->nr_sects));
L
Linus Torvalds 已提交
387 388 389
		p++;
	}
	put_dev_sector(sect);
390
	strlcat(state->pp_buf, " >\n", PAGE_SIZE);
L
Linus Torvalds 已提交
391 392 393 394 395 396 397 398
#endif
}

/*
 * Minix 2.0.0/2.0.2 subpartition support.
 * Anand Krishnamurthy <anandk@wiproge.med.ge.com>
 * Rajeev V. Pillai    <rajeevvp@yahoo.com>
 */
399 400
static void parse_minix(struct parsed_partitions *state,
			sector_t offset, sector_t size, int origin)
L
Linus Torvalds 已提交
401 402 403 404
{
#ifdef CONFIG_MINIX_SUBPARTITION
	Sector sect;
	unsigned char *data;
405
	struct msdos_partition *p;
L
Linus Torvalds 已提交
406 407
	int i;

408
	data = read_part_sector(state, offset, &sect);
L
Linus Torvalds 已提交
409 410 411
	if (!data)
		return;

412
	p = (struct msdos_partition *)(data + 0x1be);
L
Linus Torvalds 已提交
413 414 415 416

	/* The first sector of a Minix partition can have either
	 * a secondary MBR describing its subpartitions, or
	 * the normal boot sector. */
417
	if (msdos_magic_present(data + 510) &&
L
Linus Torvalds 已提交
418
	    SYS_IND(p) == MINIX_PARTITION) { /* subpartition table present */
419
		char tmp[1 + BDEVNAME_SIZE + 10 + 9 + 1];
L
Linus Torvalds 已提交
420

421 422
		snprintf(tmp, sizeof(tmp), " %s%d: <minix:", state->name, origin);
		strlcat(state->pp_buf, tmp, PAGE_SIZE);
L
Linus Torvalds 已提交
423 424 425 426 427 428
		for (i = 0; i < MINIX_NR_SUBPARTITIONS; i++, p++) {
			if (state->next == state->limit)
				break;
			/* add each partition in use */
			if (SYS_IND(p) == MINIX_PARTITION)
				put_partition(state, state->next++,
429
					      start_sect(p), nr_sects(p));
L
Linus Torvalds 已提交
430
		}
431
		strlcat(state->pp_buf, " >\n", PAGE_SIZE);
L
Linus Torvalds 已提交
432 433 434 435 436 437 438
	}
	put_dev_sector(sect);
#endif /* CONFIG_MINIX_SUBPARTITION */
}

static struct {
	unsigned char id;
439
	void (*parse)(struct parsed_partitions *, sector_t, sector_t, int);
L
Linus Torvalds 已提交
440 441 442 443 444 445 446 447 448 449
} subtypes[] = {
	{FREEBSD_PARTITION, parse_freebsd},
	{NETBSD_PARTITION, parse_netbsd},
	{OPENBSD_PARTITION, parse_openbsd},
	{MINIX_PARTITION, parse_minix},
	{UNIXWARE_PARTITION, parse_unixware},
	{SOLARIS_X86_PARTITION, parse_solaris_x86},
	{NEW_SOLARIS_X86_PARTITION, parse_solaris_x86},
	{0, NULL},
};
450

451
int msdos_partition(struct parsed_partitions *state)
L
Linus Torvalds 已提交
452
{
453
	sector_t sector_size = bdev_logical_block_size(state->bdev) / 512;
L
Linus Torvalds 已提交
454 455
	Sector sect;
	unsigned char *data;
456
	struct msdos_partition *p;
457
	struct fat_boot_sector *fb;
L
Linus Torvalds 已提交
458
	int slot;
459
	u32 disksig;
L
Linus Torvalds 已提交
460

461
	data = read_part_sector(state, 0, &sect);
L
Linus Torvalds 已提交
462 463
	if (!data)
		return -1;
464 465 466 467 468 469

	/*
	 * Note order! (some AIX disks, e.g. unbootable kind,
	 * have no MSDOS 55aa)
	 */
	if (aix_magic_present(state, data)) {
L
Linus Torvalds 已提交
470
		put_dev_sector(sect);
471 472 473
#ifdef CONFIG_AIX_PARTITION
		return aix_partition(state);
#else
474
		strlcat(state->pp_buf, " [AIX]", PAGE_SIZE);
L
Linus Torvalds 已提交
475
		return 0;
476
#endif
L
Linus Torvalds 已提交
477 478
	}

479
	if (!msdos_magic_present(data + 510)) {
480 481 482 483
		put_dev_sector(sect);
		return 0;
	}

L
Linus Torvalds 已提交
484 485 486 487 488 489
	/*
	 * Now that the 55aa signature is present, this is probably
	 * either the boot sector of a FAT filesystem or a DOS-type
	 * partition table. Reject this in case the boot indicator
	 * is not 0 or 0x80.
	 */
490
	p = (struct msdos_partition *) (data + 0x1be);
L
Linus Torvalds 已提交
491 492
	for (slot = 1; slot <= 4; slot++, p++) {
		if (p->boot_ind != 0 && p->boot_ind != 0x80) {
493 494 495 496 497 498 499 500
			/*
			 * Even without a valid boot inidicator value
			 * its still possible this is valid FAT filesystem
			 * without a partition table.
			 */
			fb = (struct fat_boot_sector *) data;
			if (slot == 1 && fb->reserved && fb->fats
				&& fat_valid_media(fb->media)) {
501
				strlcat(state->pp_buf, "\n", PAGE_SIZE);
502 503 504 505 506 507
				put_dev_sector(sect);
				return 1;
			} else {
				put_dev_sector(sect);
				return 0;
			}
L
Linus Torvalds 已提交
508 509 510 511
		}
	}

#ifdef CONFIG_EFI_PARTITION
512
	p = (struct msdos_partition *) (data + 0x1be);
L
Linus Torvalds 已提交
513 514 515 516 517 518 519 520
	for (slot = 1 ; slot <= 4 ; slot++, p++) {
		/* If this is an EFI GPT disk, msdos should ignore it. */
		if (SYS_IND(p) == EFI_PMBR_OSTYPE_EFI_GPT) {
			put_dev_sector(sect);
			return 0;
		}
	}
#endif
521
	p = (struct msdos_partition *) (data + 0x1be);
L
Linus Torvalds 已提交
522

523 524
	disksig = le32_to_cpup((__le32 *)(data + 0x1b8));

L
Linus Torvalds 已提交
525 526 527 528 529 530 531 532
	/*
	 * Look for partitions in two passes:
	 * First find the primary and DOS-type extended partitions.
	 * On the second pass look inside *BSD, Unixware and Solaris partitions.
	 */

	state->next = 5;
	for (slot = 1 ; slot <= 4 ; slot++, p++) {
533 534
		sector_t start = start_sect(p)*sector_size;
		sector_t size = nr_sects(p)*sector_size;
535

L
Linus Torvalds 已提交
536 537 538
		if (!size)
			continue;
		if (is_extended_partition(p)) {
539 540 541 542 543 544 545
			/*
			 * prevent someone doing mkfs or mkswap on an
			 * extended partition, but leave room for LILO
			 * FIXME: this uses one logical sector for > 512b
			 * sector, although it may not be enough/proper.
			 */
			sector_t n = 2;
546

547 548 549
			n = min(size, max(sector_size, n));
			put_partition(state, slot, start, n);

550
			strlcat(state->pp_buf, " <", PAGE_SIZE);
551
			parse_extended(state, start, size, disksig);
552
			strlcat(state->pp_buf, " >", PAGE_SIZE);
L
Linus Torvalds 已提交
553 554 555
			continue;
		}
		put_partition(state, slot, start, size);
556
		set_info(state, slot, disksig);
L
Linus Torvalds 已提交
557
		if (SYS_IND(p) == LINUX_RAID_PARTITION)
558
			state->parts[slot].flags = ADDPART_FLAG_RAID;
L
Linus Torvalds 已提交
559
		if (SYS_IND(p) == DM6_PARTITION)
560
			strlcat(state->pp_buf, "[DM]", PAGE_SIZE);
L
Linus Torvalds 已提交
561
		if (SYS_IND(p) == EZD_PARTITION)
562
			strlcat(state->pp_buf, "[EZD]", PAGE_SIZE);
L
Linus Torvalds 已提交
563 564
	}

565
	strlcat(state->pp_buf, "\n", PAGE_SIZE);
L
Linus Torvalds 已提交
566 567

	/* second pass - output for each on a separate line */
568
	p = (struct msdos_partition *) (0x1be + data);
L
Linus Torvalds 已提交
569 570 571 572
	for (slot = 1 ; slot <= 4 ; slot++, p++) {
		unsigned char id = SYS_IND(p);
		int n;

573
		if (!nr_sects(p))
L
Linus Torvalds 已提交
574 575 576 577 578 579 580
			continue;

		for (n = 0; subtypes[n].parse && id != subtypes[n].id; n++)
			;

		if (!subtypes[n].parse)
			continue;
581 582
		subtypes[n].parse(state, start_sect(p) * sector_size,
				  nr_sects(p) * sector_size, slot);
L
Linus Torvalds 已提交
583 584 585 586
	}
	put_dev_sector(sect);
	return 1;
}