/* This function changes volume table record @idx. If @vtbl_rec is NULL, empty volume table record is written. The caller does not have to calculate CRC of the record as it is done by this function. Returns zero in case of success and a negative error code in case of failure.  */
int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, struct ubi_vtbl_record *vtbl_rec)
/* This function changes volume table record @idx. If @vtbl_rec is NULL, empty volume table record is written. The caller does not have to calculate CRC of the record as it is done by this function. Returns zero in case of success and a negative error code in case of failure.  */
int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, struct ubi_vtbl_record *vtbl_rec)
{
	int err;
	uint32_t crc;
	ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);
	if (!vtbl_rec)
		vtbl_rec = &empty_vtbl_record;
	else {
		crc = crc32(UBI_CRC32_INIT, vtbl_rec, UBI_VTBL_RECORD_SIZE_CRC);
		vtbl_rec->crc = cpu_to_be32(crc);
	}
	memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
	err = ubi_update_layout_vol(ubi);
	self_vtbl_check(ubi);
	return err ? err : 0;
}