Silly udev script [was Re: udev and devfs - The final word]
[Posted January 6, 2004 by corbet]
| From: |
| Greg KH <greg-AT-kroah.com> |
| To: |
| Linus Torvalds <torvalds-AT-osdl.org>,
linux-hotplug-devel-AT-lists.sourceforge.net |
| Subject: |
| Silly udev script [was Re: udev and devfs - The final word] |
| Date: |
| Mon, 5 Jan 2004 16:36:14 -0800 |
| Cc: |
| Andries Brouwer <aebr-AT-win.tue.nl>,
Daniel Jacobowitz <dan-AT-debian.org>, Rob Love <rml-AT-ximian.com>,
rob-AT-landley.net, Pascal Schmidt <der.eremit-AT-email.de>,
linux-kernel-AT-vger.kernel.org |
On Mon, Jan 05, 2004 at 08:13:26AM -0800, Linus Torvalds wrote:
>
> For example, if you wanted to, you could make udev do a cddb lookup on the
> CD-ROM, and use that as the pathname, so that when you insert your
> favorite audio disk, it will always show up in the same place, regardless
> of whether you put it in the DVD slot or the CD-RW drive.
>
> [ Yeah, that sounds like a singularly silly thing to do, but it's a good
> example of something where there is no actual serial number, but you can
> "identify" it automatically through its contents, and name it stably
> according to that. ]
That was such a silly thing to do, here's a script that does it, along
with the udev rule to add to udev.rules for it. It names your cdrom
Artist_Title, and creates a symlink called cdrom that points to it, just
to be a tiny bit sane :)
I had been saying for a long time that you could have udev make a query
across the network to get a device name, this provides the perfect
example of just that...
thanks,
greg k-h
#!/usr/bin/perl
# a horribly funny script that shows how flexible udev can really be
# This is to be executed by udev with the following rules:
# CALLOUT, BUS="ide", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%1c", SYMLINK="cdrom"
# CALLOUT, BUS="scsi", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%1c", SYMLINK="cdrom"
#
# The scsi rule catches USB cdroms and ide-scsi devices.
#
use CDDB_get qw( get_cddb );
my %config;
$dev_node = "/tmp/cd_foo";
# following variables just need to be declared if different from defaults
$config{CDDB_HOST}="freedb.freedb.org"; # set cddb host
$config{CDDB_PORT}=8880; # set cddb port
$config{CDDB_MODE}="cddb"; # set cddb mode: cddb or http
$config{CD_DEVICE}="$dev_node"; # set cd device
# No user interaction, this is a automated script!
$config{input}=0;
$major = $ARGV[0];
$minor = $ARGV[1];
# create our temp device node to read the cd info from
if (system("mknod $dev_node b $major $minor")) {
die "bad mknod failed";
}
# get it on
my %cd=get_cddb(\%config);
# remove the dev node we just created
unlink($dev_node);
# print out our cd name if we have found it
unless(defined $cd{title}) {
print"bad unknown cdrom\n";
} else {
print "good $cd{artist}_$cd{title}\n";
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
(
Log in to post comments)