X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev_add.c;h=aa19d874c3b31fd85760f42761287e7879ae6f58;hp=66264f06e0771b3b85e0a05d6a7d8540719db504;hb=5f335ca4afaa189799225f856f3af8b3d9fd2e1c;hpb=7e720bd4ad8257d81d273d98294ebbcc03ade9ba diff --git a/udev_add.c b/udev_add.c index 66264f06e..aa19d874c 100644 --- a/udev_add.c +++ b/udev_add.c @@ -70,16 +70,12 @@ int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mo create: switch (udev->type) { - case 'b': + case BLOCK: mode |= S_IFBLK; break; - case 'c': - case 'u': + case CLASS: mode |= S_IFCHR; break; - case 'p': - mode |= S_IFIFO; - break; default: dbg("unknown node type %c\n", udev->type); return -EINVAL; @@ -117,12 +113,11 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de { char filename[NAME_SIZE]; char partitionname[NAME_SIZE]; + struct name_entry *name_loop; uid_t uid = 0; gid_t gid = 0; int tail; - char *pos; - int len; - int i; + int i; snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name); filename[NAME_SIZE-1] = '\0'; @@ -190,8 +185,8 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de for (i = 1; i <= udev->partitions; i++) { dev_t part_devt; - strfieldcpy(partitionname, filename); - strintcat(partitionname, i); + snprintf(partitionname, NAME_SIZE, "%s%d", filename, i); + partitionname[NAME_SIZE-1] = '\0'; part_devt = makedev(major(udev->devt), minor(udev->devt)+1); udev_make_node(udev, partitionname, part_devt, udev->mode, uid, gid); } @@ -199,30 +194,28 @@ static int create_node(struct udevice *udev, struct sysfs_class_device *class_de } /* create symlink(s) if requested */ - foreach_strpart(udev->symlink, " ", pos, len) { - char linkname[NAME_SIZE]; + list_for_each_entry(name_loop, &udev->symlink_list, node) { char linktarget[NAME_SIZE]; - strfieldcpymax(linkname, pos, len+1); - snprintf(filename, NAME_SIZE, "%s/%s", udev_root, linkname); + snprintf(filename, NAME_SIZE, "%s/%s", udev_root, name_loop->name); filename[NAME_SIZE-1] = '\0'; dbg("symlink '%s' to node '%s' requested", filename, udev->name); if (!udev->test_run) - if (strrchr(linkname, '/')) + if (strchr(filename, '/')) create_path(filename); /* optimize relative link */ linktarget[0] = '\0'; i = 0; tail = 0; - while ((udev->name[i] == linkname[i]) && udev->name[i]) { + while (udev->name[i] && (udev->name[i] == name_loop->name[i])) { if (udev->name[i] == '/') tail = i+1; i++; } - while (linkname[i] != '\0') { - if (linkname[i] == '/') + while (name_loop->name[i] != '\0') { + if (name_loop->name[i] == '/') strfieldcat(linktarget, "../"); i++; } @@ -277,7 +270,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) char *pos; int retval = 0; - if (udev->type == 'b' || udev->type == 'c') { + if (udev->type == BLOCK || udev->type == CLASS) { udev->devt = get_devt(class_dev); if (!udev->devt) { dbg("no dev-file found, do nothing"); @@ -292,7 +285,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) selinux_init(); - if (udev->type == 'b' || udev->type == 'c') { + if (udev->type == BLOCK || udev->type == CLASS) { retval = create_node(udev, class_dev); if (retval != 0) goto exit; @@ -305,7 +298,7 @@ int udev_add_device(struct udevice *udev, struct sysfs_class_device *class_dev) snprintf(udev->devname, NAME_SIZE, "%s/%s", udev_root, udev->name); udev->devname[NAME_SIZE-1] = '\0'; - } else if (udev->type == 'n') { + } else if (udev->type == NET) { /* look if we want to change the name of the netif */ if (strcmp(udev->name, udev->kernel_name) != 0) { retval = rename_net_if(udev);