/* The open funcion. This is mostly needed to keep refcounting, but also to support media checks on removable media drives.  */
static int ub_bd_open(struct block_device *bdev, fmode_t mode)
/* The open funcion. This is mostly needed to keep refcounting, but also to support media checks on removable media drives.  */
static int ub_bd_open(struct block_device *bdev, fmode_t mode)
{
	struct ub_lun *lun = bdev->bd_disk->private_data;
	struct ub_dev *sc = lun->udev;
	unsigned long flags;
	int rc;
	spin_lock_irqsave(&ub_lock, flags);
	if (atomic_read(&sc->poison)) {
		spin_unlock_irqrestore(&ub_lock, flags);
		return -ENXIO;
	}
	sc->openc++;
	spin_unlock_irqrestore(&ub_lock, flags);
	if (lun->removable || lun->readonly)
		check_disk_change(bdev);
	if (lun->removable && lun->changed && !(mode & FMODE_NDELAY)) {
		rc = -ENOMEDIUM;
		goto err_open;
	}
	if (lun->readonly && (mode & FMODE_WRITE)) {
		rc = -EROFS;
		goto err_open;
	}
	return 0;
err_open:
	ub_put(sc);
	return rc;
}