+ struct udevice udev;
+ struct name_entry *name_loop;
+ char buf[4096];
+ size_t bufpos = 0;
+ ssize_t count;
+ char path[PATH_SIZE];
+ int fd;
+ char link_target[PATH_SIZE];
+ int len;
+ int err = 0;
+
+ udev_device_init(&udev);
+ udev_db_get_device(&udev, devpath);
+
+ /* add header */
+ bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
+ bufpos++;
+
+ /* add standard keys */
+ bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "DEVPATH=%s", devpath);
+ bufpos++;
+ bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "ACTION=%s", action);
+ bufpos++;
+
+ /* add subsystem */
+ strlcpy(path, sysfs_path, sizeof(path));
+ strlcat(path, devpath, sizeof(path));
+ strlcat(path, "/subsystem", sizeof(path));
+ len = readlink(path, link_target, sizeof(link_target));
+ if (len > 0) {
+ char *pos;
+
+ link_target[len] = '\0';
+ pos = strrchr(link_target, '/');
+ if (pos != NULL) {
+ bufpos += snprintf(&buf[bufpos], sizeof(buf)-1, "SUBSYSTEM=%s", &pos[1]);
+ bufpos++;
+ }
+ }