diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:33 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:33 -0400 |
commit | aa7687738af3332470e02ac1060f6c046d83c9a3 (patch) | |
tree | 2eb2cd89de0b8dcad12534e28a9178d0325ae491 /drivers/ide/ide-disk.c | |
parent | 9232c14bff36d65de254f34386c00b732c5b6099 (diff) |
ide: add ide_setting_ioctl() helper
* Add struct ide_ioctl_devset representing ioctl device setting.
* Add ide_setting_ioctl() helper for matching given ioctl
and its parameters against table of ioctl device settings.
* Convert ide_setting_ioctl() and idedisk_ioctl() to use
ide_setting_ioctl().
* Un-export ide_setting_mtx.
While at it:
* {get,set}_lba_addressing() -> {get,set}_addressing()
There should be no functional changes caused by this patch.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-disk.c')
-rw-r--r-- | drivers/ide/ide-disk.c | 59 |
1 files changed, 18 insertions, 41 deletions
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 43025c9d8355..119063470820 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c | |||
@@ -676,7 +676,7 @@ static int set_acoustic(ide_drive_t *drive, int arg) | |||
676 | return 0; | 676 | return 0; |
677 | } | 677 | } |
678 | 678 | ||
679 | ide_devset_get(lba_addressing, addressing); | 679 | ide_devset_get(addressing, addressing); |
680 | 680 | ||
681 | /* | 681 | /* |
682 | * drive->addressing: | 682 | * drive->addressing: |
@@ -684,7 +684,7 @@ ide_devset_get(lba_addressing, addressing); | |||
684 | * 1: 48-bit | 684 | * 1: 48-bit |
685 | * 2: 48-bit capable doing 28-bit | 685 | * 2: 48-bit capable doing 28-bit |
686 | */ | 686 | */ |
687 | static int set_lba_addressing(ide_drive_t *drive, int arg) | 687 | static int set_addressing(ide_drive_t *drive, int arg) |
688 | { | 688 | { |
689 | if (arg < 0 || arg > 2) | 689 | if (arg < 0 || arg > 2) |
690 | return -EINVAL; | 690 | return -EINVAL; |
@@ -704,7 +704,7 @@ static int set_lba_addressing(ide_drive_t *drive, int arg) | |||
704 | 704 | ||
705 | #ifdef CONFIG_IDE_PROC_FS | 705 | #ifdef CONFIG_IDE_PROC_FS |
706 | ide_devset_rw_nolock(acoustic, 0, 254, acoustic); | 706 | ide_devset_rw_nolock(acoustic, 0, 254, acoustic); |
707 | ide_devset_rw_nolock(address, 0, 2, lba_addressing); | 707 | ide_devset_rw_nolock(address, 0, 2, addressing); |
708 | ide_devset_rw_nolock(multcount, 0, 16, multcount); | 708 | ide_devset_rw_nolock(multcount, 0, 16, multcount); |
709 | ide_devset_rw_nolock(nowerr, 0, 1, nowerr); | 709 | ide_devset_rw_nolock(nowerr, 0, 1, nowerr); |
710 | ide_devset_rw_nolock(wcache, 0, 1, wcache); | 710 | ide_devset_rw_nolock(wcache, 0, 1, wcache); |
@@ -753,7 +753,7 @@ static void idedisk_setup(ide_drive_t *drive) | |||
753 | drive->doorlocking = 1; | 753 | drive->doorlocking = 1; |
754 | } | 754 | } |
755 | 755 | ||
756 | (void)set_lba_addressing(drive, 1); | 756 | (void)set_addressing(drive, 1); |
757 | 757 | ||
758 | if (drive->addressing == 1) { | 758 | if (drive->addressing == 1) { |
759 | int max_s = 2048; | 759 | int max_s = 2048; |
@@ -1000,51 +1000,28 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo) | |||
1000 | return 0; | 1000 | return 0; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = { | ||
1004 | { HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, get_addressing, set_addressing }, | ||
1005 | { HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, get_multcount, set_multcount }, | ||
1006 | { HDIO_GET_NOWERR, HDIO_SET_NOWERR, get_nowerr, set_nowerr }, | ||
1007 | { HDIO_GET_WCACHE, HDIO_SET_WCACHE, get_wcache, set_wcache }, | ||
1008 | { HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, get_acoustic, set_acoustic }, | ||
1009 | { 0 } | ||
1010 | }; | ||
1011 | |||
1003 | static int idedisk_ioctl(struct inode *inode, struct file *file, | 1012 | static int idedisk_ioctl(struct inode *inode, struct file *file, |
1004 | unsigned int cmd, unsigned long arg) | 1013 | unsigned int cmd, unsigned long arg) |
1005 | { | 1014 | { |
1006 | unsigned long flags; | ||
1007 | struct block_device *bdev = inode->i_bdev; | 1015 | struct block_device *bdev = inode->i_bdev; |
1008 | struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); | 1016 | struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); |
1009 | ide_drive_t *drive = idkp->drive; | 1017 | ide_drive_t *drive = idkp->drive; |
1010 | int err, (*getfunc)(ide_drive_t *), (*setfunc)(ide_drive_t *, int); | 1018 | int err; |
1011 | |||
1012 | switch (cmd) { | ||
1013 | case HDIO_GET_ADDRESS: getfunc = get_lba_addressing; goto read_val; | ||
1014 | case HDIO_GET_MULTCOUNT: getfunc = get_multcount; goto read_val; | ||
1015 | case HDIO_GET_NOWERR: getfunc = get_nowerr; goto read_val; | ||
1016 | case HDIO_GET_WCACHE: getfunc = get_wcache; goto read_val; | ||
1017 | case HDIO_GET_ACOUSTIC: getfunc = get_acoustic; goto read_val; | ||
1018 | case HDIO_SET_ADDRESS: setfunc = set_lba_addressing; goto set_val; | ||
1019 | case HDIO_SET_MULTCOUNT: setfunc = set_multcount; goto set_val; | ||
1020 | case HDIO_SET_NOWERR: setfunc = set_nowerr; goto set_val; | ||
1021 | case HDIO_SET_WCACHE: setfunc = set_wcache; goto set_val; | ||
1022 | case HDIO_SET_ACOUSTIC: setfunc = set_acoustic; goto set_val; | ||
1023 | } | ||
1024 | 1019 | ||
1025 | return generic_ide_ioctl(drive, file, bdev, cmd, arg); | 1020 | err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); |
1021 | if (err != -EOPNOTSUPP) | ||
1022 | return err; | ||
1026 | 1023 | ||
1027 | read_val: | 1024 | return generic_ide_ioctl(drive, file, bdev, cmd, arg); |
1028 | mutex_lock(&ide_setting_mtx); | ||
1029 | spin_lock_irqsave(&ide_lock, flags); | ||
1030 | err = getfunc(drive); | ||
1031 | spin_unlock_irqrestore(&ide_lock, flags); | ||
1032 | mutex_unlock(&ide_setting_mtx); | ||
1033 | return err >= 0 ? put_user(err, (long __user *)arg) : err; | ||
1034 | |||
1035 | set_val: | ||
1036 | if (bdev != bdev->bd_contains) | ||
1037 | err = -EINVAL; | ||
1038 | else { | ||
1039 | if (!capable(CAP_SYS_ADMIN)) | ||
1040 | err = -EACCES; | ||
1041 | else { | ||
1042 | mutex_lock(&ide_setting_mtx); | ||
1043 | err = setfunc(drive, arg); | ||
1044 | mutex_unlock(&ide_setting_mtx); | ||
1045 | } | ||
1046 | } | ||
1047 | return err; | ||
1048 | } | 1025 | } |
1049 | 1026 | ||
1050 | static int idedisk_media_changed(struct gendisk *disk) | 1027 | static int idedisk_media_changed(struct gendisk *disk) |