Adding new IOCTL's into kernel (number range)

萝らか妹 提交于 2019-12-23 16:41:31

问题


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.


回答1:


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.


来源:https://stackoverflow.com/questions/8922102/adding-new-ioctls-into-kernel-number-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!