/* This function changes the contents of a logical eraseblock atomically. @buf has to contain new logical eraseblock data, and @len - the length of the data, which has to be aligned. The length may be shorter than the logical eraseblock size, ant the logical eraseblock may be appended to more times later on. This function guarantees that in case of an unclean reboot the old contents is preserved. Returns zero in case of success and a negative error code in case of failure.  */
int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, int len)
/* This function changes the contents of a logical eraseblock atomically. @buf has to contain new logical eraseblock data, and @len - the length of the data, which has to be aligned. The length may be shorter than the logical eraseblock size, ant the logical eraseblock may be appended to more times later on. This function guarantees that in case of an unclean reboot the old contents is preserved. Returns zero in case of success and a negative error code in case of failure.  */
int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, int len)
{
	struct ubi_volume *vol = desc->vol;
	struct ubi_device *ubi = vol->ubi;
	int vol_id = vol->vol_id;
	dbg_gen("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum);
	if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
		return -EINVAL;
	if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
		return -EROFS;
	if (lnum < 0 || lnum >= vol->reserved_pebs || len < 0 ||
	    len > vol->usable_leb_size || len & (ubi->min_io_size - 1))
		return -EINVAL;
	if (vol->upd_marker)
		return -EBADF;
	if (len == 0)
		return 0;
	return ubi_eba_atomic_leb_change(ubi, vol, lnum, buf, len);
}