aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-23 13:23:07 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-23 13:23:07 -0400
commit22484856402bfa1ff3defe47f6029ab0418240d9 (patch)
tree140c67bf59674da350a7b51765d6ff7eb101b597 /drivers
parent5ed487bc2c44ca4e9668ef9cb54c830e2a9fac47 (diff)
parent56b26add02b4bdea81d5e0ebda60db1fe3311ad4 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/viro/bdev
* git://git.kernel.org/pub/scm/linux/kernel/git/viro/bdev: (66 commits) [PATCH] kill the rest of struct file propagation in block ioctls [PATCH] get rid of struct file use in blkdev_ioctl() BLKBSZSET [PATCH] get rid of blkdev_locked_ioctl() [PATCH] get rid of blkdev_driver_ioctl() [PATCH] sanitize blkdev_get() and friends [PATCH] remember mode of reiserfs journal [PATCH] propagate mode through swsusp_close() [PATCH] propagate mode through open_bdev_excl/close_bdev_excl [PATCH] pass fmode_t to blkdev_put() [PATCH] kill the unused bsize on the send side of /dev/loop [PATCH] trim file propagation in block/compat_ioctl.c [PATCH] end of methods switch: remove the old ones [PATCH] switch sr [PATCH] switch sd [PATCH] switch ide-scsi [PATCH] switch tape_block [PATCH] switch dcssblk [PATCH] switch dasd [PATCH] switch mtd_blkdevs [PATCH] switch mmc ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/DAC960.c6
-rw-r--r--drivers/block/amiflop.c46
-rw-r--r--drivers/block/aoe/aoeblk.c12
-rw-r--r--drivers/block/ataflop.c37
-rw-r--r--drivers/block/brd.c5
-rw-r--r--drivers/block/cciss.c71
-rw-r--r--drivers/block/cpqarray.c28
-rw-r--r--drivers/block/floppy.c54
-rw-r--r--drivers/block/loop.c59
-rw-r--r--drivers/block/nbd.c28
-rw-r--r--drivers/block/paride/pcd.c21
-rw-r--r--drivers/block/paride/pd.c14
-rw-r--r--drivers/block/paride/pf.c22
-rw-r--r--drivers/block/paride/pt.c2
-rw-r--r--drivers/block/pktcdvd.c56
-rw-r--r--drivers/block/swim3.c32
-rw-r--r--drivers/block/ub.c22
-rw-r--r--drivers/block/viodasd.c10
-rw-r--r--drivers/block/virtio_blk.c8
-rw-r--r--drivers/block/xd.c4
-rw-r--r--drivers/block/xd.h2
-rw-r--r--drivers/block/xen-blkfront.c15
-rw-r--r--drivers/block/xsysace.c11
-rw-r--r--drivers/block/z2ram.c7
-rw-r--r--drivers/cdrom/cdrom.c23
-rw-r--r--drivers/cdrom/gdrom.c14
-rw-r--r--drivers/cdrom/viocd.c21
-rw-r--r--drivers/char/nvram.c6
-rw-r--r--drivers/char/raw.c8
-rw-r--r--drivers/ide/ide-cd.c22
-rw-r--r--drivers/ide/ide-disk.h2
-rw-r--r--drivers/ide/ide-disk_ioctl.c5
-rw-r--r--drivers/ide/ide-floppy.h4
-rw-r--r--drivers/ide/ide-floppy_ioctl.c17
-rw-r--r--drivers/ide/ide-gd.c20
-rw-r--r--drivers/ide/ide-ioctls.c3
-rw-r--r--drivers/ide/ide-tape.c17
-rw-r--r--drivers/md/dm-ioctl.c4
-rw-r--r--drivers/md/dm-linear.c13
-rw-r--r--drivers/md/dm-mpath.c14
-rw-r--r--drivers/md/dm-table.c16
-rw-r--r--drivers/md/dm.c27
-rw-r--r--drivers/md/md.c20
-rw-r--r--drivers/memstick/core/mspro_block.c9
-rw-r--r--drivers/message/i2o/i2o_block.c13
-rw-r--r--drivers/mmc/card/block.c13
-rw-r--r--drivers/mtd/devices/block2mtd.c4
-rw-r--r--drivers/mtd/mtd_blkdevs.c24
-rw-r--r--drivers/mtd/mtdchar.c10
-rw-r--r--drivers/parisc/eisa_eeprom.c2
-rw-r--r--drivers/s390/block/dasd.c11
-rw-r--r--drivers/s390/block/dasd_genhd.c4
-rw-r--r--drivers/s390/block/dasd_int.h3
-rw-r--r--drivers/s390/block/dasd_ioctl.c15
-rw-r--r--drivers/s390/block/dcssblk.c17
-rw-r--r--drivers/s390/char/tape_block.c25
-rw-r--r--drivers/scsi/ide-scsi.c22
-rw-r--r--drivers/scsi/scsi_ioctl.c6
-rw-r--r--drivers/scsi/sd.c35
-rw-r--r--drivers/scsi/sg.c2
-rw-r--r--drivers/scsi/sr.c40
-rw-r--r--drivers/scsi/st.c7
62 files changed, 496 insertions, 594 deletions
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index a002a381df92..f6a337c34ac4 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -72,9 +72,9 @@ static long disk_size(DAC960_Controller_T *p, int drive_nr)
72 } 72 }
73} 73}
74 74
75static int DAC960_open(struct inode *inode, struct file *file) 75static int DAC960_open(struct block_device *bdev, fmode_t mode)
76{ 76{
77 struct gendisk *disk = inode->i_bdev->bd_disk; 77 struct gendisk *disk = bdev->bd_disk;
78 DAC960_Controller_T *p = disk->queue->queuedata; 78 DAC960_Controller_T *p = disk->queue->queuedata;
79 int drive_nr = (long)disk->private_data; 79 int drive_nr = (long)disk->private_data;
80 80
@@ -89,7 +89,7 @@ static int DAC960_open(struct inode *inode, struct file *file)
89 return -ENXIO; 89 return -ENXIO;
90 } 90 }
91 91
92 check_disk_change(inode->i_bdev); 92 check_disk_change(bdev);
93 93
94 if (!get_capacity(p->disks[drive_nr])) 94 if (!get_capacity(p->disks[drive_nr]))
95 return -ENXIO; 95 return -ENXIO;
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 7516baff3bb9..4b1d4ac960f1 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -1437,10 +1437,11 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1437 return 0; 1437 return 0;
1438} 1438}
1439 1439
1440static int fd_ioctl(struct inode *inode, struct file *filp, 1440static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1441 unsigned int cmd, unsigned long param) 1441 unsigned int cmd, unsigned long param)
1442{ 1442{
1443 int drive = iminor(inode) & 3; 1443 struct amiga_floppy_struct *p = bdev->bd_disk->private_data;
1444 int drive = p - unit;
1444 static struct floppy_struct getprm; 1445 static struct floppy_struct getprm;
1445 void __user *argp = (void __user *)param; 1446 void __user *argp = (void __user *)param;
1446 1447
@@ -1451,7 +1452,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
1451 rel_fdc(); 1452 rel_fdc();
1452 return -EBUSY; 1453 return -EBUSY;
1453 } 1454 }
1454 fsync_bdev(inode->i_bdev); 1455 fsync_bdev(bdev);
1455 if (fd_motor_on(drive) == 0) { 1456 if (fd_motor_on(drive) == 0) {
1456 rel_fdc(); 1457 rel_fdc();
1457 return -ENODEV; 1458 return -ENODEV;
@@ -1464,12 +1465,12 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
1464 rel_fdc(); 1465 rel_fdc();
1465 break; 1466 break;
1466 case FDFMTTRK: 1467 case FDFMTTRK:
1467 if (param < unit[drive].type->tracks * unit[drive].type->heads) 1468 if (param < p->type->tracks * p->type->heads)
1468 { 1469 {
1469 get_fdc(drive); 1470 get_fdc(drive);
1470 if (fd_seek(drive,param) != 0){ 1471 if (fd_seek(drive,param) != 0){
1471 memset(unit[drive].trackbuf, FD_FILL_BYTE, 1472 memset(p->trackbuf, FD_FILL_BYTE,
1472 unit[drive].dtype->sects * unit[drive].type->sect_mult * 512); 1473 p->dtype->sects * p->type->sect_mult * 512);
1473 non_int_flush_track(drive); 1474 non_int_flush_track(drive);
1474 } 1475 }
1475 floppy_off(drive); 1476 floppy_off(drive);
@@ -1480,14 +1481,14 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
1480 break; 1481 break;
1481 case FDFMTEND: 1482 case FDFMTEND:
1482 floppy_off(drive); 1483 floppy_off(drive);
1483 invalidate_bdev(inode->i_bdev); 1484 invalidate_bdev(bdev);
1484 break; 1485 break;
1485 case FDGETPRM: 1486 case FDGETPRM:
1486 memset((void *)&getprm, 0, sizeof (getprm)); 1487 memset((void *)&getprm, 0, sizeof (getprm));
1487 getprm.track=unit[drive].type->tracks; 1488 getprm.track=p->type->tracks;
1488 getprm.head=unit[drive].type->heads; 1489 getprm.head=p->type->heads;
1489 getprm.sect=unit[drive].dtype->sects * unit[drive].type->sect_mult; 1490 getprm.sect=p->dtype->sects * p->type->sect_mult;
1490 getprm.size=unit[drive].blocks; 1491 getprm.size=p->blocks;
1491 if (copy_to_user(argp, &getprm, sizeof(struct floppy_struct))) 1492 if (copy_to_user(argp, &getprm, sizeof(struct floppy_struct)))
1492 return -EFAULT; 1493 return -EFAULT;
1493 break; 1494 break;
@@ -1500,10 +1501,10 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
1500 break; 1501 break;
1501#ifdef RAW_IOCTL 1502#ifdef RAW_IOCTL
1502 case IOCTL_RAW_TRACK: 1503 case IOCTL_RAW_TRACK:
1503 if (copy_to_user(argp, raw_buf, unit[drive].type->read_size)) 1504 if (copy_to_user(argp, raw_buf, p->type->read_size))
1504 return -EFAULT; 1505 return -EFAULT;
1505 else 1506 else
1506 return unit[drive].type->read_size; 1507 return p->type->read_size;
1507#endif 1508#endif
1508 default: 1509 default:
1509 printk(KERN_DEBUG "fd_ioctl: unknown cmd %d for drive %d.", 1510 printk(KERN_DEBUG "fd_ioctl: unknown cmd %d for drive %d.",
@@ -1548,10 +1549,10 @@ static void fd_probe(int dev)
1548 * /dev/PS0 etc), and disallows simultaneous access to the same 1549 * /dev/PS0 etc), and disallows simultaneous access to the same
1549 * drive with different device numbers. 1550 * drive with different device numbers.
1550 */ 1551 */
1551static int floppy_open(struct inode *inode, struct file *filp) 1552static int floppy_open(struct block_device *bdev, fmode_t mode)
1552{ 1553{
1553 int drive = iminor(inode) & 3; 1554 int drive = MINOR(bdev->bd_dev) & 3;
1554 int system = (iminor(inode) & 4) >> 2; 1555 int system = (MINOR(bdev->bd_dev) & 4) >> 2;
1555 int old_dev; 1556 int old_dev;
1556 unsigned long flags; 1557 unsigned long flags;
1557 1558
@@ -1560,9 +1561,9 @@ static int floppy_open(struct inode *inode, struct file *filp)
1560 if (fd_ref[drive] && old_dev != system) 1561 if (fd_ref[drive] && old_dev != system)
1561 return -EBUSY; 1562 return -EBUSY;
1562 1563
1563 if (filp && filp->f_mode & 3) { 1564 if (mode & (FMODE_READ|FMODE_WRITE)) {
1564 check_disk_change(inode->i_bdev); 1565 check_disk_change(bdev);
1565 if (filp->f_mode & 2 ) { 1566 if (mode & FMODE_WRITE) {
1566 int wrprot; 1567 int wrprot;
1567 1568
1568 get_fdc(drive); 1569 get_fdc(drive);
@@ -1592,9 +1593,10 @@ static int floppy_open(struct inode *inode, struct file *filp)
1592 return 0; 1593 return 0;
1593} 1594}
1594 1595
1595static int floppy_release(struct inode * inode, struct file * filp) 1596static int floppy_release(struct gendisk *disk, fmode_t mode)
1596{ 1597{
1597 int drive = iminor(inode) & 3; 1598 struct amiga_floppy_struct *p = disk->private_data;
1599 int drive = p - unit;
1598 1600
1599 if (unit[drive].dirty == 1) { 1601 if (unit[drive].dirty == 1) {
1600 del_timer (flush_track_timer + drive); 1602 del_timer (flush_track_timer + drive);
@@ -1650,7 +1652,7 @@ static struct block_device_operations floppy_fops = {
1650 .owner = THIS_MODULE, 1652 .owner = THIS_MODULE,
1651 .open = floppy_open, 1653 .open = floppy_open,
1652 .release = floppy_release, 1654 .release = floppy_release,
1653 .ioctl = fd_ioctl, 1655 .locked_ioctl = fd_ioctl,
1654 .getgeo = fd_getgeo, 1656 .getgeo = fd_getgeo,
1655 .media_changed = amiga_floppy_change, 1657 .media_changed = amiga_floppy_change,
1656}; 1658};
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index d876ad861237..1747dd272cd4 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -118,13 +118,11 @@ aoedisk_rm_sysfs(struct aoedev *d)
118} 118}
119 119
120static int 120static int
121aoeblk_open(struct inode *inode, struct file *filp) 121aoeblk_open(struct block_device *bdev, fmode_t mode)
122{ 122{
123 struct aoedev *d; 123 struct aoedev *d = bdev->bd_disk->private_data;
124 ulong flags; 124 ulong flags;
125 125
126 d = inode->i_bdev->bd_disk->private_data;
127
128 spin_lock_irqsave(&d->lock, flags); 126 spin_lock_irqsave(&d->lock, flags);
129 if (d->flags & DEVFL_UP) { 127 if (d->flags & DEVFL_UP) {
130 d->nopen++; 128 d->nopen++;
@@ -136,13 +134,11 @@ aoeblk_open(struct inode *inode, struct file *filp)
136} 134}
137 135
138static int 136static int
139aoeblk_release(struct inode *inode, struct file *filp) 137aoeblk_release(struct gendisk *disk, fmode_t mode)
140{ 138{
141 struct aoedev *d; 139 struct aoedev *d = disk->private_data;
142 ulong flags; 140 ulong flags;
143 141
144 d = inode->i_bdev->bd_disk->private_data;
145
146 spin_lock_irqsave(&d->lock, flags); 142 spin_lock_irqsave(&d->lock, flags);
147 143
148 if (--d->nopen == 0) { 144 if (--d->nopen == 0) {
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 432cf4018291..69e1df7dfa14 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -361,13 +361,13 @@ static void finish_fdc( void );
361static void finish_fdc_done( int dummy ); 361static void finish_fdc_done( int dummy );
362static void setup_req_params( int drive ); 362static void setup_req_params( int drive );
363static void redo_fd_request( void); 363static void redo_fd_request( void);
364static int fd_ioctl( struct inode *inode, struct file *filp, unsigned int 364static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
365 cmd, unsigned long param); 365 cmd, unsigned long param);
366static void fd_probe( int drive ); 366static void fd_probe( int drive );
367static int fd_test_drive_present( int drive ); 367static int fd_test_drive_present( int drive );
368static void config_types( void ); 368static void config_types( void );
369static int floppy_open( struct inode *inode, struct file *filp ); 369static int floppy_open(struct block_device *bdev, fmode_t mode);
370static int floppy_release( struct inode * inode, struct file * filp ); 370static int floppy_release(struct gendisk *disk, fmode_t mode);
371 371
372/************************* End of Prototypes **************************/ 372/************************* End of Prototypes **************************/
373 373
@@ -1483,10 +1483,10 @@ void do_fd_request(struct request_queue * q)
1483 atari_enable_irq( IRQ_MFP_FDC ); 1483 atari_enable_irq( IRQ_MFP_FDC );
1484} 1484}
1485 1485
1486static int fd_ioctl(struct inode *inode, struct file *filp, 1486static int fd_ioctl(struct block_device *bdev, fmode_t mode,
1487 unsigned int cmd, unsigned long param) 1487 unsigned int cmd, unsigned long param)
1488{ 1488{
1489 struct gendisk *disk = inode->i_bdev->bd_disk; 1489 struct gendisk *disk = bdev->bd_disk;
1490 struct atari_floppy_struct *floppy = disk->private_data; 1490 struct atari_floppy_struct *floppy = disk->private_data;
1491 int drive = floppy - unit; 1491 int drive = floppy - unit;
1492 int type = floppy->type; 1492 int type = floppy->type;
@@ -1661,7 +1661,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
1661 /* invalidate the buffer track to force a reread */ 1661 /* invalidate the buffer track to force a reread */
1662 BufferDrive = -1; 1662 BufferDrive = -1;
1663 set_bit(drive, &fake_change); 1663 set_bit(drive, &fake_change);
1664 check_disk_change(inode->i_bdev); 1664 check_disk_change(bdev);
1665 return 0; 1665 return 0;
1666 default: 1666 default:
1667 return -EINVAL; 1667 return -EINVAL;
@@ -1804,37 +1804,36 @@ static void __init config_types( void )
1804 * drive with different device numbers. 1804 * drive with different device numbers.
1805 */ 1805 */
1806 1806
1807static int floppy_open( struct inode *inode, struct file *filp ) 1807static int floppy_open(struct block_device *bdev, fmode_t mode)
1808{ 1808{
1809 struct atari_floppy_struct *p = inode->i_bdev->bd_disk->private_data; 1809 struct atari_floppy_struct *p = bdev->bd_disk->private_data;
1810 int type = iminor(inode) >> 2; 1810 int type = MINOR(bdev->bd_dev) >> 2;
1811 1811
1812 DPRINT(("fd_open: type=%d\n",type)); 1812 DPRINT(("fd_open: type=%d\n",type));
1813 if (p->ref && p->type != type) 1813 if (p->ref && p->type != type)
1814 return -EBUSY; 1814 return -EBUSY;
1815 1815
1816 if (p->ref == -1 || (p->ref && filp->f_flags & O_EXCL)) 1816 if (p->ref == -1 || (p->ref && mode & FMODE_EXCL))
1817 return -EBUSY; 1817 return -EBUSY;
1818 1818
1819 if (filp->f_flags & O_EXCL) 1819 if (mode & FMODE_EXCL)
1820 p->ref = -1; 1820 p->ref = -1;
1821 else 1821 else
1822 p->ref++; 1822 p->ref++;
1823 1823
1824 p->type = type; 1824 p->type = type;
1825 1825
1826 if (filp->f_flags & O_NDELAY) 1826 if (mode & FMODE_NDELAY)
1827 return 0; 1827 return 0;
1828 1828
1829 if (filp->f_mode & 3) { 1829 if (mode & (FMODE_READ|FMODE_WRITE)) {
1830 check_disk_change(inode->i_bdev); 1830 check_disk_change(bdev);
1831 if (filp->f_mode & 2) { 1831 if (mode & FMODE_WRITE) {
1832 if (p->wpstat) { 1832 if (p->wpstat) {
1833 if (p->ref < 0) 1833 if (p->ref < 0)
1834 p->ref = 0; 1834 p->ref = 0;
1835 else 1835 else
1836 p->ref--; 1836 p->ref--;
1837 floppy_release(inode, filp);
1838 return -EROFS; 1837 return -EROFS;
1839 } 1838 }
1840 } 1839 }
@@ -1843,9 +1842,9 @@ static int floppy_open( struct inode *inode, struct file *filp )
1843} 1842}
1844 1843
1845 1844
1846static int floppy_release( struct inode * inode, struct file * filp ) 1845static int floppy_release(struct gendisk *disk, fmode_t mode)
1847{ 1846{
1848 struct atari_floppy_struct *p = inode->i_bdev->bd_disk->private_data; 1847 struct atari_floppy_struct *p = disk->private_data;
1849 if (p->ref < 0) 1848 if (p->ref < 0)
1850 p->ref = 0; 1849 p->ref = 0;
1851 else if (!p->ref--) { 1850 else if (!p->ref--) {
@@ -1859,7 +1858,7 @@ static struct block_device_operations floppy_fops = {
1859 .owner = THIS_MODULE, 1858 .owner = THIS_MODULE,
1860 .open = floppy_open, 1859 .open = floppy_open,
1861 .release = floppy_release, 1860 .release = floppy_release,
1862 .ioctl = fd_ioctl, 1861 .locked_ioctl = fd_ioctl,
1863 .media_changed = check_floppy_change, 1862 .media_changed = check_floppy_change,
1864 .revalidate_disk= floppy_revalidate, 1863 .revalidate_disk= floppy_revalidate,
1865}; 1864};
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index d070d492e385..bdd4f5f45575 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -340,11 +340,10 @@ static int brd_direct_access (struct block_device *bdev, sector_t sector,
340} 340}
341#endif 341#endif
342 342
343static int brd_ioctl(struct inode *inode, struct file *file, 343static int brd_ioctl(struct block_device *bdev, fmode_t mode,
344 unsigned int cmd, unsigned long arg) 344 unsigned int cmd, unsigned long arg)
345{ 345{
346 int error; 346 int error;
347 struct block_device *bdev = inode->i_bdev;
348 struct brd_device *brd = bdev->bd_disk->private_data; 347 struct brd_device *brd = bdev->bd_disk->private_data;
349 348
350 if (cmd != BLKFLSBUF) 349 if (cmd != BLKFLSBUF)
@@ -376,7 +375,7 @@ static int brd_ioctl(struct inode *inode, struct file *file,
376 375
377static struct block_device_operations brd_fops = { 376static struct block_device_operations brd_fops = {
378 .owner = THIS_MODULE, 377 .owner = THIS_MODULE,
379 .ioctl = brd_ioctl, 378 .locked_ioctl = brd_ioctl,
380#ifdef CONFIG_BLK_DEV_XIP 379#ifdef CONFIG_BLK_DEV_XIP
381 .direct_access = brd_direct_access, 380 .direct_access = brd_direct_access,
382#endif 381#endif
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 1e1f9153000c..4023885353e0 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -152,9 +152,9 @@ static ctlr_info_t *hba[MAX_CTLR];
152 152
153static void do_cciss_request(struct request_queue *q); 153static void do_cciss_request(struct request_queue *q);
154static irqreturn_t do_cciss_intr(int irq, void *dev_id); 154static irqreturn_t do_cciss_intr(int irq, void *dev_id);
155static int cciss_open(struct inode *inode, struct file *filep); 155static int cciss_open(struct block_device *bdev, fmode_t mode);
156static int cciss_release(struct inode *inode, struct file *filep); 156static int cciss_release(struct gendisk *disk, fmode_t mode);
157static int cciss_ioctl(struct inode *inode, struct file *filep, 157static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
158 unsigned int cmd, unsigned long arg); 158 unsigned int cmd, unsigned long arg);
159static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo); 159static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo);
160 160
@@ -192,14 +192,15 @@ static void cciss_procinit(int i)
192#endif /* CONFIG_PROC_FS */ 192#endif /* CONFIG_PROC_FS */
193 193
194#ifdef CONFIG_COMPAT 194#ifdef CONFIG_COMPAT
195static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg); 195static int cciss_compat_ioctl(struct block_device *, fmode_t,
196 unsigned, unsigned long);
196#endif 197#endif
197 198
198static struct block_device_operations cciss_fops = { 199static struct block_device_operations cciss_fops = {
199 .owner = THIS_MODULE, 200 .owner = THIS_MODULE,
200 .open = cciss_open, 201 .open = cciss_open,
201 .release = cciss_release, 202 .release = cciss_release,
202 .ioctl = cciss_ioctl, 203 .locked_ioctl = cciss_ioctl,
203 .getgeo = cciss_getgeo, 204 .getgeo = cciss_getgeo,
204#ifdef CONFIG_COMPAT 205#ifdef CONFIG_COMPAT
205 .compat_ioctl = cciss_compat_ioctl, 206 .compat_ioctl = cciss_compat_ioctl,
@@ -547,13 +548,13 @@ static inline drive_info_struct *get_drv(struct gendisk *disk)
547/* 548/*
548 * Open. Make sure the device is really there. 549 * Open. Make sure the device is really there.
549 */ 550 */
550static int cciss_open(struct inode *inode, struct file *filep) 551static int cciss_open(struct block_device *bdev, fmode_t mode)
551{ 552{
552 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); 553 ctlr_info_t *host = get_host(bdev->bd_disk);
553 drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk); 554 drive_info_struct *drv = get_drv(bdev->bd_disk);
554 555
555#ifdef CCISS_DEBUG 556#ifdef CCISS_DEBUG
556 printk(KERN_DEBUG "cciss_open %s\n", inode->i_bdev->bd_disk->disk_name); 557 printk(KERN_DEBUG "cciss_open %s\n", bdev->bd_disk->disk_name);
557#endif /* CCISS_DEBUG */ 558#endif /* CCISS_DEBUG */
558 559
559 if (host->busy_initializing || drv->busy_configuring) 560 if (host->busy_initializing || drv->busy_configuring)
@@ -567,9 +568,9 @@ static int cciss_open(struct inode *inode, struct file *filep)
567 * for "raw controller". 568 * for "raw controller".
568 */ 569 */
569 if (drv->heads == 0) { 570 if (drv->heads == 0) {
570 if (iminor(inode) != 0) { /* not node 0? */ 571 if (MINOR(bdev->bd_dev) != 0) { /* not node 0? */
571 /* if not node 0 make sure it is a partition = 0 */ 572 /* if not node 0 make sure it is a partition = 0 */
572 if (iminor(inode) & 0x0f) { 573 if (MINOR(bdev->bd_dev) & 0x0f) {
573 return -ENXIO; 574 return -ENXIO;
574 /* if it is, make sure we have a LUN ID */ 575 /* if it is, make sure we have a LUN ID */
575 } else if (drv->LunID == 0) { 576 } else if (drv->LunID == 0) {
@@ -587,14 +588,13 @@ static int cciss_open(struct inode *inode, struct file *filep)
587/* 588/*
588 * Close. Sync first. 589 * Close. Sync first.
589 */ 590 */
590static int cciss_release(struct inode *inode, struct file *filep) 591static int cciss_release(struct gendisk *disk, fmode_t mode)
591{ 592{
592 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); 593 ctlr_info_t *host = get_host(disk);
593 drive_info_struct *drv = get_drv(inode->i_bdev->bd_disk); 594 drive_info_struct *drv = get_drv(disk);
594 595
595#ifdef CCISS_DEBUG 596#ifdef CCISS_DEBUG
596 printk(KERN_DEBUG "cciss_release %s\n", 597 printk(KERN_DEBUG "cciss_release %s\n", disk->disk_name);
597 inode->i_bdev->bd_disk->disk_name);
598#endif /* CCISS_DEBUG */ 598#endif /* CCISS_DEBUG */
599 599
600 drv->usage_count--; 600 drv->usage_count--;
@@ -604,21 +604,23 @@ static int cciss_release(struct inode *inode, struct file *filep)
604 604
605#ifdef CONFIG_COMPAT 605#ifdef CONFIG_COMPAT
606 606
607static int do_ioctl(struct file *f, unsigned cmd, unsigned long arg) 607static int do_ioctl(struct block_device *bdev, fmode_t mode,
608 unsigned cmd, unsigned long arg)
608{ 609{
609 int ret; 610 int ret;
610 lock_kernel(); 611 lock_kernel();
611 ret = cciss_ioctl(f->f_path.dentry->d_inode, f, cmd, arg); 612 ret = cciss_ioctl(bdev, mode, cmd, arg);
612 unlock_kernel(); 613 unlock_kernel();
613 return ret; 614 return ret;
614} 615}
615 616
616static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, 617static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
617 unsigned long arg); 618 unsigned cmd, unsigned long arg);
618static int cciss_ioctl32_big_passthru(struct file *f, unsigned cmd, 619static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode,
619 unsigned long arg); 620 unsigned cmd, unsigned long arg);
620 621
621static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg) 622static int cciss_compat_ioctl(struct block_device *bdev, fmode_t mode,
623 unsigned cmd, unsigned long arg)
622{ 624{
623 switch (cmd) { 625 switch (cmd) {
624 case CCISS_GETPCIINFO: 626 case CCISS_GETPCIINFO:
@@ -636,20 +638,20 @@ static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg)
636 case CCISS_REGNEWD: 638 case CCISS_REGNEWD:
637 case CCISS_RESCANDISK: 639 case CCISS_RESCANDISK:
638 case CCISS_GETLUNINFO: 640 case CCISS_GETLUNINFO:
639 return do_ioctl(f, cmd, arg); 641 return do_ioctl(bdev, mode, cmd, arg);
640 642
641 case CCISS_PASSTHRU32: 643 case CCISS_PASSTHRU32:
642 return cciss_ioctl32_passthru(f, cmd, arg); 644 return cciss_ioctl32_passthru(bdev, mode, cmd, arg);
643 case CCISS_BIG_PASSTHRU32: 645 case CCISS_BIG_PASSTHRU32:
644 return cciss_ioctl32_big_passthru(f, cmd, arg); 646 return cciss_ioctl32_big_passthru(bdev, mode, cmd, arg);
645 647
646 default: 648 default:
647 return -ENOIOCTLCMD; 649 return -ENOIOCTLCMD;
648 } 650 }
649} 651}
650 652
651static int cciss_ioctl32_passthru(struct file *f, unsigned cmd, 653static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
652 unsigned long arg) 654 unsigned cmd, unsigned long arg)
653{ 655{
654 IOCTL32_Command_struct __user *arg32 = 656 IOCTL32_Command_struct __user *arg32 =
655 (IOCTL32_Command_struct __user *) arg; 657 (IOCTL32_Command_struct __user *) arg;
@@ -676,7 +678,7 @@ static int cciss_ioctl32_passthru(struct file *f, unsigned cmd,
676 if (err) 678 if (err)
677 return -EFAULT; 679 return -EFAULT;
678 680
679 err = do_ioctl(f, CCISS_PASSTHRU, (unsigned long)p); 681 err = do_ioctl(bdev, mode, CCISS_PASSTHRU, (unsigned long)p);
680 if (err) 682 if (err)
681 return err; 683 return err;
682 err |= 684 err |=
@@ -687,8 +689,8 @@ static int cciss_ioctl32_passthru(struct file *f, unsigned cmd,
687 return err; 689 return err;
688} 690}
689 691
690static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd, 692static int cciss_ioctl32_big_passthru(struct block_device *bdev, fmode_t mode,
691 unsigned long arg) 693 unsigned cmd, unsigned long arg)
692{ 694{
693 BIG_IOCTL32_Command_struct __user *arg32 = 695 BIG_IOCTL32_Command_struct __user *arg32 =
694 (BIG_IOCTL32_Command_struct __user *) arg; 696 (BIG_IOCTL32_Command_struct __user *) arg;
@@ -717,7 +719,7 @@ static int cciss_ioctl32_big_passthru(struct file *file, unsigned cmd,
717 if (err) 719 if (err)
718 return -EFAULT; 720 return -EFAULT;
719 721
720 err = do_ioctl(file, CCISS_BIG_PASSTHRU, (unsigned long)p); 722 err = do_ioctl(bdev, mode, CCISS_BIG_PASSTHRU, (unsigned long)p);
721 if (err) 723 if (err)
722 return err; 724 return err;
723 err |= 725 err |=
@@ -745,10 +747,9 @@ static int cciss_getgeo(struct block_device *bdev, struct hd_geometry *geo)
745/* 747/*
746 * ioctl 748 * ioctl
747 */ 749 */
748static int cciss_ioctl(struct inode *inode, struct file *filep, 750static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
749 unsigned int cmd, unsigned long arg) 751 unsigned int cmd, unsigned long arg)
750{ 752{
751 struct block_device *bdev = inode->i_bdev;
752 struct gendisk *disk = bdev->bd_disk; 753 struct gendisk *disk = bdev->bd_disk;
753 ctlr_info_t *host = get_host(disk); 754 ctlr_info_t *host = get_host(disk);
754 drive_info_struct *drv = get_drv(disk); 755 drive_info_struct *drv = get_drv(disk);
@@ -1232,7 +1233,7 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
1232 case SG_EMULATED_HOST: 1233 case SG_EMULATED_HOST:
1233 case SG_IO: 1234 case SG_IO:
1234 case SCSI_IOCTL_SEND_COMMAND: 1235 case SCSI_IOCTL_SEND_COMMAND:
1235 return scsi_cmd_ioctl(filep, disk->queue, disk, cmd, argp); 1236 return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
1236 1237
1237 /* scsi_cmd_ioctl would normally handle these, below, but */ 1238 /* scsi_cmd_ioctl would normally handle these, below, but */
1238 /* they aren't a good fit for cciss, as CD-ROMs are */ 1239 /* they aren't a good fit for cciss, as CD-ROMs are */
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index 3d967525e9a9..47d233c6d0b3 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -156,9 +156,9 @@ static int sendcmd(
156 unsigned int blkcnt, 156 unsigned int blkcnt,
157 unsigned int log_unit ); 157 unsigned int log_unit );
158 158
159static int ida_open(struct inode *inode, struct file *filep); 159static int ida_open(struct block_device *bdev, fmode_t mode);
160static int ida_release(struct inode *inode, struct file *filep); 160static int ida_release(struct gendisk *disk, fmode_t mode);
161static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg); 161static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg);
162static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo); 162static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo);
163static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io); 163static int ida_ctlr_ioctl(ctlr_info_t *h, int dsk, ida_ioctl_t *io);
164 164
@@ -197,7 +197,7 @@ static struct block_device_operations ida_fops = {
197 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
198 .open = ida_open, 198 .open = ida_open,
199 .release = ida_release, 199 .release = ida_release,
200 .ioctl = ida_ioctl, 200 .locked_ioctl = ida_ioctl,
201 .getgeo = ida_getgeo, 201 .getgeo = ida_getgeo,
202 .revalidate_disk= ida_revalidate, 202 .revalidate_disk= ida_revalidate,
203}; 203};
@@ -818,12 +818,12 @@ DBGINFO(
818/* 818/*
819 * Open. Make sure the device is really there. 819 * Open. Make sure the device is really there.
820 */ 820 */
821static int ida_open(struct inode *inode, struct file *filep) 821static int ida_open(struct block_device *bdev, fmode_t mode)
822{ 822{
823 drv_info_t *drv = get_drv(inode->i_bdev->bd_disk); 823 drv_info_t *drv = get_drv(bdev->bd_disk);
824 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); 824 ctlr_info_t *host = get_host(bdev->bd_disk);
825 825
826 DBGINFO(printk("ida_open %s\n", inode->i_bdev->bd_disk->disk_name)); 826 DBGINFO(printk("ida_open %s\n", bdev->bd_disk->disk_name));
827 /* 827 /*
828 * Root is allowed to open raw volume zero even if it's not configured 828 * Root is allowed to open raw volume zero even if it's not configured
829 * so array config can still work. I don't think I really like this, 829 * so array config can still work. I don't think I really like this,
@@ -843,9 +843,9 @@ static int ida_open(struct inode *inode, struct file *filep)
843/* 843/*
844 * Close. Sync first. 844 * Close. Sync first.
845 */ 845 */
846static int ida_release(struct inode *inode, struct file *filep) 846static int ida_release(struct gendisk *disk, fmode_t mode)
847{ 847{
848 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); 848 ctlr_info_t *host = get_host(disk);
849 host->usage_count--; 849 host->usage_count--;
850 return 0; 850 return 0;
851} 851}
@@ -1128,10 +1128,10 @@ static int ida_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1128 * ida_ioctl does some miscellaneous stuff like reporting drive geometry, 1128 * ida_ioctl does some miscellaneous stuff like reporting drive geometry,
1129 * setting readahead and submitting commands from userspace to the controller. 1129 * setting readahead and submitting commands from userspace to the controller.
1130 */ 1130 */
1131static int ida_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, unsigned long arg) 1131static int ida_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
1132{ 1132{
1133 drv_info_t *drv = get_drv(inode->i_bdev->bd_disk); 1133 drv_info_t *drv = get_drv(bdev->bd_disk);
1134 ctlr_info_t *host = get_host(inode->i_bdev->bd_disk); 1134 ctlr_info_t *host = get_host(bdev->bd_disk);
1135 int error; 1135 int error;
1136 ida_ioctl_t __user *io = (ida_ioctl_t __user *)arg; 1136 ida_ioctl_t __user *io = (ida_ioctl_t __user *)arg;
1137 ida_ioctl_t *my_io; 1137 ida_ioctl_t *my_io;
@@ -1165,7 +1165,7 @@ out_passthru:
1165 put_user(host->ctlr_sig, (int __user *)arg); 1165 put_user(host->ctlr_sig, (int __user *)arg);
1166 return 0; 1166 return 0;
1167 case IDAREVALIDATEVOLS: 1167 case IDAREVALIDATEVOLS:
1168 if (iminor(inode) != 0) 1168 if (MINOR(bdev->bd_dev) != 0)
1169 return -ENXIO; 1169 return -ENXIO;
1170 return revalidate_allvol(host); 1170 return revalidate_allvol(host);
1171 case IDADRIVERVERSION: 1171 case IDADRIVERVERSION:
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 2cea27aba9a0..14db747a636e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -3450,14 +3450,14 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
3450 return 0; 3450 return 0;
3451} 3451}
3452 3452
3453static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 3453static int fd_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd,
3454 unsigned long param) 3454 unsigned long param)
3455{ 3455{
3456#define FD_IOCTL_ALLOWED ((filp) && (filp)->private_data) 3456#define FD_IOCTL_ALLOWED (mode & (FMODE_WRITE|FMODE_WRITE_IOCTL))
3457#define OUT(c,x) case c: outparam = (const char *) (x); break 3457#define OUT(c,x) case c: outparam = (const char *) (x); break
3458#define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0 3458#define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0
3459 3459
3460 int drive = (long)inode->i_bdev->bd_disk->private_data; 3460 int drive = (long)bdev->bd_disk->private_data;
3461 int type = ITYPE(UDRS->fd_device); 3461 int type = ITYPE(UDRS->fd_device);
3462 int i; 3462 int i;
3463 int ret; 3463 int ret;
@@ -3516,11 +3516,11 @@ static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
3516 current_type[drive] = NULL; 3516 current_type[drive] = NULL;
3517 floppy_sizes[drive] = MAX_DISK_SIZE << 1; 3517 floppy_sizes[drive] = MAX_DISK_SIZE << 1;
3518 UDRS->keep_data = 0; 3518 UDRS->keep_data = 0;
3519 return invalidate_drive(inode->i_bdev); 3519 return invalidate_drive(bdev);
3520 case FDSETPRM: 3520 case FDSETPRM:
3521 case FDDEFPRM: 3521 case FDDEFPRM:
3522 return set_geometry(cmd, &inparam.g, 3522 return set_geometry(cmd, &inparam.g,
3523 drive, type, inode->i_bdev); 3523 drive, type, bdev);
3524 case FDGETPRM: 3524 case FDGETPRM:
3525 ECALL(get_floppy_geometry(drive, type, 3525 ECALL(get_floppy_geometry(drive, type,
3526 (struct floppy_struct **) 3526 (struct floppy_struct **)
@@ -3551,7 +3551,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
3551 case FDFMTEND: 3551 case FDFMTEND:
3552 case FDFLUSH: 3552 case FDFLUSH:
3553 LOCK_FDC(drive, 1); 3553 LOCK_FDC(drive, 1);
3554 return invalidate_drive(inode->i_bdev); 3554 return invalidate_drive(bdev);
3555 3555
3556 case FDSETEMSGTRESH: 3556 case FDSETEMSGTRESH:
3557 UDP->max_errors.reporting = 3557 UDP->max_errors.reporting =
@@ -3659,9 +3659,9 @@ static void __init config_types(void)
3659 printk("\n"); 3659 printk("\n");
3660} 3660}
3661 3661
3662static int floppy_release(struct inode *inode, struct file *filp) 3662static int floppy_release(struct gendisk *disk, fmode_t mode)
3663{ 3663{
3664 int drive = (long)inode->i_bdev->bd_disk->private_data; 3664 int drive = (long)disk->private_data;
3665 3665
3666 mutex_lock(&open_lock); 3666 mutex_lock(&open_lock);
3667 if (UDRS->fd_ref < 0) 3667 if (UDRS->fd_ref < 0)
@@ -3682,18 +3682,17 @@ static int floppy_release(struct inode *inode, struct file *filp)
3682 * /dev/PS0 etc), and disallows simultaneous access to the same 3682 * /dev/PS0 etc), and disallows simultaneous access to the same
3683 * drive with different device numbers. 3683 * drive with different device numbers.
3684 */ 3684 */
3685static int floppy_open(struct inode *inode, struct file *filp) 3685static int floppy_open(struct block_device *bdev, fmode_t mode)
3686{ 3686{
3687 int drive = (long)inode->i_bdev->bd_disk->private_data; 3687 int drive = (long)bdev->bd_disk->private_data;
3688 int old_dev; 3688 int old_dev, new_dev;
3689 int try; 3689 int try;
3690 int res = -EBUSY; 3690 int res = -EBUSY;
3691 char *tmp; 3691 char *tmp;
3692 3692
3693 filp->private_data = (void *)0;
3694 mutex_lock(&open_lock); 3693 mutex_lock(&open_lock);
3695 old_dev = UDRS->fd_device; 3694 old_dev = UDRS->fd_device;
3696 if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev) 3695 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
3697 goto out2; 3696 goto out2;
3698 3697
3699 if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) { 3698 if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) {
@@ -3701,15 +3700,15 @@ static int floppy_open(struct inode *inode, struct file *filp)
3701 USETF(FD_VERIFY); 3700 USETF(FD_VERIFY);
3702 } 3701 }
3703 3702
3704 if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL))) 3703 if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (mode & FMODE_EXCL)))
3705 goto out2; 3704 goto out2;
3706 3705
3707 if (filp->f_flags & O_EXCL) 3706 if (mode & FMODE_EXCL)
3708 UDRS->fd_ref = -1; 3707 UDRS->fd_ref = -1;
3709 else 3708 else
3710 UDRS->fd_ref++; 3709 UDRS->fd_ref++;
3711 3710
3712 opened_bdev[drive] = inode->i_bdev; 3711 opened_bdev[drive] = bdev;
3713 3712
3714 res = -ENXIO; 3713 res = -ENXIO;
3715 3714
@@ -3744,31 +3743,26 @@ static int floppy_open(struct inode *inode, struct file *filp)
3744 } 3743 }
3745 } 3744 }
3746 3745
3747 UDRS->fd_device = iminor(inode); 3746 new_dev = MINOR(bdev->bd_dev);
3748 set_capacity(disks[drive], floppy_sizes[iminor(inode)]); 3747 UDRS->fd_device = new_dev;
3749 if (old_dev != -1 && old_dev != iminor(inode)) { 3748 set_capacity(disks[drive], floppy_sizes[new_dev]);
3749 if (old_dev != -1 && old_dev != new_dev) {
3750 if (buffer_drive == drive) 3750 if (buffer_drive == drive)
3751 buffer_track = -1; 3751 buffer_track = -1;
3752 } 3752 }
3753 3753
3754 /* Allow ioctls if we have write-permissions even if read-only open.
3755 * Needed so that programs such as fdrawcmd still can work on write
3756 * protected disks */
3757 if ((filp->f_mode & FMODE_WRITE) || !file_permission(filp, MAY_WRITE))
3758 filp->private_data = (void *)8;
3759
3760 if (UFDCS->rawcmd == 1) 3754 if (UFDCS->rawcmd == 1)
3761 UFDCS->rawcmd = 2; 3755 UFDCS->rawcmd = 2;
3762 3756
3763 if (!(filp->f_flags & O_NDELAY)) { 3757 if (!(mode & FMODE_NDELAY)) {
3764 if (filp->f_mode & 3) { 3758 if (mode & (FMODE_READ|FMODE_WRITE)) {
3765 UDRS->last_checked = 0; 3759 UDRS->last_checked = 0;
3766 check_disk_change(inode->i_bdev); 3760 check_disk_change(bdev);
3767 if (UTESTF(FD_DISK_CHANGED)) 3761 if (UTESTF(FD_DISK_CHANGED))
3768 goto out; 3762 goto out;
3769 } 3763 }
3770 res = -EROFS; 3764 res = -EROFS;
3771 if ((filp->f_mode & 2) && !(UTESTF(FD_DISK_WRITABLE))) 3765 if ((mode & FMODE_WRITE) && !(UTESTF(FD_DISK_WRITABLE)))
3772 goto out; 3766 goto out;
3773 } 3767 }
3774 mutex_unlock(&open_lock); 3768 mutex_unlock(&open_lock);
@@ -3911,7 +3905,7 @@ static struct block_device_operations floppy_fops = {
3911 .owner = THIS_MODULE, 3905 .owner = THIS_MODULE,
3912 .open = floppy_open, 3906 .open = floppy_open,
3913 .release = floppy_release, 3907 .release = floppy_release,
3914 .ioctl = fd_ioctl, 3908 .locked_ioctl = fd_ioctl,
3915 .getgeo = fd_getgeo, 3909 .getgeo = fd_getgeo,
3916 .media_changed = check_floppy_change, 3910 .media_changed = check_floppy_change,
3917 .revalidate_disk = floppy_revalidate, 3911 .revalidate_disk = floppy_revalidate,
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index d3a25b027ff9..3f09cd8bcc38 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -210,7 +210,7 @@ lo_do_transfer(struct loop_device *lo, int cmd,
210 * space operations write_begin and write_end. 210 * space operations write_begin and write_end.
211 */ 211 */
212static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec, 212static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
213 int bsize, loff_t pos, struct page *unused) 213 loff_t pos, struct page *unused)
214{ 214{
215 struct file *file = lo->lo_backing_file; /* kudos to NFsckingS */ 215 struct file *file = lo->lo_backing_file; /* kudos to NFsckingS */
216 struct address_space *mapping = file->f_mapping; 216 struct address_space *mapping = file->f_mapping;
@@ -302,7 +302,7 @@ static int __do_lo_send_write(struct file *file,
302 * filesystems. 302 * filesystems.
303 */ 303 */
304static int do_lo_send_direct_write(struct loop_device *lo, 304static int do_lo_send_direct_write(struct loop_device *lo,
305 struct bio_vec *bvec, int bsize, loff_t pos, struct page *page) 305 struct bio_vec *bvec, loff_t pos, struct page *page)
306{ 306{
307 ssize_t bw = __do_lo_send_write(lo->lo_backing_file, 307 ssize_t bw = __do_lo_send_write(lo->lo_backing_file,
308 kmap(bvec->bv_page) + bvec->bv_offset, 308 kmap(bvec->bv_page) + bvec->bv_offset,
@@ -326,7 +326,7 @@ static int do_lo_send_direct_write(struct loop_device *lo,
326 * destination pages of the backing file. 326 * destination pages of the backing file.
327 */ 327 */
328static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec, 328static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec,
329 int bsize, loff_t pos, struct page *page) 329 loff_t pos, struct page *page)
330{ 330{
331 int ret = lo_do_transfer(lo, WRITE, page, 0, bvec->bv_page, 331 int ret = lo_do_transfer(lo, WRITE, page, 0, bvec->bv_page,
332 bvec->bv_offset, bvec->bv_len, pos >> 9); 332 bvec->bv_offset, bvec->bv_len, pos >> 9);
@@ -341,10 +341,9 @@ static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec,
341 return ret; 341 return ret;
342} 342}
343 343
344static int lo_send(struct loop_device *lo, struct bio *bio, int bsize, 344static int lo_send(struct loop_device *lo, struct bio *bio, loff_t pos)
345 loff_t pos)
346{ 345{
347 int (*do_lo_send)(struct loop_device *, struct bio_vec *, int, loff_t, 346 int (*do_lo_send)(struct loop_device *, struct bio_vec *, loff_t,
348 struct page *page); 347 struct page *page);
349 struct bio_vec *bvec; 348 struct bio_vec *bvec;
350 struct page *page = NULL; 349 struct page *page = NULL;
@@ -362,7 +361,7 @@ static int lo_send(struct loop_device *lo, struct bio *bio, int bsize,
362 } 361 }
363 } 362 }
364 bio_for_each_segment(bvec, bio, i) { 363 bio_for_each_segment(bvec, bio, i) {
365 ret = do_lo_send(lo, bvec, bsize, pos, page); 364 ret = do_lo_send(lo, bvec, pos, page);
366 if (ret < 0) 365 if (ret < 0)
367 break; 366 break;
368 pos += bvec->bv_len; 367 pos += bvec->bv_len;
@@ -478,7 +477,7 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
478 477
479 pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset; 478 pos = ((loff_t) bio->bi_sector << 9) + lo->lo_offset;
480 if (bio_rw(bio) == WRITE) 479 if (bio_rw(bio) == WRITE)
481 ret = lo_send(lo, bio, lo->lo_blocksize, pos); 480 ret = lo_send(lo, bio, pos);
482 else 481 else
483 ret = lo_receive(lo, bio, lo->lo_blocksize, pos); 482 ret = lo_receive(lo, bio, lo->lo_blocksize, pos);
484 return ret; 483 return ret;
@@ -652,8 +651,8 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
652 * This can only work if the loop device is used read-only, and if the 651 * This can only work if the loop device is used read-only, and if the
653 * new backing store is the same size and type as the old backing store. 652 * new backing store is the same size and type as the old backing store.
654 */ 653 */
655static int loop_change_fd(struct loop_device *lo, struct file *lo_file, 654static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
656 struct block_device *bdev, unsigned int arg) 655 unsigned int arg)
657{ 656{
658 struct file *file, *old_file; 657 struct file *file, *old_file;
659 struct inode *inode; 658 struct inode *inode;
@@ -712,7 +711,7 @@ static inline int is_loop_device(struct file *file)
712 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR; 711 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
713} 712}
714 713
715static int loop_set_fd(struct loop_device *lo, struct file *lo_file, 714static int loop_set_fd(struct loop_device *lo, fmode_t mode,
716 struct block_device *bdev, unsigned int arg) 715 struct block_device *bdev, unsigned int arg)
717{ 716{
718 struct file *file, *f; 717 struct file *file, *f;
@@ -740,7 +739,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
740 while (is_loop_device(f)) { 739 while (is_loop_device(f)) {
741 struct loop_device *l; 740 struct loop_device *l;
742 741
743 if (f->f_mapping->host->i_rdev == lo_file->f_mapping->host->i_rdev) 742 if (f->f_mapping->host->i_bdev == bdev)
744 goto out_putf; 743 goto out_putf;
745 744
746 l = f->f_mapping->host->i_bdev->bd_disk->private_data; 745 l = f->f_mapping->host->i_bdev->bd_disk->private_data;
@@ -786,7 +785,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
786 goto out_putf; 785 goto out_putf;
787 } 786 }
788 787
789 if (!(lo_file->f_mode & FMODE_WRITE)) 788 if (!(mode & FMODE_WRITE))
790 lo_flags |= LO_FLAGS_READ_ONLY; 789 lo_flags |= LO_FLAGS_READ_ONLY;
791 790
792 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0); 791 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
@@ -918,9 +917,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
918 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); 917 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
919 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 918 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
920 memset(lo->lo_file_name, 0, LO_NAME_SIZE); 919 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
921 invalidate_bdev(bdev); 920 if (bdev)
921 invalidate_bdev(bdev);
922 set_capacity(lo->lo_disk, 0); 922 set_capacity(lo->lo_disk, 0);
923 bd_set_size(bdev, 0); 923 if (bdev)
924 bd_set_size(bdev, 0);
924 mapping_set_gfp_mask(filp->f_mapping, gfp); 925 mapping_set_gfp_mask(filp->f_mapping, gfp);
925 lo->lo_state = Lo_unbound; 926 lo->lo_state = Lo_unbound;
926 fput(filp); 927 fput(filp);
@@ -1137,22 +1138,22 @@ loop_get_status64(struct loop_device *lo, struct loop_info64 __user *arg) {
1137 return err; 1138 return err;
1138} 1139}
1139 1140
1140static int lo_ioctl(struct inode * inode, struct file * file, 1141static int lo_ioctl(struct block_device *bdev, fmode_t mode,
1141 unsigned int cmd, unsigned long arg) 1142 unsigned int cmd, unsigned long arg)
1142{ 1143{
1143 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1144 struct loop_device *lo = bdev->bd_disk->private_data;
1144 int err; 1145 int err;
1145 1146
1146 mutex_lock(&lo->lo_ctl_mutex); 1147 mutex_lock(&lo->lo_ctl_mutex);
1147 switch (cmd) { 1148 switch (cmd) {
1148 case LOOP_SET_FD: 1149 case LOOP_SET_FD:
1149 err = loop_set_fd(lo, file, inode->i_bdev, arg); 1150 err = loop_set_fd(lo, mode, bdev, arg);
1150 break; 1151 break;
1151 case LOOP_CHANGE_FD: 1152 case LOOP_CHANGE_FD:
1152 err = loop_change_fd(lo, file, inode->i_bdev, arg); 1153 err = loop_change_fd(lo, bdev, arg);
1153 break; 1154 break;
1154 case LOOP_CLR_FD: 1155 case LOOP_CLR_FD:
1155 err = loop_clr_fd(lo, inode->i_bdev); 1156 err = loop_clr_fd(lo, bdev);
1156 break; 1157 break;
1157 case LOOP_SET_STATUS: 1158 case LOOP_SET_STATUS:
1158 err = loop_set_status_old(lo, (struct loop_info __user *) arg); 1159 err = loop_set_status_old(lo, (struct loop_info __user *) arg);
@@ -1292,10 +1293,10 @@ loop_get_status_compat(struct loop_device *lo,
1292 return err; 1293 return err;
1293} 1294}
1294 1295
1295static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 1296static int lo_compat_ioctl(struct block_device *bdev, fmode_t mode,
1297 unsigned int cmd, unsigned long arg)
1296{ 1298{
1297 struct inode *inode = file->f_path.dentry->d_inode; 1299 struct loop_device *lo = bdev->bd_disk->private_data;
1298 struct loop_device *lo = inode->i_bdev->bd_disk->private_data;
1299 int err; 1300 int err;
1300 1301
1301 switch(cmd) { 1302 switch(cmd) {
@@ -1317,7 +1318,7 @@ static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
1317 arg = (unsigned long) compat_ptr(arg); 1318 arg = (unsigned long) compat_ptr(arg);
1318 case LOOP_SET_FD: 1319 case LOOP_SET_FD:
1319 case LOOP_CHANGE_FD: 1320 case LOOP_CHANGE_FD:
1320 err = lo_ioctl(inode, file, cmd, arg); 1321 err = lo_ioctl(bdev, mode, cmd, arg);
1321 break; 1322 break;
1322 default: 1323 default:
1323 err = -ENOIOCTLCMD; 1324 err = -ENOIOCTLCMD;
@@ -1327,9 +1328,9 @@ static long lo_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a
1327} 1328}
1328#endif 1329#endif
1329 1330
1330static int lo_open(struct inode *inode, struct file *file) 1331static int lo_open(struct block_device *bdev, fmode_t mode)
1331{ 1332{
1332 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1333 struct loop_device *lo = bdev->bd_disk->private_data;
1333 1334
1334 mutex_lock(&lo->lo_ctl_mutex); 1335 mutex_lock(&lo->lo_ctl_mutex);
1335 lo->lo_refcnt++; 1336 lo->lo_refcnt++;
@@ -1338,15 +1339,15 @@ static int lo_open(struct inode *inode, struct file *file)
1338 return 0; 1339 return 0;
1339} 1340}
1340 1341
1341static int lo_release(struct inode *inode, struct file *file) 1342static int lo_release(struct gendisk *disk, fmode_t mode)
1342{ 1343{
1343 struct loop_device *lo = inode->i_bdev->bd_disk->private_data; 1344 struct loop_device *lo = disk->private_data;
1344 1345
1345 mutex_lock(&lo->lo_ctl_mutex); 1346 mutex_lock(&lo->lo_ctl_mutex);
1346 --lo->lo_refcnt; 1347 --lo->lo_refcnt;
1347 1348
1348 if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !lo->lo_refcnt) 1349 if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !lo->lo_refcnt)
1349 loop_clr_fd(lo, inode->i_bdev); 1350 loop_clr_fd(lo, NULL);
1350 1351
1351 mutex_unlock(&lo->lo_ctl_mutex); 1352 mutex_unlock(&lo->lo_ctl_mutex);
1352 1353
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 9034ca585afd..d3a91cacee8c 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -557,10 +557,11 @@ static void do_nbd_request(struct request_queue * q)
557 } 557 }
558} 558}
559 559
560static int nbd_ioctl(struct inode *inode, struct file *file, 560static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
561 unsigned int cmd, unsigned long arg) 561 unsigned int cmd, unsigned long arg)
562{ 562{
563 struct nbd_device *lo = inode->i_bdev->bd_disk->private_data; 563 struct nbd_device *lo = bdev->bd_disk->private_data;
564 struct file *file;
564 int error; 565 int error;
565 struct request sreq ; 566 struct request sreq ;
566 struct task_struct *thread; 567 struct task_struct *thread;
@@ -612,8 +613,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
612 error = -EINVAL; 613 error = -EINVAL;
613 file = fget(arg); 614 file = fget(arg);
614 if (file) { 615 if (file) {
615 struct block_device *bdev = inode->i_bdev; 616 struct inode *inode = file->f_path.dentry->d_inode;
616 inode = file->f_path.dentry->d_inode;
617 if (S_ISSOCK(inode->i_mode)) { 617 if (S_ISSOCK(inode->i_mode)) {
618 lo->file = file; 618 lo->file = file;
619 lo->sock = SOCKET_I(inode); 619 lo->sock = SOCKET_I(inode);
@@ -628,14 +628,14 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
628 case NBD_SET_BLKSIZE: 628 case NBD_SET_BLKSIZE:
629 lo->blksize = arg; 629 lo->blksize = arg;
630 lo->bytesize &= ~(lo->blksize-1); 630 lo->bytesize &= ~(lo->blksize-1);
631 inode->i_bdev->bd_inode->i_size = lo->bytesize; 631 bdev->bd_inode->i_size = lo->bytesize;
632 set_blocksize(inode->i_bdev, lo->blksize); 632 set_blocksize(bdev, lo->blksize);
633 set_capacity(lo->disk, lo->bytesize >> 9); 633 set_capacity(lo->disk, lo->bytesize >> 9);
634 return 0; 634 return 0;
635 case NBD_SET_SIZE: 635 case NBD_SET_SIZE:
636 lo->bytesize = arg & ~(lo->blksize-1); 636 lo->bytesize = arg & ~(lo->blksize-1);
637 inode->i_bdev->bd_inode->i_size = lo->bytesize; 637 bdev->bd_inode->i_size = lo->bytesize;
638 set_blocksize(inode->i_bdev, lo->blksize); 638 set_blocksize(bdev, lo->blksize);
639 set_capacity(lo->disk, lo->bytesize >> 9); 639 set_capacity(lo->disk, lo->bytesize >> 9);
640 return 0; 640 return 0;
641 case NBD_SET_TIMEOUT: 641 case NBD_SET_TIMEOUT:
@@ -643,8 +643,8 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
643 return 0; 643 return 0;
644 case NBD_SET_SIZE_BLOCKS: 644 case NBD_SET_SIZE_BLOCKS:
645 lo->bytesize = ((u64) arg) * lo->blksize; 645 lo->bytesize = ((u64) arg) * lo->blksize;
646 inode->i_bdev->bd_inode->i_size = lo->bytesize; 646 bdev->bd_inode->i_size = lo->bytesize;
647 set_blocksize(inode->i_bdev, lo->blksize); 647 set_blocksize(bdev, lo->blksize);
648 set_capacity(lo->disk, lo->bytesize >> 9); 648 set_capacity(lo->disk, lo->bytesize >> 9);
649 return 0; 649 return 0;
650 case NBD_DO_IT: 650 case NBD_DO_IT:
@@ -666,10 +666,10 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
666 if (file) 666 if (file)
667 fput(file); 667 fput(file);
668 lo->bytesize = 0; 668 lo->bytesize = 0;
669 inode->i_bdev->bd_inode->i_size = 0; 669 bdev->bd_inode->i_size = 0;
670 set_capacity(lo->disk, 0); 670 set_capacity(lo->disk, 0);
671 if (max_part > 0) 671 if (max_part > 0)
672 ioctl_by_bdev(inode->i_bdev, BLKRRPART, 0); 672 ioctl_by_bdev(bdev, BLKRRPART, 0);
673 return lo->harderror; 673 return lo->harderror;
674 case NBD_CLEAR_QUE: 674 case NBD_CLEAR_QUE:
675 /* 675 /*
@@ -680,7 +680,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
680 return 0; 680 return 0;
681 case NBD_PRINT_DEBUG: 681 case NBD_PRINT_DEBUG:
682 printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n", 682 printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n",
683 inode->i_bdev->bd_disk->disk_name, 683 bdev->bd_disk->disk_name,
684 lo->queue_head.next, lo->queue_head.prev, 684 lo->queue_head.next, lo->queue_head.prev,
685 &lo->queue_head); 685 &lo->queue_head);
686 return 0; 686 return 0;
@@ -691,7 +691,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
691static struct block_device_operations nbd_fops = 691static struct block_device_operations nbd_fops =
692{ 692{
693 .owner = THIS_MODULE, 693 .owner = THIS_MODULE,
694 .ioctl = nbd_ioctl, 694 .locked_ioctl = nbd_ioctl,
695}; 695};
696 696
697/* 697/*
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index b8a994a2b013..e91d4b4b014f 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -223,23 +223,24 @@ static int pcd_warned; /* Have we logged a phase warning ? */
223 223
224/* kernel glue structures */ 224/* kernel glue structures */
225 225
226static int pcd_block_open(struct inode *inode, struct file *file) 226static int pcd_block_open(struct block_device *bdev, fmode_t mode)
227{ 227{
228 struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data; 228 struct pcd_unit *cd = bdev->bd_disk->private_data;
229 return cdrom_open(&cd->info, inode, file); 229 return cdrom_open(&cd->info, bdev, mode);
230} 230}
231 231
232static int pcd_block_release(struct inode *inode, struct file *file) 232static int pcd_block_release(struct gendisk *disk, fmode_t mode)
233{ 233{
234 struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data; 234 struct pcd_unit *cd = disk->private_data;
235 return cdrom_release(&cd->info, file); 235 cdrom_release(&cd->info, mode);
236 return 0;
236} 237}
237 238
238static int pcd_block_ioctl(struct inode *inode, struct file *file, 239static int pcd_block_ioctl(struct block_device *bdev, fmode_t mode,
239 unsigned cmd, unsigned long arg) 240 unsigned cmd, unsigned long arg)
240{ 241{
241 struct pcd_unit *cd = inode->i_bdev->bd_disk->private_data; 242 struct pcd_unit *cd = bdev->bd_disk->private_data;
242 return cdrom_ioctl(file, &cd->info, inode, cmd, arg); 243 return cdrom_ioctl(&cd->info, bdev, mode, cmd, arg);
243} 244}
244 245
245static int pcd_block_media_changed(struct gendisk *disk) 246static int pcd_block_media_changed(struct gendisk *disk)
@@ -252,7 +253,7 @@ static struct block_device_operations pcd_bdops = {
252 .owner = THIS_MODULE, 253 .owner = THIS_MODULE,
253 .open = pcd_block_open, 254 .open = pcd_block_open,
254 .release = pcd_block_release, 255 .release = pcd_block_release,
255 .ioctl = pcd_block_ioctl, 256 .locked_ioctl = pcd_block_ioctl,
256 .media_changed = pcd_block_media_changed, 257 .media_changed = pcd_block_media_changed,
257}; 258};
258 259
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 5fdfa7c888ce..9299455b0af6 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -728,9 +728,9 @@ static int pd_special_command(struct pd_unit *disk,
728 728
729/* kernel glue structures */ 729/* kernel glue structures */
730 730
731static int pd_open(struct inode *inode, struct file *file) 731static int pd_open(struct block_device *bdev, fmode_t mode)
732{ 732{
733 struct pd_unit *disk = inode->i_bdev->bd_disk->private_data; 733 struct pd_unit *disk = bdev->bd_disk->private_data;
734 734
735 disk->access++; 735 disk->access++;
736 736
@@ -758,10 +758,10 @@ static int pd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
758 return 0; 758 return 0;
759} 759}
760 760
761static int pd_ioctl(struct inode *inode, struct file *file, 761static int pd_ioctl(struct block_device *bdev, fmode_t mode,
762 unsigned int cmd, unsigned long arg) 762 unsigned int cmd, unsigned long arg)
763{ 763{
764 struct pd_unit *disk = inode->i_bdev->bd_disk->private_data; 764 struct pd_unit *disk = bdev->bd_disk->private_data;
765 765
766 switch (cmd) { 766 switch (cmd) {
767 case CDROMEJECT: 767 case CDROMEJECT:
@@ -773,9 +773,9 @@ static int pd_ioctl(struct inode *inode, struct file *file,
773 } 773 }
774} 774}
775 775
776static int pd_release(struct inode *inode, struct file *file) 776static int pd_release(struct gendisk *p, fmode_t mode)
777{ 777{
778 struct pd_unit *disk = inode->i_bdev->bd_disk->private_data; 778 struct pd_unit *disk = p->private_data;
779 779
780 if (!--disk->access && disk->removable) 780 if (!--disk->access && disk->removable)
781 pd_special_command(disk, pd_door_unlock); 781 pd_special_command(disk, pd_door_unlock);
@@ -809,7 +809,7 @@ static struct block_device_operations pd_fops = {
809 .owner = THIS_MODULE, 809 .owner = THIS_MODULE,
810 .open = pd_open, 810 .open = pd_open,
811 .release = pd_release, 811 .release = pd_release,
812 .ioctl = pd_ioctl, 812 .locked_ioctl = pd_ioctl,
813 .getgeo = pd_getgeo, 813 .getgeo = pd_getgeo,
814 .media_changed = pd_check_media, 814 .media_changed = pd_check_media,
815 .revalidate_disk= pd_revalidate 815 .revalidate_disk= pd_revalidate
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index e7fe6ca97dd8..bef3b997ba3e 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -201,13 +201,13 @@ module_param_array(drive3, int, NULL, 0);
201#define ATAPI_READ_10 0x28 201#define ATAPI_READ_10 0x28
202#define ATAPI_WRITE_10 0x2a 202#define ATAPI_WRITE_10 0x2a
203 203
204static int pf_open(struct inode *inode, struct file *file); 204static int pf_open(struct block_device *bdev, fmode_t mode);
205static void do_pf_request(struct request_queue * q); 205static void do_pf_request(struct request_queue * q);
206static int pf_ioctl(struct inode *inode, struct file *file, 206static int pf_ioctl(struct block_device *bdev, fmode_t mode,
207 unsigned int cmd, unsigned long arg); 207 unsigned int cmd, unsigned long arg);
208static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo); 208static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo);
209 209
210static int pf_release(struct inode *inode, struct file *file); 210static int pf_release(struct gendisk *disk, fmode_t mode);
211 211
212static int pf_detect(void); 212static int pf_detect(void);
213static void do_pf_read(void); 213static void do_pf_read(void);
@@ -266,7 +266,7 @@ static struct block_device_operations pf_fops = {
266 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
267 .open = pf_open, 267 .open = pf_open,
268 .release = pf_release, 268 .release = pf_release,
269 .ioctl = pf_ioctl, 269 .locked_ioctl = pf_ioctl,
270 .getgeo = pf_getgeo, 270 .getgeo = pf_getgeo,
271 .media_changed = pf_check_media, 271 .media_changed = pf_check_media,
272}; 272};
@@ -296,16 +296,16 @@ static void __init pf_init_units(void)
296 } 296 }
297} 297}
298 298
299static int pf_open(struct inode *inode, struct file *file) 299static int pf_open(struct block_device *bdev, fmode_t mode)
300{ 300{
301 struct pf_unit *pf = inode->i_bdev->bd_disk->private_data; 301 struct pf_unit *pf = bdev->bd_disk->private_data;
302 302
303 pf_identify(pf); 303 pf_identify(pf);
304 304
305 if (pf->media_status == PF_NM) 305 if (pf->media_status == PF_NM)
306 return -ENODEV; 306 return -ENODEV;
307 307
308 if ((pf->media_status == PF_RO) && (file->f_mode & 2)) 308 if ((pf->media_status == PF_RO) && (mode & FMODE_WRITE))
309 return -EROFS; 309 return -EROFS;
310 310
311 pf->access++; 311 pf->access++;
@@ -333,9 +333,9 @@ static int pf_getgeo(struct block_device *bdev, struct hd_geometry *geo)
333 return 0; 333 return 0;
334} 334}
335 335
336static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 336static int pf_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
337{ 337{
338 struct pf_unit *pf = inode->i_bdev->bd_disk->private_data; 338 struct pf_unit *pf = bdev->bd_disk->private_data;
339 339
340 if (cmd != CDROMEJECT) 340 if (cmd != CDROMEJECT)
341 return -EINVAL; 341 return -EINVAL;
@@ -346,9 +346,9 @@ static int pf_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
346 return 0; 346 return 0;
347} 347}
348 348
349static int pf_release(struct inode *inode, struct file *file) 349static int pf_release(struct gendisk *disk, fmode_t mode)
350{ 350{
351 struct pf_unit *pf = inode->i_bdev->bd_disk->private_data; 351 struct pf_unit *pf = disk->private_data;
352 352
353 if (pf->access <= 0) 353 if (pf->access <= 0)
354 return -EINVAL; 354 return -EINVAL;
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index 5ae229656eaa..1e4006e18f03 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -667,7 +667,7 @@ static int pt_open(struct inode *inode, struct file *file)
667 goto out; 667 goto out;
668 668
669 err = -EROFS; 669 err = -EROFS;
670 if ((!(tape->flags & PT_WRITE_OK)) && (file->f_mode & 2)) 670 if ((!(tape->flags & PT_WRITE_OK)) && (file->f_mode & FMODE_WRITE))
671 goto out; 671 goto out;
672 672
673 if (!(iminor(inode) & 128)) 673 if (!(iminor(inode) & 128))
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 195ca7c720f5..f20bf359b84f 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2320,7 +2320,7 @@ static int pkt_open_write(struct pktcdvd_device *pd)
2320/* 2320/*
2321 * called at open time. 2321 * called at open time.
2322 */ 2322 */
2323static int pkt_open_dev(struct pktcdvd_device *pd, int write) 2323static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write)
2324{ 2324{
2325 int ret; 2325 int ret;
2326 long lba; 2326 long lba;
@@ -2332,7 +2332,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write)
2332 * so bdget() can't fail. 2332 * so bdget() can't fail.
2333 */ 2333 */
2334 bdget(pd->bdev->bd_dev); 2334 bdget(pd->bdev->bd_dev);
2335 if ((ret = blkdev_get(pd->bdev, FMODE_READ, O_RDONLY))) 2335 if ((ret = blkdev_get(pd->bdev, FMODE_READ)))
2336 goto out; 2336 goto out;
2337 2337
2338 if ((ret = bd_claim(pd->bdev, pd))) 2338 if ((ret = bd_claim(pd->bdev, pd)))
@@ -2381,7 +2381,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, int write)
2381out_unclaim: 2381out_unclaim:
2382 bd_release(pd->bdev); 2382 bd_release(pd->bdev);
2383out_putdev: 2383out_putdev:
2384 blkdev_put(pd->bdev); 2384 blkdev_put(pd->bdev, FMODE_READ);
2385out: 2385out:
2386 return ret; 2386 return ret;
2387} 2387}
@@ -2399,7 +2399,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush)
2399 2399
2400 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); 2400 pkt_set_speed(pd, MAX_SPEED, MAX_SPEED);
2401 bd_release(pd->bdev); 2401 bd_release(pd->bdev);
2402 blkdev_put(pd->bdev); 2402 blkdev_put(pd->bdev, FMODE_READ);
2403 2403
2404 pkt_shrink_pktlist(pd); 2404 pkt_shrink_pktlist(pd);
2405} 2405}
@@ -2411,7 +2411,7 @@ static struct pktcdvd_device *pkt_find_dev_from_minor(int dev_minor)
2411 return pkt_devs[dev_minor]; 2411 return pkt_devs[dev_minor];
2412} 2412}
2413 2413
2414static int pkt_open(struct inode *inode, struct file *file) 2414static int pkt_open(struct block_device *bdev, fmode_t mode)
2415{ 2415{
2416 struct pktcdvd_device *pd = NULL; 2416 struct pktcdvd_device *pd = NULL;
2417 int ret; 2417 int ret;
@@ -2419,7 +2419,7 @@ static int pkt_open(struct inode *inode, struct file *file)
2419 VPRINTK(DRIVER_NAME": entering open\n"); 2419 VPRINTK(DRIVER_NAME": entering open\n");
2420 2420
2421 mutex_lock(&ctl_mutex); 2421 mutex_lock(&ctl_mutex);
2422 pd = pkt_find_dev_from_minor(iminor(inode)); 2422 pd = pkt_find_dev_from_minor(MINOR(bdev->bd_dev));
2423 if (!pd) { 2423 if (!pd) {
2424 ret = -ENODEV; 2424 ret = -ENODEV;
2425 goto out; 2425 goto out;
@@ -2428,20 +2428,20 @@ static int pkt_open(struct inode *inode, struct file *file)
2428 2428
2429 pd->refcnt++; 2429 pd->refcnt++;
2430 if (pd->refcnt > 1) { 2430 if (pd->refcnt > 1) {
2431 if ((file->f_mode & FMODE_WRITE) && 2431 if ((mode & FMODE_WRITE) &&
2432 !test_bit(PACKET_WRITABLE, &pd->flags)) { 2432 !test_bit(PACKET_WRITABLE, &pd->flags)) {
2433 ret = -EBUSY; 2433 ret = -EBUSY;
2434 goto out_dec; 2434 goto out_dec;
2435 } 2435 }
2436 } else { 2436 } else {
2437 ret = pkt_open_dev(pd, file->f_mode & FMODE_WRITE); 2437 ret = pkt_open_dev(pd, mode & FMODE_WRITE);
2438 if (ret) 2438 if (ret)
2439 goto out_dec; 2439 goto out_dec;
2440 /* 2440 /*
2441 * needed here as well, since ext2 (among others) may change 2441 * needed here as well, since ext2 (among others) may change
2442 * the blocksize at mount time 2442 * the blocksize at mount time
2443 */ 2443 */
2444 set_blocksize(inode->i_bdev, CD_FRAMESIZE); 2444 set_blocksize(bdev, CD_FRAMESIZE);
2445 } 2445 }
2446 2446
2447 mutex_unlock(&ctl_mutex); 2447 mutex_unlock(&ctl_mutex);
@@ -2455,9 +2455,9 @@ out:
2455 return ret; 2455 return ret;
2456} 2456}
2457 2457
2458static int pkt_close(struct inode *inode, struct file *file) 2458static int pkt_close(struct gendisk *disk, fmode_t mode)
2459{ 2459{
2460 struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; 2460 struct pktcdvd_device *pd = disk->private_data;
2461 int ret = 0; 2461 int ret = 0;
2462 2462
2463 mutex_lock(&ctl_mutex); 2463 mutex_lock(&ctl_mutex);
@@ -2765,7 +2765,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2765 bdev = bdget(dev); 2765 bdev = bdget(dev);
2766 if (!bdev) 2766 if (!bdev)
2767 return -ENOMEM; 2767 return -ENOMEM;
2768 ret = blkdev_get(bdev, FMODE_READ, O_RDONLY | O_NONBLOCK); 2768 ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY);
2769 if (ret) 2769 if (ret)
2770 return ret; 2770 return ret;
2771 2771
@@ -2790,19 +2790,28 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev)
2790 return 0; 2790 return 0;
2791 2791
2792out_mem: 2792out_mem:
2793 blkdev_put(bdev); 2793 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2794 /* This is safe: open() is still holding a reference. */ 2794 /* This is safe: open() is still holding a reference. */
2795 module_put(THIS_MODULE); 2795 module_put(THIS_MODULE);
2796 return ret; 2796 return ret;
2797} 2797}
2798 2798
2799static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 2799static int pkt_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, unsigned long arg)
2800{ 2800{
2801 struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data; 2801 struct pktcdvd_device *pd = bdev->bd_disk->private_data;
2802 2802
2803 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd, imajor(inode), iminor(inode)); 2803 VPRINTK("pkt_ioctl: cmd %x, dev %d:%d\n", cmd,
2804 MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev));
2804 2805
2805 switch (cmd) { 2806 switch (cmd) {
2807 case CDROMEJECT:
2808 /*
2809 * The door gets locked when the device is opened, so we
2810 * have to unlock it or else the eject command fails.
2811 */
2812 if (pd->refcnt == 1)
2813 pkt_lock_door(pd, 0);
2814 /* fallthru */
2806 /* 2815 /*
2807 * forward selected CDROM ioctls to CD-ROM, for UDF 2816 * forward selected CDROM ioctls to CD-ROM, for UDF
2808 */ 2817 */
@@ -2811,16 +2820,7 @@ static int pkt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
2811 case CDROM_LAST_WRITTEN: 2820 case CDROM_LAST_WRITTEN:
2812 case CDROM_SEND_PACKET: 2821 case CDROM_SEND_PACKET:
2813 case SCSI_IOCTL_SEND_COMMAND: 2822 case SCSI_IOCTL_SEND_COMMAND:
2814 return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg); 2823 return __blkdev_driver_ioctl(pd->bdev, mode, cmd, arg);
2815
2816 case CDROMEJECT:
2817 /*
2818 * The door gets locked when the device is opened, so we
2819 * have to unlock it or else the eject command fails.
2820 */
2821 if (pd->refcnt == 1)
2822 pkt_lock_door(pd, 0);
2823 return blkdev_ioctl(pd->bdev->bd_inode, file, cmd, arg);
2824 2824
2825 default: 2825 default:
2826 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd); 2826 VPRINTK(DRIVER_NAME": Unknown ioctl for %s (%x)\n", pd->name, cmd);
@@ -2849,7 +2849,7 @@ static struct block_device_operations pktcdvd_ops = {
2849 .owner = THIS_MODULE, 2849 .owner = THIS_MODULE,
2850 .open = pkt_open, 2850 .open = pkt_open,
2851 .release = pkt_close, 2851 .release = pkt_close,
2852 .ioctl = pkt_ioctl, 2852 .locked_ioctl = pkt_ioctl,
2853 .media_changed = pkt_media_changed, 2853 .media_changed = pkt_media_changed,
2854}; 2854};
2855 2855
@@ -2975,7 +2975,7 @@ static int pkt_remove_dev(dev_t pkt_dev)
2975 pkt_debugfs_dev_remove(pd); 2975 pkt_debugfs_dev_remove(pd);
2976 pkt_sysfs_dev_remove(pd); 2976 pkt_sysfs_dev_remove(pd);
2977 2977
2978 blkdev_put(pd->bdev); 2978 blkdev_put(pd->bdev, FMODE_READ|FMODE_WRITE);
2979 2979
2980 remove_proc_entry(pd->name, pkt_proc); 2980 remove_proc_entry(pd->name, pkt_proc);
2981 DPRINTK(DRIVER_NAME": writer %s unmapped\n", pd->name); 2981 DPRINTK(DRIVER_NAME": writer %s unmapped\n", pd->name);
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 730ccea78e45..612965307ba0 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -244,10 +244,10 @@ static int grab_drive(struct floppy_state *fs, enum swim_state state,
244 int interruptible); 244 int interruptible);
245static void release_drive(struct floppy_state *fs); 245static void release_drive(struct floppy_state *fs);
246static int fd_eject(struct floppy_state *fs); 246static int fd_eject(struct floppy_state *fs);
247static int floppy_ioctl(struct inode *inode, struct file *filp, 247static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
248 unsigned int cmd, unsigned long param); 248 unsigned int cmd, unsigned long param);
249static int floppy_open(struct inode *inode, struct file *filp); 249static int floppy_open(struct block_device *bdev, fmode_t mode);
250static int floppy_release(struct inode *inode, struct file *filp); 250static int floppy_release(struct gendisk *disk, fmode_t mode);
251static int floppy_check_change(struct gendisk *disk); 251static int floppy_check_change(struct gendisk *disk);
252static int floppy_revalidate(struct gendisk *disk); 252static int floppy_revalidate(struct gendisk *disk);
253 253
@@ -839,10 +839,10 @@ static int fd_eject(struct floppy_state *fs)
839static struct floppy_struct floppy_type = 839static struct floppy_struct floppy_type =
840 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */ 840 { 2880,18,2,80,0,0x1B,0x00,0xCF,0x6C,NULL }; /* 7 1.44MB 3.5" */
841 841
842static int floppy_ioctl(struct inode *inode, struct file *filp, 842static int floppy_ioctl(struct block_device *bdev, fmode_t mode,
843 unsigned int cmd, unsigned long param) 843 unsigned int cmd, unsigned long param)
844{ 844{
845 struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; 845 struct floppy_state *fs = bdev->bd_disk->private_data;
846 int err; 846 int err;
847 847
848 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN)) 848 if ((cmd & 0x80) && !capable(CAP_SYS_ADMIN))
@@ -868,9 +868,9 @@ static int floppy_ioctl(struct inode *inode, struct file *filp,
868 return -ENOTTY; 868 return -ENOTTY;
869} 869}
870 870
871static int floppy_open(struct inode *inode, struct file *filp) 871static int floppy_open(struct block_device *bdev, fmode_t mode)
872{ 872{
873 struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; 873 struct floppy_state *fs = bdev->bd_disk->private_data;
874 struct swim3 __iomem *sw = fs->swim3; 874 struct swim3 __iomem *sw = fs->swim3;
875 int n, err = 0; 875 int n, err = 0;
876 876
@@ -904,17 +904,17 @@ static int floppy_open(struct inode *inode, struct file *filp)
904 swim3_action(fs, SETMFM); 904 swim3_action(fs, SETMFM);
905 swim3_select(fs, RELAX); 905 swim3_select(fs, RELAX);
906 906
907 } else if (fs->ref_count == -1 || filp->f_flags & O_EXCL) 907 } else if (fs->ref_count == -1 || mode & FMODE_EXCL)
908 return -EBUSY; 908 return -EBUSY;
909 909
910 if (err == 0 && (filp->f_flags & O_NDELAY) == 0 910 if (err == 0 && (mode & FMODE_NDELAY) == 0
911 && (filp->f_mode & 3)) { 911 && (mode & (FMODE_READ|FMODE_WRITE))) {
912 check_disk_change(inode->i_bdev); 912 check_disk_change(bdev);
913 if (fs->ejected) 913 if (fs->ejected)
914 err = -ENXIO; 914 err = -ENXIO;
915 } 915 }
916 916
917 if (err == 0 && (filp->f_mode & 2)) { 917 if (err == 0 && (mode & FMODE_WRITE)) {
918 if (fs->write_prot < 0) 918 if (fs->write_prot < 0)
919 fs->write_prot = swim3_readbit(fs, WRITE_PROT); 919 fs->write_prot = swim3_readbit(fs, WRITE_PROT);
920 if (fs->write_prot) 920 if (fs->write_prot)
@@ -930,7 +930,7 @@ static int floppy_open(struct inode *inode, struct file *filp)
930 return err; 930 return err;
931 } 931 }
932 932
933 if (filp->f_flags & O_EXCL) 933 if (mode & FMODE_EXCL)
934 fs->ref_count = -1; 934 fs->ref_count = -1;
935 else 935 else
936 ++fs->ref_count; 936 ++fs->ref_count;
@@ -938,9 +938,9 @@ static int floppy_open(struct inode *inode, struct file *filp)
938 return 0; 938 return 0;
939} 939}
940 940
941static int floppy_release(struct inode *inode, struct file *filp) 941static int floppy_release(struct gendisk *disk, fmode_t mode)
942{ 942{
943 struct floppy_state *fs = inode->i_bdev->bd_disk->private_data; 943 struct floppy_state *fs = disk->private_data;
944 struct swim3 __iomem *sw = fs->swim3; 944 struct swim3 __iomem *sw = fs->swim3;
945 if (fs->ref_count > 0 && --fs->ref_count == 0) { 945 if (fs->ref_count > 0 && --fs->ref_count == 0) {
946 swim3_action(fs, MOTOR_OFF); 946 swim3_action(fs, MOTOR_OFF);
@@ -1000,7 +1000,7 @@ static int floppy_revalidate(struct gendisk *disk)
1000static struct block_device_operations floppy_fops = { 1000static struct block_device_operations floppy_fops = {
1001 .open = floppy_open, 1001 .open = floppy_open,
1002 .release = floppy_release, 1002 .release = floppy_release,
1003 .ioctl = floppy_ioctl, 1003 .locked_ioctl = floppy_ioctl,
1004 .media_changed = floppy_check_change, 1004 .media_changed = floppy_check_change,
1005 .revalidate_disk= floppy_revalidate, 1005 .revalidate_disk= floppy_revalidate,
1006}; 1006};
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index f60e41833f69..fccac18d3111 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -1667,10 +1667,9 @@ static void ub_revalidate(struct ub_dev *sc, struct ub_lun *lun)
1667 * This is mostly needed to keep refcounting, but also to support 1667 * This is mostly needed to keep refcounting, but also to support
1668 * media checks on removable media drives. 1668 * media checks on removable media drives.
1669 */ 1669 */
1670static int ub_bd_open(struct inode *inode, struct file *filp) 1670static int ub_bd_open(struct block_device *bdev, fmode_t mode)
1671{ 1671{
1672 struct gendisk *disk = inode->i_bdev->bd_disk; 1672 struct ub_lun *lun = bdev->bd_disk->private_data;
1673 struct ub_lun *lun = disk->private_data;
1674 struct ub_dev *sc = lun->udev; 1673 struct ub_dev *sc = lun->udev;
1675 unsigned long flags; 1674 unsigned long flags;
1676 int rc; 1675 int rc;
@@ -1684,19 +1683,19 @@ static int ub_bd_open(struct inode *inode, struct file *filp)
1684 spin_unlock_irqrestore(&ub_lock, flags); 1683 spin_unlock_irqrestore(&ub_lock, flags);
1685 1684
1686 if (lun->removable || lun->readonly) 1685 if (lun->removable || lun->readonly)
1687 check_disk_change(inode->i_bdev); 1686 check_disk_change(bdev);
1688 1687
1689 /* 1688 /*
1690 * The sd.c considers ->media_present and ->changed not equivalent, 1689 * The sd.c considers ->media_present and ->changed not equivalent,
1691 * under some pretty murky conditions (a failure of READ CAPACITY). 1690 * under some pretty murky conditions (a failure of READ CAPACITY).
1692 * We may need it one day. 1691 * We may need it one day.
1693 */ 1692 */
1694 if (lun->removable && lun->changed && !(filp->f_flags & O_NDELAY)) { 1693 if (lun->removable && lun->changed && !(mode & FMODE_NDELAY)) {
1695 rc = -ENOMEDIUM; 1694 rc = -ENOMEDIUM;
1696 goto err_open; 1695 goto err_open;
1697 } 1696 }
1698 1697
1699 if (lun->readonly && (filp->f_mode & FMODE_WRITE)) { 1698 if (lun->readonly && (mode & FMODE_WRITE)) {
1700 rc = -EROFS; 1699 rc = -EROFS;
1701 goto err_open; 1700 goto err_open;
1702 } 1701 }
@@ -1710,9 +1709,8 @@ err_open:
1710 1709
1711/* 1710/*
1712 */ 1711 */
1713static int ub_bd_release(struct inode *inode, struct file *filp) 1712static int ub_bd_release(struct gendisk *disk, fmode_t mode)
1714{ 1713{
1715 struct gendisk *disk = inode->i_bdev->bd_disk;
1716 struct ub_lun *lun = disk->private_data; 1714 struct ub_lun *lun = disk->private_data;
1717 struct ub_dev *sc = lun->udev; 1715 struct ub_dev *sc = lun->udev;
1718 1716
@@ -1723,13 +1721,13 @@ static int ub_bd_release(struct inode *inode, struct file *filp)
1723/* 1721/*
1724 * The ioctl interface. 1722 * The ioctl interface.
1725 */ 1723 */
1726static int ub_bd_ioctl(struct inode *inode, struct file *filp, 1724static int ub_bd_ioctl(struct block_device *bdev, fmode_t mode,
1727 unsigned int cmd, unsigned long arg) 1725 unsigned int cmd, unsigned long arg)
1728{ 1726{
1729 struct gendisk *disk = inode->i_bdev->bd_disk; 1727 struct gendisk *disk = bdev->bd_disk;
1730 void __user *usermem = (void __user *) arg; 1728 void __user *usermem = (void __user *) arg;
1731 1729
1732 return scsi_cmd_ioctl(filp, disk->queue, disk, cmd, usermem); 1730 return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, usermem);
1733} 1731}
1734 1732
1735/* 1733/*
@@ -1793,7 +1791,7 @@ static struct block_device_operations ub_bd_fops = {
1793 .owner = THIS_MODULE, 1791 .owner = THIS_MODULE,
1794 .open = ub_bd_open, 1792 .open = ub_bd_open,
1795 .release = ub_bd_release, 1793 .release = ub_bd_release,
1796 .ioctl = ub_bd_ioctl, 1794 .locked_ioctl = ub_bd_ioctl,
1797 .media_changed = ub_bd_media_changed, 1795 .media_changed = ub_bd_media_changed,
1798 .revalidate_disk = ub_bd_revalidate, 1796 .revalidate_disk = ub_bd_revalidate,
1799}; 1797};
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index 1730d29e6044..ecccf65dce2f 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -130,15 +130,15 @@ struct viodasd_device {
130/* 130/*
131 * External open entry point. 131 * External open entry point.
132 */ 132 */
133static int viodasd_open(struct inode *ino, struct file *fil) 133static int viodasd_open(struct block_device *bdev, fmode_t mode)
134{ 134{
135 struct viodasd_device *d = ino->i_bdev->bd_disk->private_data; 135 struct viodasd_device *d = bdev->bd_disk->private_data;
136 HvLpEvent_Rc hvrc; 136 HvLpEvent_Rc hvrc;
137 struct viodasd_waitevent we; 137 struct viodasd_waitevent we;
138 u16 flags = 0; 138 u16 flags = 0;
139 139
140 if (d->read_only) { 140 if (d->read_only) {
141 if ((fil != NULL) && (fil->f_mode & FMODE_WRITE)) 141 if (mode & FMODE_WRITE)
142 return -EROFS; 142 return -EROFS;
143 flags = vioblockflags_ro; 143 flags = vioblockflags_ro;
144 } 144 }
@@ -179,9 +179,9 @@ static int viodasd_open(struct inode *ino, struct file *fil)
179/* 179/*
180 * External release entry point. 180 * External release entry point.
181 */ 181 */
182static int viodasd_release(struct inode *ino, struct file *fil) 182static int viodasd_release(struct gendisk *disk, fmode_t mode)
183{ 183{
184 struct viodasd_device *d = ino->i_bdev->bd_disk->private_data; 184 struct viodasd_device *d = disk->private_data;
185 HvLpEvent_Rc hvrc; 185 HvLpEvent_Rc hvrc;
186 186
187 /* Send the event to OS/400. We DON'T expect a response */ 187 /* Send the event to OS/400. We DON'T expect a response */
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 6ec5fc052786..85d79a02d487 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -146,11 +146,11 @@ static void do_virtblk_request(struct request_queue *q)
146 vblk->vq->vq_ops->kick(vblk->vq); 146 vblk->vq->vq_ops->kick(vblk->vq);
147} 147}
148 148
149static int virtblk_ioctl(struct inode *inode, struct file *filp, 149static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
150 unsigned cmd, unsigned long data) 150 unsigned cmd, unsigned long data)
151{ 151{
152 return scsi_cmd_ioctl(filp, inode->i_bdev->bd_disk->queue, 152 return scsi_cmd_ioctl(bdev->bd_disk->queue,
153 inode->i_bdev->bd_disk, cmd, 153 bdev->bd_disk, mode, cmd,
154 (void __user *)data); 154 (void __user *)data);
155} 155}
156 156
@@ -180,7 +180,7 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
180} 180}
181 181
182static struct block_device_operations virtblk_fops = { 182static struct block_device_operations virtblk_fops = {
183 .ioctl = virtblk_ioctl, 183 .locked_ioctl = virtblk_ioctl,
184 .owner = THIS_MODULE, 184 .owner = THIS_MODULE,
185 .getgeo = virtblk_getgeo, 185 .getgeo = virtblk_getgeo,
186}; 186};
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 624d30f7da3f..64b496fce98b 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -132,7 +132,7 @@ static int xd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
132 132
133static struct block_device_operations xd_fops = { 133static struct block_device_operations xd_fops = {
134 .owner = THIS_MODULE, 134 .owner = THIS_MODULE,
135 .ioctl = xd_ioctl, 135 .locked_ioctl = xd_ioctl,
136 .getgeo = xd_getgeo, 136 .getgeo = xd_getgeo,
137}; 137};
138static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int); 138static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int);
@@ -343,7 +343,7 @@ static int xd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
343} 343}
344 344
345/* xd_ioctl: handle device ioctl's */ 345/* xd_ioctl: handle device ioctl's */
346static int xd_ioctl (struct inode *inode,struct file *file,u_int cmd,u_long arg) 346static int xd_ioctl(struct block_device *bdev, fmode_t mode, u_int cmd, u_long arg)
347{ 347{
348 switch (cmd) { 348 switch (cmd) {
349 case HDIO_SET_DMA: 349 case HDIO_SET_DMA:
diff --git a/drivers/block/xd.h b/drivers/block/xd.h
index cffd44a20383..37cacef16e93 100644
--- a/drivers/block/xd.h
+++ b/drivers/block/xd.h
@@ -105,7 +105,7 @@ static u_char xd_detect (u_char *controller, unsigned int *address);
105static u_char xd_initdrives (void (*init_drive)(u_char drive)); 105static u_char xd_initdrives (void (*init_drive)(u_char drive));
106 106
107static void do_xd_request (struct request_queue * q); 107static void do_xd_request (struct request_queue * q);
108static int xd_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg); 108static int xd_ioctl (struct block_device *bdev,fmode_t mode,unsigned int cmd,unsigned long arg);
109static int xd_readwrite (u_char operation,XD_INFO *disk,char *buffer,u_int block,u_int count); 109static int xd_readwrite (u_char operation,XD_INFO *disk,char *buffer,u_int block,u_int count);
110static void xd_recalibrate (u_char drive); 110static void xd_recalibrate (u_char drive);
111 111
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 1a50ae70f716..b220c686089d 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -156,11 +156,10 @@ static int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg)
156 return 0; 156 return 0;
157} 157}
158 158
159static int blkif_ioctl(struct inode *inode, struct file *filep, 159static int blkif_ioctl(struct block_device *bdev, fmode_t mode,
160 unsigned command, unsigned long argument) 160 unsigned command, unsigned long argument)
161{ 161{
162 struct blkfront_info *info = 162 struct blkfront_info *info = bdev->bd_disk->private_data;
163 inode->i_bdev->bd_disk->private_data;
164 int i; 163 int i;
165 164
166 dev_dbg(&info->xbdev->dev, "command: 0x%x, argument: 0x%lx\n", 165 dev_dbg(&info->xbdev->dev, "command: 0x%x, argument: 0x%lx\n",
@@ -1014,16 +1013,16 @@ static int blkfront_is_ready(struct xenbus_device *dev)
1014 return info->is_ready; 1013 return info->is_ready;
1015} 1014}
1016 1015
1017static int blkif_open(struct inode *inode, struct file *filep) 1016static int blkif_open(struct block_device *bdev, fmode_t mode)
1018{ 1017{
1019 struct blkfront_info *info = inode->i_bdev->bd_disk->private_data; 1018 struct blkfront_info *info = bdev->bd_disk->private_data;
1020 info->users++; 1019 info->users++;
1021 return 0; 1020 return 0;
1022} 1021}
1023 1022
1024static int blkif_release(struct inode *inode, struct file *filep) 1023static int blkif_release(struct gendisk *disk, fmode_t mode)
1025{ 1024{
1026 struct blkfront_info *info = inode->i_bdev->bd_disk->private_data; 1025 struct blkfront_info *info = disk->private_data;
1027 info->users--; 1026 info->users--;
1028 if (info->users == 0) { 1027 if (info->users == 0) {
1029 /* Check whether we have been instructed to close. We will 1028 /* Check whether we have been instructed to close. We will
@@ -1044,7 +1043,7 @@ static struct block_device_operations xlvbd_block_fops =
1044 .open = blkif_open, 1043 .open = blkif_open,
1045 .release = blkif_release, 1044 .release = blkif_release,
1046 .getgeo = blkif_getgeo, 1045 .getgeo = blkif_getgeo,
1047 .ioctl = blkif_ioctl, 1046 .locked_ioctl = blkif_ioctl,
1048}; 1047};
1049 1048
1050 1049
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 4a7a059ebaf7..ecab9e67d47a 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -870,25 +870,24 @@ static int ace_revalidate_disk(struct gendisk *gd)
870 return ace->id_result; 870 return ace->id_result;
871} 871}
872 872
873static int ace_open(struct inode *inode, struct file *filp) 873static int ace_open(struct block_device *bdev, fmode_t mode)
874{ 874{
875 struct ace_device *ace = inode->i_bdev->bd_disk->private_data; 875 struct ace_device *ace = bdev->bd_disk->private_data;
876 unsigned long flags; 876 unsigned long flags;
877 877
878 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1); 878 dev_dbg(ace->dev, "ace_open() users=%i\n", ace->users + 1);
879 879
880 filp->private_data = ace;
881 spin_lock_irqsave(&ace->lock, flags); 880 spin_lock_irqsave(&ace->lock, flags);
882 ace->users++; 881 ace->users++;
883 spin_unlock_irqrestore(&ace->lock, flags); 882 spin_unlock_irqrestore(&ace->lock, flags);
884 883
885 check_disk_change(inode->i_bdev); 884 check_disk_change(bdev);
886 return 0; 885 return 0;
887} 886}
888 887
889static int ace_release(struct inode *inode, struct file *filp) 888static int ace_release(struct gendisk *disk, fmode_t mode)
890{ 889{
891 struct ace_device *ace = inode->i_bdev->bd_disk->private_data; 890 struct ace_device *ace = disk->private_data;
892 unsigned long flags; 891 unsigned long flags;
893 u16 val; 892 u16 val;
894 893
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index be20a67f1fa8..80754cdd3119 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -137,8 +137,7 @@ get_chipram( void )
137 return; 137 return;
138} 138}
139 139
140static int 140static int z2_open(struct block_device *bdev, fmode_t mode)
141z2_open( struct inode *inode, struct file *filp )
142{ 141{
143 int device; 142 int device;
144 int max_z2_map = ( Z2RAM_SIZE / Z2RAM_CHUNKSIZE ) * 143 int max_z2_map = ( Z2RAM_SIZE / Z2RAM_CHUNKSIZE ) *
@@ -147,7 +146,7 @@ z2_open( struct inode *inode, struct file *filp )
147 sizeof( z2ram_map[0] ); 146 sizeof( z2ram_map[0] );
148 int rc = -ENOMEM; 147 int rc = -ENOMEM;
149 148
150 device = iminor(inode); 149 device = MINOR(bdev->bd_dev);
151 150
152 if ( current_device != -1 && current_device != device ) 151 if ( current_device != -1 && current_device != device )
153 { 152 {
@@ -299,7 +298,7 @@ err_out:
299} 298}
300 299
301static int 300static int
302z2_release( struct inode *inode, struct file *filp ) 301z2_release(struct gendisk *disk, fmode_t mode)
303{ 302{
304 if ( current_device == -1 ) 303 if ( current_device == -1 )
305 return 0; 304 return 0;
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index d47f2f80accd..d16b02423d61 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -973,7 +973,7 @@ static int cdrom_close_write(struct cdrom_device_info *cdi)
973 * is in their own interest: device control becomes a lot easier 973 * is in their own interest: device control becomes a lot easier
974 * this way. 974 * this way.
975 */ 975 */
976int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp) 976int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, fmode_t mode)
977{ 977{
978 int ret; 978 int ret;
979 979
@@ -982,14 +982,14 @@ int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp)
982 /* if this was a O_NONBLOCK open and we should honor the flags, 982 /* if this was a O_NONBLOCK open and we should honor the flags,
983 * do a quick open without drive/disc integrity checks. */ 983 * do a quick open without drive/disc integrity checks. */
984 cdi->use_count++; 984 cdi->use_count++;
985 if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) { 985 if ((mode & FMODE_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) {
986 ret = cdi->ops->open(cdi, 1); 986 ret = cdi->ops->open(cdi, 1);
987 } else { 987 } else {
988 ret = open_for_data(cdi); 988 ret = open_for_data(cdi);
989 if (ret) 989 if (ret)
990 goto err; 990 goto err;
991 cdrom_mmc3_profile(cdi); 991 cdrom_mmc3_profile(cdi);
992 if (fp->f_mode & FMODE_WRITE) { 992 if (mode & FMODE_WRITE) {
993 ret = -EROFS; 993 ret = -EROFS;
994 if (cdrom_open_write(cdi)) 994 if (cdrom_open_write(cdi))
995 goto err_release; 995 goto err_release;
@@ -1007,7 +1007,7 @@ int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp)
1007 cdi->name, cdi->use_count); 1007 cdi->name, cdi->use_count);
1008 /* Do this on open. Don't wait for mount, because they might 1008 /* Do this on open. Don't wait for mount, because they might
1009 not be mounting, but opening with O_NONBLOCK */ 1009 not be mounting, but opening with O_NONBLOCK */
1010 check_disk_change(ip->i_bdev); 1010 check_disk_change(bdev);
1011 return 0; 1011 return 0;
1012err_release: 1012err_release:
1013 if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) { 1013 if (CDROM_CAN(CDC_LOCK) && cdi->options & CDO_LOCK) {
@@ -1184,7 +1184,7 @@ static int check_for_audio_disc(struct cdrom_device_info * cdi,
1184 return 0; 1184 return 0;
1185} 1185}
1186 1186
1187int cdrom_release(struct cdrom_device_info *cdi, struct file *fp) 1187void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode)
1188{ 1188{
1189 struct cdrom_device_ops *cdo = cdi->ops; 1189 struct cdrom_device_ops *cdo = cdi->ops;
1190 int opened_for_data; 1190 int opened_for_data;
@@ -1205,7 +1205,7 @@ int cdrom_release(struct cdrom_device_info *cdi, struct file *fp)
1205 } 1205 }
1206 1206
1207 opened_for_data = !(cdi->options & CDO_USE_FFLAGS) || 1207 opened_for_data = !(cdi->options & CDO_USE_FFLAGS) ||
1208 !(fp && fp->f_flags & O_NONBLOCK); 1208 !(mode & FMODE_NDELAY);
1209 1209
1210 /* 1210 /*
1211 * flush cache on last write release 1211 * flush cache on last write release
@@ -1219,7 +1219,6 @@ int cdrom_release(struct cdrom_device_info *cdi, struct file *fp)
1219 cdi->options & CDO_AUTO_EJECT && CDROM_CAN(CDC_OPEN_TRAY)) 1219 cdi->options & CDO_AUTO_EJECT && CDROM_CAN(CDC_OPEN_TRAY))
1220 cdo->tray_move(cdi, 1); 1220 cdo->tray_move(cdi, 1);
1221 } 1221 }
1222 return 0;
1223} 1222}
1224 1223
1225static int cdrom_read_mech_status(struct cdrom_device_info *cdi, 1224static int cdrom_read_mech_status(struct cdrom_device_info *cdi,
@@ -2662,17 +2661,17 @@ static int cdrom_ioctl_audioctl(struct cdrom_device_info *cdi,
2662 * these days. 2661 * these days.
2663 * ATAPI / SCSI specific code now mainly resides in mmc_ioctl(). 2662 * ATAPI / SCSI specific code now mainly resides in mmc_ioctl().
2664 */ 2663 */
2665int cdrom_ioctl(struct file * file, struct cdrom_device_info *cdi, 2664int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
2666 struct inode *ip, unsigned int cmd, unsigned long arg) 2665 fmode_t mode, unsigned int cmd, unsigned long arg)
2667{ 2666{
2668 void __user *argp = (void __user *)arg; 2667 void __user *argp = (void __user *)arg;
2669 int ret; 2668 int ret;
2670 struct gendisk *disk = ip->i_bdev->bd_disk; 2669 struct gendisk *disk = bdev->bd_disk;
2671 2670
2672 /* 2671 /*
2673 * Try the generic SCSI command ioctl's first. 2672 * Try the generic SCSI command ioctl's first.
2674 */ 2673 */
2675 ret = scsi_cmd_ioctl(file, disk->queue, disk, cmd, argp); 2674 ret = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
2676 if (ret != -ENOTTY) 2675 if (ret != -ENOTTY)
2677 return ret; 2676 return ret;
2678 2677
@@ -2696,7 +2695,7 @@ int cdrom_ioctl(struct file * file, struct cdrom_device_info *cdi,
2696 case CDROM_SELECT_DISC: 2695 case CDROM_SELECT_DISC:
2697 return cdrom_ioctl_select_disc(cdi, arg); 2696 return cdrom_ioctl_select_disc(cdi, arg);
2698 case CDROMRESET: 2697 case CDROMRESET:
2699 return cdrom_ioctl_reset(cdi, ip->i_bdev); 2698 return cdrom_ioctl_reset(cdi, bdev);
2700 case CDROM_LOCKDOOR: 2699 case CDROM_LOCKDOOR:
2701 return cdrom_ioctl_lock_door(cdi, arg); 2700 return cdrom_ioctl_lock_door(cdi, arg);
2702 case CDROM_DEBUG: 2701 case CDROM_DEBUG:
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index d6ba77a2dd7b..9aaa86b232b1 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -490,14 +490,14 @@ static struct cdrom_device_ops gdrom_ops = {
490 .n_minors = 1, 490 .n_minors = 1,
491}; 491};
492 492
493static int gdrom_bdops_open(struct inode *inode, struct file *file) 493static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
494{ 494{
495 return cdrom_open(gd.cd_info, inode, file); 495 return cdrom_open(gd.cd_info, bdev, mode);
496} 496}
497 497
498static int gdrom_bdops_release(struct inode *inode, struct file *file) 498static int gdrom_bdops_release(struct block_device *bdev, fmode_t mode)
499{ 499{
500 return cdrom_release(gd.cd_info, file); 500 return cdrom_release(gd.cd_info, mode);
501} 501}
502 502
503static int gdrom_bdops_mediachanged(struct gendisk *disk) 503static int gdrom_bdops_mediachanged(struct gendisk *disk)
@@ -505,10 +505,10 @@ static int gdrom_bdops_mediachanged(struct gendisk *disk)
505 return cdrom_media_changed(gd.cd_info); 505 return cdrom_media_changed(gd.cd_info);
506} 506}
507 507
508static int gdrom_bdops_ioctl(struct inode *inode, struct file *file, 508static int gdrom_bdops_ioctl(struct block_device *bdev, fmode_t mode,
509 unsigned cmd, unsigned long arg) 509 unsigned cmd, unsigned long arg)
510{ 510{
511 return cdrom_ioctl(file, gd.cd_info, inode, cmd, arg); 511 return cdrom_ioctl(gd.cd_info, bdev, mode, cmd, arg);
512} 512}
513 513
514static struct block_device_operations gdrom_bdops = { 514static struct block_device_operations gdrom_bdops = {
@@ -516,7 +516,7 @@ static struct block_device_operations gdrom_bdops = {
516 .open = gdrom_bdops_open, 516 .open = gdrom_bdops_open,
517 .release = gdrom_bdops_release, 517 .release = gdrom_bdops_release,
518 .media_changed = gdrom_bdops_mediachanged, 518 .media_changed = gdrom_bdops_mediachanged,
519 .ioctl = gdrom_bdops_ioctl, 519 .locked_ioctl = gdrom_bdops_ioctl,
520}; 520};
521 521
522static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) 522static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id)
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 031e0e1a1a3b..13929356135c 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -151,23 +151,24 @@ static const struct file_operations proc_viocd_operations = {
151 .release = single_release, 151 .release = single_release,
152}; 152};
153 153
154static int viocd_blk_open(struct inode *inode, struct file *file) 154static int viocd_blk_open(struct block_device *bdev, fmode_t mode)
155{ 155{
156 struct disk_info *di = inode->i_bdev->bd_disk->private_data; 156 struct disk_info *di = bdev->bd_disk->private_data;
157 return cdrom_open(&di->viocd_info, inode, file); 157 return cdrom_open(&di->viocd_info, bdev, mode);
158} 158}
159 159
160static int viocd_blk_release(struct inode *inode, struct file *file) 160static int viocd_blk_release(struct gendisk *disk, fmode_t mode)
161{ 161{
162 struct disk_info *di = inode->i_bdev->bd_disk->private_data; 162 struct disk_info *di = disk->private_data;
163 return cdrom_release(&di->viocd_info, file); 163 cdrom_release(&di->viocd_info, mode);
164 return 0;
164} 165}
165 166
166static int viocd_blk_ioctl(struct inode *inode, struct file *file, 167static int viocd_blk_ioctl(struct block_device *bdev, fmode_t mode,
167 unsigned cmd, unsigned long arg) 168 unsigned cmd, unsigned long arg)
168{ 169{
169 struct disk_info *di = inode->i_bdev->bd_disk->private_data; 170 struct disk_info *di = bdev->bd_disk->private_data;
170 return cdrom_ioctl(file, &di->viocd_info, inode, cmd, arg); 171 return cdrom_ioctl(&di->viocd_info, bdev, mode, cmd, arg);
171} 172}
172 173
173static int viocd_blk_media_changed(struct gendisk *disk) 174static int viocd_blk_media_changed(struct gendisk *disk)
@@ -180,7 +181,7 @@ struct block_device_operations viocd_fops = {
180 .owner = THIS_MODULE, 181 .owner = THIS_MODULE,
181 .open = viocd_blk_open, 182 .open = viocd_blk_open,
182 .release = viocd_blk_release, 183 .release = viocd_blk_release,
183 .ioctl = viocd_blk_ioctl, 184 .locked_ioctl = viocd_blk_ioctl,
184 .media_changed = viocd_blk_media_changed, 185 .media_changed = viocd_blk_media_changed,
185}; 186};
186 187
diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
index 39f6357e3b5d..8054ee839b3c 100644
--- a/drivers/char/nvram.c
+++ b/drivers/char/nvram.c
@@ -338,7 +338,7 @@ nvram_open(struct inode *inode, struct file *file)
338 338
339 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) || 339 if ((nvram_open_cnt && (file->f_flags & O_EXCL)) ||
340 (nvram_open_mode & NVRAM_EXCL) || 340 (nvram_open_mode & NVRAM_EXCL) ||
341 ((file->f_mode & 2) && (nvram_open_mode & NVRAM_WRITE))) { 341 ((file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE))) {
342 spin_unlock(&nvram_state_lock); 342 spin_unlock(&nvram_state_lock);
343 unlock_kernel(); 343 unlock_kernel();
344 return -EBUSY; 344 return -EBUSY;
@@ -346,7 +346,7 @@ nvram_open(struct inode *inode, struct file *file)
346 346
347 if (file->f_flags & O_EXCL) 347 if (file->f_flags & O_EXCL)
348 nvram_open_mode |= NVRAM_EXCL; 348 nvram_open_mode |= NVRAM_EXCL;
349 if (file->f_mode & 2) 349 if (file->f_mode & FMODE_WRITE)
350 nvram_open_mode |= NVRAM_WRITE; 350 nvram_open_mode |= NVRAM_WRITE;
351 nvram_open_cnt++; 351 nvram_open_cnt++;
352 352
@@ -366,7 +366,7 @@ nvram_release(struct inode *inode, struct file *file)
366 /* if only one instance is open, clear the EXCL bit */ 366 /* if only one instance is open, clear the EXCL bit */
367 if (nvram_open_mode & NVRAM_EXCL) 367 if (nvram_open_mode & NVRAM_EXCL)
368 nvram_open_mode &= ~NVRAM_EXCL; 368 nvram_open_mode &= ~NVRAM_EXCL;
369 if (file->f_mode & 2) 369 if (file->f_mode & FMODE_WRITE)
370 nvram_open_mode &= ~NVRAM_WRITE; 370 nvram_open_mode &= ~NVRAM_WRITE;
371 371
372 spin_unlock(&nvram_state_lock); 372 spin_unlock(&nvram_state_lock);
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index e139372d0e69..96adf28a17e4 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -65,7 +65,7 @@ static int raw_open(struct inode *inode, struct file *filp)
65 if (!bdev) 65 if (!bdev)
66 goto out; 66 goto out;
67 igrab(bdev->bd_inode); 67 igrab(bdev->bd_inode);
68 err = blkdev_get(bdev, filp->f_mode, 0); 68 err = blkdev_get(bdev, filp->f_mode);
69 if (err) 69 if (err)
70 goto out; 70 goto out;
71 err = bd_claim(bdev, raw_open); 71 err = bd_claim(bdev, raw_open);
@@ -87,7 +87,7 @@ static int raw_open(struct inode *inode, struct file *filp)
87out2: 87out2:
88 bd_release(bdev); 88 bd_release(bdev);
89out1: 89out1:
90 blkdev_put(bdev); 90 blkdev_put(bdev, filp->f_mode);
91out: 91out:
92 mutex_unlock(&raw_mutex); 92 mutex_unlock(&raw_mutex);
93 return err; 93 return err;
@@ -112,7 +112,7 @@ static int raw_release(struct inode *inode, struct file *filp)
112 mutex_unlock(&raw_mutex); 112 mutex_unlock(&raw_mutex);
113 113
114 bd_release(bdev); 114 bd_release(bdev);
115 blkdev_put(bdev); 115 blkdev_put(bdev, filp->f_mode);
116 return 0; 116 return 0;
117} 117}
118 118
@@ -125,7 +125,7 @@ raw_ioctl(struct inode *inode, struct file *filp,
125{ 125{
126 struct block_device *bdev = filp->private_data; 126 struct block_device *bdev = filp->private_data;
127 127
128 return blkdev_ioctl(bdev->bd_inode, NULL, command, arg); 128 return blkdev_ioctl(bdev, 0, command, arg);
129} 129}
130 130
131static void bind_device(struct raw_config_request *rq) 131static void bind_device(struct raw_config_request *rq)
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 13265a8827da..133afd09843c 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -2089,17 +2089,15 @@ static ide_driver_t ide_cdrom_driver = {
2089#endif 2089#endif
2090}; 2090};
2091 2091
2092static int idecd_open(struct inode *inode, struct file *file) 2092static int idecd_open(struct block_device *bdev, fmode_t mode)
2093{ 2093{
2094 struct gendisk *disk = inode->i_bdev->bd_disk; 2094 struct cdrom_info *info = ide_cd_get(bdev->bd_disk);
2095 struct cdrom_info *info;
2096 int rc = -ENOMEM; 2095 int rc = -ENOMEM;
2097 2096
2098 info = ide_cd_get(disk);
2099 if (!info) 2097 if (!info)
2100 return -ENXIO; 2098 return -ENXIO;
2101 2099
2102 rc = cdrom_open(&info->devinfo, inode, file); 2100 rc = cdrom_open(&info->devinfo, bdev, mode);
2103 2101
2104 if (rc < 0) 2102 if (rc < 0)
2105 ide_cd_put(info); 2103 ide_cd_put(info);
@@ -2107,12 +2105,11 @@ static int idecd_open(struct inode *inode, struct file *file)
2107 return rc; 2105 return rc;
2108} 2106}
2109 2107
2110static int idecd_release(struct inode *inode, struct file *file) 2108static int idecd_release(struct gendisk *disk, fmode_t mode)
2111{ 2109{
2112 struct gendisk *disk = inode->i_bdev->bd_disk;
2113 struct cdrom_info *info = ide_drv_g(disk, cdrom_info); 2110 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2114 2111
2115 cdrom_release(&info->devinfo, file); 2112 cdrom_release(&info->devinfo, mode);
2116 2113
2117 ide_cd_put(info); 2114 ide_cd_put(info);
2118 2115
@@ -2158,10 +2155,9 @@ static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg)
2158 return 0; 2155 return 0;
2159} 2156}
2160 2157
2161static int idecd_ioctl(struct inode *inode, struct file *file, 2158static int idecd_ioctl(struct block_device *bdev, fmode_t mode,
2162 unsigned int cmd, unsigned long arg) 2159 unsigned int cmd, unsigned long arg)
2163{ 2160{
2164 struct block_device *bdev = inode->i_bdev;
2165 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info); 2161 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
2166 int err; 2162 int err;
2167 2163
@@ -2174,9 +2170,9 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2174 break; 2170 break;
2175 } 2171 }
2176 2172
2177 err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); 2173 err = generic_ide_ioctl(info->drive, bdev, cmd, arg);
2178 if (err == -EINVAL) 2174 if (err == -EINVAL)
2179 err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); 2175 err = cdrom_ioctl(&info->devinfo, bdev, mode, cmd, arg);
2180 2176
2181 return err; 2177 return err;
2182} 2178}
@@ -2201,7 +2197,7 @@ static struct block_device_operations idecd_ops = {
2201 .owner = THIS_MODULE, 2197 .owner = THIS_MODULE,
2202 .open = idecd_open, 2198 .open = idecd_open,
2203 .release = idecd_release, 2199 .release = idecd_release,
2204 .ioctl = idecd_ioctl, 2200 .locked_ioctl = idecd_ioctl,
2205 .media_changed = idecd_media_changed, 2201 .media_changed = idecd_media_changed,
2206 .revalidate_disk = idecd_revalidate_disk 2202 .revalidate_disk = idecd_revalidate_disk
2207}; 2203};
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
index b234b0feaf7b..d511dab7c4aa 100644
--- a/drivers/ide/ide-disk.h
+++ b/drivers/ide/ide-disk.h
@@ -13,7 +13,7 @@ ide_decl_devset(wcache);
13ide_decl_devset(acoustic); 13ide_decl_devset(acoustic);
14 14
15/* ide-disk_ioctl.c */ 15/* ide-disk_ioctl.c */
16int ide_disk_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, 16int ide_disk_ioctl(ide_drive_t *, struct block_device *, fmode_t, unsigned int,
17 unsigned long); 17 unsigned long);
18 18
19#ifdef CONFIG_IDE_PROC_FS 19#ifdef CONFIG_IDE_PROC_FS
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
index a49698bcf966..7b783dd7c0be 100644
--- a/drivers/ide/ide-disk_ioctl.c
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -13,15 +13,14 @@ static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
13{ 0 } 13{ 0 }
14}; 14};
15 15
16int ide_disk_ioctl(ide_drive_t *drive, struct inode *inode, struct file *file, 16int ide_disk_ioctl(ide_drive_t *drive, struct block_device *bdev, fmode_t mode,
17 unsigned int cmd, unsigned long arg) 17 unsigned int cmd, unsigned long arg)
18{ 18{
19 struct block_device *bdev = inode->i_bdev;
20 int err; 19 int err;
21 20
22 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); 21 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
23 if (err != -EOPNOTSUPP) 22 if (err != -EOPNOTSUPP)
24 return err; 23 return err;
25 24
26 return generic_ide_ioctl(drive, file, bdev, cmd, arg); 25 return generic_ide_ioctl(drive, bdev, cmd, arg);
27} 26}
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
index c17124dd6079..6dd2beb48434 100644
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -23,8 +23,8 @@ void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
23void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *); 23void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
24 24
25/* ide-floppy_ioctl.c */ 25/* ide-floppy_ioctl.c */
26int ide_floppy_ioctl(ide_drive_t *, struct inode *, struct file *, unsigned int, 26int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t,
27 unsigned long); 27 unsigned int, unsigned long);
28 28
29#ifdef CONFIG_IDE_PROC_FS 29#ifdef CONFIG_IDE_PROC_FS
30/* ide-floppy_proc.c */ 30/* ide-floppy_proc.c */
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 409e4c15f9b7..2bc51ff73fee 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -241,7 +241,7 @@ static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
241 return 0; 241 return 0;
242} 242}
243 243
244static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file, 244static int ide_floppy_format_ioctl(ide_drive_t *drive, fmode_t mode,
245 unsigned int cmd, void __user *argp) 245 unsigned int cmd, void __user *argp)
246{ 246{
247 switch (cmd) { 247 switch (cmd) {
@@ -250,7 +250,7 @@ static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
250 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: 250 case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
251 return ide_floppy_get_format_capacities(drive, argp); 251 return ide_floppy_get_format_capacities(drive, argp);
252 case IDEFLOPPY_IOCTL_FORMAT_START: 252 case IDEFLOPPY_IOCTL_FORMAT_START:
253 if (!(file->f_mode & 2)) 253 if (!(mode & FMODE_WRITE))
254 return -EPERM; 254 return -EPERM;
255 return ide_floppy_format_unit(drive, (int __user *)argp); 255 return ide_floppy_format_unit(drive, (int __user *)argp);
256 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: 256 case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS:
@@ -260,10 +260,9 @@ static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
260 } 260 }
261} 261}
262 262
263int ide_floppy_ioctl(ide_drive_t *drive, struct inode *inode, 263int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
264 struct file *file, unsigned int cmd, unsigned long arg) 264 fmode_t mode, unsigned int cmd, unsigned long arg)
265{ 265{
266 struct block_device *bdev = inode->i_bdev;
267 struct ide_atapi_pc pc; 266 struct ide_atapi_pc pc;
268 void __user *argp = (void __user *)arg; 267 void __user *argp = (void __user *)arg;
269 int err; 268 int err;
@@ -271,7 +270,7 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct inode *inode,
271 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) 270 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
272 return ide_floppy_lockdoor(drive, &pc, arg, cmd); 271 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
273 272
274 err = ide_floppy_format_ioctl(drive, file, cmd, argp); 273 err = ide_floppy_format_ioctl(drive, mode, cmd, argp);
275 if (err != -ENOTTY) 274 if (err != -ENOTTY)
276 return err; 275 return err;
277 276
@@ -280,11 +279,11 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct inode *inode,
280 * and CDROM_SEND_PACKET (legacy) ioctls 279 * and CDROM_SEND_PACKET (legacy) ioctls
281 */ 280 */
282 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) 281 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
283 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, 282 err = scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk,
284 bdev->bd_disk, cmd, argp); 283 mode, cmd, argp);
285 284
286 if (err == -ENOTTY) 285 if (err == -ENOTTY)
287 err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 286 err = generic_ide_ioctl(drive, bdev, cmd, arg);
288 287
289 return err; 288 return err;
290} 289}
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index d44898f46c33..7b6662854374 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -169,9 +169,9 @@ static ide_driver_t ide_gd_driver = {
169#endif 169#endif
170}; 170};
171 171
172static int ide_gd_open(struct inode *inode, struct file *filp) 172static int ide_gd_open(struct block_device *bdev, fmode_t mode)
173{ 173{
174 struct gendisk *disk = inode->i_bdev->bd_disk; 174 struct gendisk *disk = bdev->bd_disk;
175 struct ide_disk_obj *idkp; 175 struct ide_disk_obj *idkp;
176 ide_drive_t *drive; 176 ide_drive_t *drive;
177 int ret = 0; 177 int ret = 0;
@@ -197,12 +197,12 @@ static int ide_gd_open(struct inode *inode, struct file *filp)
197 * unreadable disk, so that we can get the format capacity 197 * unreadable disk, so that we can get the format capacity
198 * of the drive or begin the format - Sam 198 * of the drive or begin the format - Sam
199 */ 199 */
200 if (ret && (filp->f_flags & O_NDELAY) == 0) { 200 if (ret && (mode & FMODE_NDELAY) == 0) {
201 ret = -EIO; 201 ret = -EIO;
202 goto out_put_idkp; 202 goto out_put_idkp;
203 } 203 }
204 204
205 if ((drive->dev_flags & IDE_DFLAG_WP) && (filp->f_mode & 2)) { 205 if ((drive->dev_flags & IDE_DFLAG_WP) && (mode & FMODE_WRITE)) {
206 ret = -EROFS; 206 ret = -EROFS;
207 goto out_put_idkp; 207 goto out_put_idkp;
208 } 208 }
@@ -214,7 +214,7 @@ static int ide_gd_open(struct inode *inode, struct file *filp)
214 */ 214 */
215 drive->disk_ops->set_doorlock(drive, disk, 1); 215 drive->disk_ops->set_doorlock(drive, disk, 1);
216 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED; 216 drive->dev_flags |= IDE_DFLAG_MEDIA_CHANGED;
217 check_disk_change(inode->i_bdev); 217 check_disk_change(bdev);
218 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) { 218 } else if (drive->dev_flags & IDE_DFLAG_FORMAT_IN_PROGRESS) {
219 ret = -EBUSY; 219 ret = -EBUSY;
220 goto out_put_idkp; 220 goto out_put_idkp;
@@ -227,9 +227,8 @@ out_put_idkp:
227 return ret; 227 return ret;
228} 228}
229 229
230static int ide_gd_release(struct inode *inode, struct file *filp) 230static int ide_gd_release(struct gendisk *disk, fmode_t mode)
231{ 231{
232 struct gendisk *disk = inode->i_bdev->bd_disk;
233 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj); 232 struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
234 ide_drive_t *drive = idkp->drive; 233 ide_drive_t *drive = idkp->drive;
235 234
@@ -286,21 +285,20 @@ static int ide_gd_revalidate_disk(struct gendisk *disk)
286 return 0; 285 return 0;
287} 286}
288 287
289static int ide_gd_ioctl(struct inode *inode, struct file *file, 288static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
290 unsigned int cmd, unsigned long arg) 289 unsigned int cmd, unsigned long arg)
291{ 290{
292 struct block_device *bdev = inode->i_bdev;
293 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj); 291 struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
294 ide_drive_t *drive = idkp->drive; 292 ide_drive_t *drive = idkp->drive;
295 293
296 return drive->disk_ops->ioctl(drive, inode, file, cmd, arg); 294 return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg);
297} 295}
298 296
299static struct block_device_operations ide_gd_ops = { 297static struct block_device_operations ide_gd_ops = {
300 .owner = THIS_MODULE, 298 .owner = THIS_MODULE,
301 .open = ide_gd_open, 299 .open = ide_gd_open,
302 .release = ide_gd_release, 300 .release = ide_gd_release,
303 .ioctl = ide_gd_ioctl, 301 .locked_ioctl = ide_gd_ioctl,
304 .getgeo = ide_gd_getgeo, 302 .getgeo = ide_gd_getgeo,
305 .media_changed = ide_gd_media_changed, 303 .media_changed = ide_gd_media_changed,
306 .revalidate_disk = ide_gd_revalidate_disk 304 .revalidate_disk = ide_gd_revalidate_disk
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index a90945f49792..fcde16bb53a7 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -240,8 +240,7 @@ static int generic_drive_reset(ide_drive_t *drive)
240 return ret; 240 return ret;
241} 241}
242 242
243int generic_ide_ioctl(ide_drive_t *drive, struct file *file, 243int generic_ide_ioctl(ide_drive_t *drive, struct block_device *bdev,
244 struct block_device *bdev,
245 unsigned int cmd, unsigned long arg) 244 unsigned int cmd, unsigned long arg)
246{ 245{
247 int err; 246 int err;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index b2b2e5e8d38e..a2d470eb2b55 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -2340,35 +2340,30 @@ static const struct file_operations idetape_fops = {
2340 .release = idetape_chrdev_release, 2340 .release = idetape_chrdev_release,
2341}; 2341};
2342 2342
2343static int idetape_open(struct inode *inode, struct file *filp) 2343static int idetape_open(struct block_device *bdev, fmode_t mode)
2344{ 2344{
2345 struct gendisk *disk = inode->i_bdev->bd_disk; 2345 struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk);
2346 struct ide_tape_obj *tape;
2347 2346
2348 tape = ide_tape_get(disk);
2349 if (!tape) 2347 if (!tape)
2350 return -ENXIO; 2348 return -ENXIO;
2351 2349
2352 return 0; 2350 return 0;
2353} 2351}
2354 2352
2355static int idetape_release(struct inode *inode, struct file *filp) 2353static int idetape_release(struct gendisk *disk, fmode_t mode)
2356{ 2354{
2357 struct gendisk *disk = inode->i_bdev->bd_disk;
2358 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj); 2355 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
2359 2356
2360 ide_tape_put(tape); 2357 ide_tape_put(tape);
2361
2362 return 0; 2358 return 0;
2363} 2359}
2364 2360
2365static int idetape_ioctl(struct inode *inode, struct file *file, 2361static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
2366 unsigned int cmd, unsigned long arg) 2362 unsigned int cmd, unsigned long arg)
2367{ 2363{
2368 struct block_device *bdev = inode->i_bdev;
2369 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj); 2364 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
2370 ide_drive_t *drive = tape->drive; 2365 ide_drive_t *drive = tape->drive;
2371 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 2366 int err = generic_ide_ioctl(drive, bdev, cmd, arg);
2372 if (err == -EINVAL) 2367 if (err == -EINVAL)
2373 err = idetape_blkdev_ioctl(drive, cmd, arg); 2368 err = idetape_blkdev_ioctl(drive, cmd, arg);
2374 return err; 2369 return err;
@@ -2378,7 +2373,7 @@ static struct block_device_operations idetape_block_ops = {
2378 .owner = THIS_MODULE, 2373 .owner = THIS_MODULE,
2379 .open = idetape_open, 2374 .open = idetape_open,
2380 .release = idetape_release, 2375 .release = idetape_release,
2381 .ioctl = idetape_ioctl, 2376 .locked_ioctl = idetape_ioctl,
2382}; 2377};
2383 2378
2384static int ide_tape_probe(ide_drive_t *drive) 2379static int ide_tape_probe(ide_drive_t *drive)
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index dca401dc70a0..777c948180f9 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -988,9 +988,9 @@ static int dev_wait(struct dm_ioctl *param, size_t param_size)
988 return r; 988 return r;
989} 989}
990 990
991static inline int get_mode(struct dm_ioctl *param) 991static inline fmode_t get_mode(struct dm_ioctl *param)
992{ 992{
993 int mode = FMODE_READ | FMODE_WRITE; 993 fmode_t mode = FMODE_READ | FMODE_WRITE;
994 994
995 if (param->flags & DM_READONLY_FLAG) 995 if (param->flags & DM_READONLY_FLAG)
996 mode = FMODE_READ; 996 mode = FMODE_READ;
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c
index 1b29e9136758..44042becad8a 100644
--- a/drivers/md/dm-linear.c
+++ b/drivers/md/dm-linear.c
@@ -110,20 +110,11 @@ static int linear_status(struct dm_target *ti, status_type_t type,
110 return 0; 110 return 0;
111} 111}
112 112
113static int linear_ioctl(struct dm_target *ti, struct inode *inode, 113static int linear_ioctl(struct dm_target *ti, unsigned int cmd,
114 struct file *filp, unsigned int cmd,
115 unsigned long arg) 114 unsigned long arg)
116{ 115{
117 struct linear_c *lc = (struct linear_c *) ti->private; 116 struct linear_c *lc = (struct linear_c *) ti->private;
118 struct block_device *bdev = lc->dev->bdev; 117 return __blkdev_driver_ioctl(lc->dev->bdev, lc->dev->mode, cmd, arg);
119 struct file fake_file = {};
120 struct dentry fake_dentry = {};
121
122 fake_file.f_mode = lc->dev->mode;
123 fake_file.f_path.dentry = &fake_dentry;
124 fake_dentry.d_inode = bdev->bd_inode;
125
126 return blkdev_driver_ioctl(bdev->bd_inode, &fake_file, bdev->bd_disk, cmd, arg);
127} 118}
128 119
129static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm, 120static int linear_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index abf6e8cfaedb..4840733cd903 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1396,19 +1396,15 @@ error:
1396 return -EINVAL; 1396 return -EINVAL;
1397} 1397}
1398 1398
1399static int multipath_ioctl(struct dm_target *ti, struct inode *inode, 1399static int multipath_ioctl(struct dm_target *ti, unsigned int cmd,
1400 struct file *filp, unsigned int cmd,
1401 unsigned long arg) 1400 unsigned long arg)
1402{ 1401{
1403 struct multipath *m = (struct multipath *) ti->private; 1402 struct multipath *m = (struct multipath *) ti->private;
1404 struct block_device *bdev = NULL; 1403 struct block_device *bdev = NULL;
1404 fmode_t mode = 0;
1405 unsigned long flags; 1405 unsigned long flags;
1406 struct file fake_file = {};
1407 struct dentry fake_dentry = {};
1408 int r = 0; 1406 int r = 0;
1409 1407
1410 fake_file.f_path.dentry = &fake_dentry;
1411
1412 spin_lock_irqsave(&m->lock, flags); 1408 spin_lock_irqsave(&m->lock, flags);
1413 1409
1414 if (!m->current_pgpath) 1410 if (!m->current_pgpath)
@@ -1416,8 +1412,7 @@ static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
1416 1412
1417 if (m->current_pgpath) { 1413 if (m->current_pgpath) {
1418 bdev = m->current_pgpath->path.dev->bdev; 1414 bdev = m->current_pgpath->path.dev->bdev;
1419 fake_dentry.d_inode = bdev->bd_inode; 1415 mode = m->current_pgpath->path.dev->mode;
1420 fake_file.f_mode = m->current_pgpath->path.dev->mode;
1421 } 1416 }
1422 1417
1423 if (m->queue_io) 1418 if (m->queue_io)
@@ -1427,8 +1422,7 @@ static int multipath_ioctl(struct dm_target *ti, struct inode *inode,
1427 1422
1428 spin_unlock_irqrestore(&m->lock, flags); 1423 spin_unlock_irqrestore(&m->lock, flags);
1429 1424
1430 return r ? : blkdev_driver_ioctl(bdev->bd_inode, &fake_file, 1425 return r ? : __blkdev_driver_ioctl(bdev, mode, cmd, arg);
1431 bdev->bd_disk, cmd, arg);
1432} 1426}
1433 1427
1434/*----------------------------------------------------------------- 1428/*-----------------------------------------------------------------
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 1407eb96f1a4..a63161aec487 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -43,7 +43,7 @@ struct dm_table {
43 * device. This should be a combination of FMODE_READ 43 * device. This should be a combination of FMODE_READ
44 * and FMODE_WRITE. 44 * and FMODE_WRITE.
45 */ 45 */
46 int mode; 46 fmode_t mode;
47 47
48 /* a list of devices used by this table */ 48 /* a list of devices used by this table */
49 struct list_head devices; 49 struct list_head devices;
@@ -217,7 +217,7 @@ static int alloc_targets(struct dm_table *t, unsigned int num)
217 return 0; 217 return 0;
218} 218}
219 219
220int dm_table_create(struct dm_table **result, int mode, 220int dm_table_create(struct dm_table **result, fmode_t mode,
221 unsigned num_targets, struct mapped_device *md) 221 unsigned num_targets, struct mapped_device *md)
222{ 222{
223 struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL); 223 struct dm_table *t = kzalloc(sizeof(*t), GFP_KERNEL);
@@ -344,7 +344,7 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev,
344 return PTR_ERR(bdev); 344 return PTR_ERR(bdev);
345 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md)); 345 r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md));
346 if (r) 346 if (r)
347 blkdev_put(bdev); 347 blkdev_put(bdev, d->dm_dev.mode);
348 else 348 else
349 d->dm_dev.bdev = bdev; 349 d->dm_dev.bdev = bdev;
350 return r; 350 return r;
@@ -359,7 +359,7 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md)
359 return; 359 return;
360 360
361 bd_release_from_disk(d->dm_dev.bdev, dm_disk(md)); 361 bd_release_from_disk(d->dm_dev.bdev, dm_disk(md));
362 blkdev_put(d->dm_dev.bdev); 362 blkdev_put(d->dm_dev.bdev, d->dm_dev.mode);
363 d->dm_dev.bdev = NULL; 363 d->dm_dev.bdev = NULL;
364} 364}
365 365
@@ -382,7 +382,7 @@ static int check_device_area(struct dm_dev_internal *dd, sector_t start,
382 * careful to leave things as they were if we fail to reopen the 382 * careful to leave things as they were if we fail to reopen the
383 * device. 383 * device.
384 */ 384 */
385static int upgrade_mode(struct dm_dev_internal *dd, int new_mode, 385static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,
386 struct mapped_device *md) 386 struct mapped_device *md)
387{ 387{
388 int r; 388 int r;
@@ -408,7 +408,7 @@ static int upgrade_mode(struct dm_dev_internal *dd, int new_mode,
408 */ 408 */
409static int __table_get_device(struct dm_table *t, struct dm_target *ti, 409static int __table_get_device(struct dm_table *t, struct dm_target *ti,
410 const char *path, sector_t start, sector_t len, 410 const char *path, sector_t start, sector_t len,
411 int mode, struct dm_dev **result) 411 fmode_t mode, struct dm_dev **result)
412{ 412{
413 int r; 413 int r;
414 dev_t uninitialized_var(dev); 414 dev_t uninitialized_var(dev);
@@ -528,7 +528,7 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
528EXPORT_SYMBOL_GPL(dm_set_device_limits); 528EXPORT_SYMBOL_GPL(dm_set_device_limits);
529 529
530int dm_get_device(struct dm_target *ti, const char *path, sector_t start, 530int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
531 sector_t len, int mode, struct dm_dev **result) 531 sector_t len, fmode_t mode, struct dm_dev **result)
532{ 532{
533 int r = __table_get_device(ti->table, ti, path, 533 int r = __table_get_device(ti->table, ti, path,
534 start, len, mode, result); 534 start, len, mode, result);
@@ -878,7 +878,7 @@ struct list_head *dm_table_get_devices(struct dm_table *t)
878 return &t->devices; 878 return &t->devices;
879} 879}
880 880
881int dm_table_get_mode(struct dm_table *t) 881fmode_t dm_table_get_mode(struct dm_table *t)
882{ 882{
883 return t->mode; 883 return t->mode;
884} 884}
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index d1d0cd0f5750..6963ad148408 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -21,7 +21,6 @@
21#include <linux/idr.h> 21#include <linux/idr.h>
22#include <linux/hdreg.h> 22#include <linux/hdreg.h>
23#include <linux/blktrace_api.h> 23#include <linux/blktrace_api.h>
24#include <linux/smp_lock.h>
25 24
26#define DM_MSG_PREFIX "core" 25#define DM_MSG_PREFIX "core"
27 26
@@ -248,13 +247,13 @@ static void __exit dm_exit(void)
248/* 247/*
249 * Block device functions 248 * Block device functions
250 */ 249 */
251static int dm_blk_open(struct inode *inode, struct file *file) 250static int dm_blk_open(struct block_device *bdev, fmode_t mode)
252{ 251{
253 struct mapped_device *md; 252 struct mapped_device *md;
254 253
255 spin_lock(&_minor_lock); 254 spin_lock(&_minor_lock);
256 255
257 md = inode->i_bdev->bd_disk->private_data; 256 md = bdev->bd_disk->private_data;
258 if (!md) 257 if (!md)
259 goto out; 258 goto out;
260 259
@@ -273,11 +272,9 @@ out:
273 return md ? 0 : -ENXIO; 272 return md ? 0 : -ENXIO;
274} 273}
275 274
276static int dm_blk_close(struct inode *inode, struct file *file) 275static int dm_blk_close(struct gendisk *disk, fmode_t mode)
277{ 276{
278 struct mapped_device *md; 277 struct mapped_device *md = disk->private_data;
279
280 md = inode->i_bdev->bd_disk->private_data;
281 atomic_dec(&md->open_count); 278 atomic_dec(&md->open_count);
282 dm_put(md); 279 dm_put(md);
283 return 0; 280 return 0;
@@ -314,21 +311,14 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
314 return dm_get_geometry(md, geo); 311 return dm_get_geometry(md, geo);
315} 312}
316 313
317static int dm_blk_ioctl(struct inode *inode, struct file *file, 314static int dm_blk_ioctl(struct block_device *bdev, fmode_t mode,
318 unsigned int cmd, unsigned long arg) 315 unsigned int cmd, unsigned long arg)
319{ 316{
320 struct mapped_device *md; 317 struct mapped_device *md = bdev->bd_disk->private_data;
321 struct dm_table *map; 318 struct dm_table *map = dm_get_table(md);
322 struct dm_target *tgt; 319 struct dm_target *tgt;
323 int r = -ENOTTY; 320 int r = -ENOTTY;
324 321
325 /* We don't really need this lock, but we do need 'inode'. */
326 unlock_kernel();
327
328 md = inode->i_bdev->bd_disk->private_data;
329
330 map = dm_get_table(md);
331
332 if (!map || !dm_table_get_size(map)) 322 if (!map || !dm_table_get_size(map))
333 goto out; 323 goto out;
334 324
@@ -344,12 +334,11 @@ static int dm_blk_ioctl(struct inode *inode, struct file *file,
344 } 334 }
345 335
346 if (tgt->type->ioctl) 336 if (tgt->type->ioctl)
347 r = tgt->type->ioctl(tgt, inode, file, cmd, arg); 337 r = tgt->type->ioctl(tgt, cmd, arg);
348 338
349out: 339out:
350 dm_table_put(map); 340 dm_table_put(map);
351 341
352 lock_kernel();
353 return r; 342 return r;
354} 343}
355 344
diff --git a/drivers/md/md.c b/drivers/md/md.c
index aaa3d465de4e..c1a837ca193c 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1520,7 +1520,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared)
1520 if (err) { 1520 if (err) {
1521 printk(KERN_ERR "md: could not bd_claim %s.\n", 1521 printk(KERN_ERR "md: could not bd_claim %s.\n",
1522 bdevname(bdev, b)); 1522 bdevname(bdev, b));
1523 blkdev_put(bdev); 1523 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1524 return err; 1524 return err;
1525 } 1525 }
1526 if (!shared) 1526 if (!shared)
@@ -1536,7 +1536,7 @@ static void unlock_rdev(mdk_rdev_t *rdev)
1536 if (!bdev) 1536 if (!bdev)
1537 MD_BUG(); 1537 MD_BUG();
1538 bd_release(bdev); 1538 bd_release(bdev);
1539 blkdev_put(bdev); 1539 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1540} 1540}
1541 1541
1542void md_autodetect_dev(dev_t dev); 1542void md_autodetect_dev(dev_t dev);
@@ -4785,7 +4785,7 @@ static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
4785 return 0; 4785 return 0;
4786} 4786}
4787 4787
4788static int md_ioctl(struct inode *inode, struct file *file, 4788static int md_ioctl(struct block_device *bdev, fmode_t mode,
4789 unsigned int cmd, unsigned long arg) 4789 unsigned int cmd, unsigned long arg)
4790{ 4790{
4791 int err = 0; 4791 int err = 0;
@@ -4823,7 +4823,7 @@ static int md_ioctl(struct inode *inode, struct file *file,
4823 * Commands creating/starting a new array: 4823 * Commands creating/starting a new array:
4824 */ 4824 */
4825 4825
4826 mddev = inode->i_bdev->bd_disk->private_data; 4826 mddev = bdev->bd_disk->private_data;
4827 4827
4828 if (!mddev) { 4828 if (!mddev) {
4829 BUG(); 4829 BUG();
@@ -4996,13 +4996,13 @@ abort:
4996 return err; 4996 return err;
4997} 4997}
4998 4998
4999static int md_open(struct inode *inode, struct file *file) 4999static int md_open(struct block_device *bdev, fmode_t mode)
5000{ 5000{
5001 /* 5001 /*
5002 * Succeed if we can lock the mddev, which confirms that 5002 * Succeed if we can lock the mddev, which confirms that
5003 * it isn't being stopped right now. 5003 * it isn't being stopped right now.
5004 */ 5004 */
5005 mddev_t *mddev = inode->i_bdev->bd_disk->private_data; 5005 mddev_t *mddev = bdev->bd_disk->private_data;
5006 int err; 5006 int err;
5007 5007
5008 if ((err = mutex_lock_interruptible_nested(&mddev->reconfig_mutex, 1))) 5008 if ((err = mutex_lock_interruptible_nested(&mddev->reconfig_mutex, 1)))
@@ -5013,14 +5013,14 @@ static int md_open(struct inode *inode, struct file *file)
5013 atomic_inc(&mddev->openers); 5013 atomic_inc(&mddev->openers);
5014 mddev_unlock(mddev); 5014 mddev_unlock(mddev);
5015 5015
5016 check_disk_change(inode->i_bdev); 5016 check_disk_change(bdev);
5017 out: 5017 out:
5018 return err; 5018 return err;
5019} 5019}
5020 5020
5021static int md_release(struct inode *inode, struct file * file) 5021static int md_release(struct gendisk *disk, fmode_t mode)
5022{ 5022{
5023 mddev_t *mddev = inode->i_bdev->bd_disk->private_data; 5023 mddev_t *mddev = disk->private_data;
5024 5024
5025 BUG_ON(!mddev); 5025 BUG_ON(!mddev);
5026 atomic_dec(&mddev->openers); 5026 atomic_dec(&mddev->openers);
@@ -5048,7 +5048,7 @@ static struct block_device_operations md_fops =
5048 .owner = THIS_MODULE, 5048 .owner = THIS_MODULE,
5049 .open = md_open, 5049 .open = md_open,
5050 .release = md_release, 5050 .release = md_release,
5051 .ioctl = md_ioctl, 5051 .locked_ioctl = md_ioctl,
5052 .getgeo = md_getgeo, 5052 .getgeo = md_getgeo,
5053 .media_changed = md_media_changed, 5053 .media_changed = md_media_changed,
5054 .revalidate_disk= md_revalidate, 5054 .revalidate_disk= md_revalidate,
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 5263913e0c69..7911151e56a3 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -172,9 +172,9 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error);
172 172
173/*** Block device ***/ 173/*** Block device ***/
174 174
175static int mspro_block_bd_open(struct inode *inode, struct file *filp) 175static int mspro_block_bd_open(struct block_device *bdev, fmode_t mode)
176{ 176{
177 struct gendisk *disk = inode->i_bdev->bd_disk; 177 struct gendisk *disk = bdev->bd_disk;
178 struct mspro_block_data *msb = disk->private_data; 178 struct mspro_block_data *msb = disk->private_data;
179 int rc = -ENXIO; 179 int rc = -ENXIO;
180 180
@@ -182,7 +182,7 @@ static int mspro_block_bd_open(struct inode *inode, struct file *filp)
182 182
183 if (msb && msb->card) { 183 if (msb && msb->card) {
184 msb->usage_count++; 184 msb->usage_count++;
185 if ((filp->f_mode & FMODE_WRITE) && msb->read_only) 185 if ((mode & FMODE_WRITE) && msb->read_only)
186 rc = -EROFS; 186 rc = -EROFS;
187 else 187 else
188 rc = 0; 188 rc = 0;
@@ -218,9 +218,8 @@ static int mspro_block_disk_release(struct gendisk *disk)
218 return 0; 218 return 0;
219} 219}
220 220
221static int mspro_block_bd_release(struct inode *inode, struct file *filp) 221static int mspro_block_bd_release(struct gendisk *disk, fmode_t mode)
222{ 222{
223 struct gendisk *disk = inode->i_bdev->bd_disk;
224 return mspro_block_disk_release(disk); 223 return mspro_block_disk_release(disk);
225} 224}
226 225
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index 81483de8c0fd..11a617ab4243 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -575,9 +575,9 @@ static void i2o_block_biosparam(unsigned long capacity, unsigned short *cyls,
575 * 575 *
576 * Returns 0 on success or negative error code on failure. 576 * Returns 0 on success or negative error code on failure.
577 */ 577 */
578static int i2o_block_open(struct inode *inode, struct file *file) 578static int i2o_block_open(struct block_device *bdev, fmode_t mode)
579{ 579{
580 struct i2o_block_device *dev = inode->i_bdev->bd_disk->private_data; 580 struct i2o_block_device *dev = bdev->bd_disk->private_data;
581 581
582 if (!dev->i2o_dev) 582 if (!dev->i2o_dev)
583 return -ENODEV; 583 return -ENODEV;
@@ -604,9 +604,8 @@ static int i2o_block_open(struct inode *inode, struct file *file)
604 * 604 *
605 * Returns 0 on success or negative error code on failure. 605 * Returns 0 on success or negative error code on failure.
606 */ 606 */
607static int i2o_block_release(struct inode *inode, struct file *file) 607static int i2o_block_release(struct gendisk *disk, fmode_t mode)
608{ 608{
609 struct gendisk *disk = inode->i_bdev->bd_disk;
610 struct i2o_block_device *dev = disk->private_data; 609 struct i2o_block_device *dev = disk->private_data;
611 u8 operation; 610 u8 operation;
612 611
@@ -653,10 +652,10 @@ static int i2o_block_getgeo(struct block_device *bdev, struct hd_geometry *geo)
653 * 652 *
654 * Return 0 on success or negative error on failure. 653 * Return 0 on success or negative error on failure.
655 */ 654 */
656static int i2o_block_ioctl(struct inode *inode, struct file *file, 655static int i2o_block_ioctl(struct block_device *bdev, fmode_t mode,
657 unsigned int cmd, unsigned long arg) 656 unsigned int cmd, unsigned long arg)
658{ 657{
659 struct gendisk *disk = inode->i_bdev->bd_disk; 658 struct gendisk *disk = bdev->bd_disk;
660 struct i2o_block_device *dev = disk->private_data; 659 struct i2o_block_device *dev = disk->private_data;
661 660
662 /* Anyone capable of this syscall can do *real bad* things */ 661 /* Anyone capable of this syscall can do *real bad* things */
@@ -933,7 +932,7 @@ static struct block_device_operations i2o_block_fops = {
933 .owner = THIS_MODULE, 932 .owner = THIS_MODULE,
934 .open = i2o_block_open, 933 .open = i2o_block_open,
935 .release = i2o_block_release, 934 .release = i2o_block_release,
936 .ioctl = i2o_block_ioctl, 935 .locked_ioctl = i2o_block_ioctl,
937 .getgeo = i2o_block_getgeo, 936 .getgeo = i2o_block_getgeo,
938 .media_changed = i2o_block_media_changed 937 .media_changed = i2o_block_media_changed
939}; 938};
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 24c97d3d16bb..3d067c35185d 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -92,18 +92,17 @@ static void mmc_blk_put(struct mmc_blk_data *md)
92 mutex_unlock(&open_lock); 92 mutex_unlock(&open_lock);
93} 93}
94 94
95static int mmc_blk_open(struct inode *inode, struct file *filp) 95static int mmc_blk_open(struct block_device *bdev, fmode_t mode)
96{ 96{
97 struct mmc_blk_data *md; 97 struct mmc_blk_data *md = mmc_blk_get(bdev->bd_disk);
98 int ret = -ENXIO; 98 int ret = -ENXIO;
99 99
100 md = mmc_blk_get(inode->i_bdev->bd_disk);
101 if (md) { 100 if (md) {
102 if (md->usage == 2) 101 if (md->usage == 2)
103 check_disk_change(inode->i_bdev); 102 check_disk_change(bdev);
104 ret = 0; 103 ret = 0;
105 104
106 if ((filp->f_mode & FMODE_WRITE) && md->read_only) { 105 if ((mode & FMODE_WRITE) && md->read_only) {
107 mmc_blk_put(md); 106 mmc_blk_put(md);
108 ret = -EROFS; 107 ret = -EROFS;
109 } 108 }
@@ -112,9 +111,9 @@ static int mmc_blk_open(struct inode *inode, struct file *filp)
112 return ret; 111 return ret;
113} 112}
114 113
115static int mmc_blk_release(struct inode *inode, struct file *filp) 114static int mmc_blk_release(struct gendisk *disk, fmode_t mode)
116{ 115{
117 struct mmc_blk_data *md = inode->i_bdev->bd_disk->private_data; 116 struct mmc_blk_data *md = disk->private_data;
118 117
119 mmc_blk_put(md); 118 mmc_blk_put(md);
120 return 0; 119 return 0;
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 91fbba767635..8c295f40d2ac 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
224 if (dev->blkdev) { 224 if (dev->blkdev) {
225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 225 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
226 0, -1); 226 0, -1);
227 close_bdev_excl(dev->blkdev); 227 close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE);
228 } 228 }
229 229
230 kfree(dev); 230 kfree(dev);
@@ -246,7 +246,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
246 return NULL; 246 return NULL;
247 247
248 /* Get a handle on the device */ 248 /* Get a handle on the device */
249 bdev = open_bdev_excl(devname, O_RDWR, NULL); 249 bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL);
250#ifndef MODULE 250#ifndef MODULE
251 if (IS_ERR(bdev)) { 251 if (IS_ERR(bdev)) {
252 252
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 681d5aca2af4..1409f01406f6 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -133,15 +133,12 @@ static void mtd_blktrans_request(struct request_queue *rq)
133} 133}
134 134
135 135
136static int blktrans_open(struct inode *i, struct file *f) 136static int blktrans_open(struct block_device *bdev, fmode_t mode)
137{ 137{
138 struct mtd_blktrans_dev *dev; 138 struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
139 struct mtd_blktrans_ops *tr; 139 struct mtd_blktrans_ops *tr = dev->tr;
140 int ret = -ENODEV; 140 int ret = -ENODEV;
141 141
142 dev = i->i_bdev->bd_disk->private_data;
143 tr = dev->tr;
144
145 if (!try_module_get(dev->mtd->owner)) 142 if (!try_module_get(dev->mtd->owner))
146 goto out; 143 goto out;
147 144
@@ -164,15 +161,12 @@ static int blktrans_open(struct inode *i, struct file *f)
164 return ret; 161 return ret;
165} 162}
166 163
167static int blktrans_release(struct inode *i, struct file *f) 164static int blktrans_release(struct gendisk *disk, fmode_t mode)
168{ 165{
169 struct mtd_blktrans_dev *dev; 166 struct mtd_blktrans_dev *dev = disk->private_data;
170 struct mtd_blktrans_ops *tr; 167 struct mtd_blktrans_ops *tr = dev->tr;
171 int ret = 0; 168 int ret = 0;
172 169
173 dev = i->i_bdev->bd_disk->private_data;
174 tr = dev->tr;
175
176 if (tr->release) 170 if (tr->release)
177 ret = tr->release(dev); 171 ret = tr->release(dev);
178 172
@@ -194,10 +188,10 @@ static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
194 return -ENOTTY; 188 return -ENOTTY;
195} 189}
196 190
197static int blktrans_ioctl(struct inode *inode, struct file *file, 191static int blktrans_ioctl(struct block_device *bdev, fmode_t mode,
198 unsigned int cmd, unsigned long arg) 192 unsigned int cmd, unsigned long arg)
199{ 193{
200 struct mtd_blktrans_dev *dev = inode->i_bdev->bd_disk->private_data; 194 struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
201 struct mtd_blktrans_ops *tr = dev->tr; 195 struct mtd_blktrans_ops *tr = dev->tr;
202 196
203 switch (cmd) { 197 switch (cmd) {
@@ -215,7 +209,7 @@ static struct block_device_operations mtd_blktrans_ops = {
215 .owner = THIS_MODULE, 209 .owner = THIS_MODULE,
216 .open = blktrans_open, 210 .open = blktrans_open,
217 .release = blktrans_release, 211 .release = blktrans_release,
218 .ioctl = blktrans_ioctl, 212 .locked_ioctl = blktrans_ioctl,
219 .getgeo = blktrans_getgeo, 213 .getgeo = blktrans_getgeo,
220}; 214};
221 215
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 963840e9b5bf..bcffeda2df3d 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -96,7 +96,7 @@ static int mtd_open(struct inode *inode, struct file *file)
96 return -ENODEV; 96 return -ENODEV;
97 97
98 /* You can't open the RO devices RW */ 98 /* You can't open the RO devices RW */
99 if ((file->f_mode & 2) && (minor & 1)) 99 if ((file->f_mode & FMODE_WRITE) && (minor & 1))
100 return -EACCES; 100 return -EACCES;
101 101
102 lock_kernel(); 102 lock_kernel();
@@ -114,7 +114,7 @@ static int mtd_open(struct inode *inode, struct file *file)
114 } 114 }
115 115
116 /* You can't open it RW if it's not a writeable device */ 116 /* You can't open it RW if it's not a writeable device */
117 if ((file->f_mode & 2) && !(mtd->flags & MTD_WRITEABLE)) { 117 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
118 put_mtd_device(mtd); 118 put_mtd_device(mtd);
119 ret = -EACCES; 119 ret = -EACCES;
120 goto out; 120 goto out;
@@ -144,7 +144,7 @@ static int mtd_close(struct inode *inode, struct file *file)
144 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); 144 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n");
145 145
146 /* Only sync if opened RW */ 146 /* Only sync if opened RW */
147 if ((file->f_mode & 2) && mtd->sync) 147 if ((file->f_mode & FMODE_WRITE) && mtd->sync)
148 mtd->sync(mtd); 148 mtd->sync(mtd);
149 149
150 put_mtd_device(mtd); 150 put_mtd_device(mtd);
@@ -443,7 +443,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
443 { 443 {
444 struct erase_info *erase; 444 struct erase_info *erase;
445 445
446 if(!(file->f_mode & 2)) 446 if(!(file->f_mode & FMODE_WRITE))
447 return -EPERM; 447 return -EPERM;
448 448
449 erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL); 449 erase=kzalloc(sizeof(struct erase_info),GFP_KERNEL);
@@ -497,7 +497,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
497 struct mtd_oob_buf __user *user_buf = argp; 497 struct mtd_oob_buf __user *user_buf = argp;
498 uint32_t retlen; 498 uint32_t retlen;
499 499
500 if(!(file->f_mode & 2)) 500 if(!(file->f_mode & FMODE_WRITE))
501 return -EPERM; 501 return -EPERM;
502 502
503 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf))) 503 if (copy_from_user(&buf, argp, sizeof(struct mtd_oob_buf)))
diff --git a/drivers/parisc/eisa_eeprom.c b/drivers/parisc/eisa_eeprom.c
index 5ac207932fd7..685d94e69d44 100644
--- a/drivers/parisc/eisa_eeprom.c
+++ b/drivers/parisc/eisa_eeprom.c
@@ -86,7 +86,7 @@ static int eisa_eeprom_open(struct inode *inode, struct file *file)
86{ 86{
87 cycle_kernel_lock(); 87 cycle_kernel_lock();
88 88
89 if (file->f_mode & 2) 89 if (file->f_mode & FMODE_WRITE)
90 return -EINVAL; 90 return -EINVAL;
91 91
92 return 0; 92 return 0;
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 0a225ccda026..4b76fca64a6f 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -2011,10 +2011,9 @@ static void dasd_flush_request_queue(struct dasd_block *block)
2011 spin_unlock_irq(&block->request_queue_lock); 2011 spin_unlock_irq(&block->request_queue_lock);
2012} 2012}
2013 2013
2014static int dasd_open(struct inode *inp, struct file *filp) 2014static int dasd_open(struct block_device *bdev, fmode_t mode)
2015{ 2015{
2016 struct gendisk *disk = inp->i_bdev->bd_disk; 2016 struct dasd_block *block = bdev->bd_disk->private_data;
2017 struct dasd_block *block = disk->private_data;
2018 struct dasd_device *base = block->base; 2017 struct dasd_device *base = block->base;
2019 int rc; 2018 int rc;
2020 2019
@@ -2052,9 +2051,8 @@ unlock:
2052 return rc; 2051 return rc;
2053} 2052}
2054 2053
2055static int dasd_release(struct inode *inp, struct file *filp) 2054static int dasd_release(struct gendisk *disk, fmode_t mode)
2056{ 2055{
2057 struct gendisk *disk = inp->i_bdev->bd_disk;
2058 struct dasd_block *block = disk->private_data; 2056 struct dasd_block *block = disk->private_data;
2059 2057
2060 atomic_dec(&block->open_count); 2058 atomic_dec(&block->open_count);
@@ -2089,8 +2087,7 @@ dasd_device_operations = {
2089 .owner = THIS_MODULE, 2087 .owner = THIS_MODULE,
2090 .open = dasd_open, 2088 .open = dasd_open,
2091 .release = dasd_release, 2089 .release = dasd_release,
2092 .ioctl = dasd_ioctl, 2090 .locked_ioctl = dasd_ioctl,
2093 .compat_ioctl = dasd_compat_ioctl,
2094 .getgeo = dasd_getgeo, 2091 .getgeo = dasd_getgeo,
2095}; 2092};
2096 2093
diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c
index aee6565aaf98..e99d566b69cc 100644
--- a/drivers/s390/block/dasd_genhd.c
+++ b/drivers/s390/block/dasd_genhd.c
@@ -99,7 +99,7 @@ int dasd_scan_partitions(struct dasd_block *block)
99 struct block_device *bdev; 99 struct block_device *bdev;
100 100
101 bdev = bdget_disk(block->gdp, 0); 101 bdev = bdget_disk(block->gdp, 0);
102 if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0) 102 if (!bdev || blkdev_get(bdev, FMODE_READ) < 0)
103 return -ENODEV; 103 return -ENODEV;
104 /* 104 /*
105 * See fs/partition/check.c:register_disk,rescan_partitions 105 * See fs/partition/check.c:register_disk,rescan_partitions
@@ -152,7 +152,7 @@ void dasd_destroy_partitions(struct dasd_block *block)
152 152
153 invalidate_partition(block->gdp, 0); 153 invalidate_partition(block->gdp, 0);
154 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */ 154 /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */
155 blkdev_put(bdev); 155 blkdev_put(bdev, FMODE_READ);
156 set_capacity(block->gdp, 0); 156 set_capacity(block->gdp, 0);
157} 157}
158 158
diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h
index 489d5fe488fb..05a14536c369 100644
--- a/drivers/s390/block/dasd_int.h
+++ b/drivers/s390/block/dasd_int.h
@@ -610,8 +610,7 @@ int dasd_scan_partitions(struct dasd_block *);
610void dasd_destroy_partitions(struct dasd_block *); 610void dasd_destroy_partitions(struct dasd_block *);
611 611
612/* externals in dasd_ioctl.c */ 612/* externals in dasd_ioctl.c */
613int dasd_ioctl(struct inode *, struct file *, unsigned int, unsigned long); 613int dasd_ioctl(struct block_device *, fmode_t, unsigned int, unsigned long);
614long dasd_compat_ioctl(struct file *, unsigned int, unsigned long);
615 614
616/* externals in dasd_proc.c */ 615/* externals in dasd_proc.c */
617int dasd_proc_init(void); 616int dasd_proc_init(void);
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 91a64630cb0f..b82d816d9ef7 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -366,10 +366,9 @@ static int dasd_ioctl_readall_cmb(struct dasd_block *block, unsigned int cmd,
366} 366}
367 367
368int 368int
369dasd_ioctl(struct inode *inode, struct file *file, 369dasd_ioctl(struct block_device *bdev, fmode_t mode,
370 unsigned int cmd, unsigned long arg) 370 unsigned int cmd, unsigned long arg)
371{ 371{
372 struct block_device *bdev = inode->i_bdev;
373 struct dasd_block *block = bdev->bd_disk->private_data; 372 struct dasd_block *block = bdev->bd_disk->private_data;
374 void __user *argp = (void __user *)arg; 373 void __user *argp = (void __user *)arg;
375 374
@@ -421,15 +420,3 @@ dasd_ioctl(struct inode *inode, struct file *file,
421 return -EINVAL; 420 return -EINVAL;
422 } 421 }
423} 422}
424
425long
426dasd_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
427{
428 int rval;
429
430 lock_kernel();
431 rval = dasd_ioctl(filp->f_path.dentry->d_inode, filp, cmd, arg);
432 unlock_kernel();
433
434 return (rval == -EINVAL) ? -ENOIOCTLCMD : rval;
435}
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index a7ff167d5b81..63f26a135fe5 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -31,8 +31,8 @@
31#define PRINT_WARN(x...) printk(KERN_WARNING DCSSBLK_NAME " warning: " x) 31#define PRINT_WARN(x...) printk(KERN_WARNING DCSSBLK_NAME " warning: " x)
32#define PRINT_ERR(x...) printk(KERN_ERR DCSSBLK_NAME " error: " x) 32#define PRINT_ERR(x...) printk(KERN_ERR DCSSBLK_NAME " error: " x)
33 33
34static int dcssblk_open(struct inode *inode, struct file *filp); 34static int dcssblk_open(struct block_device *bdev, fmode_t mode);
35static int dcssblk_release(struct inode *inode, struct file *filp); 35static int dcssblk_release(struct gendisk *disk, fmode_t mode);
36static int dcssblk_make_request(struct request_queue *q, struct bio *bio); 36static int dcssblk_make_request(struct request_queue *q, struct bio *bio);
37static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum, 37static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum,
38 void **kaddr, unsigned long *pfn); 38 void **kaddr, unsigned long *pfn);
@@ -776,32 +776,31 @@ out_buf:
776} 776}
777 777
778static int 778static int
779dcssblk_open(struct inode *inode, struct file *filp) 779dcssblk_open(struct block_device *bdev, fmode_t mode)
780{ 780{
781 struct dcssblk_dev_info *dev_info; 781 struct dcssblk_dev_info *dev_info;
782 int rc; 782 int rc;
783 783
784 dev_info = inode->i_bdev->bd_disk->private_data; 784 dev_info = bdev->bd_disk->private_data;
785 if (NULL == dev_info) { 785 if (NULL == dev_info) {
786 rc = -ENODEV; 786 rc = -ENODEV;
787 goto out; 787 goto out;
788 } 788 }
789 atomic_inc(&dev_info->use_count); 789 atomic_inc(&dev_info->use_count);
790 inode->i_bdev->bd_block_size = 4096; 790 bdev->bd_block_size = 4096;
791 rc = 0; 791 rc = 0;
792out: 792out:
793 return rc; 793 return rc;
794} 794}
795 795
796static int 796static int
797dcssblk_release(struct inode *inode, struct file *filp) 797dcssblk_release(struct gendisk *disk, fmode_t mode)
798{ 798{
799 struct dcssblk_dev_info *dev_info; 799 struct dcssblk_dev_info *dev_info = disk->private_data;
800 struct segment_info *entry; 800 struct segment_info *entry;
801 int rc; 801 int rc;
802 802
803 dev_info = inode->i_bdev->bd_disk->private_data; 803 if (!dev_info) {
804 if (NULL == dev_info) {
805 rc = -ENODEV; 804 rc = -ENODEV;
806 goto out; 805 goto out;
807 } 806 }
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index a25b8bf54f41..023803dbb0c7 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -43,9 +43,9 @@
43/* 43/*
44 * file operation structure for tape block frontend 44 * file operation structure for tape block frontend
45 */ 45 */
46static int tapeblock_open(struct inode *, struct file *); 46static int tapeblock_open(struct block_device *, fmode_t);
47static int tapeblock_release(struct inode *, struct file *); 47static int tapeblock_release(struct gendisk *, fmode_t);
48static int tapeblock_ioctl(struct inode *, struct file *, unsigned int, 48static int tapeblock_ioctl(struct block_device *, fmode_t, unsigned int,
49 unsigned long); 49 unsigned long);
50static int tapeblock_medium_changed(struct gendisk *); 50static int tapeblock_medium_changed(struct gendisk *);
51static int tapeblock_revalidate_disk(struct gendisk *); 51static int tapeblock_revalidate_disk(struct gendisk *);
@@ -54,7 +54,7 @@ static struct block_device_operations tapeblock_fops = {
54 .owner = THIS_MODULE, 54 .owner = THIS_MODULE,
55 .open = tapeblock_open, 55 .open = tapeblock_open,
56 .release = tapeblock_release, 56 .release = tapeblock_release,
57 .ioctl = tapeblock_ioctl, 57 .locked_ioctl = tapeblock_ioctl,
58 .media_changed = tapeblock_medium_changed, 58 .media_changed = tapeblock_medium_changed,
59 .revalidate_disk = tapeblock_revalidate_disk, 59 .revalidate_disk = tapeblock_revalidate_disk,
60}; 60};
@@ -364,13 +364,12 @@ tapeblock_medium_changed(struct gendisk *disk)
364 * Block frontend tape device open function. 364 * Block frontend tape device open function.
365 */ 365 */
366static int 366static int
367tapeblock_open(struct inode *inode, struct file *filp) 367tapeblock_open(struct block_device *bdev, fmode_t mode)
368{ 368{
369 struct gendisk * disk; 369 struct gendisk * disk = bdev->bd_disk;
370 struct tape_device * device; 370 struct tape_device * device;
371 int rc; 371 int rc;
372 372
373 disk = inode->i_bdev->bd_disk;
374 device = tape_get_device_reference(disk->private_data); 373 device = tape_get_device_reference(disk->private_data);
375 374
376 if (device->required_tapemarks) { 375 if (device->required_tapemarks) {
@@ -410,9 +409,8 @@ release:
410 * we just get the pointer here and release the reference. 409 * we just get the pointer here and release the reference.
411 */ 410 */
412static int 411static int
413tapeblock_release(struct inode *inode, struct file *filp) 412tapeblock_release(struct gendisk *disk, fmode_t mode)
414{ 413{
415 struct gendisk *disk = inode->i_bdev->bd_disk;
416 struct tape_device *device = disk->private_data; 414 struct tape_device *device = disk->private_data;
417 415
418 tape_state_set(device, TS_IN_USE); 416 tape_state_set(device, TS_IN_USE);
@@ -427,22 +425,21 @@ tapeblock_release(struct inode *inode, struct file *filp)
427 */ 425 */
428static int 426static int
429tapeblock_ioctl( 427tapeblock_ioctl(
430 struct inode * inode, 428 struct block_device * bdev,
431 struct file * file, 429 fmode_t mode,
432 unsigned int command, 430 unsigned int command,
433 unsigned long arg 431 unsigned long arg
434) { 432) {
435 int rc; 433 int rc;
436 int minor; 434 int minor;
437 struct gendisk *disk; 435 struct gendisk *disk = bdev->bd_disk;
438 struct tape_device *device; 436 struct tape_device *device;
439 437
440 rc = 0; 438 rc = 0;
441 disk = inode->i_bdev->bd_disk;
442 BUG_ON(!disk); 439 BUG_ON(!disk);
443 device = disk->private_data; 440 device = disk->private_data;
444 BUG_ON(!device); 441 BUG_ON(!device);
445 minor = iminor(inode); 442 minor = MINOR(bdev->bd_dev);
446 443
447 DBF_LH(6, "tapeblock_ioctl(0x%0x)\n", command); 444 DBF_LH(6, "tapeblock_ioctl(0x%0x)\n", command);
448 DBF_LH(6, "device = %d:%d\n", tapeblock_major, minor); 445 DBF_LH(6, "device = %d:%d\n", tapeblock_major, minor);
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index afc96e844a25..2370fd82ebfe 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -452,40 +452,34 @@ static ide_driver_t idescsi_driver = {
452#endif 452#endif
453}; 453};
454 454
455static int idescsi_ide_open(struct inode *inode, struct file *filp) 455static int idescsi_ide_open(struct block_device *bdev, fmode_t mode)
456{ 456{
457 struct gendisk *disk = inode->i_bdev->bd_disk; 457 struct ide_scsi_obj *scsi = ide_scsi_get(bdev->bd_disk);
458 struct ide_scsi_obj *scsi;
459 458
460 if (!(scsi = ide_scsi_get(disk))) 459 if (!scsi)
461 return -ENXIO; 460 return -ENXIO;
462 461
463 return 0; 462 return 0;
464} 463}
465 464
466static int idescsi_ide_release(struct inode *inode, struct file *filp) 465static int idescsi_ide_release(struct gendisk *disk, fmode_t mode)
467{ 466{
468 struct gendisk *disk = inode->i_bdev->bd_disk; 467 ide_scsi_put(ide_scsi_g(disk));
469 struct ide_scsi_obj *scsi = ide_scsi_g(disk);
470
471 ide_scsi_put(scsi);
472
473 return 0; 468 return 0;
474} 469}
475 470
476static int idescsi_ide_ioctl(struct inode *inode, struct file *file, 471static int idescsi_ide_ioctl(struct block_device *bdev, fmode_t mode,
477 unsigned int cmd, unsigned long arg) 472 unsigned int cmd, unsigned long arg)
478{ 473{
479 struct block_device *bdev = inode->i_bdev;
480 struct ide_scsi_obj *scsi = ide_scsi_g(bdev->bd_disk); 474 struct ide_scsi_obj *scsi = ide_scsi_g(bdev->bd_disk);
481 return generic_ide_ioctl(scsi->drive, file, bdev, cmd, arg); 475 return generic_ide_ioctl(scsi->drive, bdev, cmd, arg);
482} 476}
483 477
484static struct block_device_operations idescsi_ops = { 478static struct block_device_operations idescsi_ops = {
485 .owner = THIS_MODULE, 479 .owner = THIS_MODULE,
486 .open = idescsi_ide_open, 480 .open = idescsi_ide_open,
487 .release = idescsi_ide_release, 481 .release = idescsi_ide_release,
488 .ioctl = idescsi_ide_ioctl, 482 .locked_ioctl = idescsi_ide_ioctl,
489}; 483};
490 484
491static int idescsi_slave_configure(struct scsi_device * sdp) 485static int idescsi_slave_configure(struct scsi_device * sdp)
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 28b19ef26309..dc1cfb2fd76b 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -237,7 +237,7 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
237 case SCSI_IOCTL_SEND_COMMAND: 237 case SCSI_IOCTL_SEND_COMMAND:
238 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) 238 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
239 return -EACCES; 239 return -EACCES;
240 return sg_scsi_ioctl(NULL, sdev->request_queue, NULL, arg); 240 return sg_scsi_ioctl(sdev->request_queue, NULL, 0, arg);
241 case SCSI_IOCTL_DOORLOCK: 241 case SCSI_IOCTL_DOORLOCK:
242 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT); 242 return scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
243 case SCSI_IOCTL_DOORUNLOCK: 243 case SCSI_IOCTL_DOORUNLOCK:
@@ -277,14 +277,14 @@ EXPORT_SYMBOL(scsi_ioctl);
277 * @filp: either NULL or a &struct file which must have the O_NONBLOCK flag. 277 * @filp: either NULL or a &struct file which must have the O_NONBLOCK flag.
278 */ 278 */
279int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd, 279int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
280 void __user *arg, struct file *filp) 280 void __user *arg, int ndelay)
281{ 281{
282 int val, result; 282 int val, result;
283 283
284 /* The first set of iocts may be executed even if we're doing 284 /* The first set of iocts may be executed even if we're doing
285 * error processing, as long as the device was opened 285 * error processing, as long as the device was opened
286 * non-blocking */ 286 * non-blocking */
287 if (filp && (filp->f_flags & O_NONBLOCK)) { 287 if (ndelay) {
288 if (scsi_host_in_recovery(sdev->host)) 288 if (scsi_host_in_recovery(sdev->host))
289 return -ENODEV; 289 return -ENODEV;
290 } else if (!scsi_block_when_processing_errors(sdev)) 290 } else if (!scsi_block_when_processing_errors(sdev))
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 7c4d2e68df1c..43f34c73df12 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -609,17 +609,15 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
609 * In the latter case @inode and @filp carry an abridged amount 609 * In the latter case @inode and @filp carry an abridged amount
610 * of information as noted above. 610 * of information as noted above.
611 **/ 611 **/
612static int sd_open(struct inode *inode, struct file *filp) 612static int sd_open(struct block_device *bdev, fmode_t mode)
613{ 613{
614 struct gendisk *disk = inode->i_bdev->bd_disk; 614 struct scsi_disk *sdkp = scsi_disk_get(bdev->bd_disk);
615 struct scsi_disk *sdkp;
616 struct scsi_device *sdev; 615 struct scsi_device *sdev;
617 int retval; 616 int retval;
618 617
619 if (!(sdkp = scsi_disk_get(disk))) 618 if (!sdkp)
620 return -ENXIO; 619 return -ENXIO;
621 620
622
623 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_open\n")); 621 SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_open\n"));
624 622
625 sdev = sdkp->device; 623 sdev = sdkp->device;
@@ -633,14 +631,13 @@ static int sd_open(struct inode *inode, struct file *filp)
633 goto error_out; 631 goto error_out;
634 632
635 if (sdev->removable || sdkp->write_prot) 633 if (sdev->removable || sdkp->write_prot)
636 check_disk_change(inode->i_bdev); 634 check_disk_change(bdev);
637 635
638 /* 636 /*
639 * If the drive is empty, just let the open fail. 637 * If the drive is empty, just let the open fail.
640 */ 638 */
641 retval = -ENOMEDIUM; 639 retval = -ENOMEDIUM;
642 if (sdev->removable && !sdkp->media_present && 640 if (sdev->removable && !sdkp->media_present && !(mode & FMODE_NDELAY))
643 !(filp->f_flags & O_NDELAY))
644 goto error_out; 641 goto error_out;
645 642
646 /* 643 /*
@@ -648,7 +645,7 @@ static int sd_open(struct inode *inode, struct file *filp)
648 * if the user expects to be able to write to the thing. 645 * if the user expects to be able to write to the thing.
649 */ 646 */
650 retval = -EROFS; 647 retval = -EROFS;
651 if (sdkp->write_prot && (filp->f_mode & FMODE_WRITE)) 648 if (sdkp->write_prot && (mode & FMODE_WRITE))
652 goto error_out; 649 goto error_out;
653 650
654 /* 651 /*
@@ -684,9 +681,8 @@ error_out:
684 * Note: may block (uninterruptible) if error recovery is underway 681 * Note: may block (uninterruptible) if error recovery is underway
685 * on this disk. 682 * on this disk.
686 **/ 683 **/
687static int sd_release(struct inode *inode, struct file *filp) 684static int sd_release(struct gendisk *disk, fmode_t mode)
688{ 685{
689 struct gendisk *disk = inode->i_bdev->bd_disk;
690 struct scsi_disk *sdkp = scsi_disk(disk); 686 struct scsi_disk *sdkp = scsi_disk(disk);
691 struct scsi_device *sdev = sdkp->device; 687 struct scsi_device *sdev = sdkp->device;
692 688
@@ -743,10 +739,9 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
743 * Note: most ioctls are forward onto the block subsystem or further 739 * Note: most ioctls are forward onto the block subsystem or further
744 * down in the scsi subsystem. 740 * down in the scsi subsystem.
745 **/ 741 **/
746static int sd_ioctl(struct inode * inode, struct file * filp, 742static int sd_ioctl(struct block_device *bdev, fmode_t mode,
747 unsigned int cmd, unsigned long arg) 743 unsigned int cmd, unsigned long arg)
748{ 744{
749 struct block_device *bdev = inode->i_bdev;
750 struct gendisk *disk = bdev->bd_disk; 745 struct gendisk *disk = bdev->bd_disk;
751 struct scsi_device *sdp = scsi_disk(disk)->device; 746 struct scsi_device *sdp = scsi_disk(disk)->device;
752 void __user *p = (void __user *)arg; 747 void __user *p = (void __user *)arg;
@@ -761,7 +756,8 @@ static int sd_ioctl(struct inode * inode, struct file * filp,
761 * may try and take the device offline, in which case all further 756 * may try and take the device offline, in which case all further
762 * access to the device is prohibited. 757 * access to the device is prohibited.
763 */ 758 */
764 error = scsi_nonblockable_ioctl(sdp, cmd, p, filp); 759 error = scsi_nonblockable_ioctl(sdp, cmd, p,
760 (mode & FMODE_NDELAY_NOW) != 0);
765 if (!scsi_block_when_processing_errors(sdp) || !error) 761 if (!scsi_block_when_processing_errors(sdp) || !error)
766 return error; 762 return error;
767 763
@@ -775,7 +771,7 @@ static int sd_ioctl(struct inode * inode, struct file * filp,
775 case SCSI_IOCTL_GET_BUS_NUMBER: 771 case SCSI_IOCTL_GET_BUS_NUMBER:
776 return scsi_ioctl(sdp, cmd, p); 772 return scsi_ioctl(sdp, cmd, p);
777 default: 773 default:
778 error = scsi_cmd_ioctl(filp, disk->queue, disk, cmd, p); 774 error = scsi_cmd_ioctl(disk->queue, disk, mode, cmd, p);
779 if (error != -ENOTTY) 775 if (error != -ENOTTY)
780 return error; 776 return error;
781 } 777 }
@@ -928,11 +924,10 @@ static void sd_rescan(struct device *dev)
928 * This gets directly called from VFS. When the ioctl 924 * This gets directly called from VFS. When the ioctl
929 * is not recognized we go back to the other translation paths. 925 * is not recognized we go back to the other translation paths.
930 */ 926 */
931static long sd_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 927static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
928 unsigned int cmd, unsigned long arg)
932{ 929{
933 struct block_device *bdev = file->f_path.dentry->d_inode->i_bdev; 930 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
934 struct gendisk *disk = bdev->bd_disk;
935 struct scsi_device *sdev = scsi_disk(disk)->device;
936 931
937 /* 932 /*
938 * If we are in the middle of error recovery, don't let anyone 933 * If we are in the middle of error recovery, don't let anyone
@@ -962,7 +957,7 @@ static struct block_device_operations sd_fops = {
962 .owner = THIS_MODULE, 957 .owner = THIS_MODULE,
963 .open = sd_open, 958 .open = sd_open,
964 .release = sd_release, 959 .release = sd_release,
965 .ioctl = sd_ioctl, 960 .locked_ioctl = sd_ioctl,
966 .getgeo = sd_getgeo, 961 .getgeo = sd_getgeo,
967#ifdef CONFIG_COMPAT 962#ifdef CONFIG_COMPAT
968 .compat_ioctl = sd_compat_ioctl, 963 .compat_ioctl = sd_compat_ioctl,
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 93bd59a1ed79..9adf35bd8b56 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1059,7 +1059,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
1059 if (sg_allow_access(filp, &opcode)) 1059 if (sg_allow_access(filp, &opcode))
1060 return -EPERM; 1060 return -EPERM;
1061 } 1061 }
1062 return sg_scsi_ioctl(filp, sdp->device->request_queue, NULL, p); 1062 return sg_scsi_ioctl(sdp->device->request_queue, NULL, filp->f_mode, p);
1063 case SG_SET_DEBUG: 1063 case SG_SET_DEBUG:
1064 result = get_user(val, ip); 1064 result = get_user(val, ip);
1065 if (result) 1065 if (result)
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 0f17009c99d2..62b6633e3a97 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -471,38 +471,31 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
471 return scsi_prep_return(q, rq, ret); 471 return scsi_prep_return(q, rq, ret);
472} 472}
473 473
474static int sr_block_open(struct inode *inode, struct file *file) 474static int sr_block_open(struct block_device *bdev, fmode_t mode)
475{ 475{
476 struct gendisk *disk = inode->i_bdev->bd_disk; 476 struct scsi_cd *cd = scsi_cd_get(bdev->bd_disk);
477 struct scsi_cd *cd; 477 int ret = -ENXIO;
478 int ret = 0;
479
480 if(!(cd = scsi_cd_get(disk)))
481 return -ENXIO;
482
483 if((ret = cdrom_open(&cd->cdi, inode, file)) != 0)
484 scsi_cd_put(cd);
485 478
479 if (cd) {
480 ret = cdrom_open(&cd->cdi, bdev, mode);
481 if (ret)
482 scsi_cd_put(cd);
483 }
486 return ret; 484 return ret;
487} 485}
488 486
489static int sr_block_release(struct inode *inode, struct file *file) 487static int sr_block_release(struct gendisk *disk, fmode_t mode)
490{ 488{
491 int ret; 489 struct scsi_cd *cd = scsi_cd(disk);
492 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk); 490 cdrom_release(&cd->cdi, mode);
493 ret = cdrom_release(&cd->cdi, file);
494 if(ret)
495 return ret;
496
497 scsi_cd_put(cd); 491 scsi_cd_put(cd);
498
499 return 0; 492 return 0;
500} 493}
501 494
502static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd, 495static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
503 unsigned long arg) 496 unsigned long arg)
504{ 497{
505 struct scsi_cd *cd = scsi_cd(inode->i_bdev->bd_disk); 498 struct scsi_cd *cd = scsi_cd(bdev->bd_disk);
506 struct scsi_device *sdev = cd->device; 499 struct scsi_device *sdev = cd->device;
507 void __user *argp = (void __user *)arg; 500 void __user *argp = (void __user *)arg;
508 int ret; 501 int ret;
@@ -517,7 +510,7 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
517 return scsi_ioctl(sdev, cmd, argp); 510 return scsi_ioctl(sdev, cmd, argp);
518 } 511 }
519 512
520 ret = cdrom_ioctl(file, &cd->cdi, inode, cmd, arg); 513 ret = cdrom_ioctl(&cd->cdi, bdev, mode, cmd, arg);
521 if (ret != -ENOSYS) 514 if (ret != -ENOSYS)
522 return ret; 515 return ret;
523 516
@@ -527,7 +520,8 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd,
527 * case fall through to scsi_ioctl, which will return ENDOEV again 520 * case fall through to scsi_ioctl, which will return ENDOEV again
528 * if it doesn't recognise the ioctl 521 * if it doesn't recognise the ioctl
529 */ 522 */
530 ret = scsi_nonblockable_ioctl(sdev, cmd, argp, NULL); 523 ret = scsi_nonblockable_ioctl(sdev, cmd, argp,
524 (mode & FMODE_NDELAY_NOW) != 0);
531 if (ret != -ENODEV) 525 if (ret != -ENODEV)
532 return ret; 526 return ret;
533 return scsi_ioctl(sdev, cmd, argp); 527 return scsi_ioctl(sdev, cmd, argp);
@@ -544,7 +538,7 @@ static struct block_device_operations sr_bdops =
544 .owner = THIS_MODULE, 538 .owner = THIS_MODULE,
545 .open = sr_block_open, 539 .open = sr_block_open,
546 .release = sr_block_release, 540 .release = sr_block_release,
547 .ioctl = sr_block_ioctl, 541 .locked_ioctl = sr_block_ioctl,
548 .media_changed = sr_block_media_changed, 542 .media_changed = sr_block_media_changed,
549 /* 543 /*
550 * No compat_ioctl for now because sr_block_ioctl never 544 * No compat_ioctl for now because sr_block_ioctl never
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 5c28d08f18f4..c959bdc55f4f 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -3263,7 +3263,8 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
3263 * may try and take the device offline, in which case all further 3263 * may try and take the device offline, in which case all further
3264 * access to the device is prohibited. 3264 * access to the device is prohibited.
3265 */ 3265 */
3266 retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p, file); 3266 retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p,
3267 file->f_flags & O_NDELAY);
3267 if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV) 3268 if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV)
3268 goto out; 3269 goto out;
3269 retval = 0; 3270 retval = 0;
@@ -3567,8 +3568,8 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
3567 !capable(CAP_SYS_RAWIO)) 3568 !capable(CAP_SYS_RAWIO))
3568 i = -EPERM; 3569 i = -EPERM;
3569 else 3570 else
3570 i = scsi_cmd_ioctl(file, STp->disk->queue, 3571 i = scsi_cmd_ioctl(STp->disk->queue, STp->disk,
3571 STp->disk, cmd_in, p); 3572 file->f_mode, cmd_in, p);
3572 if (i != -ENOTTY) 3573 if (i != -ENOTTY)
3573 return i; 3574 return i;
3574 break; 3575 break;