Skip to contentSkip to conversation

multple rules files support/symlink rules support

PATCH In review Andrey Borzenkov 6 participants 16 messages Jan 17, 2004 – Feb 17, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multple rules files support/symlink rules support

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

directory is scanned and all files are read. Currently it does not descend into subdirs.

- to make the above really useful it allows multiple rules with symlinks; all rules are collected and applied (note 100 characters limit for total names length currently). It still takes the first found name and warns if more were seen.

The multiple files support for rules file is actually for the case when you need be sure about ordering; sorting readdir results was too clumsy.

The patch allows easy local customization without any need to edit existing rules. It is expected that distributions will ship basic rules (based on required policy or compatibility or whatever) and users will create extra rules to name some devices to taste. E.g. I currently have basic Mandrake config that creates compatible devfs names and local rules to name some local devices. Ie.

udev_rules="/etc/udev/conf.d"

with

{pts/0}% LC_ALL=C ll /etc/udev/conf.d
total 8

-rw-r--r--    1 root     root          142 Jan 17 22:07 bor
-rwxr-xr-x    1 root     root         3848 Jan 17 22:58 udev.rules.devfs*

where

{pts/0}% cat /etc/udev/conf.d/bor
KERNEL="hd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D" KERNEL="sd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D"

and I get

{pts/0}% LC_ALL=C ll /udev/flash0
total 1

lrwxrwxrwx    1 root     root            6 Jan 17 22:59 disc -> ../sdb
lrwxrwxrwx    1 root     root            7 Jan 17 22:59 part1 -> ../sdb1

for USB stick (upper one :)

(not that interesting because currently SCSI devfs names are missing, but that would create them as well just fine).

regards

-andrey

namedev.c renamed from namedev.c.multi +35 -17
@@ -602,6 +602,7 @@ int namedev_name_device(struct sysfs_cla
 	struct config_device *dev;
 	struct perm_device *perm;
 	char *pos;
+	int found = 0;
 
 	udev->mode = 0;
 
@@ -714,29 +715,46 @@ int namedev_name_device(struct sysfs_cla
 			}
 		}
 
-		/* check if we are instructed to ignore this device */
-		if (dev->name[0] == '\0') {
-			dbg("instructed to ignore this device");
-			return -1;
+		/* if everything matched add symlink to list of aliases */
+		if (dev->symlink[0] != '\0') {
+			char temp[NAME_MAX];
+
+			/* do not clobber dev */
+			strfieldcpy(temp, dev->symlink);
+			apply_format(udev, temp);
+			if (strlen(udev->symlink) + strlen(temp) + 2 > sizeof(udev->symlink))
+				dbg("could not append symlink %s for %s",
+				    dev->symlink, udev->kernel_name);
+			else {
+				strfieldcat(udev->symlink, temp);
+				strfieldcat(udev->symlink, " ");
+			}
 		}
 
-		/* Yup, this rule belongs to us! */
-		dbg("found matching rule, '%s' becomes '%s'", dev->kernel, dev->name);
-		strfieldcpy(udev->name, dev->name);
-		strfieldcpy(udev->symlink, dev->symlink);
-		goto found;
+		/* is this symlink only rule? */
+		if (dev->name[0] == '\0')
+			continue;
+
+		/* Yup, this rule belongs to us!
+		 * but continue to collect symlinks */
+		if (!found) {
+			dbg("found matching rule, '%s' becomes '%s'",
+			    dev->kernel, dev->name);
+			strfieldcpy(udev->name, dev->name);
+
+			/* substitute placeholder */
+			apply_format(udev, udev->name);
+			found = 1;
+		} else
+			dbg("conflicting rule for '%s' would become '%s'",
+			    dev->kernel, dev->name);
 	}
 
 	/* no rule was found so we use the kernel name */
-	strfieldcpy(udev->name, class_dev->name);
-	goto done;
-
-found:
-	/* substitute placeholder */
-	apply_format(udev, udev->name);
-	apply_format(udev, udev->symlink);
+	if (!found)
+		strfieldcpy(udev->name, class_dev->name);
+	dbg("symlinks for '%s' are: '%s'", udev->name, udev->symlink);
 
