static int __init usb_init(void)
{
...
retval = usbfs_init();
if (retval)
goto fs_init_failed;
...
}
int __init usbfs_init(void)
{
int retval;
retval = register_filesystem(&usb_fs_type);
//定义在fs/filesystems.c中
//在读写锁file_systems_lock的保护下,遍历file_systems,比对usb_fs_type的name "usbfs"和file_systems指向的struct file_system_type的name
//如果匹配,则返回-EBUSY; 如果不匹配,则沿着file_systems指向的struct file_system_type的next继续比对,如果next为null,跳出比对,并将要注册的usb_fs_type
//地址插入到当前next域
//整个过程是将usb_fs_type添加到file_systems指向的结构体struct file_system_type中
if (retval)
return retval;
usb_register_notify(&usbfs_nb);
//注册通知块,将usbfs_nb添加到usb_notifier_list中
//可以处理USB_DEVICE_ADD,USB_DEVICE_REMOVE,USB_BUS_ADD,USB_BUS_REMOVE四种行为
/* create mount point for usbfs */
usbdir = proc_mkdir("bus/usb", NULL);
return 0;
}
//举例添加母线
static void usbfs_add_bus(struct usb_bus *bus)
{
struct dentry *parent;
char name[8];
int retval;
/* create the special files if this is the first bus added
usbcore之usbfs_init
最新推荐文章于 2024-08-13 10:31:26 发布
本文介绍了USB内核模块的初始化过程,包括`usbfs_init`函数的执行步骤,如何注册文件系统,创建挂载点,以及如何添加USB总线。通过`usbfs_add_bus`函数,当有新的USB总线加入时,会在`/dev/bus/usb`下创建相应的目录,每个目录下有对应设备的字符设备文件。这些设备文件的操作与`usbdev_file_operations`结构体关联。

最低0.47元/天 解锁文章
755

被折叠的 条评论
为什么被折叠?



