/* If the volume is damaged because of an interrupted update this function just returns immediately with %-EBADF code.  */
int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
/* If the volume is damaged because of an interrupted update this function just returns immediately with %-EBADF code.  */
int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
{
	struct ubi_volume *vol = desc->vol;
	struct ubi_device *ubi = vol->ubi;
	int err;
	dbg_msg("erase LEB %d:%d", vol->vol_id, lnum);
	if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
		return -EROFS;
	if (lnum < 0 || lnum >= vol->reserved_pebs)
		return -EINVAL;
	if (vol->upd_marker)
		return -EBADF;
	err = ubi_eba_unmap_leb(ubi, vol, lnum);
	if (err)
		return err;
	return ubi_wl_flush(ubi);
}