-done:
 	perm = find_perm(udev->name);
 	if (perm) {
 		udev->mode = perm->mode;
namedev_parse.c renamed from namedev_parse.c.multi +73 -8

119 lines not on this page · raw message

udev.h renamed from udev.h.multi +7 -0
@@ -80,6 +80,13 @@ do { \
 	strncpy(to, from, sizeof(to)-1); \
 } while (0)
 
+#define strfieldcat(to, from) \
+do { \
+	to[sizeof(to)-1] = '\0'; \
+	strncat(to, from, sizeof(to)-1); \
+} while (0)
+
+
 extern int udev_add_device(char *path, char *subsystem);
 extern int udev_remove_device(char *path, char *subsystem);
 extern void udev_init_config(void);
#1 lore raw

svetoslav pointed that patch removed possibility to ignore devices. Updated version attached. Now name is ignored if neither SYMLINK nor NAME is specified.

regards

-andrey

Quoted 46 lines · Andrey Borzenkov

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

directory is scanned and all files are read. Currently it does not descend into subdirs.

- to make the above really useful it allows multiple rules with symlinks; all rules are collected and applied (note 100 characters limit for total names length currently). It still takes the first found name and warns if more were seen.

The multiple files support for rules file is actually for the case when you need be sure about ordering; sorting readdir results was too clumsy.

The patch allows easy local customization without any need to edit existing rules. It is expected that distributions will ship basic rules (based on required policy or compatibility or whatever) and users will create extra rules to name some devices to taste. E.g. I currently have basic Mandrake config that creates compatible devfs names and local rules to name some local devices. Ie.

udev_rules="/etc/udev/conf.d"

with

{pts/0}% LC_ALL=C ll /etc/udev/conf.d
total 8

(quoted diff) +0 -2
-rw-r--r--    1 root     root          142 Jan 17 22:07 bor
-rwxr-xr-x    1 root     root         3848 Jan 17 22:58 udev.rules.devfs*

where

{pts/0}% cat /etc/udev/conf.d/bor
KERNEL="hd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D" KERNEL="sd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D"

and I get

{pts/0}% LC_ALL=C ll /udev/flash0
total 1

lrwxrwxrwx    1 root     root            6 Jan 17 22:59 disc -> ../sdb
lrwxrwxrwx    1 root     root            7 Jan 17 22:59 part1 -> ../sdb1
Quoted 8 lines

for USB stick (upper one :)

(not that interesting because currently SCSI devfs names are missing, but that would create them as well just fine).

regards

-andrey

namedev.c renamed from namedev.c.multi +36 -14
@@ -715,28 +715,50 @@ int namedev_name_device(struct sysfs_cla
 		}
 
 		/* check if we are instructed to ignore this device */
-		if (dev->name[0] == '\0') {
+		if (dev->name[0] == '\0' && dev->symlink[0] == '\0') {
 			dbg("instructed to ignore this device");
 			return -1;
 		}
 
-		/* Yup, this rule belongs to us! */
-		dbg("found matching rule, '%s' becomes '%s'", dev->kernel, dev->name);
-		strfieldcpy(udev->name, dev->name);
-		strfieldcpy(udev->symlink, dev->symlink);
-		goto found;
+		/* if everything matched add symlink to list of aliases */
+		if (dev->symlink[0] != '\0') {
+			char temp[NAME_MAX];
+
+			/* do not clobber dev */
+			strfieldcpy(temp, dev->symlink);
+			apply_format(udev, temp);
+			if (strlen(udev->symlink) + strlen(temp) + 2 > sizeof(udev->symlink))
+				dbg("could not append symlink %s for %s",
+				    dev->symlink, udev->kernel_name);
+			else {
+				strfieldcat(udev->symlink, temp);
+				strfieldcat(udev->symlink, " ");
+			}
+		}
+
+		/* is this symlink only rule? */
+		if (dev->name[0] == '\0')
+			continue;
+
+		/* Yup, this rule belongs to us!
+		 * but continue to collect symlinks */
+		if (udev->name[0] == '\0') {
+			dbg("found matching rule, '%s' becomes '%s'",
+			    dev->kernel, dev->name);
+			strfieldcpy(udev->name, dev->name);
+
+			/* substitute placeholder */
+			apply_format(udev, udev->name);
+		} else
+			dbg("conflicting rule for '%s' would become '%s'",
+			    dev->kernel, dev->name);
 	}
 
 	/* no rule was found so we use the kernel name */
-	strfieldcpy(udev->name, class_dev->name);
-	goto done;
-
-found:
-	/* substitute placeholder */
-	apply_format(udev, udev->name);
-	apply_format(udev, udev->symlink);
+	if (udev->name[0] == '\0')
+		strfieldcpy(udev->name, class_dev->name);
+	dbg("symlinks for '%s' are: '%s'", udev->name, udev->symlink);
 
-done:
 	perm = find_perm(udev->name);
 	if (perm) {
 		udev->mode = perm->mode;
namedev_parse.c renamed from namedev_parse.c.multi +73 -8

119 lines not on this page · raw message

udev.h renamed from udev.h.multi +7 -0
@@ -80,6 +80,13 @@ do { \
 	strncpy(to, from, sizeof(to)-1); \
 } while (0)
 
+#define strfieldcat(to, from) \
+do { \
+	to[sizeof(to)-1] = '\0'; \
+	strncat(to, from, sizeof(to)-1); \
+} while (0)
+
+
 extern int udev_add_device(char *path, char *subsystem);
 extern int udev_remove_device(char *path, char *subsystem);
 extern void udev_init_config(void);
#2 lore raw
In reply to Andrey Borzenkov
Quoted 4 lines

svetoslav pointed that patch removed possibility to ignore devices. Updated
version attached. Now name is ignored if neither SYMLINK nor NAME is specified.

i'm not sure i got what does "neither SYMLINK nor NAME is specified" mean :(

do you mean that if there is no rule at all the device will be ignored ? (have to catch all devices with 'KERNEL="*", NAME="%k" '

or
ignoreing is achieved by single line containing 'KERNEL="device to ignore" '

best,

svetljo

Quoted 66 lines · Andrey Borzenkov
Quoted 7 lines

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

directory is scanned and all files are read. Currently it does not

descend

Quoted 3 lines

into subdirs.

- to make the above really useful it allows multiple rules with

symlinks;

Quoted 2 lines

all rules are collected and applied (note 100 characters limit for total names length currently). It still takes the first found name and warns

if

Quoted 3 lines

more were seen.

The multiple files support for rules file is actually for the case when

you

Quoted 3 lines

need be sure about ordering; sorting readdir results was too clumsy.

The patch allows easy local customization without any need to edit

existing

Quoted 2 lines

rules. It is expected that distributions will ship basic rules (based on required policy or compatibility or whatever) and users will create

extra

Quoted 1 line

rules to name some devices to taste. E.g. I currently have basic

Mandrake

Review

Quoted 11 lines

config that creates compatible devfs names and local rules to name some local devices. Ie.

udev_rules="/etc/udev/conf.d"

with

{pts/0}% LC_ALL=C ll /etc/udev/conf.d
total 8

(quoted diff) +0 -2
-rw-r--r--    1 root     root          142 Jan 17 22:07 bor
-rwxr-xr-x    1 root     root         3848 Jan 17 22:58

udev.rules.devfs*

Quoted 9 lines

where

{pts/0}% cat /etc/udev/conf.d/bor
KERNEL="hd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D" KERNEL="sd*" PROGRAM="/etc/udev/scripts/removables %k" SYMLINK="%c/%D"

and I get

Quoted 8 lines

{pts/0}% LC_ALL=C ll /udev/flash0
total 1

lrwxrwxrwx    1 root     root            6 Jan 17 22:59 disc -> ../sdb
lrwxrwxrwx    1 root     root            7 Jan 17 22:59 part1 -> ../sdb1

for USB stick (upper one :)

(not that interesting because currently SCSI devfs names are missing,

but

Quoted 5 lines

that would create them as well just fine).

regards

-andrey

Signature · 14 lines
+++ GMX - die erste Adresse für Mail, Message, More +++
Bis 31.1.: TopMail + Digicam für nur 29 EUR http://www.gmx.net/topmail



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#3 lore raw
In reply to Andrey Borzenkov
Quoted 4 lines · Svetoslav Slavtchev

or
ignoreing is achieved by single line containing 'KERNEL="device to ignore" '

yes.

KERNEL="foo" NAME="" SYMLINK=""

both NAME and SYMLINK are redundant as they default to NULL anyway currently but using explicit empty strings is better if this is ever changed. Your Mandrake devfs.rules should now work as is again.

-andrey

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Andrey Borzenkov
Quoted 7 lines · Svetoslav Slavtchev
Quoted 3 lines

or
ignoreing is achieved by single line containing 'KERNEL="device to

ignore"

Quoted 1 line

'

Quoted 8 lines

yes.

KERNEL="foo" NAME="" SYMLINK=""

both NAME and SYMLINK are redundant as they default to NULL anyway currently
but using explicit empty strings is better if this is ever changed. Your Mandrake devfs.rules should now work as is again.

Yep, it works :-)
i haven't tried only with
KERNEL="dm-[0-9]*

but the following works as previously :-)
KERNEL="dm-[0-9]*, NAME=""

svetljo

Signature · 14 lines
+++ GMX - die erste Adresse für Mail, Message, More +++
Bis 31.1.: TopMail + Digicam für nur 29 EUR http://www.gmx.net/topmail



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#5 lore raw
In reply to Andrey Borzenkov
Quoted 8 lines · Andrey Borzenkov

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

directory is scanned and all files are read. Currently it does not descend into subdirs.

Ok, that is nice. I like that part of the patch.

Quoted 4 lines

- to make the above really useful it allows multiple rules with symlinks; all rules are collected and applied (note 100 characters limit for total names length currently). It still takes the first found name and warns if more were seen.

I don't really understand this. Can you give an example of how this would work? Why do we want to have multiple symlinks from different rules?

thanks,

greg k-h

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Andrey Borzenkov
Quoted 16 lines · Andrey Borzenkov
Quoted 7 lines

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

directory is scanned and all files are read. Currently it does not

descend

Quoted 1 line

into subdirs.

Ok, that is nice. I like that part of the patch.

Quoted 1 line

- to make the above really useful it allows multiple rules with

symlinks; all

Quoted 1 line

rules are collected and applied (note 100 characters limit for total

Quoted 8 lines

names

Quoted 1 line

length currently). It still takes the first found name and warns if more

were

Quoted 1 line

seen.

I don't really understand this. Can you give an example of how this would work? Why do we want to have multiple symlinks from different rules?

please take a look in the attached files

- the first should create layout as the one of static /dev (00-lsb)
- the second adds devfs symlinks (01-devfs)
- additional one's could be used by the configuration
tools of the distribution( e.g. to create /dev/cd-writer or /dev/dvd)
- and at the end would come the personal rules of the
owner of the system

in this way the device would be accessable from the standard static /dev, devfs, and the additional system/personal namespaces

in this way, if the owner changes only his rule file, he can not harm the system
he only add's a personal symlink, devices are created as in static dev, with symlink for devfs

best,

svetljo

PS.
small example
in 00-lsb
---------------
KERNEL="psaux", SYMLINK="psmouse"
KERNEL="video0", SYMLINK="video"
KERNEL="radio0", SYMLINK="radio"
KERNEL="vbi0", SYMLINK="vbi"
KERNEL="vtx0", SYMLINK="vtx"
-----------------
in 01-devfs
---------------
KERNEL="psaux", SYMLINK="misc/%k"
KERNEL="video[0-9]", SYMLINK="v4l/video%n"
KERNEL="radio[0-9]", SYMLINK="v4l/radio%n"
KERNEL="vbi[0-9]", SYMLINK="v4l/vbi%n"
KERNEL="vtx[0-9]", SYMLINK="v4l/vtx%n"

Signature · 2 lines
+++ GMX - die erste Adresse für Mail, Message, More +++
Bis 31.1.: TopMail + Digicam für nur 29 EUR http://www.gmx.net/topmail

# There are a number of modifiers that are allowed to be used in the NAME or PROGRAM fields. # They provide the following subsitutions:
# %n - the "kernel number" of the device.
# for example, 'sda3' has a "kernel number" of '3'
# %k - the kernel name for the device.
# %M - the kernel major number for the device
# %m - the kernel minor number for the device
# %b - the bus id for the device
# %c - the return value for the CALLOUT program (note, this doesn't work within
# the PROGRAM field for the obvious reason.)
# %D - use the devfs style disk name for this device.
# For partitions, this will result in 'part%n'
# If this is not a partition, it will result in 'disc'
#

# block
# ignore dm
KERNEL="dm-[0-9]*",	NAME=""
KERNEL="device-mapper",	NAME="mapper/control"

KERNEL="raw[0-9]*", NAME="raw/%k"

#KERNEL="dri-card[1-9]*",NAME="dri/card%n"

# some stuff is commented out below, as IIRC the max of tv cards == 8
KERNEL="video0",	SYMLINK="video"
KERNEL="radio0",	SYMLINK="radio"
KERNEL="vbi0",		SYMLINK="vbi"
KERNEL="vtx0",		SYMLINK="vtx"

KERNEL="em8300", NAME="video/%k"
KERNEL="em8300_ma", NAME="video/%k"
KERNEL="em8300_mv", NAME="video/%k"
KERNEL="em8300_sp", NAME="video/%k"

# input 
KERNEL="psaux",					SYMLINK="psmouse mouse"
KERNEL="mice",		NAME="input/%k",	SYMLINK="usbmouse"
KERNEL="mouse[0-9]*",	NAME="input/%k"
KERNEL="event[0-9]*",	NAME="input/%k"
KERNEL="js0",		NAME="input/%k",	SYMLINK="js"
KERNEL="js[1-9]",	NAME="input/%k",	SYMLINK="js%n"

KERNEL="controlC[0-9]", NAME="snd/%k"
KERNEL="hwC[0-9]D[0-9]", NAME="snd/%k"
KERNEL="midiC[0-9]D[0-9]", NAME="snd/%k"
KERNEL="pcmC[0-9]D[0-9]c", NAME="snd/%k"
KERNEL="pcmC[0-9]D[0-9]p", NAME="snd/%k"
KERNEL="timer", NAME="snd/%k"
KERNEL="seq", NAME="snd/%k"

# There are a number of modifiers that are allowed to be used in the NAME or PROGRAM fields. # They provide the following subsitutions:
# %n - the "kernel number" of the device.
# for example, 'sda3' has a "kernel number" of '3'
# %k - the kernel name for the device.
# %M - the kernel major number for the device
# %m - the kernel minor number for the device
# %b - the bus id for the device
# %c - the return value for the CALLOUT program (note, this doesn't work within
# the PROGRAM field for the obvious reason.)
# %D - use the devfs style disk name for this device.
# For partitions, this will result in 'part%n'
# If this is not a partition, it will result in 'disc'
#

# block
BUS="ide", KERNEL="hd*", PROGRAM="/etc/udev/scripts/ide-devfs.sh %k %b %n",  SYMLINK="%1c %2c %3c %4c %5c"

KERNEL="md[0-9]*", SYMLINK="md/%n"
KERNEL="loop[0-9]*", SYMLINK="loop/%n"
KERNEL="fd[0-9]*", SYMLINK="floppy/%n"
KERNEL="pktcdvd[0-9]*", SYMLINK="pktcdvd/%n"

KERNEL="ram[0-9]*", SYMLINK="rd/%n"

KERNEL="raw[0-9]*", SYMLINK="%k"
KERNEL="rawctl", SYMLINK="raw/%k"

KERNEL="lp[0-9]*", SYMLINK="printers/%n"

# char
KERNEL="vcs",		SYMLINK="vcc/0"
KERNEL="vcs[1-9]*",	SYMLINK="vcc/%n"
KERNEL="vcsa",		NAME="%k",		SYMLINK="vcc/a0 vcsa0"
KERNEL="vcsa[0-9]*",	SYMLINK="vcc/a%n"
KERNEL="tty",		NAME="%k",		SYMLINK="vc/0 tty0"
KERNEL="tty[0-9]*",	SYMLINK="vc/%n"
KERNEL="ttyS[0-9]*",	SYMLINK="tts/%n"
KERNEL="ttyUSB[0-9]*",	SYMLINK="tts/USB%n"
# can one have more then one from these ?
KERNEL="agpgart", 	SYMLINK="misc/agpgart",
KERNEL="apm_bios",	SYMLINK="misc/apm_bios"
KERNEL="rtc",		SYMLINK="misc/rtc"

KERNEL="i2c-[0-9]*", SYMLINK="i2c/%n"

KERNEL="lirc", SYMLINK="lirc/lirc%n"
KERNEL="lirc[1-9]", SYMLINK="lirc/%k"

KERNEL="fb[1-9]*", SYMLINK="fb/%n"

# some stuff is commented out below, as IIRC the max of tv cards == 8
KERNEL="video0",	SYMLINK="v4l/video0"
KERNEL="video[1-9]",	SYMLINK="v4l/video%n"
KERNEL="radio0",	SYMLINK="v4l/radio0"
KERNEL="radio[1-9]",	SYMLINK="v4l/radio%n"
KERNEL="vbi0",		SYMLINK="v4l/vbi0"
KERNEL="vbi[1-9]",	SYMLINK="v4l/vbi%n"
KERNEL="vtx0",		SYMLINK="v4l/vtx0"
KERNEL="vtx[1-9]",	SYMLINK="v4l/vtx%n"
# input 
KERNEL="psaux",		SYMLINK="misc/%k"

############################ sound ######################################
KERNEL="admmidi", SYMLINK="sound/admmidi"
KERNEL="admmidi[1-9]", SYMLINK="sound/admmidi%n"
KERNEL="adsp", SYMLINK="sound/adsp"
KERNEL="adsp[1-9]", SYMLINK="sound/adsp%n"
KERNEL="amidi", SYMLINK="sound/amidi"
KERNEL="amidi[1-9]", SYMLINK="sound/amidi%n"
KERNEL="amixer", SYMLINK="sound/amixer"
KERNEL="amixer[1-9]", SYMLINK="sound/amixer%n"

KERNEL="audio", SYMLINK="sound/audio"
KERNEL="audio[1-9]", SYMLINK="sound/audio%n"
KERNEL="dmmidi", SYMLINK="sound/dmmidi"
KERNEL="dmmidi[1-9]", SYMLINK="sound/dmmidi%n"
KERNEL="dsp", SYMLINK="sound/dsp"
KERNEL="dsp[1-9]", SYMLINK="sound/dsp%n"
KERNEL="dmfm", SYMLINK="sound/dmfm"
KERNEL="dmfm[1-9]", SYMLINK="sound/dmfm%n"
KERNEL="midi", SYMLINK="sound/midi"
KERNEL="midi[1-9]", SYMLINK="sound/midi%n"
KERNEL="mixer", SYMLINK="sound/mixer"
KERNEL="mixer[1-9]", SYMLINK="sound/mixer%n"
KERNEL="music", SYMLINK="sound/music"
KERNEL="music[1-9]", SYMLINK="sound/music%n"
KERNEL="sequencer", SYMLINK="sound/sequencer"
KERNEL="sequencer[1-9]",SYMLINK="sound/%k"

#7 lore raw
In reply to Andrey Borzenkov
Quoted 7 lines · Svetoslav Slavtchev
Quoted 7 lines · Andrey Borzenkov
Quoted 6 lines

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

directory is scanned and all files are read. Currently it does not

descend

Quoted 1 line

into subdirs.

Ok, that is nice. I like that part of the patch.

I do not :) the only reason to allow multiple files was to allow overriding; I had to update patch for ude-014 and sorting directory contents turned out to be quite easy so this is the final version - it takes single name which is either file or directory; directory is scanned, sorted in ascending order and read. klibc version does not support directory.

