Skip to content

Commit c103d6e

Browse files
committed
compat_ioctl: ide: floppy: add handler
Rather than relying on fs/compat_ioctl.c, this adds support for a compat_ioctl() callback in the ide-floppy driver directly, which lets it translate the scsi commands. Reviewed-by: Ben Hutchings <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent fe0da4e commit c103d6e

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

drivers/ide/ide-floppy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/types.h>
2020
#include <linux/string.h>
2121
#include <linux/kernel.h>
22+
#include <linux/compat.h>
2223
#include <linux/delay.h>
2324
#include <linux/timer.h>
2425
#include <linux/mm.h>
@@ -546,4 +547,7 @@ const struct ide_disk_ops ide_atapi_disk_ops = {
546547
.set_doorlock = ide_set_media_lock,
547548
.do_request = ide_floppy_do_request,
548549
.ioctl = ide_floppy_ioctl,
550+
#ifdef CONFIG_COMPAT
551+
.compat_ioctl = ide_floppy_compat_ioctl,
552+
#endif
549553
};

drivers/ide/ide-floppy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
2626
/* ide-floppy_ioctl.c */
2727
int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t,
2828
unsigned int, unsigned long);
29+
int ide_floppy_compat_ioctl(ide_drive_t *, struct block_device *, fmode_t,
30+
unsigned int, unsigned long);
2931

3032
#ifdef CONFIG_IDE_PROC_FS
3133
/* ide-floppy_proc.c */

drivers/ide/ide-floppy_ioctl.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/kernel.h>
77
#include <linux/ide.h>
8+
#include <linux/compat.h>
89
#include <linux/cdrom.h>
910
#include <linux/mutex.h>
1011

@@ -302,3 +303,38 @@ int ide_floppy_ioctl(ide_drive_t *drive, struct block_device *bdev,
302303
mutex_unlock(&ide_floppy_ioctl_mutex);
303304
return err;
304305
}
306+
307+
#ifdef CONFIG_COMPAT
308+
int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev,
309+
fmode_t mode, unsigned int cmd, unsigned long arg)
310+
{
311+
struct ide_atapi_pc pc;
312+
void __user *argp = compat_ptr(arg);
313+
int err;
314+
315+
mutex_lock(&ide_floppy_ioctl_mutex);
316+
if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
317+
err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
318+
goto out;
319+
}
320+
321+
err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
322+
if (err != -ENOTTY)
323+
goto out;
324+
325+
/*
326+
* skip SCSI_IOCTL_SEND_COMMAND (deprecated)
327+
* and CDROM_SEND_PACKET (legacy) ioctls
328+
*/
329+
if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
330+
err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);
331+
332+
/*
333+
* there is no generic_ide_compat_ioctl(), that is handled
334+
* through compat_blkdev_ioctl().
335+
*/
336+
out:
337+
mutex_unlock(&ide_floppy_ioctl_mutex);
338+
return err;
339+
}
340+
#endif

drivers/ide/ide-gd.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,28 @@ static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
341341
return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg);
342342
}
343343

344+
#ifdef CONFIG_COMPAT
345+
static int ide_gd_compat_ioctl(struct block_device *bdev, fmode_t mode,
346+
unsigned int cmd, unsigned long arg)
347+
{
348+
struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
349+
ide_drive_t *drive = idkp->drive;
350+
351+
if (!drive->disk_ops->compat_ioctl)
352+
return -ENOIOCTLCMD;
353+
354+
return drive->disk_ops->compat_ioctl(drive, bdev, mode, cmd, arg);
355+
}
356+
#endif
357+
344358
static const struct block_device_operations ide_gd_ops = {
345359
.owner = THIS_MODULE,
346360
.open = ide_gd_unlocked_open,
347361
.release = ide_gd_release,
348362
.ioctl = ide_gd_ioctl,
363+
#ifdef CONFIG_COMPAT
364+
.ioctl = ide_gd_compat_ioctl,
365+
#endif
349366
.getgeo = ide_gd_getgeo,
350367
.check_events = ide_gd_check_events,
351368
.unlock_native_capacity = ide_gd_unlock_native_capacity,

include/linux/ide.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,8 @@ struct ide_disk_ops {
413413
sector_t);
414414
int (*ioctl)(struct ide_drive_s *, struct block_device *,
415415
fmode_t, unsigned int, unsigned long);
416+
int (*compat_ioctl)(struct ide_drive_s *, struct block_device *,
417+
fmode_t, unsigned int, unsigned long);
416418
};
417419

418420
/* ATAPI device flags */

0 commit comments

Comments
 (0)