+ }
+
+ /* substitute anything that needs to be in the program name */
+ apply_format(udev, dev->exec_program);
+ if (exec_callout(dev, udev->callout_value, NAME_SIZE))
+ continue;
+ if (strncmp_wildcard(udev->callout_value, dev->id, NAME_SIZE) != 0)
+ continue;
+ strfieldcpy(udev->name, dev->name);
+ if (dev->mode != 0) {
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }
+ dbg_parse("callout returned matching value '%s', '%s' becomes '%s'"
+ " - owner='%s', group='%s', mode=%#o",
+ dev->id, class_dev->name, udev->name,
+ dev->owner, dev->group, dev->mode);
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static int do_label(struct sysfs_class_device *class_dev, struct udevice *udev, struct sysfs_device *sysfs_device)
+{
+ struct sysfs_attribute *tmpattr = NULL;
+ struct config_device *dev;
+ struct list_head *tmp;
+
+ list_for_each(tmp, &config_device_list) {
+ dev = list_entry(tmp, struct config_device, node);
+ if (dev->type != LABEL)
+ continue;
+
+ if (sysfs_device) {
+ dbg_parse("dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus);
+ if (strcasecmp(dev->bus, sysfs_device->bus) != 0)
+ continue;
+ }
+
+ dbg_parse("look for device attribute '%s'", dev->sysfs_file);
+ /* try to find the attribute in the class device directory */
+ tmpattr = sysfs_get_classdev_attr(class_dev, dev->sysfs_file);
+ if (tmpattr)
+ goto label_found;
+
+ /* look in the class device directory if present */
+ if (sysfs_device) {
+ tmpattr = sysfs_get_device_attr(sysfs_device, dev->sysfs_file);
+ if (tmpattr)
+ goto label_found;
+ }
+
+ continue;
+
+label_found:
+ tmpattr->value[strlen(tmpattr->value)-1] = 0x00;
+ dbg_parse("compare attribute '%s' value '%s' with '%s'",
+ dev->sysfs_file, tmpattr->value, dev->sysfs_value);
+ if (strcmp(dev->sysfs_value, tmpattr->value) != 0)
+ continue;
+
+ strfieldcpy(udev->name, dev->name);
+ if (dev->mode != 0) {
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }
+ dbg_parse("found matching attribute '%s', '%s' becomes '%s' "
+ "- owner='%s', group='%s', mode=%#o",
+ dev->sysfs_file, class_dev->name, udev->name,
+ dev->owner, dev->group, dev->mode);
+
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static int do_number(struct sysfs_class_device *class_dev, struct udevice *udev, struct sysfs_device *sysfs_device)
+{
+ struct config_device *dev;
+ struct list_head *tmp;
+ char path[SYSFS_PATH_MAX];
+ int found;
+ char *temp = NULL;
+
+ /* we have to have a sysfs device for NUMBER to work */
+ if (!sysfs_device)
+ return -ENODEV;
+
+ list_for_each(tmp, &config_device_list) {
+ dev = list_entry(tmp, struct config_device, node);
+ if (dev->type != NUMBER)
+ continue;
+
+ dbg_parse("dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus);
+ if (strcasecmp(dev->bus, sysfs_device->bus) != 0)
+ continue;
+
+ found = 0;
+ strfieldcpy(path, sysfs_device->path);
+ temp = strrchr(path, '/');
+ dbg_parse("search '%s' in '%s', path='%s'", dev->id, temp, path);
+ if (strstr(temp, dev->id) != NULL) {
+ found = 1;
+ } else {
+ *temp = 0x00;
+ temp = strrchr(path, '/');
+ dbg_parse("search '%s' in '%s', path='%s'", dev->id, temp, path);
+ if (strstr(temp, dev->id) != NULL)
+ found = 1;
+ }
+ if (!found)
+ continue;
+ strfieldcpy(udev->name, dev->name);
+ if (dev->mode != 0) {
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }
+ dbg_parse("found matching id '%s', '%s' becomes '%s'"
+ " - owner='%s', group ='%s', mode=%#o",
+ dev->id, class_dev->name, udev->name,
+ dev->owner, dev->group, dev->mode);
+ return 0;
+ }
+ return -ENODEV;
+}
+
+
+static int do_topology(struct sysfs_class_device *class_dev, struct udevice *udev, struct sysfs_device *sysfs_device)
+{
+ struct config_device *dev;
+ struct list_head *tmp;
+ char path[SYSFS_PATH_MAX];
+ int found;
+ char *temp = NULL;
+
+ /* we have to have a sysfs device for TOPOLOGY to work */
+ if (!sysfs_device)
+ return -ENODEV;
+
+ list_for_each(tmp, &config_device_list) {
+ dev = list_entry(tmp, struct config_device, node);
+ if (dev->type != TOPOLOGY)
+ continue;
+
+ dbg_parse("dev->bus='%s' sysfs_device->bus='%s'", dev->bus, sysfs_device->bus);
+ if (strcasecmp(dev->bus, sysfs_device->bus) != 0)
+ continue;
+
+ found = 0;
+ strfieldcpy(path, sysfs_device->path);
+ temp = strrchr(path, '/');
+ dbg_parse("search '%s' in '%s', path='%s'", dev->place, temp, path);
+ if (strstr(temp, dev->place) != NULL) {
+ found = 1;
+ } else {
+ *temp = 0x00;
+ temp = strrchr(path, '/');
+ dbg_parse("search '%s' in '%s', path='%s'", dev->place, temp, path);
+ if (strstr(temp, dev->place) != NULL)
+ found = 1;
+ }
+ if (!found)
+ continue;
+
+ strfieldcpy(udev->name, dev->name);
+ if (dev->mode != 0) {
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }
+ dbg_parse("found matching place '%s', '%s' becomes '%s'"
+ " - owner='%s', group ='%s', mode=%#o",
+ dev->place, class_dev->name, udev->name,
+ dev->owner, dev->group, dev->mode);
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static int do_replace(struct sysfs_class_device *class_dev, struct udevice *udev, struct sysfs_device *sysfs_device)
+{
+ struct config_device *dev;
+ struct list_head *tmp;
+
+ list_for_each(tmp, &config_device_list) {
+ dev = list_entry(tmp, struct config_device, node);
+ if (dev->type != REPLACE)
+ continue;
+
+ dbg_parse("compare name '%s' with '%s'",
+ dev->kernel_name, dev->name);
+ if (strcmp(dev->kernel_name, class_dev->name) != 0)
+ continue;
+
+ strfieldcpy(udev->name, dev->name);
+ if (dev->mode != 0) {
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }
+ dbg_parse("found name, '%s' becomes '%s' - owner='%s', group='%s', mode = %#o",
+ dev->kernel_name, udev->name,
+ dev->owner, dev->group, dev->mode);
+
+ return 0;
+ }
+ return -ENODEV;
+}
+
+static void do_kernelname(struct sysfs_class_device *class_dev, struct udevice *udev)
+{
+ struct config_device *dev;
+ struct list_head *tmp;
+ int len;
+
+ strfieldcpy(udev->name, class_dev->name);
+ /* look for permissions */
+ list_for_each(tmp, &config_device_list) {
+ dev = list_entry(tmp, struct config_device, node);
+ len = strlen(dev->name);
+ if (strncmp_wildcard(class_dev->name, dev->name, sizeof(dev->name)))
+ continue;
+ if (dev->mode != 0) {
+ dbg_parse("found permissions for '%s'", class_dev->name);
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ strfieldcpy(udev->group, dev->group);
+ }