* Silly udev script [was Re: udev and devfs - The final word]
[not found] ` <Pine.LNX.4.58.0401050749490.21265@home.osdl.org>
@ 2004-01-06 0:36 ` Greg KH
2004-01-06 4:02 ` Kay Sievers
2004-01-10 1:04 ` Greg KH
0 siblings, 2 replies; 3+ messages in thread
From: Greg KH @ 2004-01-06 0:36 UTC (permalink / raw)
To: Linus Torvalds, linux-hotplug-devel
Cc: Andries Brouwer, Daniel Jacobowitz, Rob Love, rob, Pascal Schmidt,
linux-kernel
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}ˆ80; # 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";
}
-------------------------------------------------------
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_id\x1278&alloc_id371&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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Silly udev script [was Re: udev and devfs - The final word]
2004-01-06 0:36 ` Silly udev script [was Re: udev and devfs - The final word] Greg KH
@ 2004-01-06 4:02 ` Kay Sievers
2004-01-10 1:04 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Kay Sievers @ 2004-01-06 4:02 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1066 bytes --]
On Mon, Jan 05, 2004 at 04:36:14PM -0800, Greg KH wrote:
> On Mon, Jan 05, 2004 at 08:13:26AM -0800, Linus Torvalds wrote:
> > [ 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 :)
Hey, this is funny.
I couldn't resist to give it a try and we need a few changes:
- it's %2c otherwise nearly all my CD's are "good", but sure I also have bad ones :)
- remove the node first, cause get_cddb() dies and leaves the old one there
- remove spaces in name, cause this is our separator
/udev/
|-- The_Cure-The_Peel_Sessions
|-- cdrom -> ./The_Cure-The_Peel_Sessions
|-- hda
|-- hda1
|-- hda2
|-- hda4
thanks,
Kay
[-- Attachment #2: 01-cddb-name.diff --]
[-- Type: text/plain, Size: 1201 bytes --]
--- ../udev/extras/name_cdrom.pl 2004-01-06 04:15:31.000000000 +0100
+++ extras/name_cdrom.pl 2004-01-06 04:34:45.000000000 +0100
@@ -2,8 +2,8 @@
# 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"
+# CALLOUT, BUS="ide", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%2c", SYMLINK="cdrom"
+# CALLOUT, BUS="scsi", PROGRAM="name_cdrom.pl %M %m", ID="good*", NAME="%2c", SYMLINK="cdrom"
#
# The scsi rule catches USB cdroms and ide-scsi devices.
#
@@ -27,9 +27,10 @@
$minor = $ARGV[1];
# create our temp device node to read the cd info from
+unlink($dev_node);
if (system("mknod $dev_node b $major $minor")) {
die "bad mknod failed";
- }
+}
# get it on
my %cd=get_cddb(\%config);
@@ -41,5 +42,7 @@
unless(defined $cd{title}) {
print"bad unknown cdrom\n";
} else {
- print "good $cd{artist}_$cd{title}\n";
+ $cd{artist} =~ s/ /_/g;
+ $cd{title} =~ s/ /_/g;
+ print "good $cd{artist}-$cd{title}\n";
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Silly udev script [was Re: udev and devfs - The final word]
2004-01-06 0:36 ` Silly udev script [was Re: udev and devfs - The final word] Greg KH
2004-01-06 4:02 ` Kay Sievers
@ 2004-01-10 1:04 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2004-01-10 1:04 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 06, 2004 at 05:02:34AM +0100, Kay Sievers wrote:
> On Mon, Jan 05, 2004 at 04:36:14PM -0800, Greg KH wrote:
> > On Mon, Jan 05, 2004 at 08:13:26AM -0800, Linus Torvalds wrote:
> > > [ 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 :)
>
> Hey, this is funny.
> I couldn't resist to give it a try and we need a few changes:
>
> - it's %2c otherwise nearly all my CD's are "good", but sure I also have bad ones :)
> - remove the node first, cause get_cddb() dies and leaves the old one there
> - remove spaces in name, cause this is our separator
Doh, that's what I get for only trying it with a 1 word title cd, and
then adding error code after testing it...
Thanks, I've applied your fixes.
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-01-10 1:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20040104034934.A3669@pclin040.win.tue.nl>
[not found] ` <Pine.LNX.4.58.0401031856130.2162@home.osdl.org>
[not found] ` <20040104142111.A11279@pclin040.win.tue.nl>
[not found] ` <Pine.LNX.4.58.0401041302080.2162@home.osdl.org>
[not found] ` <20040104230104.A11439@pclin040.win.tue.nl>
[not found] ` <Pine.LNX.4.58.0401041847370.2162@home.osdl.org>
[not found] ` <20040105030737.GA29964@nevyn.them.org>
[not found] ` <Pine.LNX.4.58.0401041918260.2162@home.osdl.org>
[not found] ` <20040105132756.A975@pclin040.win.tue.nl>
[not found] ` <Pine.LNX.4.58.0401050749490.21265@home.osdl.org>
2004-01-06 0:36 ` Silly udev script [was Re: udev and devfs - The final word] Greg KH
2004-01-06 4:02 ` Kay Sievers
2004-01-10 1:04 ` Greg KH
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).