Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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