/* This function returns a positive number if the physical eraseblock is bad, zero if not, and a negative error code if an error occurred.  */
int ubi_io_is_bad(const struct ubi_device *ubi, int pnum)
/* This function returns a positive number if the physical eraseblock is bad, zero if not, and a negative error code if an error occurred.  */
int ubi_io_is_bad(const struct ubi_device *ubi, int pnum)
{
	struct mtd_info *mtd = ubi->mtd;
	ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
	if (ubi->bad_allowed) {
		int ret;
		ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size);
		if (ret < 0)
			ubi_err(ubi, "error %d while checking if PEB %d is bad",
				ret, pnum);
		else if (ret)
			dbg_io("PEB %d is bad", pnum);
		return ret;
	}
	return 0;
}