+ /* create all_partitions if requested */
+ if (dev->partitions > 0) {
+ info("creating device partition nodes '%s[1-%i]'", filename, dev->partitions);
+ if (!fake) {
+ for (i = 1; i <= dev->partitions; i++) {
+ strfieldcpy(partitionname, filename);
+ strintcat(partitionname, i);
+ make_node(partitionname, dev->major,
+ dev->minor + i, dev->mode, uid, gid);
+ }
+ }
+ }
+
+ /* 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;