From: David Zeuthen <david@fubar.dk>
To: linux-hotplug@vger.kernel.org
Subject: [patch] compatibility symlinks for udev
Date: Mon, 06 Sep 2004 14:46:37 +0000 [thread overview]
Message-ID: <1094481997.4727.14.camel@localhost.localdomain> (raw)
[-- Attachment #1: Type: text/plain, Size: 1918 bytes --]
Hey Greg,
Here's a patch against udev-030 that can help create compatibility
symlinks like /dev/cdrom, /dev/cdrom1 etc. The patch introduces a new
substitution type %C (for Compatibility) that can be used as follows
KERNEL="sr*", NAME="%k", SYMLINK="cdrom%C"
KERNEL="scd*", NAME="%k", SYMLINK="cdrom%C"
KERNEL="pcd*", NAME="%k", SYMLINK="cdrom%C"
KERNEL="fd[0-9]", NAME="%k", SYMLINK="floppy%C"
KERNEL="hd[a-z]", PROGRAM="/home/david/udev_ide_cdrom_or_floppy.sh %k", NAME="%k", SYMLINK="%c%C"
KERNEL="fd[0-9]", NAME="%k", SYMLINK="floppy%C"
%C will be substitued with nothing if the text prior to the %C doesn't
exist, otherwise it will be substituted with the minimal positive
integer such that text prior to %C and the integer doesn't exist. Pretty
basic.
Together with a simple helper script (that can be removed as soon as IDE
exports the type in sysfs; alternatively this is trivial to write in C
for e.g. early boot)
#!/bin/sh
TYPE=`cat /proc/ide/$1/media`
if test "$TYPE" = "cdrom"; then
echo -n cdrom
exit 0
elif test "$TYPE" = "floppy"; then
echo -n floppy
exit 0
fi
exit 1
I get the following symlinks
[root@laptop udev]# ls -l floppy
lrwxrwxrwx 1 root root 3 Sep 6 16:29 floppy -> hdc
[root@laptop udev]# ls -l cdrom*
lrwxrwxrwx 1 root root 3 Sep 6 16:29 cdrom -> hdd
lrwxrwxrwx 1 root root 3 Sep 6 16:29 cdrom1 -> sr0
which I think is nice (... as far as programs relying on names of device
nodes is nice, ahem). While the patch is somewhat against the spirit of
udev it's very useful for maintaining compatibility with old software.
People who depend and care about what /dev/cdrom%d is can always write
exact rules to match them perfectly.
I hope you will apply this patch.
Thanks,
David
[-- Attachment #2: udev-compat-symlinks.patch --]
[-- Type: text/x-patch, Size: 2186 bytes --]
--- udev-030.orig/namedev.c 2004-07-09 19:59:10.000000000 +0200
+++ udev-030/namedev.c 2004-09-06 16:22:03.000000000 +0200
@@ -42,6 +42,7 @@
#include "logging.h"
#include "namedev.h"
#include "klibc_fixups.h"
+#include "udevdb.h"
static struct sysfs_attribute *find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, char *attr);
@@ -179,6 +180,37 @@ static int get_format_len(char **str)
return -1;
}
+/** Finds the lowest positive N such that <name>N isn't present in
+ * $(udevroot) either as a file or a symlink.
+ *
+ * @param name Name to check for
+ * @return 0 if <name> didn't exist and N otherwise.
+ */
+static unsigned int find_free_number (struct udevice *udev, char *name)
+{
+ char temp[NAME_SIZE];
+ char path[NAME_SIZE];
+ struct udevice dev;
+ int result;
+
+ /* have to sweep the database for each lookup */
+ result = 0;
+ strncpy(temp, name, sizeof (temp));
+ while (1) {
+ if (udevdb_get_dev_byname(temp, path, &dev) != 0)
+ goto found;
+ /* symlink might be stale if $(udevroot) isn't cleaned; check
+ * on major/minor to see if it's the same device
+ */
+ if (dev.major == udev->major && dev.minor == udev->minor)
+ goto found;
+ snprintf (temp, sizeof(temp), "%s%d", name, ++result);
+ }
+
+found:
+ return result;
+}
+
static void apply_format(struct udevice *udev, char *string, size_t maxsize,
struct sysfs_class_device *class_dev,
struct sysfs_device *sysfs_device)
@@ -195,6 +227,7 @@ static void apply_format(struct udevice
char *rest;
int slen;
struct sysfs_attribute *tmpattr;
+ unsigned int next_free_number;
pos = string;
while (1) {
@@ -284,6 +317,13 @@ static void apply_format(struct udevice
strfieldcatmax(string, "%", maxsize);
pos++;
break;
+ case 'C':
+ next_free_number = find_free_number(udev, string);
+ if (next_free_number > 0) {
+ snprintf(temp2, sizeof(temp2), "%d", next_free_number);
+ strfieldcatmax(string, temp2, maxsize);
+ }
+ break;
default:
dbg("unknown substitution type '%%%c'", c);
break;
next reply other threads:[~2004-09-06 14:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-06 14:46 David Zeuthen [this message]
2004-09-06 15:45 ` [patch] compatibility symlinks for udev Kay Sievers
2004-09-07 11:19 ` David Zeuthen
2004-09-10 20:09 ` Greg KH
2004-09-14 17:50 ` Kay Sievers
2004-09-14 20:50 ` Greg KH
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=1094481997.4727.14.camel@localhost.localdomain \
--to=david@fubar.dk \
--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).