static DEFINE_MUTEX(idedisk_ref_mutex);
-#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
-
static void ide_disk_release(struct kref *);
static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
struct ide_disk_obj *idkp = NULL;
mutex_lock(&idedisk_ref_mutex);
- idkp = ide_disk_g(disk);
+ idkp = ide_drv_g(disk, ide_disk_obj);
if (idkp) {
if (ide_device_get(idkp->drive))
idkp = NULL;
if (ata_id_hpa_enabled(id))
idedisk_check_hpa(drive);
}
+
+ /* limit drive capacity to 137GB if LBA48 cannot be used */
+ if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
+ drive->capacity64 > 1ULL << 28) {
+ printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
+ "%llu sectors (%llu MB)\n",
+ drive->name, (unsigned long long)drive->capacity64,
+ sectors_to_MB(drive->capacity64));
+ drive->capacity64 = 1ULL << 28;
+ }
+
+ if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
+ (drive->dev_flags & IDE_DFLAG_LBA48)) {
+ if (drive->capacity64 > 1ULL << 28) {
+ printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
+ " will be used for accessing sectors "
+ "> %u\n", drive->name, 1 << 28);
+ } else
+ drive->dev_flags &= ~IDE_DFLAG_LBA48;
+ }
}
sector_t ide_disk_capacity(ide_drive_t *drive)
/* calculate drive capacity, and select LBA if possible */
init_idedisk_capacity(drive);
- /* limit drive capacity to 137GB if LBA48 cannot be used */
- if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
- drive->capacity64 > 1ULL << 28) {
- printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
- "%llu sectors (%llu MB)\n",
- drive->name, (unsigned long long)drive->capacity64,
- sectors_to_MB(drive->capacity64));
- drive->capacity64 = 1ULL << 28;
- }
-
- if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
- (drive->dev_flags & IDE_DFLAG_LBA48)) {
- if (drive->capacity64 > 1ULL << 28) {
- printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
- " will be used for accessing sectors "
- "> %u\n", drive->name, 1 << 28);
- } else
- drive->dev_flags &= ~IDE_DFLAG_LBA48;
- }
-
/*
* if possible, give fdisk access to more of the drive,
* by correcting bios_cyls:
static void ide_disk_release(struct kref *kref)
{
- struct ide_disk_obj *idkp = to_ide_disk(kref);
+ struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
struct gendisk *g = idkp->disk;
static int idedisk_set_doorlock(ide_drive_t *drive, int on)
{
ide_task_t task;
+ int ret;
+
+ if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
+ return 0;
memset(&task, 0, sizeof(task));
task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
- return ide_no_data_taskfile(drive, &task);
+ ret = ide_no_data_taskfile(drive, &task);
+
+ if (ret)
+ drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+
+ return ret;
}
static int idedisk_open(struct inode *inode, struct file *filp)
idkp->openers++;
if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
- check_disk_change(inode->i_bdev);
/*
* Ignore the return code from door_lock,
* since the open() has already succeeded,
* and the door_lock is irrelevant at this point.
*/
- if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
- idedisk_set_doorlock(drive, 1))
- drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+ idedisk_set_doorlock(drive, 1);
+ check_disk_change(inode->i_bdev);
}
return 0;
}
static int idedisk_release(struct inode *inode, struct file *filp)
{
struct gendisk *disk = inode->i_bdev->bd_disk;
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
if (idkp->openers == 1)
ide_cacheflush_p(drive);
- if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
- if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
- idedisk_set_doorlock(drive, 0))
- drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
- }
+ if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
+ idedisk_set_doorlock(drive, 0);
idkp->openers--;
static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{
- struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
+ struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
geo->heads = drive->bios_head;
static int idedisk_media_changed(struct gendisk *disk)
{
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
ide_drive_t *drive = idkp->drive;
/* do not scan partitions twice if this is a removable device */
static int idedisk_revalidate_disk(struct gendisk *disk)
{
- struct ide_disk_obj *idkp = ide_disk_g(disk);
+ struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
set_capacity(disk, ide_disk_capacity(idkp->drive));
return 0;
}