Quoted 5 lines
Quoted 4 lines

I don't really understand this. Can you give an example of how this would work? Why do we want to have multiple symlinks from different rules?

distribution comes with predefined rules. Taking Mandrake (which is likely to use Svetoslav config) it ships with devfs rules that are keyed on kernel name.

Now user may want to name specific device based on different criteria, e.g. serial number. I.e. you now have

KERNEL="sd*" SYMLINK="ide/host..."

SYSFS_serial="XYZ123" SYMLINK="my_removable"

you simply can't easily merge these two rules. Allowing second rule (in second file) is much more flexible - you simply get two symlinks pointing to the same file. None of them knows or cares about device is really named as long as symlinks are correctly created.

because this version assumes configuration be ordered it now ignores name only if it has not already been defined; else name with empty NAME/SYMLINK is silently ignored.

Quoted 4 lines

please take a look in the attached files

- the first should create layout as the one of static /dev (00-lsb)
- the second adds devfs symlinks (01-devfs)

Svetoslav did very good job making devfs compatibility config; please consider adding it to distribution. It appeears to be mostly complete; there is inherent problem with /dev/discs and /dev/cdroms that probably is not worth time spent on it (i.e. - drop it).

regards

-andrey

Quoted 26 lines

- additional one's could be used by the configuration
tools of the distribution( e.g. to create /dev/cd-writer or /dev/dvd)
- and at the end would come the personal rules of the
owner of the system

