Re: ioctl cleanups: enable sg_io and serial stuff to be shared

Arnd Bergmann
2003-05-07T19:04:52Z

On Wednesday 07 May 2003 18:04, David S. Miller wrote:
> You can define it as follows:
>
> 1) If entry exists in COMPAT or TRANSLATE table, invoke
> fops->ioctl(), else
>
> 2) If ->compat_ioctl() exists, invoke that, else
>
> 3) Fail.

Another solution could be to use the tables only if
->compat_ioctl() is undefined or returned -ENOTTY. That
would save the hash table lookup in many cases and makes
it possible for a driver to override a generic handler
with its more specialized version (e.g. CIODEVPRIVATE).

> The COMPAT tables are sort of valuable, in that it eliminates
> the need to duplicate code when all of a drivers ioctls need
> no translation.

Right. Of course you can just as well do

.ioctl = &foo_ioctl,
.compat_ioctl = &foo_ioctl,

in that case.

Btw: is there any bit in the ioctl number definition that can
be (ab)used for compat_ioctl? Maybe we don't even need another
callback if the compatibility mode can be encoded in the
number itself (simplified):

long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
unsigned long arg)
{
long err = sys_ioctl(fd, cmd | _IOC_COMPAT, arg);
if (err == -ENOTTY) /* use ioctl_trans table */
err = compat_do_ioctl(fd, cmd, arg);
return err;
}
...
long foo_ioctl(struct inode * inode, struct file * filp,
unsigned int cmd, unsigned long arg)
{
switch(cmd) {
case SOMEIOCTL:
return do_something(inode, arg);
case SOMEIOCTL | _IOC_COMPAT:
return compat_do_something(inode, arg);
case ANOTHERIOCTL:
case ANOTHERIOCTL | _IOC_COMPAT:
return do_something_else(inode, arg);
}
return -ENOTTY;
}