/* This function changes UBI volume open mode to "exclusive". Returns previous mode value (positive integer) in case of success and a negative error code in case of failure.  */
static int get_exclusive(struct ubi_volume_desc *desc)
/* This function changes UBI volume open mode to "exclusive". Returns previous mode value (positive integer) in case of success and a negative error code in case of failure.  */
static int get_exclusive(struct ubi_volume_desc *desc)
{
	int users, err;
	struct ubi_volume *vol = desc->vol;
	spin_lock(&vol->ubi->volumes_lock);
	users = vol->readers + vol->writers + vol->exclusive;
	ubi_assert(users > 0);
	if (users > 1) {
		dbg_err("%d users for volume %d", users, vol->vol_id);
		err = -EBUSY;
	} else {
		vol->readers = vol->writers = 0;
		vol->exclusive = 1;
		err = desc->mode;
		desc->mode = UBI_EXCLUSIVE;
	}
	spin_unlock(&vol->ubi->volumes_lock);
	return err;
}