class_device_create
剖析: busybox mdev.c
100ask: uevent_helper = /sbin/mdev
envp[0] = HOME=/
envp[1] = PATH=/sbin:/bin:/usr/sbin:/usr/bin
envp[2] = ACTION=add
envp[3] = DEVPATH=/class/sixth_drv/buttons
envp[4] = SUBSYSTEM=sixth_drv
envp[5] = SEQNUM=720
envp[6] = MAJOR=252
envp[7] = MINOR=0
mdev_main
我接上U盘,想主动挂载,怎么办?
mdev.conf的格局:
: [<@|$|*> ]
device regex:正则表达式,表明哪一个设备
uid: owner
gid: 组ID
octal permissions:以八进制表明的特点
@:创建造备节点之后履行指令
$:删去设备节点之前履行指令
*: 创建造备节点之后 和 删去设备节点之前 履行指令
command:要履行的指令
指令:vi /etc/mdev.conf
写mdev.conf
1.
leds 0:0 777
led1 0:0 777
led2 0:0 777
led3 0:0 777
2.
leds?[123]? 0:0 777
3.
leds?[123]? 0:0 777 @ echo create /dev/$MDEV > /dev/console
4.
leds?[123]? 0:0 777 * if [ $ACTION = “add” ]; then echo create /dev/$MDEV > /dev/console; else echo remove /dev/$MDEV > /dev/console; fi
5.
leds?[123]? 0:0 777 * /bin/add_remove_led.sh
把指令写入一个脚本:
add_remove_led.sh
#!/bin/sh
if [ $ACTION = “add” ];
then
else
fi
6. U盘主动加载
sda[1-9]+ 0:0 777 * if [ $ACTION = “add” ]; then mount /dev/$MDEV /mnt; else umount /mnt; fi
7.
sda[1-9]+ 0:0 777 * /bin/add_remove_udisk.sh
add_remove_udisk.sh
#!/bin/sh
if [ $ACTION = “add” ];
then
else
fi