您的位置 首页 设计

hotplug_uevent机制

class_device_createclass_device_registerclass_device_addkobject_uevent(class_dev-

class_device_create

class_device_register
class_device_add
kobject_uevent(&class_dev->kobj, KOBJ_ADD);
kobject_uevent_env(kobj, action, NULL);
// action_string = “add”;
action_string = action_to_string(action);
// 分配保存环境变量的内存 //
// environment values //
buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL);
// 设置环境变量 //
envp [i++] = scratch;
scratch += sprintf(scratch, “ACTION=%s”, action_string) + 1;
envp [i++] = scratch;
scratch += sprintf (scratch, “DEVPATH=%s”, devpath) + 1;
envp [i++] = scratch;
scratch += sprintf(scratch, “SUBSYSTEM=%s”, subsystem) + 1;
// 调用应用程序: 比方mdev //
// 发动脚本 echo /sbin/mdev > /proc/sys/kernel/hotplug
// 设置了uevent_helper为“/sbin/mdev“
//
argv [0] = uevent_helper; // = “/sbin/mdev”
argv [1] = (char *)subsystem;
argv [2] = NULL;
call_usermodehelper (argv[0], argv, envp, 0);
剖析: 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
temp = /sys/class/sixth_drv/buttons
make_device(temp, 0);
// 确认设备文件名,类型,主次设备号 //
device_name = bb_basename(path); = “buttons”
c == > 字符设备节点
依据”/sys/class/sixth_drv/buttons/dev”的内容确认主次设备号
mknod(device_name, mode | type, makedev(major, minor)
我接上U盘,想主动挂载,怎么办?
mdev.conf的格局:
: [<@|$|*> ]
device regex:正则表达式,表明哪一个设备
uid: owner
gid: 组ID
octal permissions:以八进制表明的特点
@:创建造备节点之后履行指令
$:删去设备节点之前履行指令
*: 创建造备节点之后 和 删去设备节点之前 履行指令
command:要履行的指令
指令:vi /etc/mdev.conf
ls -l /dev/led*
vi /bin/add_remove_led.sh
chmod +x /bin/add_remove_led.sh
写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
echo create /dev/$MDEV > /dev/console;
else
echo remove /dev/$MDEV > /dev/console;
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
mount /dev/$MDEV /mnt;
else
umount /mnt;
fi

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/sheji/263404.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部