in this way the device would be accessable from the standard static /dev, devfs, and the additional system/personal namespaces

in this way, if the owner changes only his rule file, he can not harm the system
he only add's a personal symlink, devices are created as in static dev, with symlink for devfs

best,

svetljo

PS.
small example
in 00-lsb
---------------
KERNEL="psaux", SYMLINK="psmouse"
KERNEL="video0", SYMLINK="video"
KERNEL="radio0", SYMLINK="radio"
KERNEL="vbi0", SYMLINK="vbi"
KERNEL="vtx0", SYMLINK="vtx"

Quoted 8 lines

-----------------
in 01-devfs
---------------
KERNEL="psaux", SYMLINK="misc/%k"
KERNEL="video[0-9]", SYMLINK="v4l/video%n"
KERNEL="radio[0-9]", SYMLINK="v4l/radio%n"
KERNEL="vbi[0-9]", SYMLINK="v4l/vbi%n"
KERNEL="vtx[0-9]", SYMLINK="v4l/vtx%n"

namedev.c renamed from namedev.c.multi +40 -16
@@ -703,30 +703,54 @@ int namedev_name_device(struct sysfs_cla
 			}
 		}
 
-		/* check if we are instructed to ignore this device */
-		if (dev->name[0] == '\0') {
+		/*
+		 * check if we are instructed to ignore this device
+		 * unless name has already beed assigned
+		 */
+		if (udev->name[0] == '\0' && dev->name[0] == '\0' && dev->symlink[0] == '\0') {
 			dbg("instructed to ignore this device");
 			return -1;
 		}
 
-		/* Yup, this rule belongs to us! */
-		info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
-		    udev_rules_filename, dev->config_line, udev->kernel_name, dev->name);
-		strfieldcpy(udev->name, dev->name);
-		strfieldcpy(udev->symlink, dev->symlink);
-		goto found;
+		/* if everything matched add symlink to list of aliases */
+		if (dev->symlink[0] != '\0') {
+			char temp[NAME_MAX];
+
+			/* do not clobber dev */
+			strfieldcpy(temp, dev->symlink);
+			apply_format(udev, temp);
+			if (strlen(udev->symlink) + strlen(temp) + 2 > sizeof(udev->symlink))
+				dbg("could not append symlink %s for %s",
+				    dev->symlink, udev->kernel_name);
+			else {
+				strfieldcat(udev->symlink, temp);
+				strfieldcat(udev->symlink, " ");
+			}
+		}
+
+		/* is this symlink only rule? */
+		if (dev->name[0] == '\0')
+			continue;
+
+		/* Yup, this rule belongs to us!
+		 * but continue to collect symlinks */
+		if (udev->name[0] == '\0') {
+			info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
+			    dev->config_file, dev->config_line, udev->kernel_name, dev->name);
+			strfieldcpy(udev->name, dev->name);
+
+			/* substitute placeholder */
+			apply_format(udev, udev->name);
+		} else
+			dbg("conflicting rule for '%s' would become '%s'",
+			    dev->kernel, dev->name);
 	}
 
 	/* no rule was found so we use the kernel name */
