in the name of zero

August 4, 2005

linux 2.6.12-BernieLove and udev

Filed under: hermetic studies

this is supposed to be the part where i would put my teaser text.. but then i figured that even a brief introduction would prove confusing …

like all the cool kids out there, i ditched devfs in favor of udev. anyway, i wrote my first two udev last night!

rule 1 : modem rule

amerei@heaven ~ $ udevinfo -a -p `udevinfo -q path -n /dev/ttyS0`
device '/sys/class/tty/ttyS0' has major:minor 4:64
  looking at class device '/sys/class/tty/ttyS0':
    SUBSYSTEM==\"tty\"
    SYSFS{dev}==\"4:64\"
	
follow the \"device\"-link to the physical device:
  looking at the device chain at '/sys/devices/pnp0/00:07':
    BUS==\"pnp\"
    ID==\"00:07\"
    DRIVER==\"serial\"
    SYSFS{id}==\"PNP0501\"
	
/etc/udev/rules.d/10-local.rules
	BUS=”pnp”, SYSFS{id}=”PNP0501″, NAME=”%k”, SYMLINK=”modem”

rule 2 : cellphone rule

back in my devfs days whenever i plugged my nokia 3300, a block device (/dev/sda1) is created, indicating that the kernel sees my phone as an external scsi hard disk. this time though, it is assigned the block device /dev/sg0. as what you’ll see in the dmesg snippet below.

— relevant part of dmesg —

usb-storage: device found at 3
usb-storage: waiting for device to settle before scanning
Vendor: NOKIA Model: 3300a Rev: 0001
Type: Direct-Access ANSI SCSI revision: 00
Attached scsi generic sg0 at scsi1, channel 0, id 0, lun 0, type 0
usb-storage: device scan complete

— end of relevant part of dmesg —

amerei@heaven /usr $ udevinfo -a -p `udevinfo -q path -n /dev/sg0`
device '/sys/class/scsi_generic/sg0' has major:minor 21:0
  looking at class device '/sys/class/scsi_generic/sg0':
    SUBSYSTEM==\"scsi_generic\"
    SYSFS{dev}==\"21:0\"
	
follow the \"device\"-link to the physical device:
  looking at the device chain at '/sys/devices/pci0000:00/0000:00:1f.2/usb1/1-2/1-2:1.0/host1/target1:0:0/1:0:0:0':
    BUS==\"scsi\"
    ID==\"1:0:0:0\"
    DRIVER==\"unknown\"
    SYSFS{device_blocked}==\"0\"
    SYSFS{iocounterbits}==\"32\"
    SYSFS{iodone_cnt}==\"0x1\"
    SYSFS{ioerr_cnt}==\"0x0\"
    SYSFS{iorequest_cnt}==\"0x1\"
    SYSFS{max_sectors}==\"240\"
    SYSFS{model}==\"3300a\"
    SYSFS{queue_depth}==\"1\"
    SYSFS{queue_type}==\"none\"
    SYSFS{rev}==\"0001\"
    SYSFS{scsi_level}==\"3\"
    SYSFS{state}==\"running\"
    SYSFS{timeout}==\"0\"
    SYSFS{type}==\"0\"
    SYSFS{vendor}==\"NOKIA   \"
	
/etc/udev/rules.d/10-local.rules
	BUS=”scsi”, SYSFS{model}==”3300a”, SYSFS{vendor}==”NOKIA*”, NAME=”%k”, SYMLINK=”nokia”

rule 3 : today .. i wrote a udev rule for my cd writer.

a) as usual, first determine the block device assigned by the kernel …

amerei@heaven ~ $ dmesg | grep -i cdrw
hdc: SAMSUNG CDRW/DVD SM-352B, ATAPI CD/DVD-ROM drive

b) get the relevant sysfs info for it…

amerei@heaven ~ $ udevinfo -a -p `udevinfo -q path -n /dev/hdc`
device '/sys/block/hdc' has major:minor 22:0
  looking at class device '/sys/block/hdc':
    SUBSYSTEM==\"block\"
    SYSFS{dev}==\"22:0\"
    SYSFS{range}==\"1\"
    SYSFS{removable}==\"1\"
    SYSFS{size}==\"8388604\"
    SYSFS{stat}==\"       0        0        0        0        0        0        0        0        0        0        0\"
	
follow the \"device\"-link to the physical device:

c) now comes the fun part!

/etc/udev/rules.d/10-local.rules
	KERNEL=”hdc”, SYSFS{dev}==”22:0″, NAME=”%k”, SYMLINK=”burner”


some thoughts
if you’ve read this far… i guess you’re terribly bored. overall, this is a very very fun and educating activity! i could only wish i had more pluggable devices to play with …

gratefulness goes out to :

gentoo linux udev guide
decibel’s udev primer
daniel drake for his excellent howto
miss b, for being very cute and cool at the same time.

2 Comments »

The URI to TrackBack this entry is: http://gnurbs.blogsome.com/2005/08/04/linux-2612-bernielove-and-udev/trackback/

  1. neil, comment on my new blogger… thanks

    Comment by jerne — August 5, 2005 @ 5:05 pm

  2. comment on my new blog…

    Comment by jerne — August 5, 2005 @ 5:05 pm

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>


Get free blog up and running in minutes with Blogsome | Theme designs available here