+ pw = getpwnam(dev->owner);
+ if (pw == NULL)
+ dbg("specified user unknown '%s'", dev->owner);
+ else
+ uid = pw->pw_uid;
+ }
+ }
+
+ if (dev->group[0] != '\0') {
+ char *endptr;
+ unsigned long id = strtoul(dev->group, &endptr, 10);
+ if (endptr[0] == '\0')
+ gid = (gid_t) id;
+ else {
+ struct group *gr = getgrnam(dev->group);
+ if (gr == NULL)
+ dbg("specified group unknown '%s'", dev->group);
+ else
+ gid = gr->gr_gid;
+ }
+ }
+
+ if (!fake) {
+ unlink_entry(filename);
+ info("creating device node '%s'", filename);
+ make_node(filename, dev->major, dev->minor, dev->mode, uid, gid);
+ } else {
+ info("creating device node '%s', major = '%d', minor = '%d', "
+ "mode = '%#o', uid = '%d', gid = '%d'", filename,
+ dev->major, dev->minor, (mode_t)dev->mode, uid, gid);
+ }
+
+ /* create 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);
+ unlink_entry(partitionname);
+ make_node(partitionname, dev->major,
+ dev->minor + i, dev->mode, uid, gid);
+ }
+ }
+ }
+
+ /* create symlink 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]);
+
+ if (!fake)
+ unlink_entry(filename);
+
+ dbg("symlink(%s, %s)", linktarget, filename);
+ if (!fake) {
+ retval = symlink(linktarget, filename);
+ if (retval != 0)
+ dbg("symlink(%s, %s) failed with error '%s'",
+ linktarget, filename, strerror(errno));
+ }
+ }
+
+ return retval;
+}
+
+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);