LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices

Reply
 
Search this Thread
Old 12-18-2008, 04:03 AM   #1
mister.teapots
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Rep: Reputation: 0
Smile 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!
 
Old 12-19-2008, 04:41 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949Reputation: 1949
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.
 
Old 12-21-2008, 07:47 PM   #3
mister.teapots
LQ Newbie
 
Registered: Jun 2007
Posts: 5

Original Poster
Rep: Reputation: 0
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.
 
  


Reply

Tags
scripts, udev, usb


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How Red Hat Lost Friends And Gained New Enemies LXer Syndicated Linux News 0 11-13-2006 08:54 AM
Portable MP3 player with corrupted mp3 files today53 Suse/Novell 1 05-22-2006 09:24 AM
S1 Mp3 player (Help Create a New Distro for an MP3 player!)) Ian_Hawdon Linux - General 3 12-05-2005 01:14 PM
iRiver iHP-120 20GB MP3 Player, a player for the rest of us ? dukeinlondon General 1 04-04-2004 04:44 AM
MP3 CD player can't read MP3 CD's burned in linux food188 Linux - Software 2 01-11-2004 04:55 PM


All times are GMT -5. The time now is 10:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration