Loading init/devices.c +126 −89 Original line number Original line Diff line number Diff line Loading @@ -393,42 +393,88 @@ err: return NULL; return NULL; } } static void handle_device_event(struct uevent *uevent) static void handle_device(const char *action, const char *devpath, const char *path, int block, int major, int minor, char **links) { { char devpath[96]; int devpath_ready = 0; char *base, *name; char **links = NULL; int block; int i; int i; if (!strcmp(uevent->action,"add")) if(!strcmp(action, "add")) { fixup_sys_perms(uevent->path); make_device(devpath, path, block, major, minor); if (links) { for (i = 0; links[i]; i++) make_link(devpath, links[i]); } } if(!strcmp(action, "remove")) { if (links) { for (i = 0; links[i]; i++) remove_link(devpath, links[i]); } unlink(devpath); } if (links) { for (i = 0; links[i]; i++) free(links[i]); free(links); } } static const char *parse_device_name(struct uevent *uevent, unsigned int len) { const char *name; /* if it's not a /dev device, nothing else to do */ /* if it's not a /dev device, nothing else to do */ if((uevent->major < 0) || (uevent->minor < 0)) if((uevent->major < 0) || (uevent->minor < 0)) return; return NULL; /* do we have a name? */ /* do we have a name? */ name = strrchr(uevent->path, '/'); name = strrchr(uevent->path, '/'); if(!name) if(!name) return; return NULL; name++; name++; /* too-long names would overrun our buffer */ /* too-long names would overrun our buffer */ if(strlen(name) > 64) if(strlen(name) > len) return NULL; return name; } static void handle_block_device_event(struct uevent *uevent) { const char *base = "/dev/block/"; const char *name; char devpath[96]; char **links = NULL; name = parse_device_name(uevent, 64); if (!name) return; return; /* are we block or char? where should we live? */ snprintf(devpath, sizeof(devpath), "%s%s", base, name); if(!strncmp(uevent->subsystem, "block", 5)) { block = 1; base = "/dev/block/"; mkdir(base, 0755); mkdir(base, 0755); if (!strncmp(uevent->path, "/devices/platform/", 18)) if (!strncmp(uevent->path, "/devices/platform/", 18)) links = parse_platform_block_device(uevent); links = parse_platform_block_device(uevent); } else { block = 0; handle_device(uevent->action, devpath, uevent->path, 1, /* this should probably be configurable somehow */ uevent->major, uevent->minor, links); } static void handle_generic_device_event(struct uevent *uevent) { char *base; const char *name; char devpath[96] = {0}; char **links = NULL; name = parse_device_name(uevent, 64); if (!name) return; if (!strncmp(uevent->subsystem, "usb", 3)) { if (!strncmp(uevent->subsystem, "usb", 3)) { if (!strcmp(uevent->subsystem, "usb")) { if (!strcmp(uevent->subsystem, "usb")) { /* This imitates the file system that would be created /* This imitates the file system that would be created Loading @@ -443,7 +489,6 @@ static void handle_device_event(struct uevent *uevent) snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); mkdir(devpath, 0755); mkdir(devpath, 0755); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); devpath_ready = 1; } else { } else { /* ignore other USB events */ /* ignore other USB events */ return; return; Loading Loading @@ -477,31 +522,23 @@ static void handle_device_event(struct uevent *uevent) } else } else base = "/dev/"; base = "/dev/"; links = get_character_device_symlinks(uevent); links = get_character_device_symlinks(uevent); } if (!devpath_ready) if (!devpath[0]) snprintf(devpath, sizeof(devpath), "%s%s", base, name); snprintf(devpath, sizeof(devpath), "%s%s", base, name); if(!strcmp(uevent->action, "add")) { handle_device(uevent->action, devpath, uevent->path, 0, make_device(devpath, uevent->path, block, uevent->major, uevent->minor); uevent->major, uevent->minor, links); if (links) { for (i = 0; links[i]; i++) make_link(devpath, links[i]); } } } if(!strcmp(uevent->action, "remove")) { static void handle_device_event(struct uevent *uevent) if (links) { { for (i = 0; links[i]; i++) if (!strcmp(uevent->action,"add")) remove_link(devpath, links[i]); fixup_sys_perms(uevent->path); } unlink(devpath); } if (links) { if (!strncmp(uevent->subsystem, "block", 5)) { for (i = 0; links[i]; i++) handle_block_device_event(uevent); free(links[i]); } else { free(links); handle_generic_device_event(uevent); } } } } Loading Loading
init/devices.c +126 −89 Original line number Original line Diff line number Diff line Loading @@ -393,42 +393,88 @@ err: return NULL; return NULL; } } static void handle_device_event(struct uevent *uevent) static void handle_device(const char *action, const char *devpath, const char *path, int block, int major, int minor, char **links) { { char devpath[96]; int devpath_ready = 0; char *base, *name; char **links = NULL; int block; int i; int i; if (!strcmp(uevent->action,"add")) if(!strcmp(action, "add")) { fixup_sys_perms(uevent->path); make_device(devpath, path, block, major, minor); if (links) { for (i = 0; links[i]; i++) make_link(devpath, links[i]); } } if(!strcmp(action, "remove")) { if (links) { for (i = 0; links[i]; i++) remove_link(devpath, links[i]); } unlink(devpath); } if (links) { for (i = 0; links[i]; i++) free(links[i]); free(links); } } static const char *parse_device_name(struct uevent *uevent, unsigned int len) { const char *name; /* if it's not a /dev device, nothing else to do */ /* if it's not a /dev device, nothing else to do */ if((uevent->major < 0) || (uevent->minor < 0)) if((uevent->major < 0) || (uevent->minor < 0)) return; return NULL; /* do we have a name? */ /* do we have a name? */ name = strrchr(uevent->path, '/'); name = strrchr(uevent->path, '/'); if(!name) if(!name) return; return NULL; name++; name++; /* too-long names would overrun our buffer */ /* too-long names would overrun our buffer */ if(strlen(name) > 64) if(strlen(name) > len) return NULL; return name; } static void handle_block_device_event(struct uevent *uevent) { const char *base = "/dev/block/"; const char *name; char devpath[96]; char **links = NULL; name = parse_device_name(uevent, 64); if (!name) return; return; /* are we block or char? where should we live? */ snprintf(devpath, sizeof(devpath), "%s%s", base, name); if(!strncmp(uevent->subsystem, "block", 5)) { block = 1; base = "/dev/block/"; mkdir(base, 0755); mkdir(base, 0755); if (!strncmp(uevent->path, "/devices/platform/", 18)) if (!strncmp(uevent->path, "/devices/platform/", 18)) links = parse_platform_block_device(uevent); links = parse_platform_block_device(uevent); } else { block = 0; handle_device(uevent->action, devpath, uevent->path, 1, /* this should probably be configurable somehow */ uevent->major, uevent->minor, links); } static void handle_generic_device_event(struct uevent *uevent) { char *base; const char *name; char devpath[96] = {0}; char **links = NULL; name = parse_device_name(uevent, 64); if (!name) return; if (!strncmp(uevent->subsystem, "usb", 3)) { if (!strncmp(uevent->subsystem, "usb", 3)) { if (!strcmp(uevent->subsystem, "usb")) { if (!strcmp(uevent->subsystem, "usb")) { /* This imitates the file system that would be created /* This imitates the file system that would be created Loading @@ -443,7 +489,6 @@ static void handle_device_event(struct uevent *uevent) snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); mkdir(devpath, 0755); mkdir(devpath, 0755); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); devpath_ready = 1; } else { } else { /* ignore other USB events */ /* ignore other USB events */ return; return; Loading Loading @@ -477,31 +522,23 @@ static void handle_device_event(struct uevent *uevent) } else } else base = "/dev/"; base = "/dev/"; links = get_character_device_symlinks(uevent); links = get_character_device_symlinks(uevent); } if (!devpath_ready) if (!devpath[0]) snprintf(devpath, sizeof(devpath), "%s%s", base, name); snprintf(devpath, sizeof(devpath), "%s%s", base, name); if(!strcmp(uevent->action, "add")) { handle_device(uevent->action, devpath, uevent->path, 0, make_device(devpath, uevent->path, block, uevent->major, uevent->minor); uevent->major, uevent->minor, links); if (links) { for (i = 0; links[i]; i++) make_link(devpath, links[i]); } } } if(!strcmp(uevent->action, "remove")) { static void handle_device_event(struct uevent *uevent) if (links) { { for (i = 0; links[i]; i++) if (!strcmp(uevent->action,"add")) remove_link(devpath, links[i]); fixup_sys_perms(uevent->path); } unlink(devpath); } if (links) { if (!strncmp(uevent->subsystem, "block", 5)) { for (i = 0; links[i]; i++) handle_block_device_event(uevent); free(links[i]); } else { free(links); handle_generic_device_event(uevent); } } } } Loading