hotplug_uevent機(jī)制
分析: 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盤,想自動(dòng)掛載,怎么辦?
mdev.conf的格式:
: [<@|$|*> ]
device regex:正則表達(dá)式,表示哪一個(gè)設(shè)備
uid: owner
gid: 組ID
octal permissions:以八進(jìn)制表示的屬性
@:創(chuàng)建設(shè)備節(jié)點(diǎn)之后執(zhí)行命令
$:刪除設(shè)備節(jié)點(diǎn)之前執(zhí)行命令
*: 創(chuàng)建設(shè)備節(jié)點(diǎn)之后 和 刪除設(shè)備節(jié)點(diǎn)之前 執(zhí)行命令
command:要執(zhí)行的命令
命令: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
把命令寫入一個(gè)腳本:
add_remove_led.sh
#!/bin/sh
if [ $ACTION = "add" ];
then
else
fi
6. U盤自動(dòng)加載
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
評(píng)論