Search code examples
linuxkernel-moduleioctl

Adding new IOCTL's into kernel (number range)


I'm writing new kernel module and I add implement new IOCTL's.
Is there any rule that I should follow with IOCTL's numbering ?
Maybe there is some "user range" ?

I work with kernel 2.6.21 on embedded platform.


Solution

  • IOCTLs are defined to be device dependent -- if there were "standard" ioctls for people to implement, these would be syscalls like read and write.

    There are a few conventions for ioctl numbers:

    • the parameter direction (in, out, both) is encoded in the ioctl number in two bits. This isn't mandatory, unless you use the common copy-from-user/copy-to-user code, which is recommended.
    • there is a magic number to avoid conflicts. There is no real harm if two devices define the same ioctl, but using different numbers gives an additional opportunity to catch errors.