U盘使用的是drivers/usb/storage/usb.c驱动

#define DRV_NAME "usb-storage"
//插入U盘时一般会打印usb-storage 1-1:1.0: USB Mass Storage device detected
static struct usb_driver usb_storage_driver = {.name =        DRV_NAME,.probe =  storage_probe,.disconnect =    usb_stor_disconnect,.suspend = usb_stor_suspend,.resume = usb_stor_resume,.reset_resume =    usb_stor_reset_resume,.pre_reset = usb_stor_pre_reset,.post_reset =   usb_stor_post_reset,.id_table =    usb_storage_usb_ids,.supports_autosuspend = 1,.soft_unbind =  1,
};
module_usb_stor_driver(usb_storage_driver, usb_stor_host_template, DRV_NAME);
/* The main probe routine for standard devices */
static int storage_probe(struct usb_interface *intf,const struct usb_device_id *id)
{struct us_unusual_dev *unusual_dev;struct us_data *us;int result;int size;/* If uas is enabled and this device can do uas then ignore it. */
#if IS_ENABLED(CONFIG_USB_UAS)if (uas_use_uas_driver(intf, id, NULL))return -ENXIO;
#endif/** If the device isn't standard (is handled by a subdriver* module) then don't accept it.*/if (usb_usual_ignore_device(intf)) //检测匹配return -ENXIO;/** Call the general probe procedures.** The unusual_dev_list array is parallel to the usb_storage_usb_ids* table, so we use the index of the id entry to find the* corresponding unusual_devs entry.*/size = ARRAY_SIZE(us_unusual_dev_list);if (id >= usb_storage_usb_ids && id < usb_storage_usb_ids + size) {unusual_dev = (id - usb_storage_usb_ids) + us_unusual_dev_list;} else {unusual_dev = &for_dynamic_ids;dev_dbg(&intf->dev, "Use Bulk-Only transport with the Transparent SCSI protocol for dynamic id: 0x%04x 0x%04x\n",id->idVendor, id->idProduct);}result = usb_stor_probe1(&us, intf, id, unusual_dev,&usb_stor_host_template);//probe的第一部分if (result)return result;/* No special transport or protocol settings in the main module */result = usb_stor_probe2(us);//probe的第二部分return result;
}/* First part of general USB mass-storage probing */
int usb_stor_probe1(struct us_data **pus,struct usb_interface *intf,const struct usb_device_id *id,struct us_unusual_dev *unusual_dev,struct scsi_host_template *sht)
{struct Scsi_Host *host;struct us_data *us;int result;dev_info(&intf->dev, "USB Mass Storage device detected\n");/** Ask the SCSI layer to allocate a host structure, with extra* space at the end for our private us_data structure.*/host = scsi_host_alloc(sht, sizeof(*us));//分配Scsi_Host结构体if (!host) {dev_warn(&intf->dev, "Unable to allocate the scsi host\n");return -ENOMEM;}/** Allow 16-byte CDBs and thus > 2TB*/host->max_cmd_len = 16;host->sg_tablesize = usb_stor_sg_tablesize(intf);*pus = us = host_to_us(host);//从host结构体中提取出us_data结构体mutex_init(&(us->dev_mutex));us_set_lock_class(&us->dev_mutex, intf);init_completion(&us->cmnd_ready);//初始化完成量init_completion(&(us->notify));init_waitqueue_head(&us->delay_wait);//初始化等待队列头INIT_DELAYED_WORK(&us->scan_dwork, usb_stor_scan_dwork);/* Associate the us_data structure with the USB device */result = associate_dev(us, intf);//将us_data与USB设备相关联if (result)goto BadDevice;/* Get the unusual_devs entries and the descriptors */result = get_device_info(us, id, unusual_dev);//获取设备信息if (result)goto BadDevice;/* Get standard transport and protocol settings */get_transport(us);//获取传输方式get_protocol(us);//获取传输协议/** Give the caller a chance to fill in specialized transport* or protocol settings.*/return 0;BadDevice:usb_stor_dbg(us, "storage_probe() failed\n");release_everything(us);return result;
}/* Second part of general USB mass-storage probing */
int usb_stor_probe2(struct us_data *us)
{int result;struct device *dev = &us->pusb_intf->dev;/* Make sure the transport and protocol have both been set */if (!us->transport || !us->proto_handler) {result = -ENXIO;goto BadDevice;}usb_stor_dbg(us, "Transport: %s\n", us->transport_name);usb_stor_dbg(us, "Protocol: %s\n", us->protocol_name);if (us->fflags & US_FL_SCM_MULT_TARG) {/** SCM eUSCSI bridge devices can have different numbers* of LUNs on different targets; allow all to be probed.*/us->max_lun = 7;/* The eUSCSI itself has ID 7, so avoid scanning that */us_to_host(us)->this_id = 7;/* max_id is 8 initially, so no need to set it here */} else {/* In the normal case there is only a single target */us_to_host(us)->max_id = 1;/** Like Windows, we won't store the LUN bits in CDB[1] for* SCSI-2 devices using the Bulk-Only transport (even though* this violates the SCSI spec).*/if (us->transport == usb_stor_Bulk_transport)us_to_host(us)->no_scsi2_lun_in_cdb = 1;}/* fix for single-lun devices */if (us->fflags & US_FL_SINGLE_LUN)us->max_lun = 0;/* Find the endpoints and calculate pipe values */result = get_pipes(us);//获得管道if (result)goto BadDevice;/** If the device returns invalid data for the first READ(10)* command, indicate the command should be retried.*/if (us->fflags & US_FL_INITIAL_READ10)set_bit(US_FLIDX_REDO_READ10, &us->dflags);/* Acquire all the other resources and add the host */result = usb_stor_acquire_resources(us);//获取资源if (result)goto BadDevice;usb_autopm_get_interface_no_resume(us->pusb_intf);snprintf(us->scsi_name, sizeof(us->scsi_name), "usb-storage %s",dev_name(&us->pusb_intf->dev));result = scsi_add_host(us_to_host(us), dev);//添加scsiif (result) {dev_warn(dev,"Unable to add the scsi host\n");goto HostAddErr;}/* Submit the delayed_work for SCSI-device scanning */set_bit(US_FLIDX_SCAN_PENDING, &us->dflags);if (delay_use > 0) //delay_use秒后如果U盘没拔出则继续执行,否则执行disconnectdev_dbg(dev, "waiting for device to settle before scanning\n");queue_delayed_work(system_freezable_wq, &us->scan_dwork,delay_use * HZ);return 0;/* We come here if there are any problems */
HostAddErr:usb_autopm_put_interface_no_suspend(us->pusb_intf);
BadDevice:usb_stor_dbg(us, "storage_probe() failed\n");release_everything(us);return result;
}

