static int ide_gd_open(struct block_device *bdev, fmode_t mode) { struct gendisk *disk = bdev->bd_disk; struct ide_disk_obj *idkp; ide_drive_t *drive; int ret = 0; idkp = ide_disk_get(disk); if (idkp == NULL) return -ENXIO; drive = idkp->drive; ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__); idkp->openers++; if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; /* Just in case */ ret = drive->disk_ops->init_media(drive, disk); /* * Allow O_NDELAY to open a drive without a disk, or with an * unreadable disk, so that we can get the format capacity * of the drive or begin the format - Sam */ if (ret && (mode & FMODE_NDELAY) == 0) { ret = -EIO; goto out_put_idkp; } if ((drive->dev_flags & IDE_DFLAG_WP) && (mode & FMODE_WRITE)) { ret = -EROFS; goto out_put_idkp; } /* * Ignore the return code from door_lock, * since the open() has already succeeded, * and the door_lock is irrelevant at this point. */ drive->disk_ops->set_doorlock(drive, disk, 1); drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; check_disk_change(bdev); } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { ret = -EBUSY; goto out_put_idkp; } return 0; out_put_idkp: idkp->openers--; ide_disk_put(idkp); return ret; }
static int ide_gd_open(struct block_device *bdev, fmode_t mode) { struct gendisk *disk = bdev->bd_disk; struct ide_disk_obj *idkp; ide_drive_t *drive; int ret = 0; idkp = ide_disk_get(disk); if (idkp == NULL) return -ENXIO; drive = idkp->drive; ide_debug_log(IDE_DBG_FUNC, "enter"); idkp->openers++; if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { drive->dev_flags &= ~IDE_DFLAG_FORMAT_IN_PROGRESS; ret = drive->disk_ops->init_media(drive, disk); if (ret && (mode & FMODE_NDELAY) == 0) { ret = -EIO; goto out_put_idkp; } if ((drive->dev_flags & IDE_DFLAG_WP) && (mode & FMODE_WRITE)) { ret = -EROFS; goto out_put_idkp; } drive->disk_ops->set_doorlock(drive, disk, 1); drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; check_disk_change(bdev); } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { ret = -EBUSY; goto out_put_idkp; } return 0; out_put_idkp: idkp->openers--; ide_disk_put(idkp); return ret; }