From mboxrd@z Thu Jan 1 00:00:00 1970 From: "John L. Fjellstad" Date: Tue, 17 Feb 2004 14:38:49 +0000 Subject: Re: additional symlinks Message-Id: <20040217143849.GA4217@fjellstad.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="aM3YZ0Iwxop3KEKx" List-Id: References: <20040217072940.GA2227@fjellstad.org> In-Reply-To: <20040217072940.GA2227@fjellstad.org> To: linux-hotplug@vger.kernel.org --aM3YZ0Iwxop3KEKx Content-Type: multipart/mixed; boundary="FL5UXtIhxfXey3p5" Content-Disposition: inline --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Feb 17, 2004 at 03:08:18PM +0300, "Andrey Borzenkov" wrote: =20 > 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 othe= rs > 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=3D"ide", KERNEL=3D"hd*", PROGRAM=3D"/etc/udev/scripts/ide-devfs.sh %k %b %n", NAME=3D"%1c", SYMLINK=3D"%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=3D"ide/host0/bus0/target0/lun0/", SYMLINK=3D"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. --=20 John email: john@fjellstad.org Quis custodiet ipsos custodes Yahoo Messenger: jfjellstad MSN Messenger: liemfjellstad@hotmail.com web: http://www.fjellstad.org/ --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="namedev.h.patch" Content-Transfer-Encoding: quoted-printable --- 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" =20 #define PROGRAM_MAXARG 10 --FL5UXtIhxfXey3p5 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="namedev_parse.c.patch" Content-Transfer-Encoding: quoted-printable --- 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; } =20 +/* Update symlink to a given device */ +static int update_config_dev(struct config_device *new_dev) +{ + struct config_device *dev =3D NULL; + int len =3D 0; +=09 + dump_config_dev(new_dev); + list_for_each_entry(dev, &config_device_list, node) { + if (strcmp(dev->name, new_dev->name)) { + continue; + } + len =3D strlen(dev->symlink);=09 + 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 =3D 0; int retval =3D 0; struct config_device dev; + int update =3D 0; =20 fd =3D fopen(udev_rules_filename, "r"); if (fd !=3D NULL) { @@ -194,6 +220,16 @@ int namedev_init_rules(void) =20 if (strcasecmp(temp2, FIELD_SYMLINK) =3D=3D 0) { strfieldcpy(dev.symlink, temp3); + if (update) { + break; + } else { + continue; + } + } + + if (strcasecmp(temp2, FIELD_UPDATE) =3D=3D 0) { + update =3D 1; + strfieldcpy(dev.name, temp3); continue; } =20 @@ -203,8 +239,8 @@ int namedev_init_rules(void) } =20 /* simple plausibility check for given keys */ - if ((dev.sysfs_pair[0].file[0] =3D=3D '\0') ^ - (dev.sysfs_pair[0].value[0] =3D=3D '\0')) { + if (!update && ((dev.sysfs_pair[0].file[0] =3D=3D '\0') ^ + (dev.sysfs_pair[0].value[0] =3D=3D '\0'))) { dbg("inconsistency in SYSFS_ key"); goto error; } @@ -214,15 +250,33 @@ int namedev_init_rules(void) goto error; } =20 + if (update) { + if ((dev.name[0] =3D=3D '\0') &&=20 + (dev.symlink[0] =3D=3D '\0')) { + dbg("Updating symlink needs both NAME and SYMLINK"); + goto error; + } + } + =09 dev.config_line =3D lineno; - retval =3D add_config_dev(&dev); + if (update) { + retval =3D update_config_dev(&dev); + // dump_config_dev_list(); + } else { + retval =3D 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=3D0; } exit: fclose(fd); --FL5UXtIhxfXey3p5-- --aM3YZ0Iwxop3KEKx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iEYEARECAAYFAkAyJ3kACgkQkz0vhQtHHRjQ8wCaAnBqA7i9N6VI5rPM1EHLfRDQ wDgAn0eJKZAfdvpRrzNzuWs2AfhVe4MW =E5rt -----END PGP SIGNATURE----- --aM3YZ0Iwxop3KEKx-- ------------------------------------------------------- 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=1356&alloc_id=3438&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