diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2003-11-18 00:59:27 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:06:24 -0700 |
commit | 98b88dbf704a1376ee4c79051086089adde5d626 (patch) | |
tree | 7ff012ae5707e101b7f640fdaca850636fe30a21 /namedev.c | |
parent | 30defadd3fbef99628a16dcd7c4a2964982deac2 (diff) |
[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
Diffstat (limited to 'namedev.c')
-rw-r--r-- | namedev.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -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); |