chiark / gitweb /
[PATCH] allow SYSFS{file}
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 17 Feb 2004 05:39:40 +0000 (21:39 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:32:28 +0000 (21:32 -0700)
On Sun, Feb 15, 2004 at 03:36:00AM +0100, Kay Sievers wrote:
>
> Since we have %s{file} it may be nice to allow SYSFS{file}.
> This patch allows:
>
>   BUS="usb", SYSFS{idProduct}="a511", NAME="video%n"
>
> compared to the current:
>
>   BUS="usb", SYSFS_idProduct="a511", NAME="video%n"
>
> The curent syntax is still supported.
> Looks a bit nicer and less hackish, I think.

Better patch with infrastructure to easily implement KEY{attribute}
for every other key. The first user is the SYSFS{file} key.
Both versions, brackets or underscore is supported for the attribute.

namedev.h
namedev_parse.c
test/udev-test.pl

index a0cdba6b16f83570b50b8adb168cde47df0efaf0..e38c4f525741b0d4bdfd2616c50715f0a735d7d6 100644 (file)
--- a/namedev.h
+++ b/namedev.h
@@ -36,7 +36,7 @@ struct sysfs_class_device;
 #define PROGRAM_SIZE   100
 
 #define FIELD_BUS      "BUS"
-#define FIELD_SYSFS    "SYSFS_"
+#define FIELD_SYSFS    "SYSFS"
 #define FIELD_ID       "ID"
 #define FIELD_PLACE    "PLACE"
 #define FIELD_PROGRAM  "PROGRAM"
index e6575fa108431958e33d0a283b2c7bd20935f4ba..20ff60d640923458bf48a5861b402fb76cba7468 100644 (file)
@@ -85,6 +85,35 @@ void dump_perm_dev_list(void)
                dump_perm_dev(dev);
 }
 
+/* extract possible KEY{attr} or KEY_attr */
+static char *get_key_attribute(char *str)
+{
+       char *pos;
+       char *attr;
+
+       attr = strchr(str, '_');
+       if (attr != NULL) {
+               attr++;
+               dbg("attribute='%s'", attr);
+               return attr;
+       }
+
+       attr = strchr(str, '{');
+       if (attr != NULL) {
+               attr++;
+               pos = strchr(attr, '}');
+               if (pos == NULL) {
+                       dbg("missing closing brace for format");
+                       return NULL;
+               }
+               pos[0] = '\0';
+               dbg("attribute='%s'", attr);
+               return attr;
+       }
+
+       return NULL;
+}
+
 int namedev_init_rules(void)
 {
        char line[255];
@@ -92,6 +121,7 @@ int namedev_init_rules(void)
        char *temp;
        char *temp2;
        char *temp3;
+       char *attr;
        FILE *fd;
        int program_given = 0;
        int retval = 0;
@@ -164,8 +194,12 @@ int namedev_init_rules(void)
                                        ++pair;
                                }
                                if (pair) {
-                                       /* remove prepended 'SYSFS_' */
-                                       strfieldcpy(pair->file, temp2 + sizeof(FIELD_SYSFS)-1);
+                                       attr = get_key_attribute(temp2 + sizeof(FIELD_SYSFS)-1);
+                                       if (attr == NULL) {
+                                               dbg("error parsing " FIELD_SYSFS " attribute");
+                                               continue;
+                                       }
+                                       strfieldcpy(pair->file, attr);
                                        strfieldcpy(pair->value, temp3);
                                }
                                continue;
@@ -205,12 +239,13 @@ int namedev_init_rules(void)
                /* simple plausibility check for given keys */
                if ((dev.sysfs_pair[0].file[0] == '\0') ^
                    (dev.sysfs_pair[0].value[0] == '\0')) {
-                       dbg("inconsistency in SYSFS_ key");
+                       dbg("inconsistency in " FIELD_SYSFS " key");
                        goto error;
                }
 
                if ((dev.result[0] != '\0') && (program_given == 0)) {
-                       dbg("RESULT is only useful when PROGRAM called in any rule before");
+                       dbg(FIELD_RESULT " is only useful when "
+                           FIELD_PROGRAM " is called in any rule before");
                        goto error;
                }
 
index cbe110f797eb33a7afe48924f9dee6f30abcab63..abe622cf8afec7307bb1fabbd11db116ed7eea19 100644 (file)
@@ -191,6 +191,16 @@ EOF
                expected => "Major:8:minor:3:kernelnumber:3:bus:0:0:0:0" ,
                conf     => <<EOF
 BUS="scsi", PLACE="0:0:0:0", NAME="Major:%M:minor:%m:kernelnumber:%n:bus:%b"
+EOF
+       },
+       {
+               desc     => "select sysfs attribute by SYSFS{vendor}",
+               subsys   => "block",
+               devpath  => "block/sda",
+               expected => "disk-IBM-ESXS-sda" ,
+               conf     => <<EOF
+BUS="scsi", SYSFS{vendor}="IBM-ESXS", NAME="disk-%s{vendor}-%k"
+KERNEL="ttyUSB0", NAME="visor"
 EOF
        },
        {