udev(二):man 7 udev

 在linux下运行man 7 udev会得到udev的一些信息:

我们将一步步根据这个信息来看看udev是什么。

 

NAME
       udev - dynamic device management

DESCRIPTION
       udev provides a dynamic device directory containing only the files for actually present devices. It creates or removes device node files in the /dev directory, or it
       renames network interfaces.

       Usually udev runs as udevd(8) and receives uevents directly from the kernel if a device is added or removed from the system.

       If udev receives a device event, it matches its configured rules against the available device attributes provided in sysfs to identify the device. Rules that match
       may provide additional device information or specify a device node name and multiple symlink names and instruct udev to run additional programs as part of the device
       event handling.
我对上面进行一下翻译:

NAME
       udev -动态设备管理

描述:

       udev为一些实际的设备提供了一个动态的设备目录,这些目录里包含这些实际设备所对应的文件。它创建或移除在/dev目录里的设备节点文件,或者重命名网络接口。

       通常udev运行udevd,如果一个设备增加进系统或者从系统中移除,它就会直接从内核中接受到这个udev的事件。

       如果udev接受到一个设备事件,它就会从它的配置(或是规则)文件( configured rules.在/etc/udev下有这些rules文件,这个纯属个人意译了) 中去匹配从sysfs中得到的设备属性来辨识这个设备。这些rules配置文件会去比较所提供的附加(新增加进来的)的设备的信息或者指定一个设备节点名并操作符号链接名来指示udev运行附加的程序来作为设备事件的处理。

 

哇,好久没翻译英文了,本来自己可以看懂什么意思,一到实际翻译,就说得很坳口,好像是这个意思又不知道怎么说,翻译得不好,要见谅了。

 

下面不翻译了,只是简单的说明一下,估计读者也知道的了。


CONFIGURATION
       udev configuration files are placed in /etc/udev/ and /lib/udev/. All empty lines, or lines beginning with ´#´ will be ignored.

   Configuration file
       udev expects its main configuration file at /etc/udev/udev.conf. It consists of a set of variables allowing the user to override default udev values. The following
       variables can be set:

       udev_root
           Specifies where to place the device nodes in the filesystem. The default value is /dev.

       udev_log
           The logging priority. Valid values are the numerical syslog priorities or their textual representations: err, info and debug.

 

这里就是说udev 的配置文件在/etc/udev和/lib/udev下。空行和以#开头的行都会被忽略。

udev的配置文件在 /etc/udev/udev.conf。

我们来看下这个文件,我的配置文件的内容如下(我的系统是ubuntu9.10,在/etc/udev/目录下有一个目录rules.d和一个文件udev.conf):

# The initial syslog(3) priority: "err", "info", "debug" or its
# numerical equivalent. For runtime debugging, the daemons internal
# state can be changed with: "udevadm control --log-priority=<value>".
 udev_log="err"

 

这里就是配置udev_log的log等级了,等级为err。

实际上, udev.conf文件里面只会解析这三个参数:

 
udev_root 定义udev的目录路径
udev_rules 定义udev的规则文件的目录路径
udev_log 定义log的级别

 


看下这句话:

Rules files

       The udev rules are read from the files located in the default rules directory /lib/udev/rules.d/, the custom rules directory /etc/udev/rules.d/ and the temporary rules directory /dev/.udev/rules.d/. All rule files are sorted and processed in lexical order, regardless in which of these directories they live.

        udev的规则(rules)是从/lib/udev/rules.d目录里读出来的,而通用的规则则在 /etc/udev/rules.d目录和临时规则目录/dev/.udev/rules.d里。所有的规则文件的存储和处理都有固定的词法规则,不管它是在哪个目录里。

 

        Rule files are required to have a unique name, duplicate file names are ignored. Files in /etc/udev/rules.d/ have precedence over files with the same name in /lib/udev/rules.d/. This can be used to ignore a default rules file if needed.

 

              这些规则文件要求要有唯一的名字,重名的会被忽略。位于/etc/udev/rules.d/目录里的相比于在/lib/udev/rules.d/里的同名文件会优先处理。如果有需要,这个会被常用于忽略一个默认的规则(这里的意思是如果你要忽略一个规则,你可以把它放到 /lib/udev/rules.d/目录里,再 在/etc/udev/rules.d/目录里建一个和它同名的文件,这样它就会被忽略掉)。

 

          Every line in the rules file contains at least one key value pair. There are two kind of keys, match and assignment keys. If all match keys are matching against its value, the rule gets applied and the assign keys get the specified value assigned.

 

         规则文件中的每一行都至少包含一个键值对。这里有两种键值--匹配和赋值。如果所有的键都匹配它的值,那么就应用这个规则,并取得一个指定的值付给这个键。

 

         A matching rule may specify the name of the device node, add a symlink pointing to the node, or run a specified program as part of the event handling. If no matching rule is found, the default device node name is used.

 

         一个匹配的规则会指定一个设备节点名,并增加一个符号链接指向这个节点,或运行一个特定的程序作为事件处理的一部分。如果没有发现匹配的规则,那么就使用默认的设备节点名。

 

        A rule consists of a list of one or more key value pairs separated by a comma. Each key has a distinct operation, depending on the used operator. Valid operators
       are:

 

