aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide
diff options
context:
space:
mode:
authorBorislav Petkov <bbpetkov@yahoo.de>2008-02-02 13:56:35 -0500
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-02-02 13:56:35 -0500
commit20bf7bdad443d473826832674230834654b31d0b (patch)
tree6bab53dad5839b04628c99a8486761d5dcb906f2 /drivers/ide
parent194ec0c07895d8f8bf3ca8e50d5225f7968ad2d0 (diff)
ide-floppy: factor out ioctl handlers from idefloppy_ioctl()
By passing idefloppy_floppy_t *floppy to the factored out functions, we get rid of (almost) all local vars so stack usage should be at minimum here. Also, we merge idefloppy_begin_format() into idefloppy_format_start() since it is its only user. Also, rename idefloppy_format_start() to idefloppy_format_unit(). Finally, rename the reworked functions to ide_floppy..(). Bart - minor CodingStyle fixup Signed-off-by: Borislav Petkov <bbpetkov@yahoo.de> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide')
-rw-r--r--drivers/ide/ide-floppy.c153
1 files changed, 78 insertions, 75 deletions
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 28a0bae94e82..af4b633fa3d1 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -1290,44 +1290,6 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
1290} 1290}
1291 1291
1292/* 1292/*
1293** Send ATAPI_FORMAT_UNIT to the drive.
1294**
1295** Userland gives us the following structure:
1296**
1297** struct idefloppy_format_command {
1298** int nblocks;
1299** int blocksize;
1300** int flags;
1301** } ;
1302**
1303** flags is a bitmask, currently, the only defined flag is:
1304**
1305** 0x01 - verify media after format.
1306*/
1307
1308static int idefloppy_begin_format(ide_drive_t *drive, int __user *arg)
1309{
1310 int blocks;
1311 int length;
1312 int flags;
1313 idefloppy_pc_t pc;
1314
1315 if (get_user(blocks, arg) ||
1316 get_user(length, arg+1) ||
1317 get_user(flags, arg+2)) {
1318 return (-EFAULT);
1319 }
1320
1321 (void) idefloppy_get_sfrp_bit(drive);
1322 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1323 if (idefloppy_queue_pc_tail(drive, &pc)) {
1324 return (-EIO);
1325 }
1326
1327 return (0);
1328}
1329
1330/*
1331** Get ATAPI_FORMAT_UNIT progress indication. 1293** Get ATAPI_FORMAT_UNIT progress indication.
1332** 1294**
1333** Userland gives a pointer to an int. The int is set to a progress 1295** Userland gives a pointer to an int. The int is set to a progress
@@ -1678,64 +1640,105 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1678 return 0; 1640 return 0;
1679} 1641}
1680 1642
1643static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, idefloppy_pc_t *pc,
1644 unsigned long arg, unsigned int cmd)
1645{
1646 if (floppy->openers > 1)
1647 return -EBUSY;
1648
1649 /* The IOMEGA Clik! Drive doesn't support this command -
1650 * no room for an eject mechanism */
1651 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1652 int prevent = arg ? 1 : 0;
1653
1654 if (cmd == CDROMEJECT)
1655 prevent = 0;
1656
1657 idefloppy_create_prevent_cmd(pc, prevent);
1658 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1659 }
1660
1661 if (cmd == CDROMEJECT) {
1662 idefloppy_create_start_stop_cmd(pc, 2);
1663 (void) idefloppy_queue_pc_tail(floppy->drive, pc);
1664 }
1665
1666 return 0;
1667}
1668
1669static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
1670 int __user *arg)
1671{
1672 int blocks, length, flags, err = 0;
1673 idefloppy_pc_t pc;
1674
1675 if (floppy->openers > 1) {
1676 /* Don't format if someone is using the disk */
1677 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1678 return -EBUSY;
1679 }
1680
1681 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1682
1683 /*
1684 * Send ATAPI_FORMAT_UNIT to the drive.
1685 *
1686 * Userland gives us the following structure:
1687 *
1688 * struct idefloppy_format_command {
1689 * int nblocks;
1690 * int blocksize;
1691 * int flags;
1692 * } ;
1693 *
1694 * flags is a bitmask, currently, the only defined flag is:
1695 *
1696 * 0x01 - verify media after format.
1697 */
1698 if (get_user(blocks, arg) ||
1699 get_user(length, arg+1) ||
1700 get_user(flags, arg+2)) {
1701 err = -EFAULT;
1702 goto out;
1703 }
1704
1705 (void) idefloppy_get_sfrp_bit(floppy->drive);
1706 idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
1707
1708 if (idefloppy_queue_pc_tail(floppy->drive, &pc))
1709 err = -EIO;
1710
1711out:
1712 if (err)
1713 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1714 return err;
1715}
1716
1717
1681static int idefloppy_ioctl(struct inode *inode, struct file *file, 1718static int idefloppy_ioctl(struct inode *inode, struct file *file,
1682 unsigned int cmd, unsigned long arg) 1719 unsigned int cmd, unsigned long arg)
1683{ 1720{
1684 struct block_device *bdev = inode->i_bdev; 1721 struct block_device *bdev = inode->i_bdev;
1685 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); 1722 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
1686 ide_drive_t *drive = floppy->drive; 1723 ide_drive_t *drive = floppy->drive;
1724 idefloppy_pc_t pc;
1687 void __user *argp = (void __user *)arg; 1725 void __user *argp = (void __user *)arg;
1688 int err; 1726 int err;
1689 int prevent = (arg) ? 1 : 0;
1690 idefloppy_pc_t pc;
1691 1727
1692 switch (cmd) { 1728 switch (cmd) {
1693 case CDROMEJECT: 1729 case CDROMEJECT:
1694 prevent = 0;
1695 /* fall through */ 1730 /* fall through */
1696 case CDROM_LOCKDOOR: 1731 case CDROM_LOCKDOOR:
1697 if (floppy->openers > 1) 1732 return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
1698 return -EBUSY;
1699
1700 /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */
1701 if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) {
1702 idefloppy_create_prevent_cmd(&pc, prevent);
1703 (void) idefloppy_queue_pc_tail(drive, &pc);
1704 }
1705 if (cmd == CDROMEJECT) {
1706 idefloppy_create_start_stop_cmd(&pc, 2);
1707 (void) idefloppy_queue_pc_tail(drive, &pc);
1708 }
1709 return 0;
1710 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 1733 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
1711 return 0; 1734 return 0;
1712 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: 1735 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
1713 return ide_floppy_get_format_capacities(drive, argp); 1736 return ide_floppy_get_format_capacities(drive, argp);
1714 case IDEFLOPPY_IOCTL_FORMAT_START: 1737 case IDEFLOPPY_IOCTL_FORMAT_START:
1715
1716 if (!(file->f_mode & 2)) 1738 if (!(file->f_mode & 2))
1717 return -EPERM; 1739 return -EPERM;
1718 1740
1719 if (floppy->openers > 1) { 1741 return ide_floppy_format_unit(floppy, (int __user *)arg);
1720 /* Don't format if someone is using the disk */
1721
1722 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS,
1723 &floppy->flags);
1724 return -EBUSY;
1725 }
1726
1727 set_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1728
1729 err = idefloppy_begin_format(drive, argp);
1730 if (err)
1731 clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags);
1732 return err;
1733 /*
1734 ** Note, the bit will be cleared when the device is
1735 ** closed. This is the cleanest way to handle the
1736 ** situation where the drive does not support
1737 ** format progress reporting.
1738 */
1739 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: 1742 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
1740 return idefloppy_get_format_progress(drive, argp); 1743 return idefloppy_get_format_progress(drive, argp);
1741 } 1744 }