From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Date: Tue, 06 Jan 2004 00:36:14 +0000 Subject: Silly udev script [was Re: udev and devfs - The final word] Message-Id: <20040106003614.GA1043@kroah.com> List-Id: References: <20040104034934.A3669@pclin040.win.tue.nl> <20040104142111.A11279@pclin040.win.tue.nl> <20040104230104.A11439@pclin040.win.tue.nl> <20040105030737.GA29964@nevyn.them.org> <20040105132756.A975@pclin040.win.tue.nl> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: quoted-printable To: Linus Torvalds , linux-hotplug-devel@lists.sourceforge.net Cc: Andries Brouwer , Daniel Jacobowitz , Rob Love , rob@landley.net, Pascal Schmidt , linux-kernel@vger.kernel.org On Mon, Jan 05, 2004 at 08:13:26AM -0800, Linus Torvalds wrote: >=20 > 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= =20 > of whether you put it in the DVD slot or the CD-RW drive.=20 >=20 > [ 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 ca= n=20 > "identify" it automatically through its contents, and name it stably=20 > 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=3D"ide", PROGRAM=3D"name_cdrom.pl %M %m", ID=3D"good*", NAME= =3D"%1c", SYMLINK=3D"cdrom"=20 # CALLOUT, BUS=3D"scsi", PROGRAM=3D"name_cdrom.pl %M %m", ID=3D"good*", NAM= E=3D"%1c", SYMLINK=3D"cdrom"=20 # # The scsi rule catches USB cdroms and ide-scsi devices. # use CDDB_get qw( get_cddb ); my %config; $dev_node =3D "/tmp/cd_foo"; # following variables just need to be declared if different from defaults $config{CDDB_HOST}=3D"freedb.freedb.org"; # set cddb host $config{CDDB_PORT}=8880; # set cddb port $config{CDDB_MODE}=3D"cddb"; # set cddb mode: cddb or http $config{CD_DEVICE}=3D"$dev_node"; # set cd device # No user interaction, this is a automated script! $config{input}=3D0; $major =3D $ARGV[0]; $minor =3D $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=3Dget_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=1278&alloc_id371&op=3Dclick _______________________________________________ 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