U盘驱动程序大概就是如此,其中probe1和probe2中还设计很多细节的内容,比如端点设置、urb控制等内容,这些内容和USB协议有很大关系,过于晦涩,所以暂时不做进一步研究。

USB驱动之U盘驱动相关推荐

  1. 爱国者u盘linux驱动,爱国者u盘驱动下载-aigo爱国者u盘驱动下载电脑版-121软件园...

    爱国者u盘驱动程序是aigo为旗下u盘开发打造的驱动软件,可以帮助使用爱国者u盘的用户更好的利用u盘,内容齐全,功能强大,在许多操作系统上都能使用.对这个感兴趣的话就快来下载使用吧,还有更多精彩的内容 ...

  2. linux设备驱动子系统,Linux设备驱动子系统终极弹 - USB

    0. 预备理论 1. USB Core 2. USB Hub 3. USB OTG 4. USB Host 5. USB Gadget 6. USB Mass Storage USB博大精深,不是一两 ...

  3. *Linux下的USB总线驱动 u盘驱动分析*

    Linux下的USB总线驱动(三) u盘驱动分析 版权所有,转载请说明转自 http://my.csdn.net/weiqing1981127 https://www.xuebuyuan.com/13 ...

  4. USB虚拟总线驱动开发扩展之(利用虚拟USB总线驱动实现U盘模拟)

    by fanxiushu 2020-03-25 转载或引用请注明原始作者. USB虚拟总线驱动的使用范围是非常广泛的,可以使用它来模拟各种通用的USB设备. 以前的文章阐述过基于windows平台和基 ...

  5. USB驱动移植(u盘)

    内核里已经做好了很完善的 USB驱动了,可以支持大多数 USB 设备,我的板子 使用了 USB HUB,扩展出四个 USB,内核里也有对 USB HUB的支持,可直接使用. 1.  配置内核,支持 U ...

  6. Linux下的USB总线驱动(三) u盘驱动分析

    版权所有,转载请说明转自 http://my.csdn.net/weiqing1981127 4.U盘驱动分析 USB Mass Storage是一类USB存储设备,这些设备包括USB磁盘.USB硬盘 ...

  7. Linux设备驱动开发---USB主机(控制器)与设备驱动(一)

    USB主机控制器与设备驱动---主机侧 一.Linux USB驱动层次 1.USB驱动(主机侧) 2.USB的逻辑组合(4个层次) 二.USB主机(控制器)驱动 1.主机控制器规格 2.主机控制器的相 ...

  8. NuttX U盘驱动

    (嵌入式 实时操作系统 rtos nuttx 7.18 stm32 源代码分析) NuttX U盘驱动 转载请注明出处: http://blog.csdn.net/zhumaill/article/d ...

  9. 对于禁止U盘驱动的安装如何解除?

    http://wenba.enet.com.cn/problem/4823.shtml 1. 禁用主板usb设备. 管理员在CMOS设置里将USB设备禁用,并且设置BIOS密码,这样U盘插到电脑上以后 ...

  10. DOS下安装U盘驱动

    DOS下安装U盘驱动 摘自([url]http://bbs.macd.cn/thread-546331-1-1.html[/url]) 绝大多数情况下我们都在Windows下使用闪盘等USB设备,那么 ...

最新文章

  1. 微软10月起将向安全厂商提前告知安全补丁内容
  2. 利用神经网络 遗传算法求得函数极小极大值
  3. Mycat高可用集群搭建
  4. linux双机热备 oracle,oracle for linux双机热备实战
  5. C++中的重难点看这一篇就够了
  6. 公共链接url出错_SEO优化技巧:关于URL的优化方法
  7. 【机器学习】K-Means(非监督学习)学习及实例使用其将图片压缩
  8. 指令系统——数据寻址(3)——堆栈寻址(详解)
  9. form提交后台注解拿不到数据_浏览器是如何将用户数据发送到服务器的?
  10. Python 3.X 调用多线程C模块,并在C模块中回调python函数的示例
  11. Jupyter notebook 转 pdf [完整转换]
  12. linux 改变文本模分辨率
  13. 一维欧拉方程matlab代码,一维欧拉方程组的warming-beam差分求解
  14. 股票分时数据HTML,股票历史分时数据
  15. 新塘单片机烧写器_新唐MCU常用的工具软件
  16. Teams登录报错最全的解决方法ERROR CAA20002 caa70004
  17. 极路由3HC5861刷openwrt
  18. 程序中的地址转换(虚拟地址-物理地址)
  19. Linux下查看CPU核数
  20. HTML5 中的 input 元素的输入类型(type 属性的取值)

热门文章

  1. 格力董明珠还想再赌五年 雷军:可以试一下
  2. AI 编辑视频!这特效太逆天了!代码开源 SIGGRAPH Asia 2021
  3. java.io的缓冲流、转换流、序列化流
  4. android手游渠道接入业务+技术全讲解
  5. html是l面包屑效果,CSS制作面包屑
  6. C# 调用outlook 发送邮件
  7. windows操作系统未关闭默认共享
  8. 如何恢复Windows默认共享
  9. python卡方检验计算pvalue值_如何用python计算临界值(critical value)和p值(p value)(scipy)...
  10. 去除黄褐斑的方法,姬净美怎么样