Lnux2.6内核udev机制(基于2.6.26

Lnux2.6内核udev机制(基于2.6.26

作者:guolele1990                                               2011112

         最近在研究输入子系统时关于应用层与handler层时有点迷惑,查找了很多资料,发现是设备节点问题,于是看起udev(嵌入式中的是mdev)机制,下面是这个机制的分析。

首先我们知道udev或者mdev都是应用程序,他们的作用就是起自动创建节点作用,这点是必须清楚,也就是它是工作在用户空间的,但是我们设备驱动,无论是event handler层还是driver 层都是工作在内核空间的,那么内核是怎样处理的?其实内核就是利用kobject_uevent来将这件事报告给用户空间,用户空间再调用相应程序(udevmdev)来创建设备文件(或叫设备节点)。

下面分析kobject_uevent,老风格,先上内核描述

/**

 * kobject_uevent - notify userspace by ending an uevent

 *

 * @action: action that is happening

 * @kobj: struct kobject that the action is happening to

 *

 * Returns 0 if kobject_uevent() is completed with success or the

 * corresponding error when it fails.

 */

这里就是说这函数是通过结束一个uevent来给用户空间报告,不过感觉翻译不对头,因为后面分析这不是结束这uevent,而是最终调用指定的uevent_helper或者是通过netlink发出这是一种特殊类型的socket,专门用于内核空间与用户空间的异步通信,比较有效率,就是通过网络发送通知)去。这函数就是kobject_uevent_env的包装。

kobject_uevent_env描述,更清楚

/**

 * kobject_uevent_env - send an uevent with environmental data

 *

 * @action: action that is happening

 * @kobj: struct kobject that the action is happening to

 * @envp_ext: pointer to environmental data

 *

 * Returns 0 if kobject_uevent() is completed with success or the

 * corresponding error when it fails.

 */

它的作用就是发送一个有参数的uevent到用户空间。

call_usermodehelper,里setup就是将一些信息放在struct subprocess_info结构里,方便调用call_usermodehelper_exec,关于这函数,上一描述

/**

 * call_usermodehelper_exec - start a usermode application

 * @sub_info: information about the subprocessa

 * @wait: wait for the application to finish and return status.

 *        when -1 don't wait at all, but you get no useful error back when

 *        the program couldn't be exec'ed. This makes it safe to call

 *        from interrupt context.

 *

 * Runs a user-space application.  The application is started

 * asynchronously if wait is not set, and runs as a child of keventd.

 * (ie. it runs with full root capabilities).

 */

这函数的就是调用用户模式的应用程序,也就是调用mdev或者udev.其中udevmdev是内核通过vfork创建一个进程执行的。具体是汇编,比较难懂。

  

还有几个具体也不分析了,大概了解一下它的主要流程就好了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值