Skip to contentSkip to conversation

make standard conversions work with compat_ioctl.

PATCH New Michael S. Tsirkin 1 participant 1 message Jan 6, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 make standard conversions work with compat_ioctl.

Hello!
Quoting r. Andrew Morton ([email protected]) "Re: [PATCH] deprecate (un)register_ioctl32_conversion":

Quoted 6 lines
Quoted 3 lines · Michael S. Tsirkin

Christoph, I know you want to remove the inode parameter :)

Otherwise I think -mm1 has the final version of the replacement.

I merged Christoph's verion of the patch into -mm.

Unfortunately, in -mm2 version, it seems that once a driver implements compat_ioctl, the standard ioctls like FIOQSIZE stop working for it, and so
do standard commands implemented with COMPATIBLE_IOCTL.

The simplest solution is, I think, to do as Arnd Bergmann suggested, and go back to the hash lookup if compat_ioctl returns -ENOIOCTLCMD.

To make it easy to use the same function for unlocked_ioctl and for ioctl_compat, for unlocked_ioctl the code -ENOIOCTLCMD shall be translated to -EINVAL.

Attached patch is for -mm2, applies over 2.6.10 as well with ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.10/2.6.10-mm2/broken-out/ioctl-rework-2.patch

MST

Handle generic ioctl commands by falling back on static conversion functions in fs/compat_ioctl.c on -ENOIOCTLCMD code.

fs/compat.c +3 -1
diff -rup linux-2.6.10/fs/compat.c linux-2.6.10-ioctls/fs/compat.c
@@ -440,8 +440,10 @@ asmlinkage long compat_sys_ioctl(unsigne
 		if (!filp->f_op->ioctl)
 			goto do_ioctl;
 	} else if (filp->f_op->compat_ioctl) {
+		/* compat_ioctl returns -ENOIOCTLCMD on unhandled command. */
 		error = filp->f_op->compat_ioctl(filp, cmd, arg);
-		goto out_fput;
+		if (error != -ENOIOCTLCMD)
+			goto out_fput;
 	}
 
 	down_read(&ioctl32_sem);
fs/ioctl.c +3 -0
diff -rup linux-2.6.10/fs/ioctl.c linux-2.6.10-ioctls/fs/ioctl.c
@@ -26,6 +26,9 @@ static long do_ioctl(struct file *filp, 
 
 	if (filp->f_op->unlocked_ioctl) {
 		error = filp->f_op->unlocked_ioctl(filp, cmd, arg);
+		if (error == -ENOIOCTLCMD)
+			error = -EINVAL;
+		goto out;
 	} else if (filp->f_op->ioctl) {
 		lock_kernel();
 		error = filp->f_op->ioctl(filp->f_dentry->d_inode,