LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (http://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   My mp3 player and udev should be friends instead of enemies! (http://www.linuxquestions.org/questions/linux-hardware-18/my-mp3-player-and-udev-should-be-friends-instead-of-enemies-691423/)

mister.teapots 12-18-2008 04:03 AM

My mp3 player and udev should be friends instead of enemies!
 
I have a Sandisk Sansa Fuze mp3 player and it works great with Linux, except that in order to mount it at full USB 2 speed I have to run this script:

Code:

sudo rmmod ehci-hcd; sleep 1s; sudo modprobe ehci-hcd
which is a very ugly hack, I know. And also super annoying that I have to load it every time I want to use my device. So I thought I could write a udev rule that could load this script automatically when I attach the mp3 player, so that I wouldn't have to lift a single finger.

I followed udev's manual, and wrote a rule that looks like this:
Code:

KERNEL=="sd?1", BUS=="scsi", SUBSYSTEMS=="usb", ATTRS{vendor}=="SanDisk*", ATTRS{model}=="Sansa*", RUN+="/bin/sh sansa"
Which is based on the info that
Code:

udevinfo -a -p /sys/block/sdb/dev
gave me about my device:

Code:

  looking at device '/block/sdb/dev':
    KERNEL=="dev"
    SUBSYSTEM=="block"
    DRIVER==""

  looking at parent device '/block/sdb':
    KERNELS=="sdb"
    SUBSYSTEMS=="block"
    DRIVERS==""
    ATTRS{dev}=="8:16"
    ATTRS{range}=="16"
    ATTRS{removable}=="1"
    ATTRS{size}=="15990784"
    ATTRS{stat}=="    244    6866    7754    3132        0        0        0        0        0    1224    3132"
    ATTRS{capability}=="13"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-3/5-3:1.0/host9/target9:0:0/9:0:0:0':
    KERNELS=="9:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="0"
    ATTRS{vendor}=="SanDisk "
    ATTRS{model}=="Sansa Fuze 8GB  "
    ATTRS{rev}=="v01."
    ATTRS{state}=="running"
    ATTRS{timeout}=="30"
    ATTRS{iocounterbits}=="32"
    ATTRS{iorequest_cnt}=="0x10e"
    ATTRS{iodone_cnt}=="0x10e"
    ATTRS{ioerr_cnt}=="0x0"
    ATTRS{modalias}=="scsi:t-0x00"
    ATTRS{evt_media_change}=="0"
    ATTRS{queue_depth}=="1"
    ATTRS{queue_type}=="none"
    ATTRS{max_sectors}=="240"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-3/5-3:1.0/host9/target9:0:0':
    KERNELS=="target9:0:0"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-3/5-3:1.0/host9':
    KERNELS=="host9"
    SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-3/5-3:1.0':
    KERNELS=="5-3:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb-storage"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{bInterfaceClass}=="08"
    ATTRS{bInterfaceSubClass}=="06"
    ATTRS{bInterfaceProtocol}=="50"
    ATTRS{modalias}=="usb:v0781p74C1d468Cdc00dsc00dp00ic08isc06ip50"
    ATTRS{interface}=="ms ifac 1 _SCSI::BULK_ONLY_"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5/5-3':
    KERNELS=="5-3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{dev}=="189:513"
    ATTRS{configuration}=="config1: Mass Storage only"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{urbnum}=="1075"
    ATTRS{idVendor}=="0781"
    ATTRS{idProduct}=="74c1"
    ATTRS{bcdDevice}=="468c"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="5"
    ATTRS{devnum}=="2"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="SanDisk"
    ATTRS{product}=="SanDisk Sansa Fuze"
    ATTRS{serial}=="D911FA110912B59F0000000000000000"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb5':
    KERNELS=="usb5"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized_default}=="1"
    ATTRS{dev}=="189:512"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="40"
    ATTRS{idVendor}=="0000"
    ATTRS{idProduct}=="0000"
    ATTRS{bcdDevice}=="0206"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="01"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="5"
    ATTRS{devnum}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="8"
    ATTRS{quirks}=="0x0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Linux 2.6.24-16-generic ehci_hcd"
    ATTRS{product}=="EHCI Host Controller"
    ATTRS{serial}=="0000:00:1d.7"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7':
    KERNELS=="0000:00:1d.7"
    SUBSYSTEMS=="pci"
    DRIVERS=="ehci_hcd"
    ATTRS{vendor}=="0x8086"
    ATTRS{device}=="0x27cc"
    ATTRS{subsystem_vendor}=="0x1028"
    ATTRS{subsystem_device}=="0x01bd"
    ATTRS{class}=="0x0c0320"
    ATTRS{irq}=="18"
    ATTRS{local_cpus}=="ff"
    ATTRS{modalias}=="pci:v00008086d000027CCsv00001028sd000001BDbc0Csc03i20"
    ATTRS{enable}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

And so my script doesn't work. I'm definitely doing something wrong, maybe this isn't the correct way to fix the usb speed anyway.

Thanks for your help in advance!

David the H. 12-19-2008 04:41 AM

I'm not a udev expert, but I'll give you some of my observations.

1) I believe programs run by udev run under the root user, so you shouldn't need to use the sudo command in your script.

2) Make sure your script is actually in proper script form. It should have an sh or bash shebang (#!) at the top, then each command on a separate line (not actually necessary, but better for readability). So it should look something like this:
Code:

#!/bin/bash

rmmod ehci-hcd
sleep 1s
modprobe ehci-hcd

And make sure the root user has execute permissions for it, of course.

3) In your udev rule, be sure to give it the full path to the script. And since the shebang in the script tells your system what shell to run it in, you shouldn't need to specify the shell in the run command itself. So your udev command should look something like this:
Code:

KERNEL=="sd?1", BUS=="scsi", SUBSYSTEMS=="usb", ATTRS{vendor}=="SanDisk*", ATTRS{model}=="Sansa*", RUN+="/path/to/sansascript.sh"
4) Finally, you might try placing a debugging line or two in the script so you can see if udev is actually running it. Adding a line such as "echo $(date) >> /path/to/sansa.logfile" somewhere in the script will send the current date and time to the specified file if the script is running properly.

mister.teapots 12-21-2008 07:47 PM

Cool, thanks so much for going to the effort of responding to me. The script (sansa.sh) definitely works (and has exec privileges), but udev still isn't running it so maybe that's because I haven't told it the correct details about the device.

Seems confusing...........so many parents.


All times are GMT -5. The time now is 07:09 AM.