Linux USB subsystem --- USB File System initialize
Linux USB subsystem --- USB File System initialize
目的:对USB作深入学习,在此留下笔记。欢迎讨论。
[Linux 3.2] [driver/usb/core/inode.c]
函数:usbfs_init()
USB文件系统的初始化取决于是否CONFIG_USB_DEVICEFS. (make menuconfig ---> Device Drivers ---> USB support ---> USB device filesystem (DEPRECATED))
如果没有配置CONFIG_USB_DEVICEFS, 则usbfs_init()为inline函数,直接return 0;
如果配置CONFIG_USB_DEVICEFS, 则代码如下:
- static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev)
- {
- switch (action) {
- case USB_DEVICE_ADD:
- usbfs_add_device(dev);
- break;
- case USB_DEVICE_REMOVE:
- usbfs_remove_device(dev);
- break;
- case USB_BUS_ADD:
- usbfs_add_bus(dev);
- break;
- case USB_BUS_REMOVE:
- usbfs_remove_bus(dev);
- }
- usbfs_update_special();
- usbfs_conn_disc_event();
- return NOTIFY_OK;
- }
- static struct notifier_block usbfs_nb = {
- .notifier_call = usbfs_notify,
- };
- /* --------------------------------------------------------------------- */
- static struct proc_dir_entry *usbdir = NULL;
- int __init usbfs_init(void)
- {
- int retval;
- retval = register_filesystem(&usb_fs_type);
- if (retval)
- return retval;
- usb_register_notify(&usbfs_nb);
- /* create mount point for usbfs */
- usbdir = proc_mkdir("bus/usb", NULL);
- return 0;
- }
其主要作用:注册usb文件系统,注册一个usbfs_nb通知链,最后是在proc文件系统下面创建bus/usb目录。
进入/proc/bus/usb目录
# ls
001 002 devices
此devices的内容完全与usb debug文件系统里的devices文件一样。
001,代表usb总线1
002,代表usb总线2
注意:具体内容可以参见<Documentations/usb/proc_usb_info.txt>
问题:这些内容是如何产生的呢?
回答:见后面分析。
评论暂时关闭