linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] Adding '%s' format specifier to NAME and SYMLINK
Date: Sun, 15 Feb 2004 02:36:00 +0000	[thread overview]
Message-ID: <20040215023600.GA1210@vrfy.org> (raw)
In-Reply-To: <402892DC.4000003@suse.de>

[-- Attachment #1: Type: text/plain, Size: 1822 bytes --]

On Sat, Feb 14, 2004 at 07:32:58PM +0100, Kay Sievers wrote:
> On Thu, Feb 12, 2004 at 05:34:57PM -0800, Greg KH wrote:
> > On Tue, Feb 10, 2004 at 09:14:20AM +0100, Hannes Reinecke wrote:
> > > Hi all,
> > > 
> > > this patch makes the format for NAME and SYMLINK a bit more flexible: 
> > > I've added a new format specifier '%s{<SYSFS_var>}', which allows for 
> > > the value of any sysfs entry found for this device to be inserted.
> > > Example (for our S/390 fcp adapter):
> > > 
> > > BUS="ccw", SYSFS_devtype="1732/03", NAME="%k" \
> > > SYMLINK="zfcp-%s{hba_id}-%s{wwpn}:%s{fcp_lun}"
> > > 
> > > I know this could also be done with an external program, but having this 
> > > incorporated into udev makes life easier, especially if run from 
> > > initramfs. Plus it makes the rules easier to follow, as the result is 
> > > directly visible and need not to be looked up in some external program.
> > > 
> > > Comments etc. welcome.
> > 
> > Oops, sorry I missed this for the 017 release.  I'll look at it tomorrow
> > and get back to you.  At first glance it looks like a good thing.
> > 
> > Oh, you forgot to update the documentation, that's important to do if
> > you want this change to make it in :)
> 
> I took a part of the code and made a version that uses already implemented
> attribute finding logic.
> 
> The parsing of the format length '%3x' and the '%x{attribute}' is a fuction now,
> maybe there are more possible users in the future.
> 
> I've also added the test to udev-test.pl.

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.


thanks,
Kay


[-- Attachment #2: 02-brackets_for_parser.patch --]
[-- Type: text/plain, Size: 1468 bytes --]

diff -Nru a/namedev_parse.c b/namedev_parse.c
--- a/namedev_parse.c	Sun Feb 15 03:18:44 2004
+++ b/namedev_parse.c	Sun Feb 15 03:18:44 2004
@@ -92,6 +92,7 @@
 	char *temp;
 	char *temp2;
 	char *temp3;
+	char *pos;
 	FILE *fd;
 	int program_given = 0;
 	int retval = 0;
@@ -150,7 +151,7 @@
 				continue;
 			}
 
-			if (strncasecmp(temp2, FIELD_SYSFS, sizeof(FIELD_SYSFS)-1) == 0) {
+			if (strncasecmp(temp2, FIELD_SYSFS, sizeof(FIELD_SYSFS)-2) == 0) {
 				struct sysfs_pair *pair = &dev.sysfs_pair[0];
 				int sysfs_pair_num = 0;
 
@@ -164,8 +165,11 @@
 					++pair;
 				}
 				if (pair) {
-					/* remove prepended 'SYSFS_' */
+					/* extract file from 'SYSFS{file}' or 'SYSFS_file' */
 					strfieldcpy(pair->file, temp2 + sizeof(FIELD_SYSFS)-1);
+					pos = strchr(pair->file, '}');
+					if (pos != NULL)
+						pos[0] = '\0';
 					strfieldcpy(pair->value, temp3);
 				}
 				continue;
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl	Sun Feb 15 03:18:44 2004
+++ b/test/udev-test.pl	Sun Feb 15 03:18:44 2004
@@ -194,6 +194,16 @@
 EOF
 	},
 	{
+		desc     => "select sysfs attribute by SYFS{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
+	},
+	{
 		desc     => "sustitution of sysfs value (%s{file})",
 		subsys   => "block",
 		devpath  => "block/sda",

  parent reply	other threads:[~2004-02-15  2:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-10  8:14 [PATCH] Adding '%s' format specifier to NAME and SYMLINK Hannes Reinecke
2004-02-13  1:34 ` Greg KH
2004-02-14 18:32 ` Kay Sievers
2004-02-15  2:36 ` Kay Sievers [this message]
2004-02-16  0:54 ` Kay Sievers
2004-02-16 21:40 ` Greg KH
2004-02-16 21:40 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040215023600.GA1210@vrfy.org \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).