/* This function returns zero in case of success, %-EBADF if the volume is damaged because of an interrupted update, %-EBADMSG if the logical eraseblock is already mapped, and other negative error codes in case of other failures.  */
int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
/* This function returns zero in case of success, %-EBADF if the volume is damaged because of an interrupted update, %-EBADMSG if the logical eraseblock is already mapped, and other negative error codes in case of other failures.  */
int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
{
	struct ubi_volume *vol = desc->vol;
	struct ubi_device *ubi = vol->ubi;
	dbg_gen("unmap 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 (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM &&
	    dtype != UBI_UNKNOWN)
		return -EINVAL;
	if (vol->upd_marker)
		return -EBADF;
	if (vol->eba_tbl[lnum] >= 0)
		return -EBADMSG;
	return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype);
}