MDEV Primer
/**************************************************************************
* 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的更多相关文章
- mdev USB disk auto mount demo
/********************************************************************* * mdev USB disk auto mount de ...
- 关于热插拔usb hotplug /proc/sys/kernel mdev udev b...
转:http://www.360doc.com/content/10/0527/18/9922_29835045.shtml 这篇文章说的很好http://blog.chinaunix.net/u1/ ...
- linux中的热插拔和mdev机制
mdev手册(自己翻译的留着看) mdev实现U盘或SD卡的自动挂载 mdev的使用以及mdev.conf的规则配置--busybox linux中的热插拔和mdev机制 关于实现udev/mdev自 ...
- Linux设备模型(热插拔、mdev 与 firmware)【转】
转自:http://www.cnblogs.com/hnrainll/archive/2011/06/10/2077469.html 转自:http://blog.chinaunix.net/spac ...
- C Primer Plus 学习体会
本月刚刚开始学习<C primer plus>,之前课上草草学过一遍,讲到指针就结束了.现在重新开始看感觉难度不大只是刚开始接触有些语言细节比较琐碎.学习这一周的体会如下: 诸多前辈推荐的 ...
- C++ Primer Plus 第六版笔记
C++ Primer Plus 第六版笔记 关于对象声明的思考 转自:http://www.cnblogs.com/weiqubo/archive/2009/11/02/1930042.html C+ ...
- 《3D Math Primer for Graphics and Game Development》读书笔记2
<3D Math Primer for Graphics and Game Development>读书笔记2 上一篇得到了"矩阵等价于变换后的基向量"这一结论. 本篇 ...
- 《3D Math Primer for Graphics and Game Development》读书笔记1
<3D Math Primer for Graphics and Game Development>读书笔记1 本文是<3D Math Primer for Graphics and ...
- 再读《C++ Primer》——变量和基本类型
刚上大学那时,几个室友一块买了本<C++ Primer>第4版,看了一遍后就没怎么碰了,偶尔拿出来翻翻,当作工具书使用.后来知道有第5版了,一直觉得内容差不多吧.直到最近,再读其中的一些内 ...
随机推荐
- AFNetworking VS ASIHTTPRequest
AFNetworking和ASIHTTPRequest,大致如下: 使用上:AFN是用上较ASI略简单,但扩展不如ASI;AFN能按普通的block写法直接用闭包的写法,但是ASI不行,这样ASI的代 ...
- sysconf和pathconf使用
问题描述: 查看系统运行时的限制值 问题解决: 执行效果: 源代码:
- 【转】欧拉回路&特殊图下的哈密顿回路题集
转自:http://blog.csdn.net/shahdza/article/details/7779385 欧拉回路[HDU]1878 欧拉回路 判断3018 Ant Trip 一笔画问题1116 ...
- cg 到hlsl的转换
http://msdn.microsoft.com/en-us/library/windows/desktop/ff471376(v=vs.85).aspx http://gamedev.stacke ...
- 01-04-03【Nhibernate (版本3.3.1.4000) 出入江湖】Criteria API关联查询
Criteria API关联查询 如果说HQL查询还有需要了解点SQL语法知识,并不是完全彻底面向对象查询, 那么Criterial API就是完全面向对象的查询方式. public IList< ...
- Guava文档翻译之 Guava简介
用户指南 User Guide Guava项目包括了一些Google的核心库,是我们在基于Java的项目中所依赖的,这些库包括:集合,缓存,对基本类型的支持,并发库,通用的注解,字符串处理,I/O,等 ...
- eclipse 开发技巧
1. ctrl+shift+r:打开资源 这可能是所有快捷键组合中最省时间的了.这组快捷键可以让你打开你的工作区中任何一个文件,而你只需要按下文件名或mask名中的前几个字母,比如applic*.xm ...
- trie树--详解
文章作者:yx_th000 文章来源:Cherish_yimi (http://www.cnblogs.com/cherish_yimi/) 转载请注明,谢谢合作.关键词:trie trie树 数据结 ...
- How do you design object oriented projects?
what are things you do during the high level design phase (before you begin programming) to determin ...
- POJ2586Y2K Accounting Bug
http://poj.org/problem?id=2586 Description Accounting for Computer Machinists (ACM) has sufferred fr ...