Linux device files and device numbers

最近给系统添加了一个驱动,结果导致系统一些功能异常。查了好久,发现是device numbers冲突引起的。开始写驱动时,很自然的使用了动态分配device numbers(major=0 minor=0)的方法,而没有符合平台的特点。后来确认,平台中的device numbers都是预先分配的。

问题现象

使用系统函数open()打开device files总是成功,用ioctl()操作device总是失败,perror()返回的错误:“Inappropriate ioctl for device”。

原因分析

通过各种方式,查出device number冲突,这也解释了perror()为什么返回“Inappropriate ioctl for device”,ioctl期望操作的device跟实际的device是不符合的。

那device files和device numbers之间的关系是怎样的?

the files in /dev each have a major and minor device number associated with them. The kernel uses these numbers to map device-file references to the corresponding driver.

The major device number identifies the driver with which the file is associated. The minor device number usually identifies which particular instance of a given device type is to be addressed. The minor device number is sometimes called the unit number.

转载于:https://www.cnblogs.com/RayLee/archive/2011/08/06/2129734.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值