博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于ioctl的cmd值如何解析...
阅读量:3556 次
发布时间:2019-05-20

本文共 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/

你可能感兴趣的文章
[LeetCode javaScript] 53.最大子序和
查看>>
[LeetCode javaScript] 101. 对称二叉树
查看>>
[LeetCode javaScript] 860. 柠檬水找零
查看>>
[LeetCode javaScript] 118. 杨辉三角
查看>>
[LeetCode javaScript] 905. 按奇偶校验排序数组
查看>>
[LeetCode javaScript] 617. 合并二叉树
查看>>
[LeetCode javaScript] 292. Nim游戏
查看>>
[LeetCode javaScript] 896. 单调数列
查看>>
[LeetCode javaScript] 804. 唯一摩尔斯密码词
查看>>
[LeetCode javaScript] 476. 数字的补数
查看>>
[LeetCode javaScript] 811. 子域名访问计数
查看>>
[LeetCode javaScript] 414. 第三大的数
查看>>
[LeetCode javaScript] 242. 有效的字母异位词
查看>>
[LeetCode javaScript] 75. 颜色分类
查看>>
[LeetCode javaScript] 56. 合并区间
查看>>
[LeetCode javaScript] 190. 颠倒二进制位
查看>>
[LeetCode javaScript] 521. 最长特殊序列 Ⅰ
查看>>
[LeetCode javaScript] 806. 写字符串需要的行数
查看>>
[LeetCode javaScript] 868. 二进制间距
查看>>
[LeetCode javaScript] 824. 山羊拉丁文
查看>>