- /* rules are looked at in priority order */
- retval = do_callout(class_dev, udev, sysfs_device);
- if (retval == 0)
- goto found;
-
- retval = do_label(class_dev, udev, sysfs_device);
- if (retval == 0)
- goto found;
-
- retval = do_number(class_dev, udev, sysfs_device);
- if (retval == 0)
- goto found;
-
- retval = do_topology(class_dev, udev, sysfs_device);
- if (retval == 0)
- goto found;
-
- retval = do_replace(class_dev, udev, sysfs_device);
- if (retval == 0)
- goto found;
-
- do_kernelname(class_dev, udev);
- goto done;
-
-found:
- /* substitute placeholder */
- apply_format(udev, udev->name);
- apply_format(udev, udev->symlink);
-
-done:
- perm = find_perm(udev->name);
- if (perm) {
- udev->mode = perm->mode;
- strfieldcpy(udev->owner, perm->owner);
- strfieldcpy(udev->group, perm->group);
- } else {
- /* no matching perms found :( */
- udev->mode = get_default_mode(class_dev);
- udev->owner[0] = 0x00;
- udev->group[0] = 0x00;
+ /* look for a matching rule to apply */
+ list_for_each_entry(dev, &config_device_list, node) {
+ dbg("process rule");
+ if (match_rule(udev, dev, class_dev, sysfs_device) == 0) {
+ /* empty name and symlink will not create any node */
+ if (dev->name[0] == '\0' && dev->symlink[0] == '\0') {
+ info("configured rule in '%s' at line %i applied, '%s' is ignored",
+ dev->config_file, dev->config_line, udev->kernel_name);
+ return -1;
+ }
+
+ /* collect symlinks for the final matching rule */
+ if (dev->symlink[0] != '\0') {
+ char temp[NAME_SIZE];
+
+ info("configured rule in '%s' at line %i applied, added symlink '%s'",
+ dev->config_file, dev->config_line, dev->symlink);
+ strfieldcpy(temp, dev->symlink);
+ apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device);
+ if (udev->symlink[0] != '\0')
+ strfieldcat(udev->symlink, " ");
+ strfieldcat(udev->symlink, temp);
+ }
+
+ /* rule matches */
+ if (dev->name[0] != '\0') {
+ /* apply all_partitions flag only at a main block device */
+ if (dev->partitions > 0 &&
+ (udev->type != 'b' || udev->kernel_number[0] != '\0'))
+ continue;
+
+ info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
+ dev->config_file, dev->config_line, udev->kernel_name, dev->name);
+
+ strfieldcpy(udev->name, dev->name);
+ apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
+ strfieldcpy(udev->config_file, dev->config_file);
+ udev->config_line = dev->config_line;
+ udev->ignore_remove = dev->ignore_remove;
+
+ if (udev->type == 'n')
+ goto exit;
+
+ udev->partitions = dev->partitions;
+ udev->mode = dev->mode;
+ strfieldcpy(udev->owner, dev->owner);
+ apply_format(udev, udev->owner, sizeof(udev->owner), class_dev, sysfs_device);
+ strfieldcpy(udev->group, dev->group);
+ apply_format(udev, udev->group, sizeof(udev->group), class_dev, sysfs_device);
+
+ goto perms;
+ }
+ }