请注意参考正确的文档以了解如何解码ioctl 命令。Documentation/ioctl-number.txt
解释了如何创建新的ioctl 代码,而上一个答案中链接的文档在关注 ioctl 创建之前概述了整个过程。asm/ioctl.h
是一个更好的来源,因为 ioctl 实际掩码可能因不同的架构而异,但可以在include/asm-generic/ioctl.h
和中找到对一般约定和位域含义和位置的解释Documentation/ioctl-decoding.txt
。
从后者:
bits meaning
31-30 00 - no parameters: uses _IO macro
10 - read: _IOR
01 - write: _IOW
11 - read/write: _IOWR
29-16 size of arguments
15-8 ascii character supposedly
unique to each driver
7-0 function #
根据上述,cmd=3222823425应该解码为:
3222823425 -> 0xC0186201 -> 11000000000110000110001000000001
- `direction` -> `11` -> read/write;
- `size` -> `00000000011000` -> 24 bytes (a pointer to a struct of
this size should be passed as 3rd
argument of ioctl();
- `type` -> `01100010` -> 0x62, ascii for character 'b';
- `number` -> `00000001` -> driver function #1.
希望这能有所帮助。问候。