+ /* create symlink(s) if requested */
+ foreach_strpart(dev->symlink, " ", pos, len) {
+ strfieldcpymax(linkname, pos, len+1);
+ strfieldcpy(filename, udev_root);
+ strfieldcat(filename, linkname);
+ dbg("symlink '%s' to node '%s' requested", filename, dev->name);
+ if (!fake)
+ if (strrchr(linkname, '/'))
+ create_path(filename);
+
+ /* optimize relative link */
+ linktarget[0] = '\0';
+ i = 0;
+ tail = 0;
+ while ((dev->name[i] == linkname[i]) && dev->name[i]) {
+ if (dev->name[i] == '/')
+ tail = i+1;
+ i++;
+ }
+ while (linkname[i] != '\0') {
+ if (linkname[i] == '/')
+ strfieldcat(linktarget, "../");
+ i++;
+ }
+
+ strfieldcat(linktarget, &dev->name[tail]);
+
+ dbg("symlink(%s, %s)", linktarget, filename);
+ if (!fake) {
+ unlink(filename);
+ if (symlink(linktarget, filename) != 0)
+ dbg("symlink(%s, %s) failed with error '%s'",
+ linktarget, filename, strerror(errno));
+ }
+ }
+
+ return 0;
+error:
+ return -1;
+}
+
+static struct sysfs_class_device *get_class_dev(char *device_name)
+{
+ char dev_path[SYSFS_PATH_MAX];
+ struct sysfs_class_device *class_dev = NULL;
+
+ strfieldcpy(dev_path, sysfs_path);
+ strfieldcat(dev_path, device_name);
+ dbg("looking at '%s'", dev_path);