- strfieldcpy(udev->subsystem, subsystem);
-
- if (strcmp(udev->subsystem, "block") == 0)
- udev->type = 'b';
- else if (strcmp(udev->subsystem, "net") == 0)
- udev->type = 'n';
- else if (strncmp(udev->devpath, "/block/", 7) == 0)
- udev->type = 'b';
- else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
- udev->type = 'n';
- else if (strncmp(udev->devpath, "/class/", 7) == 0)
- udev->type = 'c';
-
- udev->mode = 0660;
- strcpy(udev->owner, "root");
- strcpy(udev->group, "root");
+ strlcpy(udev->subsystem, subsystem, sizeof(udev->subsystem));
+
+ if (action)
+ strlcpy(udev->action, action, sizeof(udev->action));
+
+ if (devpath) {
+ strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
+ remove_trailing_char(udev->devpath, '/');
+
+ if (strncmp(udev->devpath, "/block/", 7) == 0)
+ udev->type = DEV_BLOCK;
+ else if (strncmp(udev->devpath, "/class/net/", 11) == 0)
+ udev->type = DEV_NET;
+ else if (strncmp(udev->devpath, "/class/", 7) == 0)
+ udev->type = DEV_CLASS;
+ else if (strncmp(udev->devpath, "/devices/", 9) == 0)
+ udev->type = DEV_DEVICE;
+
+ /* get kernel name */
+ pos = strrchr(udev->devpath, '/');
+ if (pos) {
+ strlcpy(udev->kernel_name, &pos[1], sizeof(udev->kernel_name));
+ dbg("kernel_name='%s'", udev->kernel_name);
+
+ /* Some block devices have '!' in their name, change that to '/' */
+ pos = udev->kernel_name;
+ while (pos[0] != '\0') {
+ if (pos[0] == '!')
+ pos[0] = '/';
+ pos++;
+ }
+
+ /* get kernel number */
+ pos = &udev->kernel_name[strlen(udev->kernel_name)];
+ while (isdigit(pos[-1]))
+ pos--;
+ strlcpy(udev->kernel_number, pos, sizeof(udev->kernel_number));
+ dbg("kernel_number='%s'", udev->kernel_number);
+ }
+ }
+
+ if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS) {
+ udev->mode = 0660;
+ strcpy(udev->owner, "root");
+ strcpy(udev->group, "root");
+ }
+
+ return 0;
+}
+
+void udev_cleanup_device(struct udevice *udev)
+{
+ struct name_entry *name_loop;
+ struct name_entry *temp_loop;
+
+ list_for_each_entry_safe(name_loop, temp_loop, &udev->symlink_list, node) {
+ list_del(&name_loop->node);
+ free(name_loop);
+ }