+ pos[0] = '\0';
+ tail = pos+1;
+ len = get_format_len(&tail);
+ c = tail[0];
+ strlcpy(temp, tail+1, sizeof(temp));
+ tail = temp;
+ dbg("format=%c, string='%s', tail='%s'",c , string, tail);
+ attr = get_format_attribute(&tail);
+
+ switch (c) {
+ case 'p':
+ strlcat(string, udev->devpath, maxsize);
+ dbg("substitute kernel name '%s'", udev->kernel_name);
+ break;
+ case 'b':
+ strlcat(string, udev->bus_id, maxsize);
+ dbg("substitute bus_id '%s'", udev->bus_id);
+ break;
+ case 'k':
+ strlcat(string, udev->kernel_name, maxsize);
+ dbg("substitute kernel name '%s'", udev->kernel_name);
+ break;
+ case 'n':
+ strlcat(string, udev->kernel_number, maxsize);
+ dbg("substitute kernel number '%s'", udev->kernel_number);
+ break;
+ case 'm':
+ sprintf(temp2, "%d", minor(udev->devt));
+ strlcat(string, temp2, maxsize);
+ dbg("substitute minor number '%s'", temp2);
+ break;
+ case 'M':
+ sprintf(temp2, "%d", major(udev->devt));
+ strlcat(string, temp2, maxsize);
+ dbg("substitute major number '%s'", temp2);
+ break;
+ case 'c':
+ if (udev->program_result[0] == '\0')
+ break;
+ /* get part part of the result string */
+ i = 0;
+ if (attr != NULL)
+ i = strtoul(attr, &rest, 10);
+ if (i > 0) {
+ dbg("request part #%d of result string", i);
+ cpos = udev->program_result;
+ while (--i) {
+ while (cpos[0] != '\0' && !isspace(cpos[0]))
+ cpos++;
+ while (isspace(cpos[0]))
+ cpos++;
+ }
+ if (i > 0) {
+ dbg("requested part of result string not found");
+ break;
+ }
+ strlcpy(temp2, cpos, sizeof(temp2));
+ /* %{2+}c copies the whole string from the second part on */
+ if (rest[0] != '+') {
+ cpos = strchr(temp2, ' ');
+ if (cpos)
+ cpos[0] = '\0';
+ }
+ strlcat(string, temp2, maxsize);
+ dbg("substitute part of result string '%s'", temp2);
+ } else {
+ strlcat(string, udev->program_result, maxsize);
+ dbg("substitute result string '%s'", udev->program_result);
+ }
+ break;
+ case 's':
+ if (!class_dev)
+ break;
+ if (attr == NULL) {
+ dbg("missing attribute");
+ break;
+ }
+ tmpattr = find_sysfs_attribute(class_dev, sysfs_device, attr);
+ if (tmpattr == NULL) {
+ dbg("sysfa attribute '%s' not found", attr);
+ break;
+ }
+ /* strip trailing whitespace of matching value */
+ if (isspace(tmpattr->value[strlen(tmpattr->value)-1])) {
+ i = len = strlen(tmpattr->value);
+ while (i > 0 && isspace(tmpattr->value[i-1]))
+ i--;
+ if (i < len) {
+ tmpattr->value[i] = '\0';
+ dbg("remove %i trailing whitespace chars from '%s'",
+ len - i, tmpattr->value);
+ }
+ }
+ strlcat(string, tmpattr->value, maxsize);
+ dbg("substitute sysfs value '%s'", tmpattr->value);
+ break;
+ case '%':
+ strlcat(string, "%", maxsize);
+ pos++;
+ break;
+ case 'e':
+ next_free_number = find_free_number(udev, string);
+ if (next_free_number > 0) {
+ sprintf(temp2, "%d", next_free_number);
+ strlcat(string, temp2, maxsize);
+ }
+ break;
+ case 'P':
+ if (!class_dev)
+ break;
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent != NULL) {
+ struct udevice udev_parent;
+
+ dbg("found parent '%s', get the node name", class_dev_parent->path);
+ udev_init_device(&udev_parent, NULL, NULL);
+ /* lookup the name in the udev_db with the DEVPATH of the parent */
+ if (udev_db_get_device(&udev_parent, &class_dev_parent->path[strlen(sysfs_path)]) == 0) {
+ strlcat(string, udev_parent.name, maxsize);
+ dbg("substitute parent node name'%s'", udev_parent.name);
+ } else
+ dbg("parent not found in database");
+ udev_cleanup_device(&udev_parent);
+ }
+ break;
+ case 'N':
+ if (udev->tmp_node[0] == '\0') {
+ dbg("create temporary device node for callout");
+ snprintf(udev->tmp_node, sizeof(udev->tmp_node), "%s/.tmp-%u-%u",
+ udev_root, major(udev->devt), minor(udev->devt));
+ udev->tmp_node[sizeof(udev->tmp_node)-1] = '\0';
+ udev_make_node(udev, udev->tmp_node, udev->devt, 0600, 0, 0);
+ }
+ strlcat(string, udev->tmp_node, maxsize);
+ dbg("substitute temporary device node name '%s'", udev->tmp_node);
+ break;
+ case 'r':
+ strlcat(string, udev_root, maxsize);
+ dbg("substitute udev_root '%s'", udev_root);
+ break;
+ default:
+ dbg("unknown substitution type '%%%c'", c);
+ break;
+ }
+ /* truncate to specified length */
+ if (len > 0)
+ pos[len] = '\0';