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/atari.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)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Copyright (C) 1991-1998  Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Re-organised Feb 1998 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "check.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "atari.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) /* ++guenther: this should be settable by the user ("make config")?.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #define ICD_PARTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) /* check if a partition entry looks valid -- Atari format is assumed if at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)    least one of the primary entries is ok this way */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define	VALID_PARTITION(pi,hdsiz)					     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)     (((pi)->flg & 1) &&							     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)      isalnum((pi)->id[0]) && isalnum((pi)->id[1]) && isalnum((pi)->id[2]) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)      be32_to_cpu((pi)->st) <= (hdsiz) &&				     \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)      be32_to_cpu((pi)->st) + be32_to_cpu((pi)->siz) <= (hdsiz))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static inline int OK_id(char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	return  memcmp (s, "GEM", 3) == 0 || memcmp (s, "BGM", 3) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		memcmp (s, "LNX", 3) == 0 || memcmp (s, "SWP", 3) == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		memcmp (s, "RAW", 3) == 0 ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) int atari_partition(struct parsed_partitions *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	Sector sect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct rootsector *rs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct partition_info *pi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	u32 extensect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	u32 hd_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #ifdef ICD_PARTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 * ATARI partition scheme supports 512 lba only.  If this is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 * the case, bail early to avoid miscalculating hd_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (bdev_logical_block_size(state->bdev) != 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	rs = read_part_sector(state, 0, &sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (!rs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/* Verify this is an Atari rootsector: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	hd_size = state->bdev->bd_inode->i_size >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (!VALID_PARTITION(&rs->part[0], hd_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	    !VALID_PARTITION(&rs->part[1], hd_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	    !VALID_PARTITION(&rs->part[2], hd_size) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	    !VALID_PARTITION(&rs->part[3], hd_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		 * if there's no valid primary partition, assume that no Atari
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 * format partition table (there's no reliable magic or the like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	         * :-()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		put_dev_sector(sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	pi = &rs->part[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	strlcat(state->pp_buf, " AHDI", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		struct rootsector *xrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		Sector sect2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		ulong partsect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		if ( !(pi->flg & 1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		/* active partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if (memcmp (pi->id, "XGM", 3) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			/* we don't care about other id's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			put_partition (state, slot, be32_to_cpu(pi->st),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 					be32_to_cpu(pi->siz));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		/* extension partition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #ifdef ICD_PARTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		part_fmt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		strlcat(state->pp_buf, " XGM<", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		partsect = extensect = be32_to_cpu(pi->st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			xrs = read_part_sector(state, partsect, &sect2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			if (!xrs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 				printk (" block %ld read failed\n", partsect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 				put_dev_sector(sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 				return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			/* ++roman: sanity check: bit 0 of flg field must be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			if (!(xrs->part[0].flg & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				printk( "\nFirst sub-partition in extended partition is not valid!\n" );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 				put_dev_sector(sect2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			put_partition(state, slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				   partsect + be32_to_cpu(xrs->part[0].st),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 				   be32_to_cpu(xrs->part[0].siz));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			if (!(xrs->part[1].flg & 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 				/* end of linked partition list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 				put_dev_sector(sect2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			if (memcmp( xrs->part[1].id, "XGM", 3 ) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				printk("\nID of extended partition is not XGM!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				put_dev_sector(sect2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			partsect = be32_to_cpu(xrs->part[1].st) + extensect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			put_dev_sector(sect2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			if (++slot == state->limit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 				printk( "\nMaximum number of partitions reached!\n" );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		strlcat(state->pp_buf, " >", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #ifdef ICD_PARTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if ( part_fmt!=1 ) { /* no extended partitions -> test ICD-format */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		pi = &rs->icdpart[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		/* sanity check: no ICD format if first partition invalid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		if (OK_id(pi->id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			strlcat(state->pp_buf, " ICD<", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 				/* accept only GEM,BGM,RAW,LNX,SWP partitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 				if (!((pi->flg & 1) && OK_id(pi->id)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				part_fmt = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				put_partition (state, slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 						be32_to_cpu(pi->st),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 						be32_to_cpu(pi->siz));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			strlcat(state->pp_buf, " >", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	put_dev_sector(sect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	strlcat(state->pp_buf, "\n", PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }