static struct hw * split_fill_path (struct hw *current, const char *device_specifier, name_specifier *spec) { /* break it up */ if (!split_device_specifier (current, device_specifier, spec)) hw_abort (current, "error parsing %s\n", device_specifier); /* fill our tree with its contents */ current = split_find_device (current, spec); /* add any additional devices as needed */ if (spec->name != NULL) { do { if (current != NULL && !hw_finished_p (current)) hw_finish (current); current = hw_create (NULL, current, spec->family, spec->name, spec->unit, spec->args); } while (split_device_name (spec)); } return current; }
split_fill_path(device *current, const char *device_specifier, name_specifier *spec) { /* break it up */ if (!split_device_specifier(current, device_specifier, spec)) device_error(current, "error parsing %s\n", device_specifier); /* fill our tree with its contents */ current = split_find_device(current, spec); /* add any additional devices as needed */ if (spec->name != NULL) { do { current = device_create(current, spec->base, spec->name, spec->unit, spec->args); } while (split_device_name(spec)); } return current; }
static struct hw * split_find_device (struct hw *current, name_specifier *spec) { /* strip off (and process) any leading ., .., ./ and / */ while (1) { if (strncmp (spec->path, "/", strlen ("/")) == 0) { /* cd /... */ while (current != NULL && hw_parent (current) != NULL) current = hw_parent (current); spec->path += strlen ("/"); } else if (strncmp (spec->path, "./", strlen ("./")) == 0) { /* cd ./... */ current = current; spec->path += strlen ("./"); } else if (strncmp (spec->path, "../", strlen ("../")) == 0) { /* cd ../... */ if (current != NULL && hw_parent (current) != NULL) current = hw_parent (current); spec->path += strlen ("../"); } else if (strcmp (spec->path, ".") == 0) { /* cd . */ current = current; spec->path += strlen ("."); } else if (strcmp (spec->path, "..") == 0) { /* cd .. */ if (current != NULL && hw_parent (current) != NULL) current = hw_parent (current); spec->path += strlen (".."); } else break; } /* now go through the path proper */ if (current == NULL) { split_device_name (spec); return NULL; } while (split_device_name (spec)) { struct hw *child; for (child = hw_child (current); child != NULL; child = hw_sibling (child)) { if (strcmp (spec->name, hw_name (child)) == 0) { if (spec->unit == NULL) break; else { hw_unit phys; hw_unit_decode (current, spec->unit, &phys); if (memcmp (&phys, hw_unit_address (child), sizeof (hw_unit)) == 0) break; } } } if (child == NULL) return current; /* search failed */ current = child; } return current; }