* Re: additional symlinks
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
1 sibling, 0 replies; 3+ messages in thread
From: "Andrey Borzenkov" @ 2004-02-17 12:08 UTC (permalink / raw)
To: linux-hotplug
> Correct me if I'm wrong, but udev currently doesn't let you specifiy
> additional symlinks, correct?
>
> That is, if you have this in the udev.rules file:
> BUS="ide", PROGRAM="/bin/cat /proc/ide/%k/media", RESULT="cdrom",
> NAME="cdroms/cdrom%m", SYMLINK="cdrom%n"
>
> I can't do something like this later on in the rules file:
> UPDATE="cdroms/cdrom%m", SYMLINK="dvd%n"
>
> I have a patch ready to do this, but didn't want to submit until I was
> clear on this issue (no point in submitting something that already been
> done)
that is what my patch (part of) did and so far it was declared useless.
I would be interested to compare your implementation. You could find mine
in this list archives (it is for older version of udev, I still did not
have time to catch up).
glad to see I am not alone :) if you could add arguments to convince others
it would be just fine.
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: additional symlinks
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
1 sibling, 0 replies; 3+ messages in thread
From: John L. Fjellstad @ 2004-02-17 14:38 UTC (permalink / raw)
To: linux-hotplug
[-- 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 --]
^ permalink raw reply [flat|nested] 3+ messages in thread