/* This function returns zero if the volume attaching information is consistent to the data read from the volume tabla, and %-EINVAL if not.  */
static int check_av(const struct ubi_volume *vol, const struct ubi_ainf_volume *av)
/* This function returns zero if the volume attaching information is consistent to the data read from the volume tabla, and %-EINVAL if not.  */
static int check_av(const struct ubi_volume *vol, const struct ubi_ainf_volume *av)
{
	int err;
	if (av->highest_lnum >= vol->reserved_pebs) {
		err = 1;
		goto bad;
	}
	if (av->leb_count > vol->reserved_pebs) {
		err = 2;
		goto bad;
	}
	if (av->vol_type != vol->vol_type) {
		err = 3;
		goto bad;
	}
	if (av->used_ebs > vol->reserved_pebs) {
		err = 4;
		goto bad;
	}
	if (av->data_pad != vol->data_pad) {
		err = 5;
		goto bad;
	}
	return 0;
bad:
	ubi_err(vol->ubi, "bad attaching information, error %d", err);
	ubi_dump_av(av);
	ubi_dump_vol_info(vol);
	return -EINVAL;
}