-	strfieldcpy(udev->name, class_dev->name);
-	goto done;
-
-found:
-	/* substitute placeholder */
-	apply_format(udev, udev->name);
-	apply_format(udev, udev->symlink);
+	if (udev->name[0] == '\0')
+		strfieldcpy(udev->name, class_dev->name);
+	dbg("symlinks for '%s' are: '%s'", udev->name, udev->symlink);
 
-done:
 	perm = find_perm(udev->name);
 	if (perm) {
 		udev->mode = perm->mode;
namedev.h renamed from namedev.h.multi +1 -0
@@ -66,6 +66,7 @@ struct config_device {
 	char symlink[NAME_SIZE];
 	struct sysfs_pair sysfs_pair[MAX_SYSFS_PAIRS];
 	int config_line;
+	char *config_file;
 };
 
 struct perm_device {
namedev_parse.c renamed from namedev_parse.c.multi +110 -9

174 lines not on this page · raw message

udev.h renamed from udev.h.multi +7 -0
@@ -56,6 +56,13 @@ do { \
 	strncpy(to, from, sizeof(to)-1); \
 } while (0)
 
+#define strfieldcat(to, from) \
+do { \
+	to[sizeof(to)-1] = '\0'; \
+	strncat(to, from, sizeof(to)-1); \
+} while (0)
+
+
 extern int udev_add_device(char *path, char *subsystem);
 extern int udev_remove_device(char *path, char *subsystem);
 extern void udev_init_config(void);
#8 lore raw
In reply to Andrey Borzenkov
Quoted 5 lines · Andrey Borzenkov
Quoted 4 lines · Svetoslav Slavtchev
Quoted 4 lines · Andrey Borzenkov
Quoted 3 lines

Attached patch adds support for

- multiple rules files. You can now do

...

Quoted 11 lines

I do not :) the only reason to allow multiple files was to allow overriding; I had to update patch for ude-014 and sorting directory contents turned out to be quite easy so this is the final version - it takes single name which is either file or directory; directory is scanned, sorted in ascending order and read. klibc version does not support directory.

Quoted 4 lines
Quoted 4 lines

I don't really understand this. Can you give an example of how this would work? Why do we want to have multiple symlinks from different rules?

Quoted 8 lines

you simply can't easily merge these two rules. Allowing second rule (in second file) is much more flexible - you simply get two symlinks pointing to the same file. None of them knows or cares about device is really named as long as symlinks are correctly created.

because this version assumes configuration be ordered it now ignores name only if it has not already been defined; else name with empty NAME/SYMLINK is silently ignored.

Uhh, why do this inside of udev?
You must be root to setup the rules. So we can expect that you are able to run a update script or something that creates the main file. This can also merge your conflicting rules if needed.

thanks,
Kay

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Andrey Borzenkov

-----Original Message-----

Quoted 26 lines · Andrey Borzenkov
Quoted 5 lines · Svetoslav Slavtchev
Quoted 4 lines
Quoted 4 lines · Andrey Borzenkov
Quoted 3 lines

Attached patch adds support for

- multiple rules files. You can now do

...

Quoted 16 lines

I do not :) the only reason to allow multiple files was to allow overriding; I had to update patch for ude-014 and sorting directory contents turned out to be quite easy so this is the final version - it takes single name which is either file or directory; directory is scanned, sorted in ascending order and read. klibc version does not support directory.

