experimental (very simple) SYMLINK creation
Quoted 1 line · Kay Sievers
It is possible now to define SYMLINK= after the NAME= in udev.rules.
Nice! Thanks.
Signature · 14 lines
USB is for mice, FireWire is for men! sUse lINUX ag, nÜRNBERG ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 7 lines · Kay Sievers
here is a experimental symlink creation patch - for discussion, in which direction we should go.
It is possible now to define SYMLINK= after the NAME= in udev.rules. The link is relative to the node, but the path is not optimized now if the node and the link are in the same nested directory. Only one link is supported, cause i need to sleep now :)
Quoted 5 lines
06-simple-symlink-creation.diff
simple symlink creation
reorganized udev-remove to have access to the symlink field subdir creation/removal are functions now udev-test.pl tests for link creation/removal
Eeh, the copy-paste-devil removed one of the tests from udev-test.pl and one comment :) So here is a new patch.
thanks,
Kay
namedev.c +8 -1
@@ -121,6 +121,7 @@copy_string (dev, new_dev, place);copy_string (dev, new_dev, kernel_name);copy_string (dev, new_dev, exec_program); +copy_string (dev, new_dev, symlink);return 0 ; }
@@ -366,6 +367,7 @@if (strcmp_pattern (dev->id, udev->callout_value) !=0 )continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("callout returned matching value '%s', '%s' becomes '%s'" , dev->id, class_dev->name, udev->name);return 0 ;
@@ -416,6 +418,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching attribute '%s', '%s' becomes '%s' " , dev->sysfs_file, class_dev->name, udev->name);
@@ -461,6 +464,7 @@if (!found)continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching id '%s', '%s' becomes '%s'" , dev->id, class_dev->name, udev->name);return 0 ;
@@ -506,6 +510,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching place '%s', '%s' becomes '%s'" , dev->place, class_dev->name, udev->name);return 0 ;
@@ -528,6 +533,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found name, '%s' becomes '%s'" , dev->kernel_name, udev->name);return 0 ;
@@ -618,8 +624,9 @@ goto done; found: -/* substitute placeholder in NAME */ +/* substitute placeholder */ apply_format (udev, udev->name); +apply_format (udev, udev->symlink); done: perm =find_perm (udev->name);
namedev.h +1 -0
@@ -63,6 +63,7 @@char kernel_name[NAME_SIZE ];char exec_program[FILE_SIZE ];char name[NAME_SIZE ]; +char symlink[NAME_SIZE ]; };struct perm_device {
namedev_parse.c +10 -1
@@ -291,9 +291,11 @@if (retval)break ;strfieldcpy (dev.name, temp3); +dbg_parse ("REPLACE name='%s', kernel_name='%s'" , dev.name, dev.kernel_name); } +if (strcasecmp (temp2,TYPE_CALLOUT ) ==0 ) {/* number type */ dev.type =CALLOUT ;
@@ -324,10 +326,17 @@if (retval)break ;strfieldcpy (dev.name, temp3); +dbg_parse ("CALLOUT name='%s', program='%s'" , dev.name, dev.exec_program); } +/* SYMLINK="name" */ + temp2 =strsep (&temp,"," ); + retval =get_value ("SYMLINK" , &temp, &temp3); +if (retval ==0 ) +strfieldcpy (dev.symlink, temp3); + retval =add_config_dev (&dev);if (retval) {dbg ("add_config_dev returned with error %d" , retval);
@@ -414,7 +423,7 @@ dev.mode); retval =add_perm_dev (&dev);if (retval) { -dbg ("add_config_dev returned with error %d" , retval); +dbg ("add_perm_dev returned with error %d" , retval); goto exit; } }
test/udev-test.pl +30 -2
@@ -39,7 +39,7 @@ expected => "boot_disk" , conf => <<EOF LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="boot_disk%n" -REPLACE, KERNEL="ttyUSB0", NAME="visor"" +REPLACE, KERNEL="ttyUSB0", NAME="visor" EOF }, {
@@ -181,6 +181,33 @@ CALLOUT, BUS="foo", PROGRAM="/bin/echo -n foo-%b", ID="*", NAME="%c" EOF }, + { + desc => "symlink creation (node)", + subsys => "tty", + devpath => "class/tty/ttyUSB0", + expected => "ttyUSB0" , + conf => <<EOF +REPLACE, KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="tts/USB%n" +EOF + }, + { + desc => "symlink creation (link)", + subsys => "tty", + devpath => "class/tty/ttyUSB0", + expected => "tts/USB0" , + conf => <<EOF +REPLACE, KERNEL="ttyUSB[0-9]*", NAME="ttyUSB%n", SYMLINK="tts/USB%n" +EOF + }, + { + desc => "symlink creation (link)", + subsys => "block", + devpath => "block/sda/sda2", + expected => "my/own/link2" , + conf => <<EOF +LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="lun0/%D", SYMLINK="my/own/link%n" +EOF + }, ); # set env
@@ -238,7 +265,8 @@ } udev("remove", $config->{subsys}, $config->{devpath}, \$config->{conf}); - if (-e "$PWD/$udev_root$config->{expected}") { + if ((-e "$PWD/$udev_root$config->{expected}") || + (-l "$PWD/$udev_root$config->{expected}")) { print "remove: error\n\n"; system("tree $udev_root"); $error++;
udev-add.c +63 -27
118 lines not on this page · raw message
udev-remove.c +60 -65
156 lines not on this page · raw message
udev.h +1 -0
@@ -64,6 +64,7 @@int major;int minor;mode_t mode; +char symlink[NAME_SIZE ];/* fields that help us in building strings */ unsigned char bus_id[SYSFS_NAME_LEN ];
Quoted 8 lines · Kay Sievers
Quoted 7 lines · Kay Sievers
here is a experimental symlink creation patch - for discussion, in which direction we should go.
It is possible now to define SYMLINK= after the NAME= in udev.rules. The link is relative to the node, but the path is not optimized now if the node and the link are in the same nested directory. Only one link is supported, cause i need to sleep now :)
Quoted 5 lines
Quoted 5 lines
06-simple-symlink-creation.diff
simple symlink creation
reorganized udev-remove to have access to the symlink field subdir creation/removal are functions now udev-test.pl tests for link creation/removal
Here is a new version with relative link target path optimization an better tests in udev-test.pl:
LABEL, BUS="scsi", vendor="IBM-ESXS", NAME="1/2/a/b/node", SYMLINK="1/2/c/d/symlink"
Dec 7 06:48:34 pim udev[13789]: create_node: symlink 'udev-root/1/2/c/d/symlink' to node '1/2/a/b/node' requested Dec 7 06:48:34 pim udev[13789]: create_path: created 'udev-root/1/2/c' Dec 7 06:48:34 pim udev[13789]: create_path: created 'udev-root/1/2/c/d' Dec 7 06:48:34 pim udev[13789]: create_node: symlink(../../a/b/node, udev-root/1/2/c/d/symlink)
thanks,
Kay
namedev.c +8 -1
@@ -121,6 +121,7 @@copy_string (dev, new_dev, place);copy_string (dev, new_dev, kernel_name);copy_string (dev, new_dev, exec_program); +copy_string (dev, new_dev, symlink);return 0 ; }
@@ -366,6 +367,7 @@if (strcmp_pattern (dev->id, udev->callout_value) !=0 )continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("callout returned matching value '%s', '%s' becomes '%s'" , dev->id, class_dev->name, udev->name);return 0 ;
@@ -416,6 +418,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching attribute '%s', '%s' becomes '%s' " , dev->sysfs_file, class_dev->name, udev->name);
@@ -461,6 +464,7 @@if (!found)continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching id '%s', '%s' becomes '%s'" , dev->id, class_dev->name, udev->name);return 0 ;
@@ -506,6 +510,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found matching place '%s', '%s' becomes '%s'" , dev->place, class_dev->name, udev->name);return 0 ;
@@ -528,6 +533,7 @@continue ;strfieldcpy (udev->name, dev->name); +strfieldcpy (udev->symlink, dev->symlink);dbg ("found name, '%s' becomes '%s'" , dev->kernel_name, udev->name);return 0 ;
@@ -618,8 +624,9 @@ goto done; found: -/* substitute placeholder in NAME */ +/* substitute placeholder */ apply_format (udev, udev->name); +apply_format (udev, udev->symlink); done: perm =find_perm (udev->name);
namedev.h +1 -0
@@ -63,6 +63,7 @@char kernel_name[NAME_SIZE ];char exec_program[FILE_SIZE ];char name[NAME_SIZE ]; +char symlink[NAME_SIZE ]; };struct perm_device {
namedev_parse.c +47 -11
97 lines not on this page · raw message
test/udev-test.pl +39 -2
59 lines not on this page · raw message
udev-add.c +72 -27
127 lines not on this page · raw message
udev-remove.c +60 -65
156 lines not on this page · raw message
udev.h +1 -0
@@ -64,6 +64,7 @@int major;int minor;mode_t mode; +char symlink[NAME_SIZE ];/* fields that help us in building strings */ unsigned char bus_id[SYSFS_NAME_LEN ];
Quoted 6 lines · Greg KH
Quoted 3 lines
Quoted 3 lines · Kay Sievers
Quoted 2 lines
here is a experimental symlink creation patch - for discussion, in which direction we should go.
Very nice, applied. I should wait a few days all the time before applying your patches :)
Oh, so I have the time to discuss it with myself :)
What do you think? Should we allow multiple symlinks? Separated by which character? So we may simply loop over the field and create more than one:
..., SYMLINK="webcam%n:camera/%n:v4l/video%n"
thanks,
Kay
Attached is a trivial cleanup patch:
01-cleanup_man+remove_symlink_comment.diff
remove "want symlinks" text from udev-add.c
mention SYMLINK in man page
man page format cleanup
man page example for SYMLINK
udev-add.c +0 -9
@@ -53,18 +53,15 @@static int get_major_minor (struct sysfs_class_device *class_dev,struct udevice *udev) {int retval = -ENODEV ; -char *dev; dev =sysfs_get_value_from_attributes (class_dev->directory->attributes,"dev" );if (dev ==NULL ) goto exit; -dbg ("dev='%s'" , dev);if (sscanf (dev,"%u:%u" , &udev->major, &udev->minor) !=2 ) goto exit; -dbg ("found major=%d, minor=%d" , udev->major, udev->minor); retval =0 ;
@@ -100,10 +97,6 @@return 0 ; } -/* -* we possibly want to add some symlinks here -* only numeric owner/group id's are supported -*/ static int create_node (struct udevice *dev) {char filename[255 ];
@@ -115,7 +108,6 @@int i;int tail; -strncpy (filename, udev_root,sizeof (filename));strncat (filename, dev->name,sizeof (filename));
@@ -238,7 +230,6 @@strcpy (dev_path, sysfs_path);strcat (dev_path, device_name); -dbg ("looking at '%s'" , dev_path);/* open up the sysfs class device for this thing... */
udev.8 +28 -31
148 lines not on this page · raw message
Quoted 1 line · Kay Sievers
What do you think? Should we allow multiple symlinks? Separated by which character?
Yes! And again, it should be able to define symlinks on a different line than the one with the definition of the device name.
Quoted 3 lines
So we may simply loop over the field and create more than one:
..., SYMLINK="webcam%n:camera/%n:v4l/video%n"
Probably a space character would be a better separator, the odds you want to use one in a device name are much lower.
Signature · 13 lines
ciao, | Marco | [3500 uniyiB8SzEyTY] ------------------------------------------------------- This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net [email protected] https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Greg KH
AppliedQuoted 8 lines · Kay Sievers
Quoted 6 lines · Greg KH
Quoted 3 lines
Quoted 3 lines · Kay Sievers
Quoted 2 lines
here is a experimental symlink creation patch - for discussion, in which direction we should go.
Very nice, applied. I should wait a few days all the time before applying your patches :)
Quoted 6 lines
Oh, so I have the time to discuss it with myself :)
What do you think? Should we allow multiple symlinks? Separated by which character? So we may simply loop over the field and create more than one:
..., SYMLINK="webcam%n:camera/%n:v4l/video%n"
Hm, I don't really think that I would ever need more than one symlink, but hey, it can't hurt to add support for it :)
Quoted 7 lines
Attached is a trivial cleanup patch:
01-cleanup_man+remove_symlink_comment.diff
remove "want symlinks" text fromudev-add.c
mention SYMLINK in man page
man page format cleanup
man page example for SYMLINK
Applied, thanks.
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Marco d'Itri
Quoted 1 line · Kay Sievers
What do you think? Should we allow multiple symlinks? Separated by which character?
Yes! And again, it should be able to define symlinks on a different line than the one with the definition of the device name.
Yes, this will be necessary. Just like permissions, we'll probably need a different config file (as we are having one type of rule per file...)
thanks,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials. Become an expert in LINUX or just sharpen your skills. Sign up for IBM's Free Linux Tutorials. Learn everything from the bash shell to sys admin. Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel