Skip to content

Commit 33c2dca

Browse files
author
Al Viro
committed
[PATCH] trim file propagation in block/compat_ioctl.c
... and remove the handling of cases when it falls back to native without changing arguments. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 90b8f28 commit 33c2dca

1 file changed

Lines changed: 26 additions & 47 deletions

File tree

‎block/compat_ioctl.c‎

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
7171
return ret;
7272
}
7373

74-
static int compat_hdio_ioctl(struct inode *inode, struct file *file,
75-
struct gendisk *disk, unsigned int cmd, unsigned long arg)
74+
static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode,
75+
unsigned int cmd, unsigned long arg)
7676
{
7777
mm_segment_t old_fs = get_fs();
7878
unsigned long kval;
7979
unsigned int __user *uvp;
8080
int error;
8181

8282
set_fs(KERNEL_DS);
83-
error = blkdev_driver_ioctl(inode, file, disk,
83+
error = __blkdev_driver_ioctl(bdev, mode,
8484
cmd, (unsigned long)(&kval));
8585
set_fs(old_fs);
8686

@@ -111,8 +111,8 @@ struct compat_cdrom_generic_command {
111111
compat_caddr_t reserved[1];
112112
};
113113

114-
static int compat_cdrom_read_audio(struct inode *inode, struct file *file,
115-
struct gendisk *disk, unsigned int cmd, unsigned long arg)
114+
static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode,
115+
unsigned int cmd, unsigned long arg)
116116
{
117117
struct cdrom_read_audio __user *cdread_audio;
118118
struct compat_cdrom_read_audio __user *cdread_audio32;
@@ -134,12 +134,12 @@ static int compat_cdrom_read_audio(struct inode *inode, struct file *file,
134134
if (put_user(datap, &cdread_audio->buf))
135135
return -EFAULT;
136136

137-
return blkdev_driver_ioctl(inode, file, disk, cmd,
137+
return __blkdev_driver_ioctl(bdev, mode, cmd,
138138
(unsigned long)cdread_audio);
139139
}
140140

141-
static int compat_cdrom_generic_command(struct inode *inode, struct file *file,
142-
struct gendisk *disk, unsigned int cmd, unsigned long arg)
141+
static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
142+
unsigned int cmd, unsigned long arg)
143143
{
144144
struct cdrom_generic_command __user *cgc;
145145
struct compat_cdrom_generic_command __user *cgc32;
@@ -167,7 +167,7 @@ static int compat_cdrom_generic_command(struct inode *inode, struct file *file,
167167
put_user(compat_ptr(data), &cgc->reserved[0]))
168168
return -EFAULT;
169169

170-
return blkdev_driver_ioctl(inode, file, disk, cmd, (unsigned long)cgc);
170+
return __blkdev_driver_ioctl(bdev, mode, cmd, (unsigned long)cgc);
171171
}
172172

173173
struct compat_blkpg_ioctl_arg {
@@ -308,8 +308,8 @@ static struct {
308308

309309
#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
310310

311-
static int compat_fd_ioctl(struct inode *inode, struct file *file,
312-
struct gendisk *disk, unsigned int cmd, unsigned long arg)
311+
static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
312+
unsigned int cmd, unsigned long arg)
313313
{
314314
mm_segment_t old_fs = get_fs();
315315
void *karg = NULL;
@@ -413,7 +413,7 @@ static int compat_fd_ioctl(struct inode *inode, struct file *file,
413413
return -EINVAL;
414414
}
415415
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);
417417
set_fs(old_fs);
418418
if (err)
419419
goto out;
@@ -579,8 +579,8 @@ static int compat_blk_trace_setup(struct block_device *bdev, char __user *arg)
579579
return 0;
580580
}
581581

582-
static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
583-
struct gendisk *disk, unsigned cmd, unsigned long arg)
582+
static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode,
583+
unsigned cmd, unsigned long arg)
584584
{
585585
int ret;
586586

@@ -596,7 +596,7 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
596596
case HDIO_GET_ACOUSTIC:
597597
case HDIO_GET_ADDRESS:
598598
case HDIO_GET_BUSSTATE:
599-
return compat_hdio_ioctl(inode, file, disk, cmd, arg);
599+
return compat_hdio_ioctl(bdev, mode, cmd, arg);
600600
case FDSETPRM32:
601601
case FDDEFPRM32:
602602
case FDGETPRM32:
@@ -606,11 +606,11 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
606606
case FDPOLLDRVSTAT32:
607607
case FDGETFDCSTAT32:
608608
case FDWERRORGET32:
609-
return compat_fd_ioctl(inode, file, disk, cmd, arg);
609+
return compat_fd_ioctl(bdev, mode, cmd, arg);
610610
case CDROMREADAUDIO:
611-
return compat_cdrom_read_audio(inode, file, disk, cmd, arg);
611+
return compat_cdrom_read_audio(bdev, mode, cmd, arg);
612612
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);
614614

615615
/*
616616
* No handler required for the ones below, we just need to
@@ -679,40 +679,16 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
679679
case DVD_WRITE_STRUCT:
680680
case DVD_AUTH:
681681
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:
705682
break;
706683
default:
707684
/* unknown ioctl number */
708685
return -ENOIOCTLCMD;
709686
}
710687

711-
return __blkdev_driver_ioctl(inode->i_bdev, file->f_mode, cmd, arg);
688+
return __blkdev_driver_ioctl(bdev, mode, cmd, arg);
712689
}
713690

714-
static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
715-
struct block_device *bdev,
691+
static int compat_blkdev_locked_ioctl(struct block_device *bdev,
716692
unsigned cmd, unsigned long arg)
717693
{
718694
struct backing_dev_info *bdi;
@@ -772,6 +748,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
772748
struct inode *inode = file->f_mapping->host;
773749
struct block_device *bdev = inode->i_bdev;
774750
struct gendisk *disk = bdev->bd_disk;
751+
fmode_t mode = file->f_mode;
752+
if (file->f_flags & O_NDELAY)
753+
mode |= FMODE_NDELAY_NOW;
775754

776755
switch (cmd) {
777756
case HDIO_GETGEO:
@@ -794,13 +773,13 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
794773
}
795774

796775
lock_kernel();
797-
ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
776+
ret = compat_blkdev_locked_ioctl(bdev, cmd, arg);
798777
unlock_kernel();
799778
if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
800-
ret = disk->fops->compat_ioctl(bdev, file->f_mode, cmd, arg);
779+
ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg);
801780

802781
if (ret != -ENOIOCTLCMD)
803782
return ret;
804783

805-
return compat_blkdev_driver_ioctl(inode, file, disk, cmd, arg);
784+
return compat_blkdev_driver_ioctl(bdev, mode, cmd, arg);
806785
}

0 commit comments

Comments
 (0)