/* This function checks if static volume @vol_id is corrupted by fully reading it and checking data CRC. This function returns %0 if the volume is not corrupted, %1 if it is corrupted and a negative error code in case of failure. Dynamic volumes are not checked and zero is returned immediately.  */
int ubi_check_volume(struct ubi_device *ubi, int vol_id)
/* This function checks if static volume @vol_id is corrupted by fully reading it and checking data CRC. This function returns %0 if the volume is not corrupted, %1 if it is corrupted and a negative error code in case of failure. Dynamic volumes are not checked and zero is returned immediately.  */
int ubi_check_volume(struct ubi_device *ubi, int vol_id)
{
	void *buf;
	int err = 0, i;
	struct ubi_volume *vol = ubi->volumes[vol_id];
	if (vol->vol_type != UBI_STATIC_VOLUME)
		return 0;
	buf = vmalloc(vol->usable_leb_size);
	if (!buf)
		return -ENOMEM;
	for (i = 0; i < vol->used_ebs; i++) {
		int size;
		if (i == vol->used_ebs - 1)
			size = vol->last_eb_bytes;
		else
			size = vol->usable_leb_size;
		err = ubi_eba_read_leb(ubi, vol, i, buf, 0, size, 1);
		if (err) {
			if (err == -EBADMSG)
				err = 1;
			break;
		}
	}
	vfree(buf);
	return err;
}