From 98b88dbf704a1376ee4c79051086089adde5d626 Mon Sep 17 00:00:00 2001 From: "kay.sievers@vrfy.org" Date: Tue, 18 Nov 2003 00:59:27 -0800 Subject: [PATCH] [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 --- namedev.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/namedev.c b/namedev.c index d76d03b4..f6be43ef 100644 --- a/namedev.c +++ b/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); -- 2.39.5