/* Check for a pattern at the given place. Used to search bad block tables and good / bad block identifiers. If the SCAN_EMPTY option is set then check, if all bytes except the pattern area contain 0xff  */
static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
/* Check for a pattern at the given place. Used to search bad block tables and good / bad block identifiers. If the SCAN_EMPTY option is set then check, if all bytes except the pattern area contain 0xff  */
static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td)
{
	int i, end = 0;
	uint8_t *p = buf;
	end = paglen + td->offs;
	if (td->options & NAND_BBT_SCANEMPTY) {
		for (i = 0; i < end; i++) {
			if (p[i] != 0xff)
				return -1;
		}
	}
	p += end;
	for (i = 0; i < td->len; i++) {
		if (p[i] != td->pattern[i])
			return -1;
	}
	if (td->options & NAND_BBT_SCANEMPTY) {
		p += td->len;
		end += td->len;
		for (i = end; i < len; i++) {
			if (*p++ != 0xff)
				return -1;
		}
	}
	return 0;
}