Linux USB subsystem --- USB File System initialize

本文详细解析了Linux USB子系统中USB文件系统的初始化过程,包括配置检查、函数调用及目录创建等关键步骤。重点阐述了在不同配置下函数的行为差异,并展示了如何通过注册文件系统和通知链来实现USB设备的动态管理和状态更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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, 则代码如下:

 

  1. static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev)  
  2. {  
  3.     switch (action) {  
  4.     case USB_DEVICE_ADD:  
  5.         usbfs_add_device(dev);  
  6.         break;  
  7.     case USB_DEVICE_REMOVE:  
  8.         usbfs_remove_device(dev);  
  9.         break;  
  10.     case USB_BUS_ADD:  
  11.         usbfs_add_bus(dev);  
  12.         break;  
  13.     case USB_BUS_REMOVE:  
  14.         usbfs_remove_bus(dev);  
  15.     }  
  16.   
  17.     usbfs_update_special();  
  18.     usbfs_conn_disc_event();  
  19.     return NOTIFY_OK;  
  20. }  
  21.   
  22. static struct notifier_block usbfs_nb = {  
  23.     .notifier_call =    usbfs_notify,  
  24. };  
  25.   
  26. /* --------------------------------------------------------------------- */  
  27.   
  28. static struct proc_dir_entry *usbdir = NULL;  
  29.   
  30. int __init usbfs_init(void)  
  31. {  
  32.     int retval;  
  33.   
  34.     retval = register_filesystem(&usb_fs_type);  
  35.     if (retval)  
  36.         return retval;  
  37.   
  38.     usb_register_notify(&usbfs_nb);  
  39.   
  40.     /* create mount point for usbfs */  
  41.     usbdir = proc_mkdir("bus/usb", NULL);  
  42.   
  43.     return 0;  
  44. }  


其主要作用:注册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>

 

问题:这些内容是如何产生的呢?

回答:见后面分析。


/lib # lldpd -u /var/run/lldpd/lldpd.socket -C /etc/lldpd.conf -dddd 1970-01-01T00:25:43 [ DBG/main] lldpd 2024-08-10 starting... 1970-01-01T00:25:43 [ DBG/main] creating control socket 1970-01-01T00:25:43 [ DBG/control] create control socket /var/run/lldpd/lldpd.socket 1970-01-01T00:25:43 [ DBG/control] listen to control socket /var/run/lldpd/lldpd.socket 1970-01-01T00:25:43 [ DBG/main] invoking lldpcli for default configuration locations 1970-01-01T00:25:43 [ DBG/main] invoke /sbin/lldpcli -sddd 1970-01-01T00:25:43 [ DBG/main] get OS/LSB release information 1970-01-01T00:25:43 [ DBG/main] invoke /sbin/lldpcli -sddd 1970-01-01T00:25:43 [ DBG/localchassis] grab OS release 1970-01-01T00:25:43 [ DBG/main] initialize privilege separation 1970-01-01T00:25:43 [ DBG/privsep] getting CAP_NET_RAW/ADMIN and CAP_DAC_OVERRIDE privilege 1970-01-01T00:25:43 [ DBG/privsep] dropping privileges 1970-01-01T00:25:43 [ DBG/privsep] dropping extra capabilities 1970-01-01T00:25:43 [ DBG/privsep] dropping privileges 1970-01-01T00:25:43 [ DBG/privsep] received command 0 1970-01-01T00:25:43 [ DBG/lldpctl] cannot find configuration file/directory /etc/lldpd.conf 1970-01-01T00:25:43 [ DBG/lldpctl] cannot find configuration file/directory /etc/lldpd.d 1970-01-01T00:25:43 [ DBG/privsep] monitor ready 1970-01-01T00:25:43 [ DBG/main] get an ioctl socket 1970-01-01T00:25:43 [ DBG/lldpctl] connect to lldpd 1970-01-01T00:25:43 [ DBG/main] set system capabilities 1970-01-01T00:25:43 [ DBG/main] initialize protocols 1970-01-01T00:25:43 [INFO/main] protocol LLDP enabled 1970-01-01T00:25:43 [ DBG/main] start main loop 1970-01-01T00:25:43 [ DBG/event] initialize libevent 1970-01-01T00:25:43 [INFO/event] libevent 2.1.12-stable initialized with epoll method 1970-01-01T00:25:43 [ DBG/event] register loop timer 1970-01-01T00:25:43 [ DBG/event] register Unix socket 1970-01-01T00:25:43 [ DBG/event] monitor the monitor process 1970-01-01T00:25:43 [ DBG/event] register signals 1970-01-01T00:25:43 [ DBG/loop] start new loop 1970-01-01T00:25:43 [ DBG/loop] update information for local ports 1970-01-01T00:25:43 [ DBG/localchassis] update information for local ports 1970-01-01T00:25:43 [ DBG/netlink] initialize netlink subsystem 1970-01-01T00:25:43 [ DBG/netlink] listening on interface changes 1970-01-01T00:25:43 [ DBG/netlink] opening netlink sockets / # ls -l /var/run/lldpd/lldpd.socket srwxrwx--- 1 _lldpd _lldpd 0 Jan 1 00:25 /var/run/lldpd/lldpd.socket adduser admin _lldpd 如何解决,lldpd启动卡主,当前账号admin
最新发布
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值