diff options
| author | Colin Cross <ccross@google.com> | 2012-03-27 14:08:26 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-03-27 14:08:26 -0700 |
| commit | b6428c07f2bfb213f85883a17d8814b68d335a5d (patch) | |
| tree | bfbc00af040cf461a28c4a8dcf3b39f06868c578 | |
| parent | 60733e9280ebd693293d6e7683af0bd94f8909aa (diff) | |
| parent | f97b887848cc64e7d88d27f198b7721c9f2f8ec8 (diff) | |
| download | system_core-b6428c07f2bfb213f85883a17d8814b68d335a5d.tar.gz system_core-b6428c07f2bfb213f85883a17d8814b68d335a5d.tar.bz2 system_core-b6428c07f2bfb213f85883a17d8814b68d335a5d.zip | |
Merge "Add handling for DEVNAME for usb devices"
| -rw-r--r-- | init/devices.c | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/init/devices.c b/init/devices.c index 3b4d369d..125f9815 100644 --- a/init/devices.c +++ b/init/devices.c @@ -63,6 +63,7 @@ struct uevent { const char *subsystem; const char *firmware; const char *partition_name; + const char *device_name; int partition_num; int major; int minor; @@ -335,6 +336,7 @@ static void parse_event(const char *msg, struct uevent *uevent) uevent->minor = -1; uevent->partition_name = NULL; uevent->partition_num = -1; + uevent->device_name = NULL; /* currently ignoring SEQNUM */ while(*msg) { @@ -362,9 +364,12 @@ static void parse_event(const char *msg, struct uevent *uevent) } else if(!strncmp(msg, "PARTNAME=", 9)) { msg += 9; uevent->partition_name = msg; + } else if(!strncmp(msg, "DEVNAME=", 8)) { + msg += 8; + uevent->device_name = msg; } - /* advance to after the next \0 */ + /* advance to after the next \0 */ while(*msg++) ; } @@ -579,18 +584,39 @@ static void handle_generic_device_event(struct uevent *uevent) if (!strncmp(uevent->subsystem, "usb", 3)) { if (!strcmp(uevent->subsystem, "usb")) { - /* This imitates the file system that would be created - * if we were using devfs instead. - * Minors are broken up into groups of 128, starting at "001" - */ - int bus_id = uevent->minor / 128 + 1; - int device_id = uevent->minor % 128 + 1; - /* build directories */ - make_dir("/dev/bus", 0755); - make_dir("/dev/bus/usb", 0755); - snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); - make_dir(devpath, 0755); - snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); + if (uevent->device_name) { + /* + * create device node provided by kernel if present + * see drivers/base/core.c + */ + char *p = devpath; + snprintf(devpath, sizeof(devpath), "/dev/%s", uevent->device_name); + /* skip leading /dev/ */ + p += 5; + /* build directories */ + while (*p) { + if (*p == '/') { + *p = 0; + make_dir(devpath, 0755); + *p = '/'; + } + p++; + } + } + else { + /* This imitates the file system that would be created + * if we were using devfs instead. + * Minors are broken up into groups of 128, starting at "001" + */ + int bus_id = uevent->minor / 128 + 1; + int device_id = uevent->minor % 128 + 1; + /* build directories */ + make_dir("/dev/bus", 0755); + make_dir("/dev/bus/usb", 0755); + snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d", bus_id); + make_dir(devpath, 0755); + snprintf(devpath, sizeof(devpath), "/dev/bus/usb/%03d/%03d", bus_id, device_id); + } } else { /* ignore other USB events */ return; |
