读usbfs的一些感想

61 篇文章 3 订阅


原因:在配置内核支持U盘的时候无意中看到了 

[*] Device Drivers --->

[*]USB support --->

[*] USB device filesystem(DEPRECATED)

的支持,以前知道是/proc文件系统下的,但不知道具体做什么,于是就看了下它的HELP.这一看,看出很多信息出来,很是开心

 

1.设备文件: /proc/bus/usb/xxx/yyy:

        xxx: bus number  

yyy: device number.

原文说:These files are "virtual", meaning they are generated on the fly and not stored on the hard drive. 这段说明很有意思,generate on the fly..可能是在实时收集信息的意思,^_^

2. 一般的系统是看不到1中后面的xxx/yyy的。。怎么办呢?文件系统没有挂载,需要

mount -t usbfs none /proc/bus/usb

3. 我用vi 打开了yyy,并且:!%xxd了。 可看到的十六进制不知所云。想看懂,正好文章下面有关于这个格式的介绍,说描述信息在 Documentation/usb/proc_usb_info.txt中,于是看了下,这里面把这个格式 介绍的挺细致的

 

4. 首先看这个文档的时间是:version 2003.05.30   哦,现在都2011.7.31了,说明有很长一段时间了,不知道有没有过时.

 

5. 对1中yyy文件的访问

   知道yyy文件是二进制文件。一些ioctl的值定义在linux/usbdevice_fs.h中。 而且内核还提供了一个访问示例在linux/driver/usb/core/devio.c中。 有了这两个文件,怎样访问usbfs就很清楚了,不过需要一些内核编程的基础知识才能看懂这个文件,可惜自己初入内核,只看懂一些结构,细节方面还是有些地方不理解。

 

6. /proc/bus/usb/devices 文件

 这个文件是ASCII码格式的,不过一看也是看不懂,呵呵,还好有格式说明, 

Each line is tagged with a one-character ID for that line:

 

T = Topology (etc.)

B = Bandwidth (applies only to USB host controllers, which are 

    virtualized as root hubs)

D = Device descriptor info.

P = Product ID info. (from Device descriptor, but they won't fit 

    together on one line)

S = String descriptors.

C = Configuration descriptor info. (* = active configuration)

I = Interface descriptor info.

E = Endpoint descriptor info.

=======================================================================

 

/proc/bus/usb/devices output format:

 

Legend:

  d = decimal number (may have leading spaces or 0's)

  x = hexadecimal number (may have leading spaces or 0's)

  s = string

 

 

Topology info:

 

T:  Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=ddd MxCh=dd

|   |      |      |       |       |      |        |       |__MaxChildren

|   |      |      |       |       |      |        |__Device Speed in Mbps

|   |      |      |       |       |      |__DeviceNumber

|   |      |      |       |       |__Count of devices at this level

|   |      |      |       |__Connector/Port on Parent for this device

|   |      |      |__Parent DeviceNumber

|   |      |__Level in topology for this bus

|   |__Bus number

|__Topology info tag

                                                              96,0-1        26%

    Speed may be:

        1.5     Mbit/s for low speed USB

        12      Mbit/s for full speed USB

        480     Mbit/s for high speed USB (added for USB 2.0)

值得说明的是: 这种文档写作方式,让人耳目一新,比较哈皮!

还有些其他字段,到内核里看Documentation/usb/proc_usb_info.txt就好了

 

 

7. 当这个理解完之后,再回到HELP文件

The usbfs functionality is replaced by real device-nodes managed by 

udev.  These nodes lived in /dev/bus/usb and are used by libusb. 

usbfs已经被udev取代了,在/dev/bus/usb里面有信息,于是我就ls了一下:

#ls /dev/bus/usb

001  002  003

root@debian:/dev/bus/usb# ls -lr

总用量 0

drwxr-xr-x 2 root root 60  7月 31 09:59 003

drwxr-xr-x 2 root root 80  7月 31 09:59 002

drwxr-xr-x 2 root root 60  7月 31 09:59 001

root@debian:/dev/bus/usb# ls -lrR

.:

总用量 0

drwxr-xr-x 2 root root 60  7月 31 09:59 003

drwxr-xr-x 2 root root 80  7月 31 09:59 002

drwxr-xr-x 2 root root 60  7月 31 09:59 001

 

./003:

总用量 0

crw-rw-r-- 1 root root 189, 256  7月 31 09:59 001

 

./002:

总用量 0

crw-rw-r-- 1 root root 189, 129  7月 31 09:59 002

crw-rw-r-- 1 root root 189, 128  7月 31 09:59 001

 

./001:

总用量 0

crw-rw-r-- 1 root root 189, 0  7月 31 09:59 001

root@debian:/dev/bus/usb# uname -a

Linux debian 2.6.32-5-686 #1 SMP Wed Jan 12 04:01:41 UTC 2011 i686 GNU/Linux

 

悲催,呵呵,udev里的东西和usbfs里不一样的说,不过收获还是很大

 

注:

本来打算配置Linux支持USB移动U盘和移动硬盘的支持的,这个我配置了几十次的功能,由于接到一些内核新的配置需求,想在这个老配置里悟出一些更通用的内核配置方法,没想到,今天没悟出,却更深入了USB的这个选项,这个过程给我一个启发,Kconfig会和Documentation联系,而Documentation也会联系内核里的一些具体文件,这样的话,这样走一圈,再看源码,是不是比直接看源码来得深刻一点!不过这还是个问题,还没有得到解决,以后有时间慢慢解决掉它们

我手里拿着Linux内核技术手册来配置Linux 2.6.32的内核,发现第7章USB存储设备的配置有问题:

  就是USB应该要配置OHCI,EHCI的, 可是,这节没讲,到外部设备->USB才讲到,这就又给了我一个启发:尽信书不如无书。  虽然这书都是实践经验的总结,也不错,但书上不一定全对,我更是发现了一个问题:在第7章 Linux默认安全模型Capabilities 里的选项

[*]   Default Linux Capabilities

在Linux 2.6.32内核里已经取消了,内核在变,而书没有变,看来,只能以书为基础,登录到内核,然后看Kconfig Makefile 和 Documentation 了, 这些权威的内核参考书,可能只适合初级学下吧,之后要全部在内核源码树里来来回回了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值