4

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.

Bartlomiej Grzeskowiak
  • 1,009
  • 5
  • 16
  • 35

1 Answers1

4

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.
Simon Richter
  • 28,572
  • 1
  • 42
  • 64