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

From: Arnd Bergmann (arnd@arndb.de)
Date: Wed May 07 2003 - 14:13:07 EST


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;
}

        Arnd <><
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed May 07 2003 - 22:00:32 EST