天天看點

linux根檔案系統/etc/mdev.conf檔案詳解

-------------------------------------------

MDEV 入門(轉)

Busybox-1.7.0/docs/mdev.txt

翻譯:tekkamanninja Email: - 1 -

-------------

MDEV Primer

MDEV 入門

For those of us who know how to use mdev, a primer might seem lame. For

這份文檔對于那些知道如何使用 mdev 的人看來可能有些膚淺。

everyone else, mdev is a weird black box that they hear is awesome, but can't

但對于其他人,mdev 可能是一個神秘的黑匣子,以至讓人敬畏。

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

mdev 有兩個主要的應用:初始化對象和動态更新。

require sysfs support in the kernel and have it mounted at /sys. For dynamic

兩個應用都需要核心 sysfs 的支援,且必須挂載到 /sys 。為了實作動态更新,

updates, you also need to have hotplugging enabled in your kernel.

你還必須在核心配置時增加熱插拔支援(hotplugging)。

Here's a typical code snippet from the init script:

以下是系統初始化腳本中一個典型的使用mdev 的代碼片段:

    [1] mount -t sysfs sysfs /sys

    [2] echo /bin/mdev > /proc/sys/kernel/hotplug

    [3] mdev -s

Of course, a more "full" setup would entail executing this before the previous

當然,一個對mdev 更完整的安裝還必須在以上代碼片段前執行下面的指令:

code snippet:

    [4] mount -t tmpfs mdev /dev

    [5] mkdir /dev/pts

    [6] mount -t devpts devpts /dev/pts

The simple explanation here is that [1] you need to have /sys mounted before

簡單說明一下上面的代碼:[1]你必須在執行mdev 前挂載 /sys 。

executing mdev. Then you [2] instruct the kernel to execute /bin/mdev whenever

随後你 [2] 指令核心在增删裝置時執行 /bin/mdev ,

a device is added or removed so that the device node can be created or

使裝置節點檔案會被建立和删除。

destroyed. Then you [3] seed /dev with all the device nodes that were created

最後你 [3] 設定mdev,讓它在系統啟動時建立所有的裝置節點。

while the system was booting.

For the "full" setup, you want to [4] make sure /dev is a tmpfs filesystem

而對mdev 更完整的安裝,你必須[4]確定 /dev 是 tmpfs 檔案系統

(assuming you're running out of flash). Then you want to [5] create the

(假設檔案系統在 flash 外運作)。 而且你必須 [5] 建立

MDEV Config (/etc/mdev.conf)

MDEV 配置 (/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

660 permissions.

如果你的系統需要一些比預設的 root/root 660 更多的權限,

你可以使用 mdev 的可選配置檔案,以控制裝置節點的 所有者 和 權限。

The file has the format:

這個檔案的格式如下:

    <device regex> <uid>:<gid> <octal permissions>

For example:

例如:

    hd[a-z][0-9]* 0:3 660

The config file parsing stops at the first matching line. If no line is

這個配置檔案在第一個比對行處停止解析。 如果沒有比對行,

matched, then the default of 0:0 660 is used. To set your own default, simply

那麼就使用預設的 0:0 660 。 你也可以通過在最後建立如下的全比對

create your own total match like so:

行,來設定你自己的預設設定:

    .* 1:1 777

If you also enable support for executing your own commands, then the file has

如果你想 mdev 在找到比對行時可以執行自定義的指令,那麼檔案格式如下:

the format:

    <device regex> <uid>:<gid> <octal 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

這些指令是通過系統函數(system())執行的(也就是說你在對shell 下指令)

command to the shell), so make sure you have a shell installed at /bin/sh.

,是以請確定你已在 /bin/sh 安裝了shell。

For your convenience, the shell env var $MDEV is set to the device name. So if

為了友善,shell 的環境變量 $MDEV 會被設定成裝置名。 例如

the device 'hdc' was matched, MDEV would be set to "hdc".

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

/lib/firmware/ 目錄。 在運作時,核心将會按固件檔案名調用 mdev ,

filename of the firmware which mdev will load out of /lib/firmware/ and into

之後 mdev 會通過 sysfs 接口将固件從 /lib/firmware/

the kernel via the sysfs interface. The exact filename is hardcoded in the

裝載到核心。 确定的檔案名被固化在核心中,

kernel, so look there if you need to want to know what to name the file in

如有必要,你必須知道如何在使用者空間命名這個檔案。

userspace.

# cat /etc/mdev.conf

# system all-writable devices

full            0:0     0666

null            0:0     0666

ptmx            0:0     0666

random          0:0     0666

tty             0:0     0666

zero            0:0     0666

# console devices

tty[0-9]*       0:5     0660

vc/[0-9]*       0:5     0660

# serial port devices

s3c2410_serial0 0:5     0666    =ttySAC0

s3c2410_serial1 0:5     0666    =ttySAC1

s3c2410_serial2 0:5     0666    =ttySAC2

s3c2410_serial3 0:5     0666    =ttySAC3

# loop devices

loop[0-9]*      0:0     0660    =loop/

# i2c devices

i2c-0           0:0     0666    =i2c/0

i2c-1           0:0     0666    =i2c/1

# frame buffer devices

fb[0-9]         0:0     0666

# input devices

mice            0:0     0660    =input/

mouse.*         0:0     0660    =input/

event.*         0:0     0660    =input/

ts.*            0:0     0660    =input/

# rtc devices

rtc0            0:0     0644    >rtc

rtc[1-9]        0:0     0644

# misc devices

mmcblk0p1       0:0     0600    =sdcard  */bin/hotplug.sh

sda1            0:0     0600    =udisk   * /bin/hotplug.sh

vntwpa          1:1     777              * /bin/ltls.sh  //$MDEV 參數 為"usb-wifi"vntwpa  執行腳本ltls.sh

# .*            1:1     777              * /bin/ltls.sh

1-1.*           1:1     777              * /bin/llll

[root@FriendlyARM /mnt]# cat ltls.sh

#!/bin/sh

echo $MDEV    >  /dev/ttySAC0  // 有變化的裝置 會在/dev産生 相應裝置 如:1-1.1 /sys 下class或block下也會變化

echo $ACTION    >  /dev/ttySAC0 // 裝置狀态"remove"   "add"

#echo  - n  "enter your name:"

#read name

#echo "ltls  "  > /dev/ttySACO

if [ "$MDEV" = "vntwpa" ];then

        /bin/wifi-ltls

        echo "going to vntwpa " > /dev/ttySAC0

fi