linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "John L. Fjellstad" <john-hotplug@fjellstad.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: additional symlinks
Date: Tue, 17 Feb 2004 14:38:49 +0000	[thread overview]
Message-ID: <20040217143849.GA4217@fjellstad.org> (raw)
In-Reply-To: <20040217072940.GA2227@fjellstad.org>


[-- Attachment #1.1: Type: text/plain, Size: 1737 bytes --]

On Tue, Feb 17, 2004 at 03:08:18PM +0300, "Andrey Borzenkov"  wrote:
  
> that is what my patch (part of) did and so far it was declared useless.

Yup, I saw it on the list. I actually read it, but then forgot about it,
and just noticed your email about additional symlinks yesterday (or so).
And I been spending the last couple of days playing around with udev and
the code, and I just thought about last night (couldn't sleep).

Your solution is probably the more elegant one.

> in this list archives (it is for older version of udev, I still did not
> have time to catch up).

If you want to, I can do it...

> glad to see I am not alone :) if you could add arguments to convince others
> it would be just fine.

Well, I thought you made some convincing arguments, but...

What got me thinking about it was trying to get ide-devfs.sh to work
as I wanted. Since my cdrom is a combined cdrom/dvd, I wanted an extra
symlink from dvd, but right now it's impossible without editing the
ide-devfs.sh script.

For instance:
BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/scripts/ide-devfs.sh %k %b
%n", NAME="%1c", SYMLINK="%2c %3c"

This rule will create ide/.../cd, with symlinks to cdroms/cdrom0 and
cdrom.

With my patch, I can write an additional rule like this:
UPDATE="ide/host0/bus0/target0/lun0/", SYMLINK="dvd"

which will add the dvd symlink to the name specified in UPDATE.

It's not as elegant as your solution, since the value in UPDATE has to
be the same as the value in NAME given in the first rule.

-- 
John
email: john@fjellstad.org               Quis custodiet ipsos custodes
Yahoo Messenger: jfjellstad
MSN Messenger: liemfjellstad@hotmail.com
web: http://www.fjellstad.org/

[-- Attachment #1.2: namedev.h.patch --]
[-- Type: text/plain, Size: 342 bytes --]

--- namedev.h.orig	2004-02-17 01:07:46.000000000 +0100
+++ namedev.h	2004-02-17 08:32:57.000000000 +0100
@@ -43,6 +43,7 @@ struct sysfs_class_device;
 #define FIELD_RESULT	"RESULT"
 #define FIELD_KERNEL	"KERNEL"
 #define FIELD_NAME	"NAME"
+#define FIELD_UPDATE	"UPDATE"
 #define FIELD_SYMLINK	"SYMLINK"
 
 #define PROGRAM_MAXARG	10

[-- Attachment #1.3: namedev_parse.c.patch --]
[-- Type: text/plain, Size: 2952 bytes --]

--- namedev_parse.c.orig	2004-02-17 00:02:53.000000000 +0100
+++ namedev_parse.c	2004-02-17 13:26:38.000000000 +0100
@@ -48,10 +48,35 @@ static int add_config_dev(struct config_
 		return -ENOMEM;
 	memcpy(tmp_dev, new_dev, sizeof(*tmp_dev));
 	list_add_tail(&tmp_dev->node, &config_device_list);
-	//dump_config_dev(tmp_dev);
+	/*dump_config_dev(tmp_dev);*/
 	return 0;
 }
 
+/* Update symlink to a given device */
+static int update_config_dev(struct config_device *new_dev)
+{
+	struct config_device *dev = NULL;
+	int len = 0;
+	
+	dump_config_dev(new_dev);
+	list_for_each_entry(dev, &config_device_list, node) {
+		if (strcmp(dev->name, new_dev->name)) {
+			continue;
+		}
+		len = strlen(dev->symlink);	
+		if ((strlen(dev->symlink) + strlen(new_dev->symlink) + 2) <
+		    sizeof(dev->symlink)) {
+			strcat(dev->symlink, " ");
+			strcat(dev->symlink, new_dev->symlink);
+			//dump_config_dev(dev);
+			return 0;
+		} else {
+			break;
+		}
+	}
+	return -1; /* Do I need a special code here?" */
+}
+
 void dump_config_dev(struct config_device *dev)
 {
 	/*FIXME dump all sysfs's */
@@ -96,6 +121,7 @@ int namedev_init_rules(void)
 	int program_given = 0;
 	int retval = 0;
 	struct config_device dev;
+	int update = 0;
 
 	fd = fopen(udev_rules_filename, "r");
 	if (fd != NULL) {
@@ -194,6 +220,16 @@ int namedev_init_rules(void)
 
 			if (strcasecmp(temp2, FIELD_SYMLINK) == 0) {
 				strfieldcpy(dev.symlink, temp3);
+				if (update) {
+					break;
+				} else {
+					continue;
+				}
+			}
+
+			if (strcasecmp(temp2, FIELD_UPDATE) == 0) {
+				update = 1;
+				strfieldcpy(dev.name, temp3);
 				continue;
 			}
 
@@ -203,8 +239,8 @@ 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')) {
+		if (!update && ((dev.sysfs_pair[0].file[0] == '\0') ^
+		    (dev.sysfs_pair[0].value[0] == '\0'))) {
 			dbg("inconsistency in SYSFS_ key");
 			goto error;
 		}
@@ -214,15 +250,33 @@ int namedev_init_rules(void)
 			goto error;
 		}
 
+		if (update) {
+			if ((dev.name[0] == '\0') && 
+			    (dev.symlink[0] == '\0')) {
+				dbg("Updating symlink needs both NAME and SYMLINK");
+				goto error;
+			}
+		}
+		
 		dev.config_line = lineno;
-		retval = add_config_dev(&dev);
+		if (update) {
+			retval = update_config_dev(&dev);
+		//	dump_config_dev_list();
+		} else {
+			retval = add_config_dev(&dev);
+		}
 		if (retval) {
-			dbg("add_config_dev returned with error %d", retval);
+			if (update) {
+				dbg("update_config_dev returned with error %d", retval);
+			} else {
+				dbg("add_config_dev returned with error %d", retval);
+			}
 			continue;
 error:
 			dbg("%s:%d:%d: parse error, rule skipped",
 				  udev_rules_filename, lineno, temp - line);
 		}
+		update=0;
 	}
 exit:
 	fclose(fd);

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

      parent reply	other threads:[~2004-02-17 14:38 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-17  7:29 additional symlinks John L. Fjellstad
2004-02-17 12:08 ` "Andrey Borzenkov" 
2004-02-17 14:38 ` John L. Fjellstad [this message]

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=20040217143849.GA4217@fjellstad.org \
    --to=john-hotplug@fjellstad.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).