+}
+
+int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *udev)
+{
+ struct sysfs_class_device *class_dev_parent;
+ struct sysfs_device *sysfs_device = NULL;
+ struct config_device *dev;
+ struct perm_device *perm;
+ struct sysinfo info;
+ char *pos;
+
+ udev->mode = 0;
+ dbg("class_dev->name='%s'", class_dev->name);
+
+ /* Figure out where the "device"-symlink is at. For char devices this will
+ * always be in the class_dev->path. On block devices, only the main block
+ * device will have the device symlink in it's path. All partition devices
+ * need to look at the symlink in its parent directory.
+ */
+ class_dev_parent = sysfs_get_classdev_parent(class_dev);
+ if (class_dev_parent != NULL) {
+ dbg("given class device has a parent, use this instead");
+ sysfs_device = sysfs_get_classdev_device(class_dev_parent);
+ } else {
+ sysfs_device = sysfs_get_classdev_device(class_dev);
+ }
+
+ if (sysfs_device) {
+ dbg("found /device-device: path='%s', bus_id='%s', bus='%s'",
+ sysfs_device->path, sysfs_device->bus_id, sysfs_device->bus);
+ strfieldcpy(udev->bus_id, sysfs_device->bus_id);
+ }
+
+ strfieldcpy(udev->kernel_name, class_dev->name);
+ fix_kernel_name(udev);
+ dbg("udev->kernel_name = '%s'", udev->kernel_name);
+
+ /* get kernel number */
+ pos = class_dev->name + strlen(class_dev->name);
+ while (isdigit(*(pos-1)))
+ pos--;
+ strfieldcpy(udev->kernel_number, pos);
+ dbg("kernel_number='%s'", udev->kernel_number);
+
+ /* look for a matching rule to apply */
+ list_for_each_entry(dev, &config_device_list, node) {
+ dbg("process rule");
+ if (match_rule(dev, class_dev, udev, sysfs_device) == 0) {
+ 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;
+ }
+
+ 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);
+ }
+
+ 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);
+ goto found;
+ }
+ }
+ }
+ /* no rule was found so we use the kernel name */
+ strfieldcpy(udev->name, udev->kernel_name);
+ if (udev->type == 'n')
+ goto done;
+ else
+ goto perms;
+
+found:
+ 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;
+
+ if (udev->type == 'n')
+ goto done;
+
+ udev->partitions = dev->partitions;
+
+ /* get permissions given in rule */
+ set_empty_perms(udev, dev->mode,
+ dev->owner,
+ dev->group);
+
+perms:
+ /* get permissions given in config file or set defaults */
+ perm = find_perm(udev->name);
+ if (perm != NULL) {
+ set_empty_perms(udev, perm->mode,
+ perm->owner,
+ perm->group);
+ } else {
+ set_empty_perms(udev, get_default_mode(),
+ get_default_owner(),
+ get_default_group());
+ }
+
+ dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o",
+ udev->name, udev->owner, udev->group, udev->mode);
+
+done:
+ /* store time of action */
+ sysinfo(&info);
+ udev->config_uptime = info.uptime;
+
+ return 0;