本文共 3170 字,大约阅读时间需要 10 分钟。
遇到ioctl内核中未定义,
打印log
[ 739.108300] No such IOCTL, cmd is -1071625723
cmd is -1071625723
这个cmd如何解释呢...?
ioctl原型
SYNOPSIS
#include <sys/ioctl.h>int ioctl(int d, int request, ...);
其中request/cmd是一个32位整数。
那这个整数是如何定义的呢??
可参考内核文档
./Documentation/ioctl/ioctl-decoding.txt
./Documentation/ioctl/ioctl-number.txt
以上cmd数字的解析规则:
1 To decode a hex IOCTL code: 2 3 Most architectures use this generic format, but check 4 include/ARCH/ioctl.h for specifics, e.g. powerpc 5 uses 3 bits to encode read/write and 13 bits for size. 6 7 bits meaning 8 31-30› 00 - no parameters: uses _IO macro 9 › 10 - read: _IOR 10 › 01 - write: _IOW 11 › 11 - read/write: _IOWR 12 13 29-16› size of arguments 14 15 15-8› ascii character supposedly 16 › unique to each driver 17 18 7-0› function # 19 20 21 So for example 0x82187201 is a read with arg length of 0x218, 22 character 'r' function 1. Grepping the source reveals this is: 23 24 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
-1071625723
写个程序转换成16进制 无符号数。
为c0204a05
根据以上规则, bits的含义:
31-30 - 11 读写
29-16 - 长度为0x020 即32byte
15-8 - magic number 魔法数字 - 0x4a
查看ascii码, 为"J"
7-0 - function number 具体的函数对应数字 - 0x5
对应内核代码, 就知道报错原因了...
转载地址:http://vpcrj.baihongyu.com/