LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   usb multi card reader doesnt detect newly inserted cards (https://www.linuxquestions.org/questions/linux-hardware-18/usb-multi-card-reader-doesnt-detect-newly-inserted-cards-356536/)

qwijibow 08-24-2005 11:53 AM

usb multi card reader doesnt detect newly inserted cards
 
EDIT

SOLVED..

use HAL (hardware abstraction layer)

once the hal daemon is running, it automatically probes USB card readers for newly inserted cards !

Igore pretty much everything in this thread !



#############################################################
Origonal post Follows.


I have an Internal Memory Card Reader. Model Trust CR-3300.

The card reader has 4 different slots, i use 2 of them.
One slot for SD (secure digital) memory cards, one for SM (Smart Media) Memory cards,
and 2 more i dont use.

When the drivers are modprobed, the kernel reports the addition of 4 scsi devices.

/dev/sda
/dev/sdb
/dev/sdc
/dev/sdd

But when i insert a memory card, for example SD card into the slot (/dev/sdd)
the card is not detected. and cannot to used.

"cat /proc/partitons" shows only my hard disks.

HOWEVER, if i insert the card BEFORE loading the drivers, then aswell as the 4 scsi controllers being registed, the kernel also makes note of a 512 meg card, and attaches it to /dev/sdd1.

"cat /proc/partitons" shows
Quote:

major minor #blocks name

8 49 500203 sdd1
and i can mount the card as /dev/sdd1.

This is very annoying,
i have to keep loading, and unloading the drivers every time i want to use, or switch over a memory card.

EDIT: ive found i can make the kernel probe the device for new cards with the "hdparm -z /dev/sdd" command. It makes the kernel re-load partiton tables.

This command also uptades the data shown in /proc/partitons.

But this is still very annoying, it means i need to become root, anter root password, an run hdparm EVERY TIME i need ot switch a card.

There are only 2 solutions i can think of, both are messy...

1) make hdparm suid root, so i can quickly add cards with a shortcut applet in KDE.
(this is very un0-secure to give un-privilaged users access to hdparm)

2) make a boot script that runs loops forever, running hdparm -z /dev/sdd, and hdparm -z /dev/sdb, every 2 seconds.

Does anyone have a better idea ???

EDIT2:
Ive tested the device in windows, the activity light blinks every half second.

in linux he activity light doesnt blink when the device is idle, however it does blink when i run the hdparm command.

so it seems windows is useing my hdparm on a loop method.

i suppose running 4 disks off a single usb connection means the device hs lost its ability to hot-plug ???

HELP.

thanks.

EDIT3:
The hdparm -z on a loop is a very bad idea.
it fills the logs with mesages about re-scanning the partiton table.

and when the device is in use, and files are being transfered, the constant poling for new cards degrages performance and genrates "media is busy" errors all over the place.

there MUST be a way ?

is there maybe a patch to usb storeage that can poll for new cards, but only when there device is idle ???

thanks again,

tredegar 08-25-2005 06:23 AM

In my experience, multi-slot USB card readers do not work unless you plug the card into the reader before you plug the card reader into the USB socket.
So I have to plug in the card, then plug in the reader. Then it works just fine, with an icon added to my desktop (Mandriva 2005LE, 2.6.11-12mdk).
As you have probably already discovered, each different card-slot is associated with a different sdx
HTH

qwijibow 08-25-2005 12:10 PM

My USB card reader is internal, you cannot unplug it.

Anyways, i have fixed it by adding an extra script to run before mount.

here is the script for others.

Code:

#!/bin/bash
# Code by Chris Stones (chris.stones@ googles email [i hate spam])
# If you can think of a better way of doing this ( patch the usb_storage drivers ?) Please let me know;)

# fake mount !!!!
# intercept parameters to mount.
# may need to re-scan the media pannel for new / removed cards before mounting.

#this script assumes you have sudo setup to allow regular users to run hdparm -z /dev/sd[a-z]
#add line "%users ALL = NOPASSWD:/sbin/hdparm -z /dev/sd[a-e]" to /etc/sudoers

#this script ALSO assumes the mount points are /mnt/sd[a-z]
#if anyone can edit this script to parse /etc/fstab, please do so, and let me know.

test_wait() {
      if [ ! -f $1 ]; then
              sleep 1
      fi
}

probe() {
  sudo /sbin/hdparm -z $1 > /dev/null
  test_wait $1"1"
  test_wait $1"1"
  test_wait $1"1"
}

if [ `echo $1| head -c 7` = "/mnt/sd" ]; then
  probe "/dev/"`echo $1 | tail -c 4`
fi


# call real mount
/bin/mount-real $1 $2 $3 $4 $5 $6 $7

Basically, you rename /bin/mount to mount-real.
and save this script as /bin/mount

so when somhing calls /bin/mount
my script looks at what you are mounting... if you are mounting a multi slot usb, the script uses hdparm to re-scan the partiton table.

this causes the kernel to SEE cards that were inserted after bootup, or after the device was plugged in.

for my full guide of how to get it working, see http://www.astahost.com/index.php?sh...=0&#entry50147


ENJOY !

tredegar 08-27-2005 01:20 AM

Interesting work-around. Thanks.

qwijibow 10-04-2005 11:51 AM

I wrote a much better, much more simplistiv, much less complicated script...

here it is.

Code:

#!/bin/bash

# re-scans partiton table of multi-media card readers prior to mounting them
# (allows linux to SEE newl inserted cards)

# INSTALL...
# 1)    edit /etc/fstab, change filesystem of multi-media card reader enteries to "card"
#      e.g. "/dev/sda1  /mnt/slot1 card noauto,user,sync,umask=0  0 0"

# 2)    run "sudoedit /etc/sudoers" and add the following line
#      %users ALL = NOPASSWD:/sbin/hdparm -z /dev/sd[a-z]
#      sudo must be installed first

# 3)    save mount.card (this file) to /sbin/mount.card
#      set owner...            "chown root /sbin/mount.card"
#      set permissions...      "chmod 755 /sbin/mount.card"

# After completing steps 1,2 and 3. you can insert a card and ount it at any time,
# without hac#ving to re-attach the usb card reader.

sudo /sbin/hdparm -z `echo $1 | head -c 8`

sleep 1

mount -t vfat $@

The script itself is the last 3 lines, Install instructions at the top of the script.

ENJOY !

qwijibow 10-11-2005 10:17 PM

SOLVED..

use HAL (hardware abstraction layer)

once the hal daemon is running, it automatically probes USB card readers for newly inserted cards !

Igore pretty much everything in this thread !


All times are GMT -5. The time now is 08:55 AM.