一个规则文件里包含一个或多个的键值对,这些键值对用逗号分隔。根据不同的操作符,每个建又会有不同的操作,可用的操作符如下:

       ==
           Compare for equality.

       !=
           Compare for inequality.

       =
           Assign a value to a key. Keys that represent a list, are reset and only this single value is assigned.

       +=
           Add the value to a key that holds a list of entries.

       :=
           Assign a value to a key finally; disallow any later changes, which may be used to prevent changes by any later rules.

 

       上面这几个操作符的说明比较简单,就不翻译了,最后的这个:=赋值是最终赋值,任何后面的赋值都不可以改变这次的赋值。

 

       The following key names can be used to match against device properties. Some of the keys also match against properties of the parent devices in sysfs, not only the device that has generated the event. If multiple keys that match a parent device are specified in a single rule, all these keys must match at one and the same parent device.

 

       下面的这些键值可用于相对应的设备属性。除了了那些可以产生事件的设备外,其中的一些键值也可以匹配于sysfs里的父设备的属性。如果在一个单独的规则里多个建匹配于同一个父设备,那么这些键值必须匹配一个有相同父设备的并且都只匹配这个设备。

 

       下面是这些键值,省略了:

ACTION
           Match the name of the event action.

       DEVPATH
           Match the devpath of the event device.


KERNEL
           Match the name of the event device.

       NAME
           Match the name of the node or network interface. It can be used once the NAME key has been set in one of the preceding rules.

       SYMLINK
           Match the name of a symlink targeting the node. It can be used once a SYMLINK key has been set in one of the preceding rules. There may be multiple symlinks;
           only one needs to match.

。。。。。。。。。。。。。。。。。。。

 

      由于这个很长,我就不全部列出。

      下面打开我的系统里的/etc/udev/rules.d/目录下 的一个规则文件看看是什么样子的,我的这个规则文件的名字为10-vboxdrv.rules,内容如下:

KERNEL=="vboxdrv", NAME="vboxdrv", OWNER="root", GROUP="root", MODE="0600"
SUBSYSTEM=="usb_device", GROUP="vboxusers", MODE="0664"
 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", GROUP="vboxusers", MODE="0664"

 

我们可以有上面的说明可以知道这些键值的意思了。

 

另外,在 /etc/udev/rules.d/目录下有个README文件,可以参考一些,我贴在下面:


The files in this directory are read by udev(7) and used when events
are performed by the kernel.  The udev daemon watches this directory
with inotify so that changes to these files are automatically picked
up, for this reason they must be files and not symlinks to another
location as in the case in Debian.

Packages do not generally install rules here, this directory is for
local rules.  If you want to override behaviour of package-supplied
rules, which can be found in /lib/udev/rules.d, you can do one of
two things:

 1) Write your own rules in this directory that assign the name,
    symlinks, permissions, etc. that you want.  Pick a number higher
    than the rules you want to override, and yours will be used.

 2) Copy the file from /lib/udev/rules.d and edit it here; you
    should generally only do this if you want to prevent a program
    from being run.


If the ordering of files in this directory are not important to you,
it's recommended that you simply name your files "descriptive-name.rules"
such that they are processed AFTER all numbered rules in both this
directory and /lib/udev/rules.d and thus override anything set there.


 


 


 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值