本文主要是对从U盘插入电脑后,驱动是咋样加载识别流程

先从device_register开始,这个函数在哪里调用的以后再分析

/**
 * 往设备驱动程序模型中插入一个新的设备驱动。
 * 并自动的在sysfs文件系统下为其创建一个新的目录
 */

//drivers\base\Core.c

int device_register(struct device *dev)
{
device_initialize(dev);
return device_add(dev);
}

int device_add(struct device *dev)
{
struct device *parent = NULL;
int error = -EINVAL;

dev = get_device(dev);
if (!dev || !strlen(dev->bus_id))
goto Error;

parent = get_device(dev->parent);

pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id);

/* first, register with generic layer. */
kobject_set_name(&dev->kobj, "%s", dev->bus_id);
if (parent)
dev->kobj.parent = &parent->kobj;

if ((error = kobject_add(&dev->kobj)))
goto Error;
if ((error = device_pm_add(dev)))
goto PMError;
if ((error = bus_add_device(dev)))
goto BusError;
down_write(&devices_subsys.rwsem);
if (parent)
list_add_tail(&dev->node, &parent->children);
up_write(&devices_subsys.rwsem);

/* notify platform of device entry */
if (platform_notify)
platform_notify(dev);
 Done:
put_device(dev);
return error;
 BusError:
device_pm_remove(dev);
 PMError:
kobject_del(&dev->kobj);
 Error:
if (parent)
put_device(parent);
goto Done;
}

int bus_add_device(struct device * dev)
{
struct bus_type * bus = get_bus(dev->bus);
int error = 0;

if (bus) {
down_write(&dev->bus->subsys.rwsem);
pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
list_add_tail(&dev->bus_list, &dev->bus->devices.list);
device_attach(dev);
up_write(&dev->bus->subsys.rwsem);
device_add_attrs(bus, dev);
sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
}
return error;
}

int device_attach(struct device * dev)
{
  struct bus_type * bus = dev->bus;
struct list_head * entry;
int error;

if (dev->driver) {
device_bind_driver(dev);
return 1;
}

if (bus->match) {
list_for_each(entry, &bus->drivers.list) {
struct device_driver * drv = to_drv(entry);
error = driver_probe_device(drv, dev);
if (!error)
/* success, driver matched */
return 1;
if (error != -ENODEV && error != -ENXIO)
/* driver matched but the probe failed */
printk(KERN_WARNING
   "%s: probe of %s failed with error %d\n",
   drv->name, dev->bus_id, error);
}
}

return 0;
}

int driver_probe_device(struct device_driver * drv, struct device * dev)
{
if (drv->bus->match && !drv->bus->match(dev, drv))
return -ENODEV;

dev->driver = drv;
if (drv->probe) {
int error = drv->probe(dev);
if (error) {
dev->driver = NULL;
return error;
}
}

device_bind_driver(dev);
return 0;
}

u盘驱动 内核代码阅读 2.6.11.12版本相关推荐

  1. 基因驱动 CovEx 代码阅读(一)

    CovEx 源代码 https://sourceforge.net/projects/cancer-pathway/ 首先重点阅读 README1.txt 一步一步执行 安装 Gurobi Optim ...

  2. intel IOMMU内核代码阅读笔记

    内核中有若干个iommu的模块,通过IOMMU_INIT组成成一个依赖树.detect_intel_iommu最先被调用,它被用来做sanity检查并设置好 x86_init.iommu.iommu_ ...

  3. 将vim打造成代码阅读利器(for mac and ubuntu)

    需要用到的工具: NERDTree Cscope ctags vundle homebrew(for mac) 目录: 文章目录 linux内核代码阅读神技 软件介绍 NERDTree Cscope ...

  4. Ubuntu14.04搭建LXR本地服务器阅读Linux内核代码

    CSDN GitHub Ubuntu14.04搭建LXR本地服务器阅读Linux内核代码 AderXCoding/system/tools/lxr 本作品采用知识共享署名-非商业性使用-相同方式共享 ...

  5. linux 内核编号含义_如何阅读linux内核代码?

    阅读代码从来就是不可行的方法,有篇文章详细讲了这个事,很多人都觉得应该多读代码, 读好的代码,比如Donald Knuth. 但事实上, 只要简单让你描述一下最近读了什么代码,绝大多数人都说不上.文章 ...

  6. 最小的linux内核代码,带你阅读linux内核源码:下载源码、编译内核并运行一个最小系统...

    要学习linux内核,先要能够编译内核,还需要了解内核如何启动根文件系统.这样你才能在修改linux内核代码之后,完成验证的过程. 本文教你完成下列过程: 1.下载linux并编译linux内核源码 ...

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

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

  8. [Linux] USB-Storage驱动 源码阅读笔记(一)

    USB-Storage驱动 源码阅读笔记--从USB子系统开始 最近在研究U盘的驱动,遇到很多难以理解的问题,虽然之前也参考过一些很不错的书籍如:<USB那些事>,但最终还是觉得下载一份最 ...

  9. 代码阅读工具学习总结

    代码阅读工具:Source Navigator和Source Insight 一.Source Insight实用技巧: Source Insight(下文的SI指的也是它)就是这样的一个东西: Wi ...

最新文章

  1. 本硕非科班,单模型获得亚军!
  2. 实验室蒋田仔研究员:脑网络组图谱近10年研究详解【附PPT】
  3. seo说_百度指数看世间沉浮_如何快速排名-互点快速排名_网站关键词排名常见问题 - 搜狗快速排名...
  4. C#中的接口 (转自吕振宇老师的blog)
  5. try...catch...finally java
  6. DWG TrueView 2010 下载地址
  7. MAC 下用GCC编译报错:“Undefined symbols for architecture x86_64: ”
  8. linux修改resolv自动清除,centos 6.2的/etc/resolv.conf自动清空问题
  9. 火狐浏览器读取ukey_火狐 83版引入HTTPS-Only模式 确保访问安全连接
  10. 百度关键词模拟发包php程序,仿百度的关键词匹配搜索示例
  11. 【编程之路(008)操作符详解】(C语言实现)
  12. Go语言泛型工具go2go
  13. 北京国家会计学院聂兴凯:用友BIP事项会计助力企业迈入智能会计时代
  14. linux多线程编程--学习笔迹4
  15. 机器人仿生控制方法研究
  16. 4g物联网卡赋能智能设备 加快社会智能化进程
  17. 女生初级健身训练计划
  18. linux 3.10在mini210s上移植----01. tftp安装
  19. 魅蓝note2android8,魅蓝Note2支持扩展储存卡吗?支持多大的储存卡?
  20. Compressing Wav file to MP3(代码实现:将Wav格式压缩成Mp3 )

热门文章

  1. Spring Security太复杂?试试这个轻量、强大、优雅的权限认证框架!
  2. Java 17 将至,可能带来哪些新特性呢?
  3. Java 中商业运算必备的精确运算类:BigDecimal
  4. Metaspace 引起的 FullGC 问题排查过程及解决方案
  5. 自律到极致-人生才精致「第6期」:领奖通知
  6. 程序员如何解决工作中的技术问题?
  7. 【SpringCloud】Ribbon-实例
  8. c++ 导入caffe
  9. 彻底卸载VS 2013
  10. android操作ui线程