aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/um/drivers/ubd_kern.c19
-rw-r--r--block/bsg.c9
-rw-r--r--block/cmd-filter.c2
-rw-r--r--block/compat_ioctl.c175
-rw-r--r--block/ioctl.c173
-rw-r--r--block/scsi_ioctl.c33
-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
-rw-r--r--fs/block_dev.c111
-rw-r--r--fs/ext2/xip.c1
-rw-r--r--fs/ext3/super.c4
-rw-r--r--fs/ext4/super.c4
-rw-r--r--fs/fifo.c6
-rw-r--r--fs/file_table.c4
-rw-r--r--fs/hostfs/hostfs_kern.c5
-rw-r--r--fs/jfs/jfs_logmgr.c4
-rw-r--r--fs/locks.c3
-rw-r--r--fs/ocfs2/cluster/heartbeat.c6
-rw-r--r--fs/open.c2
-rw-r--r--fs/partitions/check.c4
-rw-r--r--fs/proc/base.c4
-rw-r--r--fs/reiserfs/journal.c11
-rw-r--r--fs/super.c14
-rw-r--r--fs/xfs/linux-2.6/xfs_super.c4
-rw-r--r--include/linux/blkdev.h27
-rw-r--r--include/linux/cdrom.h10
-rw-r--r--include/linux/device-mapper.h11
-rw-r--r--include/linux/file.h4
-rw-r--r--include/linux/fs.h49
-rw-r--r--include/linux/fsnotify.h2
-rw-r--r--include/linux/ide.h7
-rw-r--r--include/linux/reiserfs_fs_sb.h1
-rw-r--r--include/linux/types.h1
-rw-r--r--include/scsi/scsi_ioctl.h2
-rw-r--r--ipc/shm.c2
-rw-r--r--kernel/power/disk.c2
-rw-r--r--kernel/power/power.h2
-rw-r--r--kernel/power/swap.c14
-rw-r--r--sound/core/oss/pcm_oss.c2
-rw-r--r--sound/oss/au1550_ac97.c2
-rw-r--r--sound/oss/dmasound/dmasound.h4
-rw-r--r--sound/oss/dmasound/dmasound_atari.c4
-rw-r--r--sound/oss/dmasound/dmasound_core.c10
-rw-r--r--sound/oss/msnd.h2
-rw-r--r--sound/oss/sound_config.h20
-rw-r--r--sound/oss/swarm_cs4297a.c2
-rw-r--r--sound/oss/vwsnd.c2
107 files changed, 868 insertions, 1002 deletions
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index b58fb8941d8d..0a868118cf06 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -98,9 +98,9 @@ static inline void ubd_set_bit(__u64 bit, unsigned char *data)
98 98
99static DEFINE_MUTEX(ubd_lock); 99static DEFINE_MUTEX(ubd_lock);
100 100
101static int ubd_open(struct inode * inode, struct file * filp); 101static int ubd_open(struct block_device *bdev, fmode_t mode);
102static int ubd_release(struct inode * inode, struct file * file); 102static int ubd_release(struct gendisk *disk, fmode_t mode);
103static int ubd_ioctl(struct inode * inode, struct file * file, 103static int ubd_ioctl(struct block_device *bdev, fmode_t mode,
104 unsigned int cmd, unsigned long arg); 104 unsigned int cmd, unsigned long arg);
105static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo); 105static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
106 106
@@ -1112,9 +1112,9 @@ static int __init ubd_driver_init(void){
1112 1112
1113device_initcall(ubd_driver_init); 1113device_initcall(ubd_driver_init);
1114 1114
1115static int ubd_open(struct inode *inode, struct file *filp) 1115static int ubd_open(struct block_device *bdev, fmode_t mode)
1116{ 1116{
1117 struct gendisk *disk = inode->i_bdev->bd_disk; 1117 struct gendisk *disk = bdev->bd_disk;
1118 struct ubd *ubd_dev = disk->private_data; 1118 struct ubd *ubd_dev = disk->private_data;
1119 int err = 0; 1119 int err = 0;
1120 1120
@@ -1131,7 +1131,7 @@ static int ubd_open(struct inode *inode, struct file *filp)
1131 1131
1132 /* This should no more be needed. And it didn't work anyway to exclude 1132 /* This should no more be needed. And it didn't work anyway to exclude
1133 * read-write remounting of filesystems.*/ 1133 * read-write remounting of filesystems.*/
1134 /*if((filp->f_mode & FMODE_WRITE) && !ubd_dev->openflags.w){ 1134 /*if((mode & FMODE_WRITE) && !ubd_dev->openflags.w){
1135 if(--ubd_dev->count == 0) ubd_close_dev(ubd_dev); 1135 if(--ubd_dev->count == 0) ubd_close_dev(ubd_dev);
1136 err = -EROFS; 1136 err = -EROFS;
1137 }*/ 1137 }*/
@@ -1139,9 +1139,8 @@ static int ubd_open(struct inode *inode, struct file *filp)
1139 return err; 1139 return err;
1140} 1140}
1141 1141
1142static int ubd_release(struct inode * inode, struct file * file) 1142static int ubd_release(struct gendisk *disk, fmode_t mode)
1143{ 1143{
1144 struct gendisk *disk = inode->i_bdev->bd_disk;
1145 struct ubd *ubd_dev = disk->private_data; 1144 struct ubd *ubd_dev = disk->private_data;
1146 1145
1147 if(--ubd_dev->count == 0) 1146 if(--ubd_dev->count == 0)
@@ -1306,10 +1305,10 @@ static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1306 return 0; 1305 return 0;
1307} 1306}
1308 1307
1309static int ubd_ioctl(struct inode * inode, struct file * file, 1308static int ubd_ioctl(struct block_device *bdev, fmode_t mode,
1310 unsigned int cmd, unsigned long arg) 1309 unsigned int cmd, unsigned long arg)
1311{ 1310{
1312 struct ubd *ubd_dev = inode->i_bdev->bd_disk->private_data; 1311 struct ubd *ubd_dev = bdev->bd_disk->private_data;
1313 struct hd_driveid ubd_id = { 1312 struct hd_driveid ubd_id = {
1314 .cyls = 0, 1313 .cyls = 0,
1315 .heads = 128, 1314 .heads = 128,
diff --git a/block/bsg.c b/block/bsg.c
index 034112bfe1f3..e8bd2475682a 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -173,7 +173,7 @@ unlock:
173 173
174static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq, 174static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
175 struct sg_io_v4 *hdr, struct bsg_device *bd, 175 struct sg_io_v4 *hdr, struct bsg_device *bd,
176 int has_write_perm) 176 fmode_t has_write_perm)
177{ 177{
178 if (hdr->request_len > BLK_MAX_CDB) { 178 if (hdr->request_len > BLK_MAX_CDB) {
179 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL); 179 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
@@ -242,7 +242,7 @@ bsg_validate_sgv4_hdr(struct request_queue *q, struct sg_io_v4 *hdr, int *rw)
242 * map sg_io_v4 to a request. 242 * map sg_io_v4 to a request.
243 */ 243 */
244static struct request * 244static struct request *
245bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm) 245bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
246{ 246{
247 struct request_queue *q = bd->queue; 247 struct request_queue *q = bd->queue;
248 struct request *rq, *next_rq = NULL; 248 struct request *rq, *next_rq = NULL;
@@ -601,7 +601,8 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
601} 601}
602 602
603static int __bsg_write(struct bsg_device *bd, const char __user *buf, 603static int __bsg_write(struct bsg_device *bd, const char __user *buf,
604 size_t count, ssize_t *bytes_written, int has_write_perm) 604 size_t count, ssize_t *bytes_written,
605 fmode_t has_write_perm)
605{ 606{
606 struct bsg_command *bc; 607 struct bsg_command *bc;
607 struct request *rq; 608 struct request *rq;
@@ -913,7 +914,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
913 case SG_EMULATED_HOST: 914 case SG_EMULATED_HOST:
914 case SCSI_IOCTL_SEND_COMMAND: { 915 case SCSI_IOCTL_SEND_COMMAND: {
915 void __user *uarg = (void __user *) arg; 916 void __user *uarg = (void __user *) arg;
916 return scsi_cmd_ioctl(file, bd->queue, NULL, cmd, uarg); 917 return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg);
917 } 918 }
918 case SG_IO: { 919 case SG_IO: {
919 struct request *rq; 920 struct request *rq;
diff --git a/block/cmd-filter.c b/block/cmd-filter.c
index e669aed4c6bc..504b275e1b90 100644
--- a/block/cmd-filter.c
+++ b/block/cmd-filter.c
@@ -27,7 +27,7 @@
27#include <linux/cdrom.h> 27#include <linux/cdrom.h>
28 28
29int blk_verify_command(struct blk_cmd_filter *filter, 29int blk_verify_command(struct blk_cmd_filter *filter,
30 unsigned char *cmd, int has_write_perm) 30 unsigned char *cmd, fmode_t has_write_perm)
31{ 31{
32 /* root can do any command. */ 32 /* root can do any command. */
33 if (capable(CAP_SYS_RAWIO)) 33 if (capable(CAP_SYS_RAWIO))
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index 1e559fba7bdf..3098c92402fd 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -71,8 +71,8 @@ static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
71 return ret; 71 return ret;
72} 72}
73 73
74static int compat_hdio_ioctl(struct inode *inode, struct file *file, 74static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode,
75 struct gendisk *disk, unsigned int cmd, unsigned long arg) 75 unsigned int cmd, unsigned long arg)
76{ 76{
77 mm_segment_t old_fs = get_fs(); 77 mm_segment_t old_fs = get_fs();
78 unsigned long kval; 78 unsigned long kval;
@@ -80,7 +80,7 @@ static int compat_hdio_ioctl(struct inode *inode, struct file *file,
80 int error; 80 int error;
81 81
82 set_fs(KERNEL_DS); 82 set_fs(KERNEL_DS);
83 error = blkdev_driver_ioctl(inode, file, disk, 83 error = __blkdev_driver_ioctl(bdev, mode,
84 cmd, (unsigned long)(&kval)); 84 cmd, (unsigned long)(&kval));
85 set_fs(old_fs); 85 set_fs(old_fs);
86 86
@@ -111,8 +111,8 @@ struct compat_cdrom_generic_command {
111 compat_caddr_t reserved[1]; 111 compat_caddr_t reserved[1];
112}; 112};
113 113
114static int compat_cdrom_read_audio(struct inode *inode, struct file *file, 114static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode,
115 struct gendisk *disk, unsigned int cmd, unsigned long arg) 115 unsigned int cmd, unsigned long arg)
116{ 116{
117 struct cdrom_read_audio __user *cdread_audio; 117 struct cdrom_read_audio __user *cdread_audio;
118 struct compat_cdrom_read_audio __user *cdread_audio32; 118 struct compat_cdrom_read_audio __user *cdread_audio32;
@@ -134,12 +134,12 @@ static int compat_cdrom_read_audio(struct inode *inode, struct file *file,
134 if (put_user(datap, &cdread_audio->buf)) 134 if (put_user(datap, &cdread_audio->buf))
135 return -EFAULT; 135 return -EFAULT;
136 136
137 return blkdev_driver_ioctl(inode, file, disk, cmd, 137 return __blkdev_driver_ioctl(bdev, mode, cmd,
138 (unsigned long)cdread_audio); 138 (unsigned long)cdread_audio);
139} 139}
140 140
141static int compat_cdrom_generic_command(struct inode *inode, struct file *file, 141static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
142 struct gendisk *disk, unsigned int cmd, unsigned long arg) 142 unsigned int cmd, unsigned long arg)
143{ 143{
144 struct cdrom_generic_command __user *cgc; 144 struct cdrom_generic_command __user *cgc;
145 struct compat_cdrom_generic_command __user *cgc32; 145 struct compat_cdrom_generic_command __user *cgc32;
@@ -167,7 +167,7 @@ static int compat_cdrom_generic_command(struct inode *inode, struct file *file,
167 put_user(compat_ptr(data), &cgc->reserved[0])) 167 put_user(compat_ptr(data), &cgc->reserved[0]))
168 return -EFAULT; 168 return -EFAULT;
169 169
170 return blkdev_driver_ioctl(inode, file, disk, cmd, (unsigned long)cgc); 170 return __blkdev_driver_ioctl(bdev, mode, cmd, (unsigned long)cgc);
171} 171}
172 172
173struct compat_blkpg_ioctl_arg { 173struct compat_blkpg_ioctl_arg {
@@ -177,7 +177,7 @@ struct compat_blkpg_ioctl_arg {
177 compat_caddr_t data; 177 compat_caddr_t data;
178}; 178};
179 179
180static int compat_blkpg_ioctl(struct inode *inode, struct file *file, 180static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode,
181 unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) 181 unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32)
182{ 182{
183 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); 183 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
@@ -196,7 +196,7 @@ static int compat_blkpg_ioctl(struct inode *inode, struct file *file,
196 if (err) 196 if (err)
197 return err; 197 return err;
198 198
199 return blkdev_ioctl(inode, file, cmd, (unsigned long)a); 199 return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a);
200} 200}
201 201
202#define BLKBSZGET_32 _IOR(0x12, 112, int) 202#define BLKBSZGET_32 _IOR(0x12, 112, int)
@@ -308,8 +308,8 @@ static struct {
308 308
309#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table) 309#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
310 310
311static int compat_fd_ioctl(struct inode *inode, struct file *file, 311static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
312 struct gendisk *disk, unsigned int cmd, unsigned long arg) 312 unsigned int cmd, unsigned long arg)
313{ 313{
314 mm_segment_t old_fs = get_fs(); 314 mm_segment_t old_fs = get_fs();
315 void *karg = NULL; 315 void *karg = NULL;
@@ -413,7 +413,7 @@ static int compat_fd_ioctl(struct inode *inode, struct file *file,
413 return -EINVAL; 413 return -EINVAL;
414 } 414 }
415 set_fs(KERNEL_DS); 415 set_fs(KERNEL_DS);
416 err = blkdev_driver_ioctl(inode, file, disk, kcmd, (unsigned long)karg); 416 err = __blkdev_driver_ioctl(bdev, mode, kcmd, (unsigned long)karg);
417 set_fs(old_fs); 417 set_fs(old_fs);
418 if (err) 418 if (err)
419 goto out; 419 goto out;
@@ -579,8 +579,8 @@ static int compat_blk_trace_setup(struct block_device *bdev, char __user *arg)
579 return 0; 579 return 0;
580} 580}
581 581
582static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file, 582static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
583 struct gendisk *disk, unsigned cmd, unsigned long arg) 583 unsigned cmd, unsigned long arg)
584{ 584{
585 int ret; 585 int ret;
586 586
@@ -596,7 +596,7 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
596 case HDIO_GET_ACOUSTIC: 596 case HDIO_GET_ACOUSTIC:
597 case HDIO_GET_ADDRESS: 597 case HDIO_GET_ADDRESS:
598 case HDIO_GET_BUSSTATE: 598 case HDIO_GET_BUSSTATE:
599 return compat_hdio_ioctl(inode, file, disk, cmd, arg); 599 return compat_hdio_ioctl(bdev, mode, cmd, arg);
600 case FDSETPRM32: 600 case FDSETPRM32:
601 case FDDEFPRM32: 601 case FDDEFPRM32:
602 case FDGETPRM32: 602 case FDGETPRM32:
@@ -606,11 +606,11 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
606 case FDPOLLDRVSTAT32: 606 case FDPOLLDRVSTAT32:
607 case FDGETFDCSTAT32: 607 case FDGETFDCSTAT32:
608 case FDWERRORGET32: 608 case FDWERRORGET32:
609 return compat_fd_ioctl(inode, file, disk, cmd, arg); 609 return compat_fd_ioctl(bdev, mode, cmd, arg);
610 case CDROMREADAUDIO: 610 case CDROMREADAUDIO:
611 return compat_cdrom_read_audio(inode, file, disk, cmd, arg); 611 return compat_cdrom_read_audio(bdev, mode, cmd, arg);
612 case CDROM_SEND_PACKET: 612 case CDROM_SEND_PACKET:
613 return compat_cdrom_generic_command(inode, file, disk, cmd, arg); 613 return compat_cdrom_generic_command(bdev, mode, cmd, arg);
614 614
615 /* 615 /*
616 * No handler required for the ones below, we just need to 616 * No handler required for the ones below, we just need to
@@ -679,55 +679,49 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
679 case DVD_WRITE_STRUCT: 679 case DVD_WRITE_STRUCT:
680 case DVD_AUTH: 680 case DVD_AUTH:
681 arg = (unsigned long)compat_ptr(arg); 681 arg = (unsigned long)compat_ptr(arg);
682 /* These intepret arg as an unsigned long, not as a pointer,
683 * so we must not do compat_ptr() conversion. */
684 case HDIO_SET_MULTCOUNT:
685 case HDIO_SET_UNMASKINTR:
686 case HDIO_SET_KEEPSETTINGS:
687 case HDIO_SET_32BIT:
688 case HDIO_SET_NOWERR:
689 case HDIO_SET_DMA:
690 case HDIO_SET_PIO_MODE:
691 case HDIO_SET_NICE:
692 case HDIO_SET_WCACHE:
693 case HDIO_SET_ACOUSTIC:
694 case HDIO_SET_BUSSTATE:
695 case HDIO_SET_ADDRESS:
696 case CDROMEJECT_SW:
697 case CDROM_SET_OPTIONS:
698 case CDROM_CLEAR_OPTIONS:
699 case CDROM_SELECT_SPEED:
700 case CDROM_SELECT_DISC:
701 case CDROM_MEDIA_CHANGED:
702 case CDROM_DRIVE_STATUS:
703 case CDROM_LOCKDOOR:
704 case CDROM_DEBUG:
705 break; 682 break;
706 default: 683 default:
707 /* unknown ioctl number */ 684 /* unknown ioctl number */
708 return -ENOIOCTLCMD; 685 return -ENOIOCTLCMD;
709 } 686 }
710 687
711 if (disk->fops->unlocked_ioctl) 688 return __blkdev_driver_ioctl(bdev, mode, cmd, arg);
712 return disk->fops->unlocked_ioctl(file, cmd, arg);
713
714 if (disk->fops->ioctl) {
715 lock_kernel();
716 ret = disk->fops->ioctl(inode, file, cmd, arg);
717 unlock_kernel();
718 return ret;
719 }
720
721 return -ENOTTY;
722} 689}
723 690
724static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file, 691/* Most of the generic ioctls are handled in the normal fallback path.
725 struct block_device *bdev, 692 This assumes the blkdev's low level compat_ioctl always returns
726 unsigned cmd, unsigned long arg) 693 ENOIOCTLCMD for unknown ioctls. */
694long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
727{ 695{
696 int ret = -ENOIOCTLCMD;
697 struct inode *inode = file->f_mapping->host;
698 struct block_device *bdev = inode->i_bdev;
699 struct gendisk *disk = bdev->bd_disk;
700 fmode_t mode = file->f_mode;
728 struct backing_dev_info *bdi; 701 struct backing_dev_info *bdi;
702 loff_t size;
703
704 if (file->f_flags & O_NDELAY)
705 mode |= FMODE_NDELAY_NOW;
729 706
730 switch (cmd) { 707 switch (cmd) {
708 case HDIO_GETGEO:
709 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
710 case BLKFLSBUF:
711 case BLKROSET:
712 case BLKDISCARD:
713 /*
714 * the ones below are implemented in blkdev_locked_ioctl,
715 * but we call blkdev_ioctl, which gets the lock for us
716 */
717 case BLKRRPART:
718 return blkdev_ioctl(bdev, mode, cmd,
719 (unsigned long)compat_ptr(arg));
720 case BLKBSZSET_32:
721 return blkdev_ioctl(bdev, mode, BLKBSZSET,
722 (unsigned long)compat_ptr(arg));
723 case BLKPG:
724 return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg));
731 case BLKRAGET: 725 case BLKRAGET:
732 case BLKFRAGET: 726 case BLKFRAGET:
733 if (!arg) 727 if (!arg)
@@ -753,65 +747,36 @@ static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
753 bdi = blk_get_backing_dev_info(bdev); 747 bdi = blk_get_backing_dev_info(bdev);
754 if (bdi == NULL) 748 if (bdi == NULL)
755 return -ENOTTY; 749 return -ENOTTY;
750 lock_kernel();
756 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE; 751 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
752 unlock_kernel();
757 return 0; 753 return 0;
758 case BLKGETSIZE: 754 case BLKGETSIZE:
759 if ((bdev->bd_inode->i_size >> 9) > ~0UL) 755 size = bdev->bd_inode->i_size;
756 if ((size >> 9) > ~0UL)
760 return -EFBIG; 757 return -EFBIG;
761 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9); 758 return compat_put_ulong(arg, size >> 9);
762 759
763 case BLKGETSIZE64_32: 760 case BLKGETSIZE64_32:
764 return compat_put_u64(arg, bdev->bd_inode->i_size); 761 return compat_put_u64(arg, bdev->bd_inode->i_size);
765 762
766 case BLKTRACESETUP32: 763 case BLKTRACESETUP32:
767 return compat_blk_trace_setup(bdev, compat_ptr(arg)); 764 lock_kernel();
765 ret = compat_blk_trace_setup(bdev, compat_ptr(arg));
766 unlock_kernel();
767 return ret;
768 case BLKTRACESTART: /* compatible */ 768 case BLKTRACESTART: /* compatible */
769 case BLKTRACESTOP: /* compatible */ 769 case BLKTRACESTOP: /* compatible */
770 case BLKTRACETEARDOWN: /* compatible */ 770 case BLKTRACETEARDOWN: /* compatible */
771 return blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); 771 lock_kernel();
772 } 772 ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg));
773 return -ENOIOCTLCMD; 773 unlock_kernel();
774}
775
776/* Most of the generic ioctls are handled in the normal fallback path.
777 This assumes the blkdev's low level compat_ioctl always returns
778 ENOIOCTLCMD for unknown ioctls. */
779long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
780{
781 int ret = -ENOIOCTLCMD;
782 struct inode *inode = file->f_mapping->host;
783 struct block_device *bdev = inode->i_bdev;
784 struct gendisk *disk = bdev->bd_disk;
785
786 switch (cmd) {
787 case HDIO_GETGEO:
788 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
789 case BLKFLSBUF:
790 case BLKROSET:
791 case BLKDISCARD:
792 /*
793 * the ones below are implemented in blkdev_locked_ioctl,
794 * but we call blkdev_ioctl, which gets the lock for us
795 */
796 case BLKRRPART:
797 return blkdev_ioctl(inode, file, cmd,
798 (unsigned long)compat_ptr(arg));
799 case BLKBSZSET_32:
800 return blkdev_ioctl(inode, file, BLKBSZSET,
801 (unsigned long)compat_ptr(arg));
802 case BLKPG:
803 return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg));
804 }
805
806 lock_kernel();
807 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
808 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */
809 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
810 ret = disk->fops->compat_ioctl(file, cmd, arg);
811 unlock_kernel();
812
813 if (ret != -ENOIOCTLCMD)
814 return ret; 774 return ret;
815 775 default:
816 return compat_blkdev_driver_ioctl(inode, file, disk, cmd, arg); 776 if (disk->fops->compat_ioctl)
777 ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg);
778 if (ret == -ENOIOCTLCMD)
779 ret = compat_blkdev_driver_ioctl(bdev, mode, cmd, arg);
780 return ret;
781 }
817} 782}
diff --git a/block/ioctl.c b/block/ioctl.c
index 38bee321e1fa..c832d639b6e2 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -201,97 +201,41 @@ static int put_u64(unsigned long arg, u64 val)
201 return put_user(val, (u64 __user *)arg); 201 return put_user(val, (u64 __user *)arg);
202} 202}
203 203
204static int blkdev_locked_ioctl(struct file *file, struct block_device *bdev, 204int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
205 unsigned cmd, unsigned long arg) 205 unsigned cmd, unsigned long arg)
206{
207 struct backing_dev_info *bdi;
208 int ret, n;
209
210 switch (cmd) {
211 case BLKRAGET:
212 case BLKFRAGET:
213 if (!arg)
214 return -EINVAL;
215 bdi = blk_get_backing_dev_info(bdev);
216 if (bdi == NULL)
217 return -ENOTTY;
218 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
219 case BLKROGET:
220 return put_int(arg, bdev_read_only(bdev) != 0);
221 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
222 return put_int(arg, block_size(bdev));
223 case BLKSSZGET: /* get block device hardware sector size */
224 return put_int(arg, bdev_hardsect_size(bdev));
225 case BLKSECTGET:
226 return put_ushort(arg, bdev_get_queue(bdev)->max_sectors);
227 case BLKRASET:
228 case BLKFRASET:
229 if(!capable(CAP_SYS_ADMIN))
230 return -EACCES;
231 bdi = blk_get_backing_dev_info(bdev);
232 if (bdi == NULL)
233 return -ENOTTY;
234 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
235 return 0;
236 case BLKBSZSET:
237 /* set the logical block size */
238 if (!capable(CAP_SYS_ADMIN))
239 return -EACCES;
240 if (!arg)
241 return -EINVAL;
242 if (get_user(n, (int __user *) arg))
243 return -EFAULT;
244 if (bd_claim(bdev, file) < 0)
245 return -EBUSY;
246 ret = set_blocksize(bdev, n);
247 bd_release(bdev);
248 return ret;
249 case BLKPG:
250 return blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg);
251 case BLKRRPART:
252 return blkdev_reread_part(bdev);
253 case BLKGETSIZE:
254 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
255 return -EFBIG;
256 return put_ulong(arg, bdev->bd_inode->i_size >> 9);
257 case BLKGETSIZE64:
258 return put_u64(arg, bdev->bd_inode->i_size);
259 case BLKTRACESTART:
260 case BLKTRACESTOP:
261 case BLKTRACESETUP:
262 case BLKTRACETEARDOWN:
263 return blk_trace_ioctl(bdev, cmd, (char __user *) arg);
264 }
265 return -ENOIOCTLCMD;
266}
267
268int blkdev_driver_ioctl(struct inode *inode, struct file *file,
269 struct gendisk *disk, unsigned cmd, unsigned long arg)
270{ 206{
207 struct gendisk *disk = bdev->bd_disk;
271 int ret; 208 int ret;
272 if (disk->fops->unlocked_ioctl)
273 return disk->fops->unlocked_ioctl(file, cmd, arg);
274 209
275 if (disk->fops->ioctl) { 210 if (disk->fops->ioctl)
211 return disk->fops->ioctl(bdev, mode, cmd, arg);
212
213 if (disk->fops->locked_ioctl) {
276 lock_kernel(); 214 lock_kernel();
277 ret = disk->fops->ioctl(inode, file, cmd, arg); 215 ret = disk->fops->locked_ioctl(bdev, mode, cmd, arg);
278 unlock_kernel(); 216 unlock_kernel();
279 return ret; 217 return ret;
280 } 218 }
281 219
282 return -ENOTTY; 220 return -ENOTTY;
283} 221}
284EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); 222/*
223 * For the record: _GPL here is only because somebody decided to slap it
224 * on the previous export. Sheer idiocy, since it wasn't copyrightable
225 * at all and could be open-coded without any exports by anybody who cares.
226 */
227EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl);
285 228
286/* 229/*
287 * always keep this in sync with compat_blkdev_ioctl() and 230 * always keep this in sync with compat_blkdev_ioctl() and
288 * compat_blkdev_locked_ioctl() 231 * compat_blkdev_locked_ioctl()
289 */ 232 */
290int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, 233int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
291 unsigned long arg) 234 unsigned long arg)
292{ 235{
293 struct block_device *bdev = inode->i_bdev;
294 struct gendisk *disk = bdev->bd_disk; 236 struct gendisk *disk = bdev->bd_disk;
237 struct backing_dev_info *bdi;
238 loff_t size;
295 int ret, n; 239 int ret, n;
296 240
297 switch(cmd) { 241 switch(cmd) {
@@ -299,7 +243,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
299 if (!capable(CAP_SYS_ADMIN)) 243 if (!capable(CAP_SYS_ADMIN))
300 return -EACCES; 244 return -EACCES;
301 245
302 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 246 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
303 /* -EINVAL to handle old uncorrected drivers */ 247 /* -EINVAL to handle old uncorrected drivers */
304 if (ret != -EINVAL && ret != -ENOTTY) 248 if (ret != -EINVAL && ret != -ENOTTY)
305 return ret; 249 return ret;
@@ -311,7 +255,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
311 return 0; 255 return 0;
312 256
313 case BLKROSET: 257 case BLKROSET:
314 ret = blkdev_driver_ioctl(inode, file, disk, cmd, arg); 258 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
315 /* -EINVAL to handle old uncorrected drivers */ 259 /* -EINVAL to handle old uncorrected drivers */
316 if (ret != -EINVAL && ret != -ENOTTY) 260 if (ret != -EINVAL && ret != -ENOTTY)
317 return ret; 261 return ret;
@@ -327,7 +271,7 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
327 case BLKDISCARD: { 271 case BLKDISCARD: {
328 uint64_t range[2]; 272 uint64_t range[2];
329 273
330 if (!(file->f_mode & FMODE_WRITE)) 274 if (!(mode & FMODE_WRITE))
331 return -EBADF; 275 return -EBADF;
332 276
333 if (copy_from_user(range, (void __user *)arg, sizeof(range))) 277 if (copy_from_user(range, (void __user *)arg, sizeof(range)))
@@ -357,14 +301,75 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
357 return -EFAULT; 301 return -EFAULT;
358 return 0; 302 return 0;
359 } 303 }
360 } 304 case BLKRAGET:
361 305 case BLKFRAGET:
362 lock_kernel(); 306 if (!arg)
363 ret = blkdev_locked_ioctl(file, bdev, cmd, arg); 307 return -EINVAL;
364 unlock_kernel(); 308 bdi = blk_get_backing_dev_info(bdev);
365 if (ret != -ENOIOCTLCMD) 309 if (bdi == NULL)
310 return -ENOTTY;
311 return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
312 case BLKROGET:
313 return put_int(arg, bdev_read_only(bdev) != 0);
314 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
315 return put_int(arg, block_size(bdev));
316 case BLKSSZGET: /* get block device hardware sector size */
317 return put_int(arg, bdev_hardsect_size(bdev));
318 case BLKSECTGET:
319 return put_ushort(arg, bdev_get_queue(bdev)->max_sectors);
320 case BLKRASET:
321 case BLKFRASET:
322 if(!capable(CAP_SYS_ADMIN))
323 return -EACCES;
324 bdi = blk_get_backing_dev_info(bdev);
325 if (bdi == NULL)
326 return -ENOTTY;
327 lock_kernel();
328 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
329 unlock_kernel();
330 return 0;
331 case BLKBSZSET:
332 /* set the logical block size */
333 if (!capable(CAP_SYS_ADMIN))
334 return -EACCES;
335 if (!arg)
336 return -EINVAL;
337 if (get_user(n, (int __user *) arg))
338 return -EFAULT;
339 if (!(mode & FMODE_EXCL) && bd_claim(bdev, &bdev) < 0)
340 return -EBUSY;
341 ret = set_blocksize(bdev, n);
342 if (!(mode & FMODE_EXCL))
343 bd_release(bdev);
366 return ret; 344 return ret;
367 345 case BLKPG:
368 return blkdev_driver_ioctl(inode, file, disk, cmd, arg); 346 lock_kernel();
347 ret = blkpg_ioctl(bdev, (struct blkpg_ioctl_arg __user *) arg);
348 unlock_kernel();
349 break;
350 case BLKRRPART:
351 lock_kernel();
352 ret = blkdev_reread_part(bdev);
353 unlock_kernel();
354 break;
355 case BLKGETSIZE:
356 size = bdev->bd_inode->i_size;
357 if ((size >> 9) > ~0UL)
358 return -EFBIG;
359 return put_ulong(arg, size >> 9);
360 case BLKGETSIZE64:
361 return put_u64(arg, bdev->bd_inode->i_size);
362 case BLKTRACESTART:
363 case BLKTRACESTOP:
364 case BLKTRACESETUP:
365 case BLKTRACETEARDOWN:
366 lock_kernel();
367 ret = blk_trace_ioctl(bdev, cmd, (char __user *) arg);
368 unlock_kernel();
369 break;
370 default:
371 ret = __blkdev_driver_ioctl(bdev, mode, cmd, arg);
372 }
373 return ret;
369} 374}
370EXPORT_SYMBOL_GPL(blkdev_ioctl); 375EXPORT_SYMBOL_GPL(blkdev_ioctl);
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index c34272a348fe..5963cf91a3a0 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -190,12 +190,11 @@ void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
190EXPORT_SYMBOL_GPL(blk_set_cmd_filter_defaults); 190EXPORT_SYMBOL_GPL(blk_set_cmd_filter_defaults);
191 191
192static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq, 192static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
193 struct sg_io_hdr *hdr, struct file *file) 193 struct sg_io_hdr *hdr, fmode_t mode)
194{ 194{
195 if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len)) 195 if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
196 return -EFAULT; 196 return -EFAULT;
197 if (blk_verify_command(&q->cmd_filter, rq->cmd, 197 if (blk_verify_command(&q->cmd_filter, rq->cmd, mode & FMODE_WRITE))
198 file->f_mode & FMODE_WRITE))
199 return -EPERM; 198 return -EPERM;
200 199
201 /* 200 /*
@@ -260,8 +259,8 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
260 return r; 259 return r;
261} 260}
262 261
263static int sg_io(struct file *file, struct request_queue *q, 262static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
264 struct gendisk *bd_disk, struct sg_io_hdr *hdr) 263 struct sg_io_hdr *hdr, fmode_t mode)
265{ 264{
266 unsigned long start_time; 265 unsigned long start_time;
267 int writing = 0, ret = 0; 266 int writing = 0, ret = 0;
@@ -293,7 +292,7 @@ static int sg_io(struct file *file, struct request_queue *q,
293 if (!rq) 292 if (!rq)
294 return -ENOMEM; 293 return -ENOMEM;
295 294
296 if (blk_fill_sghdr_rq(q, rq, hdr, file)) { 295 if (blk_fill_sghdr_rq(q, rq, hdr, mode)) {
297 blk_put_request(rq); 296 blk_put_request(rq);
298 return -EFAULT; 297 return -EFAULT;
299 } 298 }
@@ -380,11 +379,11 @@ out:
380 * bytes in one int) where the lowest byte is the SCSI status. 379 * bytes in one int) where the lowest byte is the SCSI status.
381 */ 380 */
382#define OMAX_SB_LEN 16 /* For backward compatibility */ 381#define OMAX_SB_LEN 16 /* For backward compatibility */
383int sg_scsi_ioctl(struct file *file, struct request_queue *q, 382int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
384 struct gendisk *disk, struct scsi_ioctl_command __user *sic) 383 struct scsi_ioctl_command __user *sic)
385{ 384{
386 struct request *rq; 385 struct request *rq;
387 int err, write_perm = 0; 386 int err;
388 unsigned int in_len, out_len, bytes, opcode, cmdlen; 387 unsigned int in_len, out_len, bytes, opcode, cmdlen;
389 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE]; 388 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
390 389
@@ -426,11 +425,7 @@ int sg_scsi_ioctl(struct file *file, struct request_queue *q,
426 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len)) 425 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
427 goto error; 426 goto error;
428 427
429 /* scsi_ioctl passes NULL */ 428 err = blk_verify_command(&q->cmd_filter, rq->cmd, mode & FMODE_WRITE);
430 if (file && (file->f_mode & FMODE_WRITE))
431 write_perm = 1;
432
433 err = blk_verify_command(&q->cmd_filter, rq->cmd, write_perm);
434 if (err) 429 if (err)
435 goto error; 430 goto error;
436 431
@@ -522,8 +517,8 @@ static inline int blk_send_start_stop(struct request_queue *q,
522 return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data); 517 return __blk_send_generic(q, bd_disk, GPCMD_START_STOP_UNIT, data);
523} 518}
524 519
525int scsi_cmd_ioctl(struct file *file, struct request_queue *q, 520int scsi_cmd_ioctl(struct request_queue *q, struct gendisk *bd_disk, fmode_t mode,
526 struct gendisk *bd_disk, unsigned int cmd, void __user *arg) 521 unsigned int cmd, void __user *arg)
527{ 522{
528 int err; 523 int err;
529 524
@@ -564,7 +559,7 @@ int scsi_cmd_ioctl(struct file *file, struct request_queue *q,
564 err = -EFAULT; 559 err = -EFAULT;
565 if (copy_from_user(&hdr, arg, sizeof(hdr))) 560 if (copy_from_user(&hdr, arg, sizeof(hdr)))
566 break; 561 break;
567 err = sg_io(file, q, bd_disk, &hdr); 562 err = sg_io(q, bd_disk, &hdr, mode);
568 if (err == -EFAULT) 563 if (err == -EFAULT)
569 break; 564 break;
570 565
@@ -612,7 +607,7 @@ int scsi_cmd_ioctl(struct file *file, struct request_queue *q,
612 hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd; 607 hdr.cmdp = ((struct cdrom_generic_command __user*) arg)->cmd;
613 hdr.cmd_len = sizeof(cgc.cmd); 608 hdr.cmd_len = sizeof(cgc.cmd);
614 609
615 err = sg_io(file, q, bd_disk, &hdr); 610 err = sg_io(q, bd_disk, &hdr, mode);
616 if (err == -EFAULT) 611 if (err == -EFAULT)
617 break; 612 break;
618 613
@@ -636,7 +631,7 @@ int scsi_cmd_ioctl(struct file *file, struct request_queue *q,
636 if (!arg) 631 if (!arg)
637 break; 632 break;
638 633
639 err = sg_scsi_ioctl(file, q, bd_disk, arg); 634 err = sg_scsi_ioctl(q, bd_disk, mode, arg);
640 break; 635 break;
641 case CDROMCLOSETRAY: 636 case CDROMCLOSETRAY:
642 err = blk_send_start_stop(q, bd_disk, 0x03); 637 err = blk_send_start_stop(q, bd_disk, 0x03);
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;
diff --git a/fs/block_dev.c b/fs/block_dev.c
index d06fe3c3dd3f..88a776fa0ef6 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -840,13 +840,12 @@ EXPORT_SYMBOL_GPL(bd_release_from_disk);
840 * to be used for internal purposes. If you ever need it - reconsider 840 * to be used for internal purposes. If you ever need it - reconsider
841 * your API. 841 * your API.
842 */ 842 */
843struct block_device *open_by_devnum(dev_t dev, unsigned mode) 843struct block_device *open_by_devnum(dev_t dev, fmode_t mode)
844{ 844{
845 struct block_device *bdev = bdget(dev); 845 struct block_device *bdev = bdget(dev);
846 int err = -ENOMEM; 846 int err = -ENOMEM;
847 int flags = mode & FMODE_WRITE ? O_RDWR : O_RDONLY;
848 if (bdev) 847 if (bdev)
849 err = blkdev_get(bdev, mode, flags); 848 err = blkdev_get(bdev, mode);
850 return err ? ERR_PTR(err) : bdev; 849 return err ? ERR_PTR(err) : bdev;
851} 850}
852 851
@@ -975,9 +974,7 @@ void bd_set_size(struct block_device *bdev, loff_t size)
975} 974}
976EXPORT_SYMBOL(bd_set_size); 975EXPORT_SYMBOL(bd_set_size);
977 976
978static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, 977static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part);
979 int for_part);
980static int __blkdev_put(struct block_device *bdev, int for_part);
981 978
982/* 979/*
983 * bd_mutex locking: 980 * bd_mutex locking:
@@ -986,7 +983,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part);
986 * mutex_lock_nested(whole->bd_mutex, 1) 983 * mutex_lock_nested(whole->bd_mutex, 1)
987 */ 984 */
988 985
989static int do_open(struct block_device *bdev, struct file *file, int for_part) 986static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
990{ 987{
991 struct gendisk *disk; 988 struct gendisk *disk;
992 struct hd_struct *part = NULL; 989 struct hd_struct *part = NULL;
@@ -994,9 +991,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
994 int partno; 991 int partno;
995 int perm = 0; 992 int perm = 0;
996 993
997 if (file->f_mode & FMODE_READ) 994 if (mode & FMODE_READ)
998 perm |= MAY_READ; 995 perm |= MAY_READ;
999 if (file->f_mode & FMODE_WRITE) 996 if (mode & FMODE_WRITE)
1000 perm |= MAY_WRITE; 997 perm |= MAY_WRITE;
1001 /* 998 /*
1002 * hooks: /n/, see "layering violations". 999 * hooks: /n/, see "layering violations".
@@ -1008,7 +1005,6 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1008 } 1005 }
1009 1006
1010 ret = -ENXIO; 1007 ret = -ENXIO;
1011 file->f_mapping = bdev->bd_inode->i_mapping;
1012 1008
1013 lock_kernel(); 1009 lock_kernel();
1014 1010
@@ -1027,7 +1023,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1027 if (!partno) { 1023 if (!partno) {
1028 struct backing_dev_info *bdi; 1024 struct backing_dev_info *bdi;
1029 if (disk->fops->open) { 1025 if (disk->fops->open) {
1030 ret = disk->fops->open(bdev->bd_inode, file); 1026 ret = disk->fops->open(bdev, mode);
1031 if (ret) 1027 if (ret)
1032 goto out_clear; 1028 goto out_clear;
1033 } 1029 }
@@ -1047,7 +1043,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1047 if (!whole) 1043 if (!whole)
1048 goto out_clear; 1044 goto out_clear;
1049 BUG_ON(for_part); 1045 BUG_ON(for_part);
1050 ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1); 1046 ret = __blkdev_get(whole, mode, 1);
1051 if (ret) 1047 if (ret)
1052 goto out_clear; 1048 goto out_clear;
1053 bdev->bd_contains = whole; 1049 bdev->bd_contains = whole;
@@ -1068,7 +1064,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1068 disk = NULL; 1064 disk = NULL;
1069 if (bdev->bd_contains == bdev) { 1065 if (bdev->bd_contains == bdev) {
1070 if (bdev->bd_disk->fops->open) { 1066 if (bdev->bd_disk->fops->open) {
1071 ret = bdev->bd_disk->fops->open(bdev->bd_inode, file); 1067 ret = bdev->bd_disk->fops->open(bdev, mode);
1072 if (ret) 1068 if (ret)
1073 goto out_unlock_bdev; 1069 goto out_unlock_bdev;
1074 } 1070 }
@@ -1088,7 +1084,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1088 bdev->bd_part = NULL; 1084 bdev->bd_part = NULL;
1089 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; 1085 bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info;
1090 if (bdev != bdev->bd_contains) 1086 if (bdev != bdev->bd_contains)
1091 __blkdev_put(bdev->bd_contains, 1); 1087 __blkdev_put(bdev->bd_contains, mode, 1);
1092 bdev->bd_contains = NULL; 1088 bdev->bd_contains = NULL;
1093 out_unlock_bdev: 1089 out_unlock_bdev:
1094 mutex_unlock(&bdev->bd_mutex); 1090 mutex_unlock(&bdev->bd_mutex);
@@ -1104,28 +1100,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1104 return ret; 1100 return ret;
1105} 1101}
1106 1102
1107static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, 1103int blkdev_get(struct block_device *bdev, fmode_t mode)
1108 int for_part)
1109{ 1104{
1110 /* 1105 return __blkdev_get(bdev, mode, 0);
1111 * This crockload is due to bad choice of ->open() type.
1112 * It will go away.
1113 * For now, block device ->open() routine must _not_
1114 * examine anything in 'inode' argument except ->i_rdev.
1115 */
1116 struct file fake_file = {};
1117 struct dentry fake_dentry = {};
1118 fake_file.f_mode = mode;
1119 fake_file.f_flags = flags;
1120 fake_file.f_path.dentry = &fake_dentry;
1121 fake_dentry.d_inode = bdev->bd_inode;
1122
1123 return do_open(bdev, &fake_file, for_part);
1124}
1125
1126int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags)
1127{
1128 return __blkdev_get(bdev, mode, flags, 0);
1129} 1106}
1130EXPORT_SYMBOL(blkdev_get); 1107EXPORT_SYMBOL(blkdev_get);
1131 1108
@@ -1142,28 +1119,36 @@ static int blkdev_open(struct inode * inode, struct file * filp)
1142 */ 1119 */
1143 filp->f_flags |= O_LARGEFILE; 1120 filp->f_flags |= O_LARGEFILE;
1144 1121
1122 if (filp->f_flags & O_NDELAY)
1123 filp->f_mode |= FMODE_NDELAY;
1124 if (filp->f_flags & O_EXCL)
1125 filp->f_mode |= FMODE_EXCL;
1126 if ((filp->f_flags & O_ACCMODE) == 3)
1127 filp->f_mode |= FMODE_WRITE_IOCTL;
1128
1145 bdev = bd_acquire(inode); 1129 bdev = bd_acquire(inode);
1146 if (bdev == NULL) 1130 if (bdev == NULL)
1147 return -ENOMEM; 1131 return -ENOMEM;
1148 1132
1149 res = do_open(bdev, filp, 0); 1133 filp->f_mapping = bdev->bd_inode->i_mapping;
1134
1135 res = blkdev_get(bdev, filp->f_mode);
1150 if (res) 1136 if (res)
1151 return res; 1137 return res;
1152 1138
1153 if (!(filp->f_flags & O_EXCL) ) 1139 if (!(filp->f_mode & FMODE_EXCL))
1154 return 0; 1140 return 0;
1155 1141
1156 if (!(res = bd_claim(bdev, filp))) 1142 if (!(res = bd_claim(bdev, filp)))
1157 return 0; 1143 return 0;
1158 1144
1159 blkdev_put(bdev); 1145 blkdev_put(bdev, filp->f_mode);
1160 return res; 1146 return res;
1161} 1147}
1162 1148
1163static int __blkdev_put(struct block_device *bdev, int for_part) 1149static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
1164{ 1150{
1165 int ret = 0; 1151 int ret = 0;
1166 struct inode *bd_inode = bdev->bd_inode;
1167 struct gendisk *disk = bdev->bd_disk; 1152 struct gendisk *disk = bdev->bd_disk;
1168 struct block_device *victim = NULL; 1153 struct block_device *victim = NULL;
1169 1154
@@ -1178,7 +1163,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
1178 } 1163 }
1179 if (bdev->bd_contains == bdev) { 1164 if (bdev->bd_contains == bdev) {
1180 if (disk->fops->release) 1165 if (disk->fops->release)
1181 ret = disk->fops->release(bd_inode, NULL); 1166 ret = disk->fops->release(disk, mode);
1182 } 1167 }
1183 if (!bdev->bd_openers) { 1168 if (!bdev->bd_openers) {
1184 struct module *owner = disk->fops->owner; 1169 struct module *owner = disk->fops->owner;
@@ -1197,13 +1182,13 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
1197 mutex_unlock(&bdev->bd_mutex); 1182 mutex_unlock(&bdev->bd_mutex);
1198 bdput(bdev); 1183 bdput(bdev);
1199 if (victim) 1184 if (victim)
1200 __blkdev_put(victim, 1); 1185 __blkdev_put(victim, mode, 1);
1201 return ret; 1186 return ret;
1202} 1187}
1203 1188
1204int blkdev_put(struct block_device *bdev) 1189int blkdev_put(struct block_device *bdev, fmode_t mode)
1205{ 1190{
1206 return __blkdev_put(bdev, 0); 1191 return __blkdev_put(bdev, mode, 0);
1207} 1192}
1208EXPORT_SYMBOL(blkdev_put); 1193EXPORT_SYMBOL(blkdev_put);
1209 1194
@@ -1212,12 +1197,16 @@ static int blkdev_close(struct inode * inode, struct file * filp)
1212 struct block_device *bdev = I_BDEV(filp->f_mapping->host); 1197 struct block_device *bdev = I_BDEV(filp->f_mapping->host);
1213 if (bdev->bd_holder == filp) 1198 if (bdev->bd_holder == filp)
1214 bd_release(bdev); 1199 bd_release(bdev);
1215 return blkdev_put(bdev); 1200 return blkdev_put(bdev, filp->f_mode);
1216} 1201}
1217 1202
1218static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) 1203static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg)
1219{ 1204{
1220 return blkdev_ioctl(file->f_mapping->host, file, cmd, arg); 1205 struct block_device *bdev = I_BDEV(file->f_mapping->host);
1206 fmode_t mode = file->f_mode;
1207 if (file->f_flags & O_NDELAY)
1208 mode |= FMODE_NDELAY_NOW;
1209 return blkdev_ioctl(bdev, mode, cmd, arg);
1221} 1210}
1222 1211
1223static const struct address_space_operations def_blk_aops = { 1212static const struct address_space_operations def_blk_aops = {
@@ -1253,7 +1242,7 @@ int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
1253 int res; 1242 int res;
1254 mm_segment_t old_fs = get_fs(); 1243 mm_segment_t old_fs = get_fs();
1255 set_fs(KERNEL_DS); 1244 set_fs(KERNEL_DS);
1256 res = blkdev_ioctl(bdev->bd_inode, NULL, cmd, arg); 1245 res = blkdev_ioctl(bdev, 0, cmd, arg);
1257 set_fs(old_fs); 1246 set_fs(old_fs);
1258 return res; 1247 return res;
1259} 1248}
@@ -1303,32 +1292,29 @@ fail:
1303EXPORT_SYMBOL(lookup_bdev); 1292EXPORT_SYMBOL(lookup_bdev);
1304 1293
1305/** 1294/**
1306 * open_bdev_excl - open a block device by name and set it up for use 1295 * open_bdev_exclusive - open a block device by name and set it up for use
1307 * 1296 *
1308 * @path: special file representing the block device 1297 * @path: special file representing the block device
1309 * @flags: %MS_RDONLY for opening read-only 1298 * @mode: FMODE_... combination to pass be used
1310 * @holder: owner for exclusion 1299 * @holder: owner for exclusion
1311 * 1300 *
1312 * Open the blockdevice described by the special file at @path, claim it 1301 * Open the blockdevice described by the special file at @path, claim it
1313 * for the @holder. 1302 * for the @holder.
1314 */ 1303 */
1315struct block_device *open_bdev_excl(const char *path, int flags, void *holder) 1304struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder)
1316{ 1305{
1317 struct block_device *bdev; 1306 struct block_device *bdev;
1318 mode_t mode = FMODE_READ;
1319 int error = 0; 1307 int error = 0;
1320 1308
1321 bdev = lookup_bdev(path); 1309 bdev = lookup_bdev(path);
1322 if (IS_ERR(bdev)) 1310 if (IS_ERR(bdev))
1323 return bdev; 1311 return bdev;
1324 1312
1325 if (!(flags & MS_RDONLY)) 1313 error = blkdev_get(bdev, mode);
1326 mode |= FMODE_WRITE;
1327 error = blkdev_get(bdev, mode, 0);
1328 if (error) 1314 if (error)
1329 return ERR_PTR(error); 1315 return ERR_PTR(error);
1330 error = -EACCES; 1316 error = -EACCES;
1331 if (!(flags & MS_RDONLY) && bdev_read_only(bdev)) 1317 if ((mode & FMODE_WRITE) && bdev_read_only(bdev))
1332 goto blkdev_put; 1318 goto blkdev_put;
1333 error = bd_claim(bdev, holder); 1319 error = bd_claim(bdev, holder);
1334 if (error) 1320 if (error)
@@ -1337,26 +1323,27 @@ struct block_device *open_bdev_excl(const char *path, int flags, void *holder)
1337 return bdev; 1323 return bdev;
1338 1324
1339blkdev_put: 1325blkdev_put:
1340 blkdev_put(bdev); 1326 blkdev_put(bdev, mode);
1341 return ERR_PTR(error); 1327 return ERR_PTR(error);
1342} 1328}
1343 1329
1344EXPORT_SYMBOL(open_bdev_excl); 1330EXPORT_SYMBOL(open_bdev_exclusive);
1345 1331
1346/** 1332/**
1347 * close_bdev_excl - release a blockdevice openen by open_bdev_excl() 1333 * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive()
1348 * 1334 *
1349 * @bdev: blockdevice to close 1335 * @bdev: blockdevice to close
1336 * @mode: mode, must match that used to open.
1350 * 1337 *
1351 * This is the counterpart to open_bdev_excl(). 1338 * This is the counterpart to open_bdev_exclusive().
1352 */ 1339 */
1353void close_bdev_excl(struct block_device *bdev) 1340void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
1354{ 1341{
1355 bd_release(bdev); 1342 bd_release(bdev);
1356 blkdev_put(bdev); 1343 blkdev_put(bdev, mode);
1357} 1344}
1358 1345
1359EXPORT_SYMBOL(close_bdev_excl); 1346EXPORT_SYMBOL(close_bdev_exclusive);
1360 1347
1361int __invalidate_device(struct block_device *bdev) 1348int __invalidate_device(struct block_device *bdev)
1362{ 1349{
diff --git a/fs/ext2/xip.c b/fs/ext2/xip.c
index 4fb94c20041b..b72b85884223 100644
--- a/fs/ext2/xip.c
+++ b/fs/ext2/xip.c
@@ -11,6 +11,7 @@
11#include <linux/buffer_head.h> 11#include <linux/buffer_head.h>
12#include <linux/ext2_fs_sb.h> 12#include <linux/ext2_fs_sb.h>
13#include <linux/ext2_fs.h> 13#include <linux/ext2_fs.h>
14#include <linux/blkdev.h>
14#include "ext2.h" 15#include "ext2.h"
15#include "xip.h" 16#include "xip.h"
16 17
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 34b6fca765d7..8147dd44cede 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -347,7 +347,7 @@ fail:
347static int ext3_blkdev_put(struct block_device *bdev) 347static int ext3_blkdev_put(struct block_device *bdev)
348{ 348{
349 bd_release(bdev); 349 bd_release(bdev);
350 return blkdev_put(bdev); 350 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
351} 351}
352 352
353static int ext3_blkdev_remove(struct ext3_sb_info *sbi) 353static int ext3_blkdev_remove(struct ext3_sb_info *sbi)
@@ -2067,7 +2067,7 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
2067 if (bd_claim(bdev, sb)) { 2067 if (bd_claim(bdev, sb)) {
2068 printk(KERN_ERR 2068 printk(KERN_ERR
2069 "EXT3: failed to claim external journal device.\n"); 2069 "EXT3: failed to claim external journal device.\n");
2070 blkdev_put(bdev); 2070 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2071 return NULL; 2071 return NULL;
2072 } 2072 }
2073 2073
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index ae35f176b697..bdddea14e782 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -399,7 +399,7 @@ fail:
399static int ext4_blkdev_put(struct block_device *bdev) 399static int ext4_blkdev_put(struct block_device *bdev)
400{ 400{
401 bd_release(bdev); 401 bd_release(bdev);
402 return blkdev_put(bdev); 402 return blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
403} 403}
404 404
405static int ext4_blkdev_remove(struct ext4_sb_info *sbi) 405static int ext4_blkdev_remove(struct ext4_sb_info *sbi)
@@ -2553,7 +2553,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2553 if (bd_claim(bdev, sb)) { 2553 if (bd_claim(bdev, sb)) {
2554 printk(KERN_ERR 2554 printk(KERN_ERR
2555 "EXT4: failed to claim external journal device.\n"); 2555 "EXT4: failed to claim external journal device.\n");
2556 blkdev_put(bdev); 2556 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2557 return NULL; 2557 return NULL;
2558 } 2558 }
2559 2559
diff --git a/fs/fifo.c b/fs/fifo.c
index 987bf9411495..f8f97b8b6d44 100644
--- a/fs/fifo.c
+++ b/fs/fifo.c
@@ -51,7 +51,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
51 filp->f_mode &= (FMODE_READ | FMODE_WRITE); 51 filp->f_mode &= (FMODE_READ | FMODE_WRITE);
52 52
53 switch (filp->f_mode) { 53 switch (filp->f_mode) {
54 case 1: 54 case FMODE_READ:
55 /* 55 /*
56 * O_RDONLY 56 * O_RDONLY
57 * POSIX.1 says that O_NONBLOCK means return with the FIFO 57 * POSIX.1 says that O_NONBLOCK means return with the FIFO
@@ -76,7 +76,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
76 } 76 }
77 break; 77 break;
78 78
79 case 2: 79 case FMODE_WRITE:
80 /* 80 /*
81 * O_WRONLY 81 * O_WRONLY
82 * POSIX.1 says that O_NONBLOCK means return -1 with 82 * POSIX.1 says that O_NONBLOCK means return -1 with
@@ -98,7 +98,7 @@ static int fifo_open(struct inode *inode, struct file *filp)
98 } 98 }
99 break; 99 break;
100 100
101 case 3: 101 case FMODE_READ | FMODE_WRITE:
102 /* 102 /*
103 * O_RDWR 103 * O_RDWR
104 * POSIX.1 leaves this case "undefined" when O_NONBLOCK is set. 104 * POSIX.1 leaves this case "undefined" when O_NONBLOCK is set.
diff --git a/fs/file_table.c b/fs/file_table.c
index f45a4493f9e7..efc06faede6c 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -161,7 +161,7 @@ EXPORT_SYMBOL(get_empty_filp);
161 * code should be moved into this function. 161 * code should be moved into this function.
162 */ 162 */
163struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, 163struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry,
164 mode_t mode, const struct file_operations *fop) 164 fmode_t mode, const struct file_operations *fop)
165{ 165{
166 struct file *file; 166 struct file *file;
167 struct path; 167 struct path;
@@ -193,7 +193,7 @@ EXPORT_SYMBOL(alloc_file);
193 * of this should be moving to alloc_file(). 193 * of this should be moving to alloc_file().
194 */ 194 */
195int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry, 195int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
196 mode_t mode, const struct file_operations *fop) 196 fmode_t mode, const struct file_operations *fop)
197{ 197{
198 int error = 0; 198 int error = 0;
199 file->f_path.dentry = dentry; 199 file->f_path.dentry = dentry;
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index d6ecabf4d231..7f34f4385de0 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -20,7 +20,7 @@
20struct hostfs_inode_info { 20struct hostfs_inode_info {
21 char *host_filename; 21 char *host_filename;
22 int fd; 22 int fd;
23 int mode; 23 fmode_t mode;
24 struct inode vfs_inode; 24 struct inode vfs_inode;
25}; 25};
26 26
@@ -373,7 +373,8 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
373int hostfs_file_open(struct inode *ino, struct file *file) 373int hostfs_file_open(struct inode *ino, struct file *file)
374{ 374{
375 char *name; 375 char *name;
376 int mode = 0, r = 0, w = 0, fd; 376 fmode_t mode = 0;
377 int r = 0, w = 0, fd;
377 378
378 mode = file->f_mode & (FMODE_READ | FMODE_WRITE); 379 mode = file->f_mode & (FMODE_READ | FMODE_WRITE);
379 if ((mode & HOSTFS_I(ino)->mode) == mode) 380 if ((mode & HOSTFS_I(ino)->mode) == mode)
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index cd2ec2988b59..335c4de6552d 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1168,7 +1168,7 @@ journal_found:
1168 bd_release(bdev); 1168 bd_release(bdev);
1169 1169
1170 close: /* close external log device */ 1170 close: /* close external log device */
1171 blkdev_put(bdev); 1171 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1172 1172
1173 free: /* free log descriptor */ 1173 free: /* free log descriptor */
1174 mutex_unlock(&jfs_log_mutex); 1174 mutex_unlock(&jfs_log_mutex);
@@ -1514,7 +1514,7 @@ int lmLogClose(struct super_block *sb)
1514 rc = lmLogShutdown(log); 1514 rc = lmLogShutdown(log);
1515 1515
1516 bd_release(bdev); 1516 bd_release(bdev);
1517 blkdev_put(bdev); 1517 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
1518 1518
1519 kfree(log); 1519 kfree(log);
1520 1520
diff --git a/fs/locks.c b/fs/locks.c
index 5eb259e3cd38..20457486d6b2 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1580,7 +1580,8 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd)
1580 cmd &= ~LOCK_NB; 1580 cmd &= ~LOCK_NB;
1581 unlock = (cmd == LOCK_UN); 1581 unlock = (cmd == LOCK_UN);
1582 1582
1583 if (!unlock && !(cmd & LOCK_MAND) && !(filp->f_mode & 3)) 1583 if (!unlock && !(cmd & LOCK_MAND) &&
1584 !(filp->f_mode & (FMODE_READ|FMODE_WRITE)))
1584 goto out_putf; 1585 goto out_putf;
1585 1586
1586 error = flock_make_lock(filp, &lock, cmd); 1587 error = flock_make_lock(filp, &lock, cmd);
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 7dce1612553e..6ebaa58e2c03 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -976,7 +976,7 @@ static void o2hb_region_release(struct config_item *item)
976 } 976 }
977 977
978 if (reg->hr_bdev) 978 if (reg->hr_bdev)
979 blkdev_put(reg->hr_bdev); 979 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
980 980
981 if (reg->hr_slots) 981 if (reg->hr_slots)
982 kfree(reg->hr_slots); 982 kfree(reg->hr_slots);
@@ -1268,7 +1268,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1268 goto out; 1268 goto out;
1269 1269
1270 reg->hr_bdev = I_BDEV(filp->f_mapping->host); 1270 reg->hr_bdev = I_BDEV(filp->f_mapping->host);
1271 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, 0); 1271 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ);
1272 if (ret) { 1272 if (ret) {
1273 reg->hr_bdev = NULL; 1273 reg->hr_bdev = NULL;
1274 goto out; 1274 goto out;
@@ -1358,7 +1358,7 @@ out:
1358 iput(inode); 1358 iput(inode);
1359 if (ret < 0) { 1359 if (ret < 0) {
1360 if (reg->hr_bdev) { 1360 if (reg->hr_bdev) {
1361 blkdev_put(reg->hr_bdev); 1361 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
1362 reg->hr_bdev = NULL; 1362 reg->hr_bdev = NULL;
1363 } 1363 }
1364 } 1364 }
diff --git a/fs/open.c b/fs/open.c
index 5596049863bf..83cdb9dee0c1 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -798,7 +798,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt,
798 int error; 798 int error;
799 799
800 f->f_flags = flags; 800 f->f_flags = flags;
801 f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | 801 f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK |
802 FMODE_PREAD | FMODE_PWRITE; 802 FMODE_PREAD | FMODE_PWRITE;
803 inode = dentry->d_inode; 803 inode = dentry->d_inode;
804 if (f->f_mode & FMODE_WRITE) { 804 if (f->f_mode & FMODE_WRITE) {
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index cfb0c80690aa..633f7a0ebb2c 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -485,10 +485,10 @@ void register_disk(struct gendisk *disk)
485 goto exit; 485 goto exit;
486 486
487 bdev->bd_invalidated = 1; 487 bdev->bd_invalidated = 1;
488 err = blkdev_get(bdev, FMODE_READ, 0); 488 err = blkdev_get(bdev, FMODE_READ);
489 if (err < 0) 489 if (err < 0)
490 goto exit; 490 goto exit;
491 blkdev_put(bdev); 491 blkdev_put(bdev, FMODE_READ);
492 492
493exit: 493exit:
494 /* announce disk after possible partitions are created */ 494 /* announce disk after possible partitions are created */
diff --git a/fs/proc/base.c b/fs/proc/base.c
index b5918ae8ca79..486cf3fe7139 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1712,9 +1712,9 @@ static struct dentry *proc_fd_instantiate(struct inode *dir,
1712 file = fcheck_files(files, fd); 1712 file = fcheck_files(files, fd);
1713 if (!file) 1713 if (!file)
1714 goto out_unlock; 1714 goto out_unlock;
1715 if (file->f_mode & 1) 1715 if (file->f_mode & FMODE_READ)
1716 inode->i_mode |= S_IRUSR | S_IXUSR; 1716 inode->i_mode |= S_IRUSR | S_IXUSR;
1717 if (file->f_mode & 2) 1717 if (file->f_mode & FMODE_WRITE)
1718 inode->i_mode |= S_IWUSR | S_IXUSR; 1718 inode->i_mode |= S_IWUSR | S_IXUSR;
1719 spin_unlock(&files->file_lock); 1719 spin_unlock(&files->file_lock);
1720 put_files_struct(files); 1720 put_files_struct(files);
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index c21df71943a6..9643c3bbeb3b 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -2575,7 +2575,7 @@ static int release_journal_dev(struct super_block *super,
2575 if (journal->j_dev_bd != NULL) { 2575 if (journal->j_dev_bd != NULL) {
2576 if (journal->j_dev_bd->bd_dev != super->s_dev) 2576 if (journal->j_dev_bd->bd_dev != super->s_dev)
2577 bd_release(journal->j_dev_bd); 2577 bd_release(journal->j_dev_bd);
2578 result = blkdev_put(journal->j_dev_bd); 2578 result = blkdev_put(journal->j_dev_bd, journal->j_dev_mode);
2579 journal->j_dev_bd = NULL; 2579 journal->j_dev_bd = NULL;
2580 } 2580 }
2581 2581
@@ -2593,7 +2593,7 @@ static int journal_init_dev(struct super_block *super,
2593{ 2593{
2594 int result; 2594 int result;
2595 dev_t jdev; 2595 dev_t jdev;
2596 int blkdev_mode = FMODE_READ | FMODE_WRITE; 2596 fmode_t blkdev_mode = FMODE_READ | FMODE_WRITE;
2597 char b[BDEVNAME_SIZE]; 2597 char b[BDEVNAME_SIZE];
2598 2598
2599 result = 0; 2599 result = 0;
@@ -2608,6 +2608,7 @@ static int journal_init_dev(struct super_block *super,
2608 /* there is no "jdev" option and journal is on separate device */ 2608 /* there is no "jdev" option and journal is on separate device */
2609 if ((!jdev_name || !jdev_name[0])) { 2609 if ((!jdev_name || !jdev_name[0])) {
2610 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode); 2610 journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode);
2611 journal->j_dev_mode = blkdev_mode;
2611 if (IS_ERR(journal->j_dev_bd)) { 2612 if (IS_ERR(journal->j_dev_bd)) {
2612 result = PTR_ERR(journal->j_dev_bd); 2613 result = PTR_ERR(journal->j_dev_bd);
2613 journal->j_dev_bd = NULL; 2614 journal->j_dev_bd = NULL;
@@ -2618,7 +2619,7 @@ static int journal_init_dev(struct super_block *super,
2618 } else if (jdev != super->s_dev) { 2619 } else if (jdev != super->s_dev) {
2619 result = bd_claim(journal->j_dev_bd, journal); 2620 result = bd_claim(journal->j_dev_bd, journal);
2620 if (result) { 2621 if (result) {
2621 blkdev_put(journal->j_dev_bd); 2622 blkdev_put(journal->j_dev_bd, blkdev_mode);
2622 return result; 2623 return result;
2623 } 2624 }
2624 2625
@@ -2628,7 +2629,9 @@ static int journal_init_dev(struct super_block *super,
2628 return 0; 2629 return 0;
2629 } 2630 }
2630 2631
2631 journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal); 2632 journal->j_dev_mode = blkdev_mode;
2633 journal->j_dev_bd = open_bdev_exclusive(jdev_name,
2634 blkdev_mode, journal);
2632 if (IS_ERR(journal->j_dev_bd)) { 2635 if (IS_ERR(journal->j_dev_bd)) {
2633 result = PTR_ERR(journal->j_dev_bd); 2636 result = PTR_ERR(journal->j_dev_bd);
2634 journal->j_dev_bd = NULL; 2637 journal->j_dev_bd = NULL;
diff --git a/fs/super.c b/fs/super.c
index f31ef824d069..400a7608f15e 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -755,9 +755,13 @@ int get_sb_bdev(struct file_system_type *fs_type,
755{ 755{
756 struct block_device *bdev; 756 struct block_device *bdev;
757 struct super_block *s; 757 struct super_block *s;
758 fmode_t mode = FMODE_READ;
758 int error = 0; 759 int error = 0;
759 760
760 bdev = open_bdev_excl(dev_name, flags, fs_type); 761 if (!(flags & MS_RDONLY))
762 mode |= FMODE_WRITE;
763
764 bdev = open_bdev_exclusive(dev_name, mode, fs_type);
761 if (IS_ERR(bdev)) 765 if (IS_ERR(bdev))
762 return PTR_ERR(bdev); 766 return PTR_ERR(bdev);
763 767
@@ -780,11 +784,12 @@ int get_sb_bdev(struct file_system_type *fs_type,
780 goto error_bdev; 784 goto error_bdev;
781 } 785 }
782 786
783 close_bdev_excl(bdev); 787 close_bdev_exclusive(bdev, mode);
784 } else { 788 } else {
785 char b[BDEVNAME_SIZE]; 789 char b[BDEVNAME_SIZE];
786 790
787 s->s_flags = flags; 791 s->s_flags = flags;
792 s->s_mode = mode;
788 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); 793 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
789 sb_set_blocksize(s, block_size(bdev)); 794 sb_set_blocksize(s, block_size(bdev));
790 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 795 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
@@ -802,7 +807,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
802error_s: 807error_s:
803 error = PTR_ERR(s); 808 error = PTR_ERR(s);
804error_bdev: 809error_bdev:
805 close_bdev_excl(bdev); 810 close_bdev_exclusive(bdev, mode);
806error: 811error:
807 return error; 812 return error;
808} 813}
@@ -812,10 +817,11 @@ EXPORT_SYMBOL(get_sb_bdev);
812void kill_block_super(struct super_block *sb) 817void kill_block_super(struct super_block *sb)
813{ 818{
814 struct block_device *bdev = sb->s_bdev; 819 struct block_device *bdev = sb->s_bdev;
820 fmode_t mode = sb->s_mode;
815 821
816 generic_shutdown_super(sb); 822 generic_shutdown_super(sb);
817 sync_blockdev(bdev); 823 sync_blockdev(bdev);
818 close_bdev_excl(bdev); 824 close_bdev_exclusive(bdev, mode);
819} 825}
820 826
821EXPORT_SYMBOL(kill_block_super); 827EXPORT_SYMBOL(kill_block_super);
diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c
index e39013619b26..37ebe36056eb 100644
--- a/fs/xfs/linux-2.6/xfs_super.c
+++ b/fs/xfs/linux-2.6/xfs_super.c
@@ -589,7 +589,7 @@ xfs_blkdev_get(
589{ 589{
590 int error = 0; 590 int error = 0;
591 591
592 *bdevp = open_bdev_excl(name, 0, mp); 592 *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
593 if (IS_ERR(*bdevp)) { 593 if (IS_ERR(*bdevp)) {
594 error = PTR_ERR(*bdevp); 594 error = PTR_ERR(*bdevp);
595 printk("XFS: Invalid device [%s], error=%d\n", name, error); 595 printk("XFS: Invalid device [%s], error=%d\n", name, error);
@@ -603,7 +603,7 @@ xfs_blkdev_put(
603 struct block_device *bdev) 603 struct block_device *bdev)
604{ 604{
605 if (bdev) 605 if (bdev)
606 close_bdev_excl(bdev); 606 close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
607} 607}
608 608
609/* 609/*
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b4fe68fe3a57..a135256b272c 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -717,10 +717,10 @@ extern void blk_plug_device(struct request_queue *);
717extern void blk_plug_device_unlocked(struct request_queue *); 717extern void blk_plug_device_unlocked(struct request_queue *);
718extern int blk_remove_plug(struct request_queue *); 718extern int blk_remove_plug(struct request_queue *);
719extern void blk_recount_segments(struct request_queue *, struct bio *); 719extern void blk_recount_segments(struct request_queue *, struct bio *);
720extern int scsi_cmd_ioctl(struct file *, struct request_queue *, 720extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t,
721 struct gendisk *, unsigned int, void __user *); 721 unsigned int, void __user *);
722extern int sg_scsi_ioctl(struct file *, struct request_queue *, 722extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
723 struct gendisk *, struct scsi_ioctl_command __user *); 723 struct scsi_ioctl_command __user *);
724 724
725/* 725/*
726 * Temporary export, until SCSI gets fixed up. 726 * Temporary export, until SCSI gets fixed up.
@@ -910,7 +910,8 @@ static inline int sb_issue_discard(struct super_block *sb,
910* command filter functions 910* command filter functions
911*/ 911*/
912extern int blk_verify_command(struct blk_cmd_filter *filter, 912extern int blk_verify_command(struct blk_cmd_filter *filter,
913 unsigned char *cmd, int has_write_perm); 913 unsigned char *cmd, fmode_t has_write_perm);
914extern void blk_unregister_filter(struct gendisk *disk);
914extern void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter); 915extern void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter);
915 916
916#define MAX_PHYS_SEGMENTS 128 917#define MAX_PHYS_SEGMENTS 128
@@ -1056,6 +1057,22 @@ static inline int blk_integrity_rq(struct request *rq)
1056 1057
1057#endif /* CONFIG_BLK_DEV_INTEGRITY */ 1058#endif /* CONFIG_BLK_DEV_INTEGRITY */
1058 1059
1060struct block_device_operations {
1061 int (*open) (struct block_device *, fmode_t);
1062 int (*release) (struct gendisk *, fmode_t);
1063 int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1064 int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1065 int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
1066 int (*direct_access) (struct block_device *, sector_t,
1067 void **, unsigned long *);
1068 int (*media_changed) (struct gendisk *);
1069 int (*revalidate_disk) (struct gendisk *);
1070 int (*getgeo)(struct block_device *, struct hd_geometry *);
1071 struct module *owner;
1072};
1073
1074extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
1075 unsigned long);
1059#else /* CONFIG_BLOCK */ 1076#else /* CONFIG_BLOCK */
1060/* 1077/*
1061 * stubs for when the block layer is configured out 1078 * stubs for when the block layer is configured out
diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
index 5db265ea60f6..0b49e08d3cb0 100644
--- a/include/linux/cdrom.h
+++ b/include/linux/cdrom.h
@@ -987,11 +987,11 @@ struct cdrom_device_ops {
987}; 987};
988 988
989/* the general block_device operations structure: */ 989/* the general block_device operations structure: */
990extern int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, 990extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
991 struct file *fp); 991 fmode_t mode);
992extern int cdrom_release(struct cdrom_device_info *cdi, struct file *fp); 992extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
993extern int cdrom_ioctl(struct file *file, struct cdrom_device_info *cdi, 993extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
994 struct inode *ip, unsigned int cmd, unsigned long arg); 994 fmode_t mode, unsigned int cmd, unsigned long arg);
995extern int cdrom_media_changed(struct cdrom_device_info *); 995extern int cdrom_media_changed(struct cdrom_device_info *);
996 996
997extern int register_cdrom(struct cdrom_device_info *cdi); 997extern int register_cdrom(struct cdrom_device_info *cdi);
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index dfb30db475ed..c17fd334e574 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -69,8 +69,7 @@ typedef int (*dm_status_fn) (struct dm_target *ti, status_type_t status_type,
69 69
70typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv); 70typedef int (*dm_message_fn) (struct dm_target *ti, unsigned argc, char **argv);
71 71
72typedef int (*dm_ioctl_fn) (struct dm_target *ti, struct inode *inode, 72typedef int (*dm_ioctl_fn) (struct dm_target *ti, unsigned int cmd,
73 struct file *filp, unsigned int cmd,
74 unsigned long arg); 73 unsigned long arg);
75 74
76typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm, 75typedef int (*dm_merge_fn) (struct dm_target *ti, struct bvec_merge_data *bvm,
@@ -85,7 +84,7 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev);
85 84
86struct dm_dev { 85struct dm_dev {
87 struct block_device *bdev; 86 struct block_device *bdev;
88 int mode; 87 fmode_t mode;
89 char name[16]; 88 char name[16];
90}; 89};
91 90
@@ -95,7 +94,7 @@ struct dm_dev {
95 * FIXME: too many arguments. 94 * FIXME: too many arguments.
96 */ 95 */
97int dm_get_device(struct dm_target *ti, const char *path, sector_t start, 96int dm_get_device(struct dm_target *ti, const char *path, sector_t start,
98 sector_t len, int mode, struct dm_dev **result); 97 sector_t len, fmode_t mode, struct dm_dev **result);
99void dm_put_device(struct dm_target *ti, struct dm_dev *d); 98void dm_put_device(struct dm_target *ti, struct dm_dev *d);
100 99
101/* 100/*
@@ -223,7 +222,7 @@ int dm_set_geometry(struct mapped_device *md, struct hd_geometry *geo);
223/* 222/*
224 * First create an empty table. 223 * First create an empty table.
225 */ 224 */
226int dm_table_create(struct dm_table **result, int mode, 225int dm_table_create(struct dm_table **result, fmode_t mode,
227 unsigned num_targets, struct mapped_device *md); 226 unsigned num_targets, struct mapped_device *md);
228 227
229/* 228/*
@@ -254,7 +253,7 @@ void dm_table_put(struct dm_table *t);
254 */ 253 */
255sector_t dm_table_get_size(struct dm_table *t); 254sector_t dm_table_get_size(struct dm_table *t);
256unsigned int dm_table_get_num_targets(struct dm_table *t); 255unsigned int dm_table_get_num_targets(struct dm_table *t);
257int dm_table_get_mode(struct dm_table *t); 256fmode_t dm_table_get_mode(struct dm_table *t);
258struct mapped_device *dm_table_get_md(struct dm_table *t); 257struct mapped_device *dm_table_get_md(struct dm_table *t);
259 258
260/* 259/*
diff --git a/include/linux/file.h b/include/linux/file.h
index a20259e248a5..335a0a5c316e 100644
--- a/include/linux/file.h
+++ b/include/linux/file.h
@@ -19,10 +19,10 @@ struct file_operations;
19struct vfsmount; 19struct vfsmount;
20struct dentry; 20struct dentry;
21extern int init_file(struct file *, struct vfsmount *mnt, 21extern int init_file(struct file *, struct vfsmount *mnt,
22 struct dentry *dentry, mode_t mode, 22 struct dentry *dentry, fmode_t mode,
23 const struct file_operations *fop); 23 const struct file_operations *fop);
24extern struct file *alloc_file(struct vfsmount *, struct dentry *dentry, 24extern struct file *alloc_file(struct vfsmount *, struct dentry *dentry,
25 mode_t mode, const struct file_operations *fop); 25 fmode_t mode, const struct file_operations *fop);
26 26
27static inline void fput_light(struct file *file, int fput_needed) 27static inline void fput_light(struct file *file, int fput_needed)
28{ 28{
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 7d719c1a18e3..43659ae52e4d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -63,18 +63,23 @@ extern int dir_notify_enable;
63#define MAY_ACCESS 16 63#define MAY_ACCESS 16
64#define MAY_OPEN 32 64#define MAY_OPEN 32
65 65
66#define FMODE_READ 1 66#define FMODE_READ ((__force fmode_t)1)
67#define FMODE_WRITE 2 67#define FMODE_WRITE ((__force fmode_t)2)
68 68
69/* Internal kernel extensions */ 69/* Internal kernel extensions */
70#define FMODE_LSEEK 4 70#define FMODE_LSEEK ((__force fmode_t)4)
71#define FMODE_PREAD 8 71#define FMODE_PREAD ((__force fmode_t)8)
72#define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */ 72#define FMODE_PWRITE FMODE_PREAD /* These go hand in hand */
73 73
74/* File is being opened for execution. Primary users of this flag are 74/* File is being opened for execution. Primary users of this flag are
75 distributed filesystems that can use it to achieve correct ETXTBUSY 75 distributed filesystems that can use it to achieve correct ETXTBUSY
76 behavior for cross-node execution/opening_for_writing of files */ 76 behavior for cross-node execution/opening_for_writing of files */
77#define FMODE_EXEC 16 77#define FMODE_EXEC ((__force fmode_t)16)
78
79#define FMODE_NDELAY ((__force fmode_t)32)
80#define FMODE_EXCL ((__force fmode_t)64)
81#define FMODE_WRITE_IOCTL ((__force fmode_t)128)
82#define FMODE_NDELAY_NOW ((__force fmode_t)256)
78 83
79#define RW_MASK 1 84#define RW_MASK 1
80#define RWA_MASK 2 85#define RWA_MASK 2
@@ -825,7 +830,7 @@ struct file {
825 const struct file_operations *f_op; 830 const struct file_operations *f_op;
826 atomic_long_t f_count; 831 atomic_long_t f_count;
827 unsigned int f_flags; 832 unsigned int f_flags;
828 mode_t f_mode; 833 fmode_t f_mode;
829 loff_t f_pos; 834 loff_t f_pos;
830 struct fown_struct f_owner; 835 struct fown_struct f_owner;
831 unsigned int f_uid, f_gid; 836 unsigned int f_uid, f_gid;
@@ -1152,6 +1157,7 @@ struct super_block {
1152 char s_id[32]; /* Informational name */ 1157 char s_id[32]; /* Informational name */
1153 1158
1154 void *s_fs_info; /* Filesystem private info */ 1159 void *s_fs_info; /* Filesystem private info */
1160 fmode_t s_mode;
1155 1161
1156 /* 1162 /*
1157 * The next field is for VFS *only*. No filesystems have any business 1163 * The next field is for VFS *only*. No filesystems have any business
@@ -1266,20 +1272,7 @@ int generic_osync_inode(struct inode *, struct address_space *, int);
1266 * to have different dirent layouts depending on the binary type. 1272 * to have different dirent layouts depending on the binary type.
1267 */ 1273 */
1268typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); 1274typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
1269 1275struct block_device_operations;
1270struct block_device_operations {
1271 int (*open) (struct inode *, struct file *);
1272 int (*release) (struct inode *, struct file *);
1273 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
1274 long (*unlocked_ioctl) (struct file *, unsigned, unsigned long);
1275 long (*compat_ioctl) (struct file *, unsigned, unsigned long);
1276 int (*direct_access) (struct block_device *, sector_t,
1277 void **, unsigned long *);
1278 int (*media_changed) (struct gendisk *);
1279 int (*revalidate_disk) (struct gendisk *);
1280 int (*getgeo)(struct block_device *, struct hd_geometry *);
1281 struct module *owner;
1282};
1283 1276
1284/* These macros are for out of kernel modules to test that 1277/* These macros are for out of kernel modules to test that
1285 * the kernel supports the unlocked_ioctl and compat_ioctl 1278 * the kernel supports the unlocked_ioctl and compat_ioctl
@@ -1713,7 +1706,7 @@ extern struct block_device *bdget(dev_t);
1713extern void bd_set_size(struct block_device *, loff_t size); 1706extern void bd_set_size(struct block_device *, loff_t size);
1714extern void bd_forget(struct inode *inode); 1707extern void bd_forget(struct inode *inode);
1715extern void bdput(struct block_device *); 1708extern void bdput(struct block_device *);
1716extern struct block_device *open_by_devnum(dev_t, unsigned); 1709extern struct block_device *open_by_devnum(dev_t, fmode_t);
1717#else 1710#else
1718static inline void bd_forget(struct inode *inode) {} 1711static inline void bd_forget(struct inode *inode) {}
1719#endif 1712#endif
@@ -1723,13 +1716,10 @@ extern const struct file_operations bad_sock_fops;
1723extern const struct file_operations def_fifo_fops; 1716extern const struct file_operations def_fifo_fops;
1724#ifdef CONFIG_BLOCK 1717#ifdef CONFIG_BLOCK
1725extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); 1718extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1726extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); 1719extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long);
1727extern int blkdev_driver_ioctl(struct inode *inode, struct file *file,
1728 struct gendisk *disk, unsigned cmd,
1729 unsigned long arg);
1730extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); 1720extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
1731extern int blkdev_get(struct block_device *, mode_t, unsigned); 1721extern int blkdev_get(struct block_device *, fmode_t);
1732extern int blkdev_put(struct block_device *); 1722extern int blkdev_put(struct block_device *, fmode_t);
1733extern int bd_claim(struct block_device *, void *); 1723extern int bd_claim(struct block_device *, void *);
1734extern void bd_release(struct block_device *); 1724extern void bd_release(struct block_device *);
1735#ifdef CONFIG_SYSFS 1725#ifdef CONFIG_SYSFS
@@ -1760,9 +1750,10 @@ extern void chrdev_show(struct seq_file *,off_t);
1760extern const char *__bdevname(dev_t, char *buffer); 1750extern const char *__bdevname(dev_t, char *buffer);
1761extern const char *bdevname(struct block_device *bdev, char *buffer); 1751extern const char *bdevname(struct block_device *bdev, char *buffer);
1762extern struct block_device *lookup_bdev(const char *); 1752extern struct block_device *lookup_bdev(const char *);
1763extern struct block_device *open_bdev_excl(const char *, int, void *); 1753extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
1764extern void close_bdev_excl(struct block_device *); 1754extern void close_bdev_exclusive(struct block_device *, fmode_t);
1765extern void blkdev_show(struct seq_file *,off_t); 1755extern void blkdev_show(struct seq_file *,off_t);
1756
1766#else 1757#else
1767#define BLKDEV_MAJOR_HASH_SIZE 0 1758#define BLKDEV_MAJOR_HASH_SIZE 0
1768#endif 1759#endif
diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
index a89513188ce7..00fbd5b245c9 100644
--- a/include/linux/fsnotify.h
+++ b/include/linux/fsnotify.h
@@ -188,7 +188,7 @@ static inline void fsnotify_close(struct file *file)
188 struct dentry *dentry = file->f_path.dentry; 188 struct dentry *dentry = file->f_path.dentry;
189 struct inode *inode = dentry->d_inode; 189 struct inode *inode = dentry->d_inode;
190 const char *name = dentry->d_name.name; 190 const char *name = dentry->d_name.name;
191 mode_t mode = file->f_mode; 191 fmode_t mode = file->f_mode;
192 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE; 192 u32 mask = (mode & FMODE_WRITE) ? IN_CLOSE_WRITE : IN_CLOSE_NOWRITE;
193 193
194 if (S_ISDIR(inode->i_mode)) 194 if (S_ISDIR(inode->i_mode))
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 89e53cfbc787..54525be4b5f8 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -474,8 +474,8 @@ struct ide_disk_ops {
474 ide_startstop_t (*do_request)(struct ide_drive_s *, struct request *, 474 ide_startstop_t (*do_request)(struct ide_drive_s *, struct request *,
475 sector_t); 475 sector_t);
476 int (*end_request)(struct ide_drive_s *, int, int); 476 int (*end_request)(struct ide_drive_s *, int, int);
477 int (*ioctl)(struct ide_drive_s *, struct inode *, 477 int (*ioctl)(struct ide_drive_s *, struct block_device *,
478 struct file *, unsigned int, unsigned long); 478 fmode_t, unsigned int, unsigned long);
479}; 479};
480 480
481/* ATAPI device flags */ 481/* ATAPI device flags */
@@ -1158,8 +1158,7 @@ struct ide_ioctl_devset {
1158int ide_setting_ioctl(ide_drive_t *, struct block_device *, unsigned int, 1158int ide_setting_ioctl(ide_drive_t *, struct block_device *, unsigned int,
1159 unsigned long, const struct ide_ioctl_devset *); 1159 unsigned long, const struct ide_ioctl_devset *);
1160 1160
1161int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, 1161int generic_ide_ioctl(ide_drive_t *, struct block_device *, unsigned, unsigned long);
1162 unsigned, unsigned long);
1163 1162
1164extern int ide_vlb_clk; 1163extern int ide_vlb_clk;
1165extern int ide_pci_clk; 1164extern int ide_pci_clk;
diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
index 315517e8bfa1..bda6b562a1e0 100644
--- a/include/linux/reiserfs_fs_sb.h
+++ b/include/linux/reiserfs_fs_sb.h
@@ -178,6 +178,7 @@ struct reiserfs_journal {
178 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */ 178 struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */
179 179
180 struct block_device *j_dev_bd; 180 struct block_device *j_dev_bd;
181 fmode_t j_dev_mode;
181 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ 182 int j_1st_reserved_block; /* first block on s_dev of reserved area journal */
182 183
183 unsigned long j_state; 184 unsigned long j_state;
diff --git a/include/linux/types.h b/include/linux/types.h
index f24f7beb47df..1d98330b1f2c 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -190,6 +190,7 @@ typedef __u32 __bitwise __wsum;
190 190
191#ifdef __KERNEL__ 191#ifdef __KERNEL__
192typedef unsigned __bitwise__ gfp_t; 192typedef unsigned __bitwise__ gfp_t;
193typedef unsigned __bitwise__ fmode_t;
193 194
194#ifdef CONFIG_PHYS_ADDR_T_64BIT 195#ifdef CONFIG_PHYS_ADDR_T_64BIT
195typedef u64 phys_addr_t; 196typedef u64 phys_addr_t;
diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h
index edb9525386da..b9006848b813 100644
--- a/include/scsi/scsi_ioctl.h
+++ b/include/scsi/scsi_ioctl.h
@@ -42,7 +42,7 @@ typedef struct scsi_fctargaddress {
42 42
43extern int scsi_ioctl(struct scsi_device *, int, void __user *); 43extern int scsi_ioctl(struct scsi_device *, int, void __user *);
44extern int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd, 44extern int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
45 void __user *arg, struct file *filp); 45 void __user *arg, int ndelay);
46 46
47#endif /* __KERNEL__ */ 47#endif /* __KERNEL__ */
48#endif /* _SCSI_IOCTL_H */ 48#endif /* _SCSI_IOCTL_H */
diff --git a/ipc/shm.c b/ipc/shm.c
index 0add3fa5f547..867e5d6a55c2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -817,7 +817,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
817 struct ipc_namespace *ns; 817 struct ipc_namespace *ns;
818 struct shm_file_data *sfd; 818 struct shm_file_data *sfd;
819 struct path path; 819 struct path path;
820 mode_t f_mode; 820 fmode_t f_mode;
821 821
822 err = -EINVAL; 822 err = -EINVAL;
823 if (shmid < 0) 823 if (shmid < 0)
diff --git a/kernel/power/disk.c b/kernel/power/disk.c
index 331f9836383f..c9d74083746f 100644
--- a/kernel/power/disk.c
+++ b/kernel/power/disk.c
@@ -651,7 +651,7 @@ static int software_resume(void)
651 pr_debug("PM: Preparing processes for restore.\n"); 651 pr_debug("PM: Preparing processes for restore.\n");
652 error = prepare_processes(); 652 error = prepare_processes();
653 if (error) { 653 if (error) {
654 swsusp_close(); 654 swsusp_close(FMODE_READ);
655 goto Done; 655 goto Done;
656 } 656 }
657 657
diff --git a/kernel/power/power.h b/kernel/power/power.h
index acc0c101dbd5..46b5ec7a3afb 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -153,7 +153,7 @@ extern int swsusp_shrink_memory(void);
153extern void swsusp_free(void); 153extern void swsusp_free(void);
154extern int swsusp_read(unsigned int *flags_p); 154extern int swsusp_read(unsigned int *flags_p);
155extern int swsusp_write(unsigned int flags); 155extern int swsusp_write(unsigned int flags);
156extern void swsusp_close(void); 156extern void swsusp_close(fmode_t);
157 157
158struct timeval; 158struct timeval;
159/* kernel/power/swsusp.c */ 159/* kernel/power/swsusp.c */
diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index 80ccac849e46..b7713b53d07a 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -172,13 +172,13 @@ static int swsusp_swap_check(void) /* This is called before saving image */
172 return res; 172 return res;
173 173
174 root_swap = res; 174 root_swap = res;
175 res = blkdev_get(resume_bdev, FMODE_WRITE, O_RDWR); 175 res = blkdev_get(resume_bdev, FMODE_WRITE);
176 if (res) 176 if (res)
177 return res; 177 return res;
178 178
179 res = set_blocksize(resume_bdev, PAGE_SIZE); 179 res = set_blocksize(resume_bdev, PAGE_SIZE);
180 if (res < 0) 180 if (res < 0)
181 blkdev_put(resume_bdev); 181 blkdev_put(resume_bdev, FMODE_WRITE);
182 182
183 return res; 183 return res;
184} 184}
@@ -426,7 +426,7 @@ int swsusp_write(unsigned int flags)
426 426
427 release_swap_writer(&handle); 427 release_swap_writer(&handle);
428 out: 428 out:
429 swsusp_close(); 429 swsusp_close(FMODE_WRITE);
430 return error; 430 return error;
431} 431}
432 432
@@ -574,7 +574,7 @@ int swsusp_read(unsigned int *flags_p)
574 error = load_image(&handle, &snapshot, header->pages - 1); 574 error = load_image(&handle, &snapshot, header->pages - 1);
575 release_swap_reader(&handle); 575 release_swap_reader(&handle);
576 576
577 blkdev_put(resume_bdev); 577 blkdev_put(resume_bdev, FMODE_READ);
578 578
579 if (!error) 579 if (!error)
580 pr_debug("PM: Image successfully loaded\n"); 580 pr_debug("PM: Image successfully loaded\n");
@@ -609,7 +609,7 @@ int swsusp_check(void)
609 return -EINVAL; 609 return -EINVAL;
610 } 610 }
611 if (error) 611 if (error)
612 blkdev_put(resume_bdev); 612 blkdev_put(resume_bdev, FMODE_READ);
613 else 613 else
614 pr_debug("PM: Signature found, resuming\n"); 614 pr_debug("PM: Signature found, resuming\n");
615 } else { 615 } else {
@@ -626,14 +626,14 @@ int swsusp_check(void)
626 * swsusp_close - close swap device. 626 * swsusp_close - close swap device.
627 */ 627 */
628 628
629void swsusp_close(void) 629void swsusp_close(fmode_t mode)
630{ 630{
631 if (IS_ERR(resume_bdev)) { 631 if (IS_ERR(resume_bdev)) {
632 pr_debug("PM: Image device not initialised\n"); 632 pr_debug("PM: Image device not initialised\n");
633 return; 633 return;
634 } 634 }
635 635
636 blkdev_put(resume_bdev); 636 blkdev_put(resume_bdev, mode); /* move up */
637} 637}
638 638
639static int swsusp_header_init(void) 639static int swsusp_header_init(void)
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 1af62b8b86c6..e17836680f49 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -2283,7 +2283,7 @@ static int snd_pcm_oss_open_file(struct file *file,
2283 int idx, err; 2283 int idx, err;
2284 struct snd_pcm_oss_file *pcm_oss_file; 2284 struct snd_pcm_oss_file *pcm_oss_file;
2285 struct snd_pcm_substream *substream; 2285 struct snd_pcm_substream *substream;
2286 unsigned int f_mode = file->f_mode; 2286 fmode_t f_mode = file->f_mode;
2287 2287
2288 if (rpcm_oss_file) 2288 if (rpcm_oss_file)
2289 *rpcm_oss_file = NULL; 2289 *rpcm_oss_file = NULL;
diff --git a/sound/oss/au1550_ac97.c b/sound/oss/au1550_ac97.c
index 23018a7c063a..81e1f443d094 100644
--- a/sound/oss/au1550_ac97.c
+++ b/sound/oss/au1550_ac97.c
@@ -93,7 +93,7 @@ static struct au1550_state {
93 spinlock_t lock; 93 spinlock_t lock;
94 struct mutex open_mutex; 94 struct mutex open_mutex;
95 struct mutex sem; 95 struct mutex sem;
96 mode_t open_mode; 96 fmode_t open_mode;
97 wait_queue_head_t open_wait; 97 wait_queue_head_t open_wait;
98 98
99 struct dmabuf { 99 struct dmabuf {
diff --git a/sound/oss/dmasound/dmasound.h b/sound/oss/dmasound/dmasound.h
index d978b0096564..1cb13fe56ec4 100644
--- a/sound/oss/dmasound/dmasound.h
+++ b/sound/oss/dmasound/dmasound.h
@@ -129,7 +129,7 @@ typedef struct {
129 int (*mixer_ioctl)(u_int, u_long); /* optional */ 129 int (*mixer_ioctl)(u_int, u_long); /* optional */
130 int (*write_sq_setup)(void); /* optional */ 130 int (*write_sq_setup)(void); /* optional */
131 int (*read_sq_setup)(void); /* optional */ 131 int (*read_sq_setup)(void); /* optional */
132 int (*sq_open)(mode_t); /* optional */ 132 int (*sq_open)(fmode_t); /* optional */
133 int (*state_info)(char *, size_t); /* optional */ 133 int (*state_info)(char *, size_t); /* optional */
134 void (*abort_read)(void); /* optional */ 134 void (*abort_read)(void); /* optional */
135 int min_dsp_speed; 135 int min_dsp_speed;
@@ -235,7 +235,7 @@ struct sound_queue {
235 */ 235 */
236 int active; 236 int active;
237 wait_queue_head_t action_queue, open_queue, sync_queue; 237 wait_queue_head_t action_queue, open_queue, sync_queue;
238 int open_mode; 238 fmode_t open_mode;
239 int busy, syncing, xruns, died; 239 int busy, syncing, xruns, died;
240}; 240};
241 241
diff --git a/sound/oss/dmasound/dmasound_atari.c b/sound/oss/dmasound/dmasound_atari.c
index 285239d64b82..4d45bd63718b 100644
--- a/sound/oss/dmasound/dmasound_atari.c
+++ b/sound/oss/dmasound/dmasound_atari.c
@@ -143,7 +143,7 @@ static int AtaMixerIoctl(u_int cmd, u_long arg);
143static int TTMixerIoctl(u_int cmd, u_long arg); 143static int TTMixerIoctl(u_int cmd, u_long arg);
144static int FalconMixerIoctl(u_int cmd, u_long arg); 144static int FalconMixerIoctl(u_int cmd, u_long arg);
145static int AtaWriteSqSetup(void); 145static int AtaWriteSqSetup(void);
146static int AtaSqOpen(mode_t mode); 146static int AtaSqOpen(fmode_t mode);
147static int TTStateInfo(char *buffer, size_t space); 147static int TTStateInfo(char *buffer, size_t space);
148static int FalconStateInfo(char *buffer, size_t space); 148static int FalconStateInfo(char *buffer, size_t space);
149 149
@@ -1461,7 +1461,7 @@ static int AtaWriteSqSetup(void)
1461 return 0 ; 1461 return 0 ;
1462} 1462}
1463 1463
1464static int AtaSqOpen(mode_t mode) 1464static int AtaSqOpen(fmode_t mode)
1465{ 1465{
1466 write_sq_ignore_int = 1; 1466 write_sq_ignore_int = 1;
1467 return 0 ; 1467 return 0 ;
diff --git a/sound/oss/dmasound/dmasound_core.c b/sound/oss/dmasound/dmasound_core.c
index 95fc5c681755..b8239f3168fb 100644
--- a/sound/oss/dmasound/dmasound_core.c
+++ b/sound/oss/dmasound/dmasound_core.c
@@ -212,7 +212,7 @@ static int irq_installed;
212#endif /* MODULE */ 212#endif /* MODULE */
213 213
214/* control over who can modify resources shared between play/record */ 214/* control over who can modify resources shared between play/record */
215static mode_t shared_resource_owner; 215static fmode_t shared_resource_owner;
216static int shared_resources_initialised; 216static int shared_resources_initialised;
217 217
218 /* 218 /*
@@ -668,7 +668,7 @@ static inline void sq_init_waitqueue(struct sound_queue *sq)
668 668
669#if 0 /* blocking open() */ 669#if 0 /* blocking open() */
670static inline void sq_wake_up(struct sound_queue *sq, struct file *file, 670static inline void sq_wake_up(struct sound_queue *sq, struct file *file,
671 mode_t mode) 671 fmode_t mode)
672{ 672{
673 if (file->f_mode & mode) { 673 if (file->f_mode & mode) {
674 sq->busy = 0; /* CHECK: IS THIS OK??? */ 674 sq->busy = 0; /* CHECK: IS THIS OK??? */
@@ -677,7 +677,7 @@ static inline void sq_wake_up(struct sound_queue *sq, struct file *file,
677} 677}
678#endif 678#endif
679 679
680static int sq_open2(struct sound_queue *sq, struct file *file, mode_t mode, 680static int sq_open2(struct sound_queue *sq, struct file *file, fmode_t mode,
681 int numbufs, int bufsize) 681 int numbufs, int bufsize)
682{ 682{
683 int rc = 0; 683 int rc = 0;
@@ -891,10 +891,10 @@ static int sq_release(struct inode *inode, struct file *file)
891 is the owner - if we have problems. 891 is the owner - if we have problems.
892*/ 892*/
893 893
894static int shared_resources_are_mine(mode_t md) 894static int shared_resources_are_mine(fmode_t md)
895{ 895{
896 if (shared_resource_owner) 896 if (shared_resource_owner)
897 return (shared_resource_owner & md ) ; 897 return (shared_resource_owner & md) != 0;
898 else { 898 else {
899 shared_resource_owner = md ; 899 shared_resource_owner = md ;
900 return 1 ; 900 return 1 ;
diff --git a/sound/oss/msnd.h b/sound/oss/msnd.h
index 61b3955481c5..c8be47ec2b7e 100644
--- a/sound/oss/msnd.h
+++ b/sound/oss/msnd.h
@@ -211,7 +211,7 @@ typedef struct multisound_dev {
211 211
212 /* State variables */ 212 /* State variables */
213 enum { msndClassic, msndPinnacle } type; 213 enum { msndClassic, msndPinnacle } type;
214 mode_t mode; 214 fmode_t mode;
215 unsigned long flags; 215 unsigned long flags;
216#define F_RESETTING 0 216#define F_RESETTING 0
217#define F_HAVEDIGITAL 1 217#define F_HAVEDIGITAL 1
diff --git a/sound/oss/sound_config.h b/sound/oss/sound_config.h
index 1a00a3210616..55271fbe7f49 100644
--- a/sound/oss/sound_config.h
+++ b/sound/oss/sound_config.h
@@ -110,24 +110,16 @@ struct channel_info {
110#define OPEN_WRITE PCM_ENABLE_OUTPUT 110#define OPEN_WRITE PCM_ENABLE_OUTPUT
111#define OPEN_READWRITE (OPEN_READ|OPEN_WRITE) 111#define OPEN_READWRITE (OPEN_READ|OPEN_WRITE)
112 112
113#if OPEN_READ == FMODE_READ && OPEN_WRITE == FMODE_WRITE
114
115static inline int translate_mode(struct file *file)
116{
117 return file->f_mode;
118}
119
120#else
121
122static inline int translate_mode(struct file *file) 113static inline int translate_mode(struct file *file)
123{ 114{
124 return ((file->f_mode & FMODE_READ) ? OPEN_READ : 0) | 115 if (OPEN_READ == (__force int)FMODE_READ &&
125 ((file->f_mode & FMODE_WRITE) ? OPEN_WRITE : 0); 116 OPEN_WRITE == (__force int)FMODE_WRITE)
117 return (__force int)(file->f_mode & (FMODE_READ | FMODE_WRITE));
118 else
119 return ((file->f_mode & FMODE_READ) ? OPEN_READ : 0) |
120 ((file->f_mode & FMODE_WRITE) ? OPEN_WRITE : 0);
126} 121}
127 122
128#endif
129
130
131#include "sound_calls.h" 123#include "sound_calls.h"
132#include "dev_table.h" 124#include "dev_table.h"
133 125
diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
index 044453a4ee5b..41562ecde5bb 100644
--- a/sound/oss/swarm_cs4297a.c
+++ b/sound/oss/swarm_cs4297a.c
@@ -295,7 +295,7 @@ struct cs4297a_state {
295 struct mutex open_mutex; 295 struct mutex open_mutex;
296 struct mutex open_sem_adc; 296 struct mutex open_sem_adc;
297 struct mutex open_sem_dac; 297 struct mutex open_sem_dac;
298 mode_t open_mode; 298 fmode_t open_mode;
299 wait_queue_head_t open_wait; 299 wait_queue_head_t open_wait;
300 wait_queue_head_t open_wait_adc; 300 wait_queue_head_t open_wait_adc;
301 wait_queue_head_t open_wait_dac; 301 wait_queue_head_t open_wait_dac;
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c
index dcbb3f739e61..78b8acc7c3b9 100644
--- a/sound/oss/vwsnd.c
+++ b/sound/oss/vwsnd.c
@@ -1509,7 +1509,7 @@ typedef struct vwsnd_dev {
1509 struct mutex open_mutex; 1509 struct mutex open_mutex;
1510 struct mutex io_mutex; 1510 struct mutex io_mutex;
1511 struct mutex mix_mutex; 1511 struct mutex mix_mutex;
1512 mode_t open_mode; 1512 fmode_t open_mode;
1513 wait_queue_head_t open_wait; 1513 wait_queue_head_t open_wait;
1514 1514
1515 lithium_t lith; 1515 lithium_t lith;