Quoted 4 lines
Quoted 4 lines

I don't really understand this. Can you give an example of how this would work? Why do we want to have multiple symlinks from different rules?

you simply can't easily merge these two rules. Allowing second rule (in second file) is much more flexible - you simply get two symlinks pointing to the same file. None of them knows or cares about device is really named as long as symlinks are correctly created.

Quoted 9 lines
Quoted 3 lines

because this version assumes configuration be ordered it now ignores name only if it has not already been defined; else name with empty NAME/SYMLINK is silently ignored.

Uhh, why do this inside of udev?
You must be root to setup the rules. So we can expect that you are able to run a update script or something that creates the main file. This can also merge your conflicting rules if needed.

unfortunately because you removed my example this statement is rather theoretical.

Once more:

NAME="sd*" PROGRAM="/build-standard-scsi-name" SYMLINK="%c" SYSFS_product="Memory Bird" SYMLINK="my_flash"

Can you explain how are you going to merge them? And even programmatically? there is nothing in those rules that suggests they will be applied to the same device. They are likely to be maintained
separately by people who do not know about other rule nor care. The first one may be part of standard distro (LSB conformance, devfs compatibility, sr -> scd mapping, whatever). The second will be created by particular user on particular system. He may not even know nor care about the other one.

And do not forget that end-users are not likely to ever edit udev configuration. They will be using some frontends provided by distributions. I just try to make life for people creating those frontends easier.

