usbfs文件系统

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是如何在文件系统体现的?


关于usb流程图:https://www.cnblogs.com/tureno/articles/6286372.html



  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值