免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7835 | 回复: 8

函数ioctl的源代码 [复制链接]

论坛徽章:
0
发表于 2006-09-01 15:57 |显示全部楼层
请问在哪里能找到ioctl这个函数的源代码?我是i386电脑。
我在/usr/src下面搜索ioctl字符串,结果也没有找到这个函数,只有很多用到这个函数的地方。

论坛徽章:
0
发表于 2006-09-01 16:48 |显示全部楼层
原帖由 redrett 于 2006-9-1 15:57 发表
请问在哪里能找到ioctl这个函数的源代码?我是i386电脑。
我在/usr/src下面搜索ioctl字符串,结果也没有找到这个函数,只有很多用到这个函数的地方。


/usr/src/sys/kern/sys_generic.c

论坛徽章:
0
发表于 2006-09-01 16:55 |显示全部楼层
3x very much

论坛徽章:
0
发表于 2006-09-01 16:57 |显示全部楼层
ioctl是一个设备驱动程序的提供给用户态传递设备控制信息接口,很多设备都会提供给用户态程序相应的ioctl接口的,所以要看你到底想知道哪个ioctl的内部实现。

[ 本帖最后由 ktrudger 于 2006-9-1 17:00 编辑 ]

论坛徽章:
0
发表于 2006-09-01 17:05 |显示全部楼层
原帖由 ktrudger 于 2006-9-1 16:57 发表
ioctl是一个设备驱动程序的提供给用户态传递设备控制信息接口,很多设备都会提供给用户态程序相应的ioctl接口的,所以要看你到底想知道哪个ioctl的内部实现。


The implementation of the ioctl system call is broken into two major levels. The upper level handles the system call itself. The ioctl call includes a descriptor, a command, and pointer to a data area. The command argument encodes what the size is of the data area for the parameters and whether the parameters are input, output, or both input and output. The upper level is responsible for decoding the command argument, allocating a buffer, and copying in any input data. If a return value is to be generated and there is no input, the buffer is zeroed. Finally, the ioctl is dispatched through the file-entry ioctl function, along with the I/O buffer, to the lower-level routine that implements the requested operation.

The lower level does the requested operation. Along with the command argument, it receives a pointer to the I/O buffer. The upper level has already checked for valid memory references, but the lower level may do more precise argument validation because it knows more about the expected nature of the arguments. However, it does not need to copy the arguments in or out of the user process. If the command is successful and produces output, the lower level places the results in the buffer provided by the top level. When the lower level returns, the upper level copies the results to the process.

论坛徽章:
0
发表于 2006-09-01 17:08 |显示全部楼层
FreeBSD下没有便捷的内核态/用户态通信的手段,不向linux。
一般只能采用ioctl,在内核态/用户态通信。
不过ioctl也挺方便的,建立一个伪设备即可。

论坛徽章:
0
发表于 2006-09-01 17:14 |显示全部楼层
原帖由 ktrudger 于 2006-9-1 17:08 发表
FreeBSD下没有便捷的内核态/用户态通信的手段,不向linux。
一般只能采用ioctl,在内核态/用户态通信。
不过ioctl也挺方便的,建立一个伪设备即可。


写篇文章详细介绍一下吧!要不可惜了你的经验了!呵呵
最近各编程版块关心这个问题的人不少。

论坛徽章:
2
技术图书徽章
日期:2013-09-04 15:21:51酉鸡
日期:2013-11-01 21:20:20
发表于 2006-09-01 17:42 |显示全部楼层
原帖由 ktrudger 于 2006-9-1 17:08 发表
FreeBSD下没有便捷的内核态/用户态通信的手段,不向linux。
一般只能采用ioctl,在内核态/用户态通信。
不过ioctl也挺方便的,建立一个伪设备即可。

不是这样地哦,有好多方法可以和内核通讯,ioctl只是一般用于设备驱动。
如果不是设备驱动,我一般比较喜欢用sysctl或者netgraph(借用它的msg),可以方便地传一些字符串之类的

论坛徽章:
0
发表于 2006-09-01 23:36 |显示全部楼层
我具体碰到的问题是这样的,我的系统是Freebsd6.1,一个USB移动硬盘,插入USB口后,首先出来以下消息:
umass0: Generic USB TO IDE Bridge, rev 2.00/1.00, addr 2
然后要过两分钟左右,才出来以下消息:
da0 at umass-sim0 bus 0 target 0 lun 0
da0: <Generic USB Disk 9.02> Fixed Direct Access SCSI-2 device
da0: 40.000MB/s transfers
da0: 76319MB (156301488 512 byte sectors: 255H 63S/T 9729C)
我在Windows和Fedora下用这个移动硬盘,都能马上认出来,不用等两分钟。
而且我借了别人的移动硬盘,在我的Freebsd6.1下使用也是没有问题的。
所以我觉得是这个移动硬盘盒的芯片和Freebsd不够兼容。
为了调查这个,我才要去研究ioctl的代码。不过经验不足,进展很慢阿。
主要是不会Debug,只能在代码中使用大量的printf,然后make buildworld/installworld,再来看log,很费事。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP