static int compare_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, struct sysfs_pair *pair)
{
struct sysfs_attribute *tmpattr;
+ int i;
+ int len;
if ((pair == NULL) || (pair->file[0] == '\0') || (pair->value == '\0'))
return -ENODEV;
if (tmpattr == NULL)
return -ENODEV;
+ /* strip trailing whitespace of value, if not asked to match for it */
+ if (! isspace(pair->value[strlen(pair->value)-1])) {
+ i = len = strlen(tmpattr->value);
+ while (i > 0 && isspace(tmpattr->value[i-1]))
+ i--;
+ if (i < len) {
+ tmpattr->value[i] = '\0';
+ dbg("remove %i trailing whitespace chars from '%s'",
+ len - i, tmpattr->value);
+ }
+ }
+
dbg("compare attribute '%s' value '%s' with '%s'",
pair->file, tmpattr->value, pair->value);
if (strcmp_pattern(pair->value, tmpattr->value) != 0)
--- /dev/null
+WHITE SPACE
conf => <<EOF
BUS="scsi", ID="*:0:0:0", NAME="scsi-0:0:0:0"
BUS="scsi", ID="0:0:0:0", NAME="bad"
+EOF
+ },
+ {
+ desc => "ignore SYSFS attribute whitespace",
+ subsys => "block",
+ devpath => "block/sda",
+ expected => "ignored",
+ conf => <<EOF
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE", NAME="ignored"
+EOF
+ },
+ {
+ desc => "do not ignore SYSFS attribute whitespace",
+ subsys => "block",
+ devpath => "block/sda",
+ expected => "matched-with-space",
+ conf => <<EOF
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="wrong-to-ignore"
+BUS="scsi", SYSFS{whitespace_test}="WHITE SPACE ", NAME="matched-with-space"
EOF
},
);
Match sysfs device attribute like label, vendor, USB serial number, SCSI UUID
or file system label. Up to 5 different sysfs files can be checked, with
all of the values being required in order to match the rule.
+.br
+Trailing whitespace characters in the sysfs attribute value are ignored, if
+the key doesn't have any trailing whitespace characters by itself.
.TP
.B PROGRAM
Call external program. This key is valid if the program returns successful.