Those two rules are not conflicting in any way. They complement each other. Having them as separate files makes maintenance much easier.

regards

-andrey

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#10 lore raw
In reply to Andrey Borzenkov
Quoted 8 lines · \"Andrey Borzenkov\"

Can you explain how are you going to merge them? And even programmatically? there is nothing in those rules that suggests they will be applied to the same device. They are likely to be maintained
separately by people who do not know about other rule nor care. The first one may be part of standard distro (LSB conformance, devfs compatibility, sr -> scd mapping, whatever). The second will be created by particular user on particular system. He may not even know nor care about the other one.

Agreed. As the debian maintainer of udev I consider *very* important for users being allowed to specify additional rules which will be merged with the ones of the default configuration. A trivial example is being able to add rules with only a SYMLINK statement which will match a specific device and create an additional symlinks (i.e. not override the ones already defined in the main configuration file).

Signature · 13 lines
ciao, |
Marco | [4327 imAdaRzQihvIU]


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
#11 lore raw
In reply to Andrey Borzenkov
Quoted 10 lines · Svetoslav Slavtchev

please take a look in the attached files

- the first should create layout as the one of static /dev (00-lsb)
- the second adds devfs symlinks (01-devfs)
- additional one's could be used by the configuration
tools of the distribution( e.g. to create /dev/cd-writer or /dev/dvd)
- and at the end would come the personal rules of the
owner of the system

