aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide.c')
-rw-r--r--drivers/ide/ide.c174
1 files changed, 0 insertions, 174 deletions
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 19181493e722..349d7fa75585 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -489,180 +489,6 @@ static int generic_ide_resume(struct device *dev)
489 return err; 489 return err;
490} 490}
491 491
492static int generic_drive_reset(ide_drive_t *drive)
493{
494 struct request *rq;
495 int ret = 0;
496
497 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
498 rq->cmd_type = REQ_TYPE_SPECIAL;
499 rq->cmd_len = 1;
500 rq->cmd[0] = REQ_DRIVE_RESET;
501 rq->cmd_flags |= REQ_SOFTBARRIER;
502 if (blk_execute_rq(drive->queue, NULL, rq, 1))
503 ret = rq->errors;
504 blk_put_request(rq);
505 return ret;
506}
507
508static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
509 unsigned long arg)
510{
511 u16 *id = NULL;
512 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
513 int rc = 0;
514
515 if (drive->id_read == 0) {
516 rc = -ENOMSG;
517 goto out;
518 }
519
520 id = kmalloc(size, GFP_KERNEL);
521 if (id == NULL) {
522 rc = -ENOMEM;
523 goto out;
524 }
525
526 memcpy(id, drive->id, size);
527 ata_id_to_hd_driveid(id);
528
529 if (copy_to_user((void __user *)arg, id, size))
530 rc = -EFAULT;
531
532 kfree(id);
533out:
534 return rc;
535}
536
537static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
538{
539 return put_user((drive->dsc_overlap << IDE_NICE_DSC_OVERLAP) |
540 (drive->nice1 << IDE_NICE_1), (long __user *)arg);
541}
542
543static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
544{
545 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
546 return -EPERM;
547
548 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
549 (drive->media == ide_disk || drive->media == ide_floppy ||
550 drive->scsi))
551 return -EPERM;
552
553 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
554 drive->nice1 = (arg >> IDE_NICE_1) & 1;
555
556 return 0;
557}
558
559static const struct ide_ioctl_devset ide_ioctl_settings[] = {
560{ HDIO_GET_32BIT, HDIO_SET_32BIT, get_io_32bit, set_io_32bit },
561{ HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, get_ksettings, set_ksettings },
562{ HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, get_unmaskirq, set_unmaskirq },
563{ HDIO_GET_DMA, HDIO_SET_DMA, get_using_dma, set_using_dma },
564{ -1, HDIO_SET_PIO_MODE, NULL, set_pio_mode },
565{ 0 }
566};
567
568int generic_ide_ioctl(ide_drive_t *drive, struct file *file,
569 struct block_device *bdev,
570 unsigned int cmd, unsigned long arg)
571{
572 int err;
573
574 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_ioctl_settings);
575 if (err != -EOPNOTSUPP)
576 return err;
577
578 switch (cmd) {
579 case HDIO_OBSOLETE_IDENTITY:
580 case HDIO_GET_IDENTITY:
581 if (bdev != bdev->bd_contains)
582 return -EINVAL;
583 return ide_get_identity_ioctl(drive, cmd, arg);
584 case HDIO_GET_NICE:
585 return ide_get_nice_ioctl(drive, arg);
586 case HDIO_SET_NICE:
587 if (!capable(CAP_SYS_ADMIN))
588 return -EACCES;
589 return ide_set_nice_ioctl(drive, arg);
590#ifdef CONFIG_IDE_TASK_IOCTL
591 case HDIO_DRIVE_TASKFILE:
592 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
593 return -EACCES;
594 if (drive->media == ide_disk)
595 return ide_taskfile_ioctl(drive, cmd, arg);
596 return -ENOMSG;
597#endif
598 case HDIO_DRIVE_CMD:
599 if (!capable(CAP_SYS_RAWIO))
600 return -EACCES;
601 return ide_cmd_ioctl(drive, cmd, arg);
602 case HDIO_DRIVE_TASK:
603 if (!capable(CAP_SYS_RAWIO))
604 return -EACCES;
605 return ide_task_ioctl(drive, cmd, arg);
606 case HDIO_DRIVE_RESET:
607 if (!capable(CAP_SYS_ADMIN))
608 return -EACCES;
609 return generic_drive_reset(drive);
610 case HDIO_GET_BUSSTATE:
611 if (!capable(CAP_SYS_ADMIN))
612 return -EACCES;
613 if (put_user(BUSSTATE_ON, (long __user *)arg))
614 return -EFAULT;
615 return 0;
616 case HDIO_SET_BUSSTATE:
617 if (!capable(CAP_SYS_ADMIN))
618 return -EACCES;
619 return -EOPNOTSUPP;
620 default:
621 return -EINVAL;
622 }
623}
624EXPORT_SYMBOL(generic_ide_ioctl);
625
626int ide_setting_ioctl(ide_drive_t *drive, struct block_device *bdev,
627 unsigned int cmd, unsigned long arg,
628 const struct ide_ioctl_devset *s)
629{
630 unsigned long flags;
631 int err = -EOPNOTSUPP;
632
633 for (; s->get_ioctl; s++) {
634 if (s->get && s->get_ioctl == cmd)
635 goto read_val;
636 else if (s->set && s->set_ioctl == cmd)
637 goto set_val;
638 }
639
640 return err;
641
642read_val:
643 mutex_lock(&ide_setting_mtx);
644 spin_lock_irqsave(&ide_lock, flags);
645 err = s->get(drive);
646 spin_unlock_irqrestore(&ide_lock, flags);
647 mutex_unlock(&ide_setting_mtx);
648 return err >= 0 ? put_user(err, (long __user *)arg) : err;
649
650set_val:
651 if (bdev != bdev->bd_contains)
652 err = -EINVAL;
653 else {
654 if (!capable(CAP_SYS_ADMIN))
655 err = -EACCES;
656 else {
657 mutex_lock(&ide_setting_mtx);
658 err = s->set(drive, arg);
659 mutex_unlock(&ide_setting_mtx);
660 }
661 }
662 return err;
663}
664EXPORT_SYMBOL_GPL(ide_setting_ioctl);
665
666/** 492/**
667 * ide_device_get - get an additional reference to a ide_drive_t 493 * ide_device_get - get an additional reference to a ide_drive_t
668 * @drive: device to get a reference to 494 * @drive: device to get a reference to