mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
[PATCH] implement printf-like placeholder support for NAME
> Problem is, if you use the LABEL rule to match a device, like a SCSI > vendor, then all of the partitions, as well as the main block device, > will end up with the same name. That's why I added the "add the number" > hack to the LABEL rule. > > So yes, your patch is correct in that we shouldn't always be adding the > number to any match for LABEL (like for char devices), but if we do > that, then we break partitions. Your '%' patch fixes this, but I'd just > like to extend it a bit. Let me see what I can come up with... Oh, I see. Do you mean something like this: LABEL, BUS="usb", model="Creative Labs WebCam 3", NAME="webcam%n-%M:%m-test" results in: "webcam0-81:0-test" Nov 15 16:51:53 pim udev[16193]: get_class_dev: looking at /sys/class/video4linux/video0 Nov 15 16:51:53 pim udev[16193]: get_class_dev: class_dev->name = video0 Nov 15 16:51:53 pim udev[16193]: get_major_minor: dev = 81:0 Nov 15 16:51:53 pim udev[16193]: get_major_minor: found major = 81, minor = 0 Nov 15 16:51:53 pim udev[16193]: udev_add_device: name = webcam0-81:0-test Nov 15 16:51:53 pim udev[16193]: create_node: mknod(/udev/webcam0-81:0-test, 020666, 81, 0) implement printf-like placeholder support for NAME %n-kernel number, %M-major number, %m-minor number
This commit is contained in:
parent
30defadd3f
commit
98b88dbf70
31
namedev.c
31
namedev.c
@ -817,6 +817,37 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
|
||||
strcpy(udev->name, class_dev->name);
|
||||
|
||||
done:
|
||||
/* substitute placeholder in NAME */
|
||||
while (1) {
|
||||
pos = strchr(udev->name, '%');
|
||||
if (pos) {
|
||||
strcpy(name, pos+2);
|
||||
*pos = 0x00;
|
||||
switch (pos[1]) {
|
||||
case 'n':
|
||||
dig = class_dev->name + strlen(class_dev->name);
|
||||
while (isdigit(*(dig-1)))
|
||||
dig--;
|
||||
strcat(udev->name, dig);
|
||||
dbg_parse("kernel number appended: %s", dig);
|
||||
break;
|
||||
case 'm':
|
||||
sprintf(pos, "%u", udev->minor);
|
||||
dbg_parse("minor number appended: %u", udev->minor);
|
||||
break;
|
||||
case 'M':
|
||||
sprintf(pos, "%u", udev->major);
|
||||
dbg_parse("major number appended: %u", udev->major);
|
||||
break;
|
||||
default:
|
||||
dbg_parse("unknown substitution type: %%%c", pos[1]);
|
||||
break;
|
||||
}
|
||||
strcat(udev->name, name);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
/* mode was never set above */
|
||||
if (!udev->mode) {
|
||||
udev->mode = get_default_mode(class_dev);
|
||||
|
Loading…
Reference in New Issue
Block a user