/**************************************************************************
* MDEV Primer
* 说明:
* 本文内容来自busybox的文档,以前一直想搞清楚热插拔的本质是什么,
* 设备节点是怎么创建,权限该如何给,如何存储设备是如何挂载的,等等信息。
*
* 2016-1-15 深圳 南山平山村 曾剑锋
*************************************************************************/ -------------
MDEV Primer
------------- For those of us who know how to use mdev, a primer might seem lame. For
everyone else, mdev is a weird black box that they hear is awesome, but can't
seem to get their head around how it works. Thus, a primer.
对于那些知道怎么使用mdev的人来说,这篇文章显得是多余的。对于其他的人来说,
像一个黑夹子,不知道她是怎么工作的,根本没有头绪。这就是这份文档的意义所在:
基础教程。 -----------
Basic Use
----------- Mdev has two primary uses: initial population and dynamic updates. Both
require sysfs support in the kernel and have it mounted at /sys. For dynamic
updates, you also need to have hotplugging enabled in your kernel.
Mdev有两个基本功能:全局初始化和动态更新。这两个都需要内核中的sysfs文件系统
的支持,并且其被挂载在/sys目录下。对于动态更新,需要在内核中开启热插拔的功能。 Here's a typical code snippet from the init script:
下面是典型的初始化脚本:
[] mount -t proc proc /proc
[] mount -t sysfs sysfs /sys
[] echo /sbin/mdev > /proc/sys/kernel/hotplug
[] mdev -s Alternatively, without procfs the above becomes:
当然在没有procfs的情况下,你也可以使用下面的形式。
[] mount -t sysfs sysfs /sys
[] sysctl -w kernel.hotplug=/sbin/mdev
[] mdev -s Of course, a more "full" setup would entail executing this before the previous
code snippet:
当然,如果你想要一个更加全面的设置如下,那么在前面的代码执行之前,你可以加入
以下的内容。
[] mount -t tmpfs -o size=64k,mode= tmpfs /dev
[] mkdir /dev/pts
[] mount -t devpts devpts /dev/pts The simple explanation here is that [] you need to have /sys mounted before
executing mdev. Then you [] instruct the kernel to execute /sbin/mdev whenever
a device is added or removed so that the device node can be created or
destroyed. Then you [] seed /dev with all the device nodes that were created
while the system was booting.
综上所述:
. 首先在执行mdev之前,你需要挂在sysfs文件系统挂在在/sys目录;
. 接下来指定执行/sbin/mdev无论什么时候设备插入、拔除,设备节点
都能够被创建或者销毁;
. 当系统跑起来之后,你可以在/dev下看到设备节点是否被创建。 For the "full" setup, you want to [] make sure /dev is a tmpfs filesystem
(assuming you're running out of flash). Then you want to [5] create the
/dev/pts mount point and finally [] mount the devpts filesystem on it.
对于完整的设置,你需要确认/dev下是一个tmpfs文件系统。同时你想要创建
/dev/pts挂载点,并将devpts文件系统挂在在上面。 -------------
MDEV Config (/etc/mdev.conf)
------------- Mdev has an optional config file for controlling ownership/permissions of
device nodes if your system needs something more than the default root/root
permissions.
当系统需要除了默认的root/root 666的用户、分组、权限之外,Mdev有一个
操作配置文件用于设置设备节点的用户、分组、权限。 The file has the format:
文件格式如下:
[-][envmatch]<device regex> <uid>:<gid> <permissions>
or
[envmatch]@<maj[,min1[-min2]]> <uid>:<gid> <permissions>
or
$envvar=<regex> <uid>:<gid> <permissions> For example:
hd[a-z][-]* : The config file parsing stops at the first matching line. If no line is
matched, then the default of : is used. To set your own default, simply
create your own total match like so:
从前往后,最先匹配的到的那一行有效,之后系统会停止解析配置文件。
如果最新的设备节点与配置文件中没有一行匹配,那么使用默认的值0: 。
对于设置自己的默认值,只需要简简单单的加入如下配置就行了。 .* : You can rename/move device nodes by using the next optional field.
你可以重命名/移动设备节点通过如下的操作域。 <device regex> <uid>:<gid> <permissions> [=path] So if you want to place the device node into a subdirectory, make sure the path
has a trailing /. If you want to rename the device node, just place the name.
这样如果你想要将一个设备节点放入子目录下,确保目录后面有一个"/"尾巴,
如果你想要重命名设备节点,仅仅需要写上名字就行了。
hda : =drives/
This will move "hda" into the drives/ subdirectory.
将"hda"设备节点放入"drives/"目录下。
hdb : =cdrom
This will rename "hdb" to "cdrom".
将"hdb"设备节点改名为"cdrom"。 Similarly, ">path" renames/moves the device but it also creates
a direct symlink /dev/DEVNAME to the renamed/moved device.
类似,">path"重命名、移动设备节点,也同时在/dev下创建一个软链
接到设备节点上。 For example:
---<---
# block devices
([hs]d[a-z]) root:disk >disk/%/
([hs]d[a-z])([-]+) root:disk >disk/%/%
mmcblk([-]+) root:disk >disk/mmc/%/
mmcblk([-]+)p([-]+) root:disk >disk/mmc/%/%
# network devices
(tun|tap) root:network >net/%
---<--- You can also prevent creation of device nodes with the 4th field as "!":
也可以防止创建设备节点使用第四个域的值:"!"
tty[a-z]. : !
pty[a-z]. : ! If you also enable support for executing your own commands, then the file has
the format:
如果你想当设备节点生成的时候执行你自己安排的命令,格式如下:
<device regex> <uid>:<gid> <permissions> [=path] [@|$|*<command>]
or
<device regex> <uid>:<gid> <permissions> [>path] [@|$|*<command>]
or
<device regex> <uid>:<gid> <permissions> [!] [@|$|*<command>] The special characters have the meaning:
@ Run after creating the device.
$ Run before removing the device.
* Run both after creating and before removing the device.
上面特殊的字符的意义如下:
@ 运行于设备节点创建之后。
$ 运行于删除设备节点之前。
* 运行于创建设备节点之后、删除设备节点之前。 The command is executed via the system() function (which means you're giving a
command to the shell), so make sure you have a shell installed at /bin/sh. You
should also keep in mind that the kernel executes hotplug helpers with stdin,
stdout, and stderr connected to /dev/null.
这些命令是通过system()函数执行的(这也就意味着是shell命令),所以请确认你
系统中有"/bin/sh"。同时在心里一定要记住热插拔的标准输入、标准输出、标准错误
都被重定向到"/dev/null"。 For your convenience, the shell env var $MDEV is set to the device name. So if
the device "hdc" was matched, MDEV would be set to "hdc".
为了方便使用,shell的环境变量$MDEV被设置为设备名,如果设备"hdc"匹配上了,
MDEV将被设置为"hdc"。 ----------
FIRMWARE
---------- Some kernel device drivers need to request firmware at runtime in order to
properly initialize a device. Place all such firmware files into the
/lib/firmware/ directory. At runtime, the kernel will invoke mdev with the
filename of the firmware which mdev will load out of /lib/firmware/ and into
the kernel via the sysfs interface. The exact filename is hardcoded in the
kernel, so look there if you need to know how to name the file in userspace.
一些内核设备驱动在运行时为了更好的初始化设备需要加载固件。将固件文件放入
"/lib/firmware"目录下,在运行时,内核将通过固件的名字激活mdev,mdev将
通过sysfs系统接口加载固件到内核,在内核中抽取的文件是硬编码,所以看
一下你是否需要知道怎么在用户空间命名。 ------------
SEQUENCING
------------ Kernel does not serialize hotplug events. It increments SEQNUM environmental
variable for each successive hotplug invocation. Normally, mdev doesn't care.
This may reorder hotplug and hot-unplug events, with typical symptoms of
device nodes sometimes not created as expected. However, if /dev/mdev.seq file is found, mdev will compare its
contents with SEQNUM. It will retry up to two seconds, waiting for them
to match. If they match exactly (not even trailing '\n' is allowed),
or if two seconds pass, mdev runs as usual, then it rewrites /dev/mdev.seq
with SEQNUM+. IOW: this will serialize concurrent mdev invocations. If you want to activate this feature, execute "echo >/dev/mdev.seq" prior to
setting mdev to be the hotplug handler. This writes single '\n' to the file.
NB: mdev recognizes /dev/mdev.seq consisting of single '\n' character
as a special case. IOW: this will not make your first hotplug event
to stall for two seconds. Example(https://git.busybox.net/busybox/tree/examples/mdev.conf):
# Note: the first field is a regex matcher
# Syntax: %s %d:%d %s
# devices user:group mode null :
zero :
grsec : urandom : console :
fd0 :
hdc :
kmem :
mem :
port :
ptmx : sda[-] :
sdb[-] :
hda[-] : ttyS[-] :
tty[-] :
tty.+ :

MDEV Primer的更多相关文章

  1. mdev USB disk auto mount demo

    /********************************************************************* * mdev USB disk auto mount de ...

  2. 关于热插拔usb hotplug /proc/sys/kernel mdev udev b...

    转:http://www.360doc.com/content/10/0527/18/9922_29835045.shtml 这篇文章说的很好http://blog.chinaunix.net/u1/ ...

  3. linux中的热插拔和mdev机制

    mdev手册(自己翻译的留着看) mdev实现U盘或SD卡的自动挂载 mdev的使用以及mdev.conf的规则配置--busybox linux中的热插拔和mdev机制 关于实现udev/mdev自 ...

  4. Linux设备模型(热插拔、mdev 与 firmware)【转】

    转自:http://www.cnblogs.com/hnrainll/archive/2011/06/10/2077469.html 转自:http://blog.chinaunix.net/spac ...

  5. C Primer Plus 学习体会

    本月刚刚开始学习<C primer plus>,之前课上草草学过一遍,讲到指针就结束了.现在重新开始看感觉难度不大只是刚开始接触有些语言细节比较琐碎.学习这一周的体会如下: 诸多前辈推荐的 ...

  6. C++ Primer Plus 第六版笔记

    C++ Primer Plus 第六版笔记 关于对象声明的思考 转自:http://www.cnblogs.com/weiqubo/archive/2009/11/02/1930042.html C+ ...

  7. 《3D Math Primer for Graphics and Game Development》读书笔记2

    <3D Math Primer for Graphics and Game Development>读书笔记2 上一篇得到了"矩阵等价于变换后的基向量"这一结论. 本篇 ...

  8. 《3D Math Primer for Graphics and Game Development》读书笔记1

    <3D Math Primer for Graphics and Game Development>读书笔记1 本文是<3D Math Primer for Graphics and ...

  9. 再读《C++ Primer》——变量和基本类型

    刚上大学那时,几个室友一块买了本<C++ Primer>第4版,看了一遍后就没怎么碰了,偶尔拿出来翻翻,当作工具书使用.后来知道有第5版了,一直觉得内容差不多吧.直到最近,再读其中的一些内 ...

随机推荐

  1. 完整实例(C# Socket)

    问题描述:          现在创建一个C# Socket实例,客户端断开服务器能立刻输出断开连接客户端信息 服务器端断开,客户端能立刻察觉服务器状态 问题解决: 服务器端代码: 客户端代码: 以上 ...

  2. WinForm员工信息表

    先搞一个panel,然后里面放label.

  3. oracle RAC--归档日志的开启方法

    oracle RAC--归档日志的开启方法 2011-10-07 15:53:04 分类: Oracle oracle RAC--归档日志的开启方法   ======================= ...

  4. HDOJ-1999 不可摸数

    不可摸数 转自:http://www.cnblogs.com/dongsheng/archive/2012/08/18/2645594.html Time Limit: 2000/1000 MS (J ...

  5. 关于ios 8 7 下的模态窗口大小的控制 代碼+場景(mainstoryboard)( Resizing UIModalPresentationFormSheet )

    1 代碼 UIViewController* modalController = [[UIViewController alloc]init];modalController.modalTransit ...

  6. cojs 自己出的题目 解题报告

    省选成功成为河北B队队长QAQ 真是忧桑 所以在cojs上出了一套鬼畜的关于树的套题 黑白树: 我们先不考虑R操作 设x是u的祖先,那么fa(x)的贡献显然是 fa(x)*(sz(fa(x))-sz( ...

  7. lintcode:插入区间

    题目: 插入区间 给出一个无重叠的按照区间起始端点排序的区间列表. 在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间). 样例 插入区间[2, 5] 到 [ ...

  8. Eclipse:快捷

    Ctrl +单击方法------------查看方法 ALT+/    -------------代码助手 Ctrl+O   -------------列出方法和成员变量或布局结构 Ctrl+D   ...

  9. 开源入侵检测系统OSSEC搭建之一:服务端安装

    OSSEC是一款开源的多平台的入侵检测系统,可以运行于Windows, Linux, OpenBSD/FreeBSD, 以及 MacOS等操作系统中.主要功能有日志分析.完整性检查.rootkit检测 ...

  10. SQL效率问题

    关于in和or的效率对比:http://blog.chinaunix.net/uid-20639775-id-3416737.html 在没有索引的情况下,in的效率高 SQL语句效率:http:// ...