Android 是如何动态管理dev下的设备节点的

http://androidos.cc/dev/simple/index.php?t4805.html
 

在PC上Linux的设备节点管理是通过udev,嵌入式linux中,busybox继承了一个简化版的udev,叫mdev。 

内核中的每个设备添加到系统都会发送一个uevent,运行在用户空间的udev会检测到这个event,event中会有设备的主次设备号等内容,udev根据event的内容做相应的动作,创建设备,删除设备等。 " u]X/ {L  
在Android中,没有独立的类似与udev或者mdev的用户程序,这个功能集成到了init中做了。 
代码见: ?YFSK  
system/core/init/init.c 
if (ufds[0].revents == POLLIN) 
handle_device_fd(device_fd); 
 
void handle_device_fd(int fd) 

char msg[UEVENT_MSG_LEN 2]; T  ^`R  
int n; 
 
while((n = recv(fd, msg, UEVENT_MSG_LEN, 0)) > 0) { 
struct uevent uevent; 
 
if(n == UEVENT_MSG_LEN) /* overflow -- discard */ 
continue; 
 
msg[n] = '\0'; 
msg[n 1] = '\0'; 
 
parse_event(msg, &uevent); 
 
handle_device_event(&uevent); 
handle_firmware_event(&uevent); 
} m? pm)w  
}
原文地址:https://www.cnblogs.com/leaven/p/1916428.html