Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6428c07 authored by Colin Cross's avatar Colin Cross Committed by Android (Google) Code Review
Browse files

Merge "Add handling for DEVNAME for usb devices"

parents 60733e92 f97b8878
Loading
Loading
Loading
Loading
+39 −13
Original line number Diff line number Diff line
@@ -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,6 +364,9 @@ 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 */
@@ -579,6 +584,26 @@ static void handle_generic_device_event(struct uevent *uevent)

    if (!strncmp(uevent->subsystem, "usb", 3)) {
         if (!strcmp(uevent->subsystem, "usb")) {
            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"
@@ -591,6 +616,7 @@ static void handle_generic_device_event(struct uevent *uevent)
                 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;