Quoted 7 lines

in this way the device would be accessable from the standard static /dev, devfs, and the additional system/personal namespaces

in this way, if the owner changes only his rule file, he can not harm the system
he only add's a personal symlink, devices are created as in static dev, with symlink for devfs

But the "owner" is the "system", right? They are really the same person. I think it looks like a neat hack to be able to add symlinks, but I can't see a real use for it in the world.

Take a look at /etc/fstab, or any of the other system wide config files in /etc. They don't provide a place that a user can add more items in another file, do they? All that is needed is to modify the original file to add your new items.

thanks,

greg k-h

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#12 lore raw
In reply to Andrey Borzenkov
Quoted 4 lines · Greg KH

On Thu, Jan 22, 2004 at 06:44:53PM +0100, Svetoslav Slavtchev wrote:
But the "owner" is the "system", right? They are really the same person. I think it looks like a neat hack to be able to add symlinks, but I can't see a real use for it in the world.

Maybe user actions should be limited to ~/Devices, or something similar...

Quoted 4 lines

Take a look at /etc/fstab, or any of the other system wide config files in /etc. They don't provide a place that a user can add more items in another file, do they? All that is needed is to modify the original file to add your new items.

But this is not a virtue of the actual way-of-doing-things!!! This is one of the most unfriendly issues that you have to face when running a Linux distro or a Unix system.

These global files are never updated enought to support the "latest cheap camera" I bougth. So I need to add items to these files... but how?
1) su -c "vim /etc/somefile" -- you need to know root password
2) sudo vim /etc/somefile -- This opens security holes like shell excaping
3) vim ~/.my_devices -- Just parse it in a safe way and use a dir under $HOME, no security probs at all

And solutions 1 and 2 permits to a simple user to screw up the whole system in a second :(
At my uni labs we run only linux boxes but we are not allowed to attach usb-keys, card-readers and other peripherals for this very problem (try to update 100+ boxes with different a configuration for every student...). It would be nice to be able to do so in the future.

--
Gioele Barabucci

-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#13 lore raw
In reply to Andrey Borzenkov
Quoted 5 lines · Andrey Borzenkov

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

Care to fix this patch up for the latest udev release?

thanks,

greg k-h

-------------------------------------------------------
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_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#14 lore raw
In reply to Andrey Borzenkov

-----Original Message-----

Quoted 10 lines · Andrey Borzenkov
Quoted 5 lines

Attached patch adds support for

- multiple rules files. You can now do

udev_rules="file1 dir2 file3 ..."

Care to fix this patch up for the latest udev release?

I will when I am back home (next week)

What about the second part (allow symlink-only rules)?

thank you

-andrey

-------------------------------------------------------
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_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#15 lore raw
In reply to Andrey Borzenkov
Quoted 10 lines · Andrey Borzenkov

-----Original Message-----

Quoted 6 lines · Andrey Borzenkov
Quoted 4 lines

Attached patch adds support for

- multiple rules files. You can now do

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

udev_rules="file1 dir2 file3 ..."

Care to fix this patch up for the latest udev release?

I will when I am back home (next week)

What about the second part (allow symlink-only rules)?

Yes, I think that would be good to have too. Just split the patches up into two pieces, only one patch per feature/fix.

thanks,

greg k-h

-------------------------------------------------------
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_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel