Commit c103d6ee authored by Arnd Bergmann's avatar Arnd Bergmann
Browse files

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: default avatarBen Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parent fe0da4e5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/compat.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/mm.h>
@@ -546,4 +547,7 @@ const struct ide_disk_ops ide_atapi_disk_ops = {
	.set_doorlock	= ide_set_media_lock,
	.do_request	= ide_floppy_do_request,
	.ioctl		= ide_floppy_ioctl,
#ifdef CONFIG_COMPAT
	.compat_ioctl	= ide_floppy_compat_ioctl,
#endif
};
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
/* ide-floppy_ioctl.c */
int ide_floppy_ioctl(ide_drive_t *, struct block_device *, fmode_t,
		     unsigned int, unsigned long);
int ide_floppy_compat_ioctl(ide_drive_t *, struct block_device *, fmode_t,
			    unsigned int, unsigned long);

#ifdef CONFIG_IDE_PROC_FS
/* ide-floppy_proc.c */
+36 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

#include <linux/kernel.h>
#include <linux/ide.h>
#include <linux/compat.h>
#include <linux/cdrom.h>
#include <linux/mutex.h>

@@ -302,3 +303,38 @@ out:
	mutex_unlock(&ide_floppy_ioctl_mutex);
	return err;
}

#ifdef CONFIG_COMPAT
int ide_floppy_compat_ioctl(ide_drive_t *drive, struct block_device *bdev,
			    fmode_t mode, unsigned int cmd, unsigned long arg)
{
	struct ide_atapi_pc pc;
	void __user *argp = compat_ptr(arg);
	int err;

	mutex_lock(&ide_floppy_ioctl_mutex);
	if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) {
		err = ide_floppy_lockdoor(drive, &pc, arg, cmd);
		goto out;
	}

	err = ide_floppy_format_ioctl(drive, &pc, mode, cmd, argp);
	if (err != -ENOTTY)
		goto out;

	/*
	 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
	 * and CDROM_SEND_PACKET (legacy) ioctls
	 */
	if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
		err = scsi_cmd_blk_ioctl(bdev, mode, cmd, argp);

	/*
	 * there is no generic_ide_compat_ioctl(), that is handled
	 * through compat_blkdev_ioctl().
	 */
out:
	mutex_unlock(&ide_floppy_ioctl_mutex);
	return err;
}
#endif
+17 −0
Original line number Diff line number Diff line
@@ -341,11 +341,28 @@ static int ide_gd_ioctl(struct block_device *bdev, fmode_t mode,
	return drive->disk_ops->ioctl(drive, bdev, mode, cmd, arg);
}

#ifdef CONFIG_COMPAT
static int ide_gd_compat_ioctl(struct block_device *bdev, fmode_t mode,
			       unsigned int cmd, unsigned long arg)
{
	struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
	ide_drive_t *drive = idkp->drive;

	if (!drive->disk_ops->compat_ioctl)
		return -ENOIOCTLCMD;

	return drive->disk_ops->compat_ioctl(drive, bdev, mode, cmd, arg);
}
#endif

static const struct block_device_operations ide_gd_ops = {
	.owner			= THIS_MODULE,
	.open			= ide_gd_unlocked_open,
	.release		= ide_gd_release,
	.ioctl			= ide_gd_ioctl,
#ifdef CONFIG_COMPAT
	.ioctl			= ide_gd_compat_ioctl,
#endif
	.getgeo			= ide_gd_getgeo,
	.check_events		= ide_gd_check_events,
	.unlock_native_capacity	= ide_gd_unlock_native_capacity,
+2 −0
Original line number Diff line number Diff line
@@ -413,6 +413,8 @@ struct ide_disk_ops {
				      sector_t);
	int		(*ioctl)(struct ide_drive_s *, struct block_device *,
				 fmode_t, unsigned int, unsigned long);
	int		(*compat_ioctl)(struct ide_drive_s *, struct block_device *,
					fmode_t, unsigned int, unsigned long);
};

/* ATAPI device flags */