usb_register(&usbfs_driver)、usb_devio_init()、usbfs_init()都是usbfs相关的初始化。usbfs为咱们提供了在用户空间直接访问usb硬件设备的接口,但它需要内核的大力支持,usbfs_driver就是用来完成这个光荣任务的。

1. usbfs简介:

2. usbfs驱动

retval = usb_register(&usbfs_driver); //usbfs驱动注册
struct usb_driver usbfs_driver = {
.name = "usbfs", //usbfs驱动名称
.probe = driver_probe, //探测函数
.disconnect = driver_disconnect,
.suspend = driver_suspend, //设备挂起
.resume = driver_resume, //设备恢复
};

关于usbfs文件系统的使用我是没有搞清楚,后续在了解...!!!!!


3. usb设备io初始化

retval = usb_devio_init();
int __init usb_devio_init(void)
{
int retval;

retval = register_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX, //注册字符设备“usb_device”
"usb_device");
if (retval) {
printk(KERN_ERR "Unable to register minors for usb_device\n");
goto out;
}
cdev_init(&usb_device_cdev, &usbdev_file_operations);
retval = cdev_add(&usb_device_cdev, USB_DEVICE_DEV, USB_DEVICE_MAX);
if (retval) {
printk(KERN_ERR "Unable to get usb_device major %d\n",
USB_DEVICE_MAJOR);
goto error_cdev;
}
usb_register_notify(&usbdev_nb); //注册通知链
out:
return retval;

error_cdev:
unregister_chrdev_region(USB_DEVICE_DEV, USB_DEVICE_MAX);
goto out;
}
const struct file_operations usbdev_file_operations = {
.owner = THIS_MODULE,
.llseek = usbdev_lseek,
.read = usbdev_read,
.poll = usbdev_poll,
.unlocked_ioctl = usbdev_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = usbdev_compat_ioctl,
#endif
.open = usbdev_open,
.release = usbdev_release,
};
static struct notifier_block usbdev_nb = {
.notifier_call = usbdev_notify,
};

这里先贴出源码,源码内容很容易理解,我这里有个疑问,这里创建的usbfs、usbdevio_init是如何在文件系统体现的?