Jump to content
xisto Community
Sign in to follow this  
qwijibow

Multislot Usb Memory Card Readers detecting newly inserted cards

Recommended Posts

Notice from qwijibow:


Ignore all scripts on this page, auto probing of USB card readers is handld by the Hardware Abstraction Layer. Make sure HAL is installed, and the daemon "hald" runs during boot-up (or at least before you start using the usb card reader)


However, the first post will still be of use for help installing the usb card reader drivers.





My Multi-Slot USB card reader didnt work exactly how i liked itout the box, so i made a few tweaks.
Here's how and why.

my Card reader is a 21 in 1 Memory card reader, which has 4 slots for cards, and is capable of using upto 4 different cards at once.

All 4 cards run off the SAME single usb connection (without an internal USB hub)

This adds an unseen consiquence.
Bu doing this, we forfeit USB's hot plug abilities.

For example, a single card reader will use its hotplug abbility's to reset the usb drivers when a new card is inserted or removed, causing the kernel to re-scan the device, and detect vital things like the cards size, partiton table read/write etc etc.

Multi slots cannot do this.
Imagine One card is in use, and we insert a second, if the device was to use the normal hot-plug trigger, the in use device would be re-set. possably losing data.

######################
Question: Ahaaaaa !
But windows seems to be able to detect new cards beeing inserted just fine !
and without upsetting other cards in use... How does windows do this ?
######################

######################
Answer: Windows does not use the hotplug usb feature either, it polls each of the 4 slots every second or 2, asking them if they have a card inserted, if the answer changes from no to yes, it knows a card was inserted, if the answer changes from yes to no, it knows a card was removed.
######################

So, a simple solution may be to implement the windows method into a linux script.
The script would be fairly simple, somthing like

white truedo/sbin/hdparm -z /dev/sdX || sleep 9sleep 1done
replace X with the slot character [a-z]

This script loops round checking the usb card reader for new cards every second.
if a card is in use, the script waits 10 seconds untill it continues checking.

This basically how windows does it.
BUT i hate this method for 3 reasons.

1) The disk activity light constantly flickers, annoying, as my card reader is eye hight, and its distracting.
2) Its a messy solution, and possably slows down performance of the card reader.
3) it fills the messages log will /dev/sdX is busy mesages.

People are always saying how customisable linux is, and how its so easy.. so lets show off, and
make a better solution.

BUT first off, lets make sure your multi slot cad reader is working.

make sure the following modules are loaded (run lsmod as root, and look for the following enteries)

sgsd_mod
usb_storage
scsi_mod
ohci_hcd
ehci_hcd  <== Only needed for USB version 2.0
usbcore


if any of those are missing, run the following comand as root, for each missing module

modprobe <name of mising module>

if the above command ever returns a module not found, dont worry, the module if porbabl in-bult into your kernel by your distro makers, and noesnt need to be loaded speratly.

now, just to make sure your card reader is supported, run the following command.

dmesg | grep scsi

you should see output similar to the following.
NOTE: you will have extra enteries if you also have SCSI disks as opposed to IDE disks.
If you dont know what SCSI is, you probably dont have SCSI disks :D

scsi0 : SCSI emulation for USB Mass Storage devicesAttached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
Attached scsi generic sg0 at scsi0, channel 0, id 0, lun 0,  type 0
Attached scsi removable disk sdb at scsi0, channel 0, id 0, lun 1
Attached scsi generic sg1 at scsi0, channel 0, id 0, lun 1,  type 0
Attached scsi removable disk sdc at scsi0, channel 0, id 0, lun 2
Attached scsi generic sg2 at scsi0, channel 0, id 0, lun 2,  type 0
Attached scsi removable disk sdd at scsi0, channel 0, id 0, lun 3
Attached scsi generic sg3 at scsi0, channel 0, id 0, lun 3,  type 0


look at the "lun x" enteries, you SHOULD see on lun for each slot in your card reader.
i have lun 0 to lun 3 (4 slots)

If you only see one lun, and have more than 1 slot, your kernel needs a re-compile.
This is very un-likely, but if this is you, reply here, and i wil help you do this.

basically you need to go to
Device Drivers -> SCSI ->
and select "PROBE ALL LUNS ON SCSI DEVICE"

and re-compile.

Each slot will be accessable as a differant /dev/sdX1 device.

Insert your memory cards, then un-plug the reader, and plug it back in.

###########
QUESTION: why did we have to re-plug it in ?

ANSWER:
Remember what i talked about above ?
because no cards were inserted when you turned the computer on / loaded the drivers, then no cards were detected, linux has not re-scanned the device, so still thinks no cards are inserted, re-plugging it in, caused linux to re-scan the device and find new cards.
###########

I am NOW going to show you how to make linux re-scan for new cards all by itself, when needed, withoout user interaction.

you will need to install sudo if sudo is not already installed (it probably is !)

edit /etc/sudoers with the following command AS ROOT

visudo -f /etc/sudoers

and add the following line. to the end of the file.

%users ALL = NOPASSWD:/sbin/hdparm -z /dev/sd[a-e]

this will allow normal users to probe the memory cards without the root password
(if you have more than 5 SCSI devices + memory card slots, edit the "[a-e]"
if in doubt [a-z] will allow ou to use all of them.

now make some mount points for your memry cards.

mkdir /mnt/sdamkdir /mnt/sdbmkdir /mnt/sdcmkdir /mnt/sddchmod 777 -R /mnt/sd*

now edit /etc/fstab
add the following lines

/dev/sda1      /mnt/sda          auto            noauto,user,sync        0 0/dev/sdb1      /mnt/sdb        auto            noauto,user,sync        0 0
/dev/sdc1      /mnt/sdc          auto            noauto,user,sync        0 0
/dev/sdd1      /mnt/sdd        auto            noauto,user,sync        0 0


AND FINALLY....
we are going to program a *FAKE MOUNT*

The job of this, is to replace the real mount.
it will snoop at what the computer wants mount to do.
if mount is beeing called to mount a memory card, it will probe that card first.
re-scanning its partiton table.

cd into /bin/ and rename the mount program

cd /binmv mount mount-real

now add the fake mount.
save the following file as root, to /bin/mount.

Notice from qwijibow:

This version of the mount script is obsolite, use the mount script, and install instruction from post =6 of this thread !!!!

#!/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

now make the script executable
chmod +x /bin/mount

This little script is quite simple, if you call mount with parameter "/mnt/sd[a-d]"
the script will instruct the kernel to re-scan the device you are about to mount.

it then waits upto 3 seconds for the kernel to find a card, and add a /dev/sd[a-d]1 device node.

it then passes control to the real mount.

If you are NOT mounding a usb card reader show, control is passed instantly to the real mount.

Try it out, you should now be ableo to mound your cards like so

mount /mnt/sda

or with KDE's graphical mount tools (or gnome / whatever graphical envronment you use)

So, what do you think ??
Better solution that constant probing ? or do you prefere the Windows method ?

Share this post


Link to post
Share on other sites

I have only 4 readers, 2 types of cards each, also on a single USB slot.

Do you really know people using multi-slot card reader with several simultaneous media ?

I only have one card in my multi-reader, but I am sure if I had several cards I would have the same behaviour.

I use the cards in my photo camera, in order to cleanup my camera memory card and put it on the disk.

Notice from username:
Here is the way I proceed
1) I remove the memory card from my photo camera.

2) I insert the card in my multi-reader.

3) Windows XP opens a explorer window.

4) I click on my pictures directory.

5) Edit, select all, edit, cut.

6) Go to my hard disk, my_camera subfolder.

7) Edit, paste.

8) Go to the windows taskbar, "safely disconnect a peripheral", disconnect my card reader.

9) Remove the card from the PC reader.

10) insert the card in my camera.

11) Remove the second memory card from my camera.

12) go to 2.

 

So, I never had two cards at the same moment, and I cleaned the Windows cache in order not to have things in cache when removing the card.

I guess it's the only safe way, so everybody should do that way, no matter how many how many memory cards you own

Share this post


Link to post
Share on other sites

If you actually READ this tutorial, you would have noticed..1) This tutorial if for making memory cards hot-pluggable for LINUX2) Windows already does this by default by probing the device on a continuous loop. (which i personally think is messy, and a waste of resources).By following this tutorial, linux users will be able to use memory cards that were NOT inserted dureing boot up.Otherwise, i user would need to unplug the usbn card reader, or re load the drivers, OR run hdparm -z /dev/sdX manually.please read a post before replying, otherwise it just clutters up the thread with nonsens like the second and third reply to this tutorial.

Share this post


Link to post
Share on other sites

@qwijibow : you are right when you give a full tutorial for Linux users.I just wanted to point out how standard Windows users should do if they have the same kind of reader and do not want to loose date. Few hardware knowledge can sometimes avoid big software trouble.Sorry for having disturbed your nice post, that was my first error and should be my last one.

Share this post


Link to post
Share on other sites

Lol, no porblem.I assumed you didnt notice this was in the linux section.Your instruction would be better suited to a windows sectionPlease keep windows specific tutorials out of the linux section.

Share this post


Link to post
Share on other sites

Script version 1.1 (to replace script in first post)
Install instructions within the script.

#!/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 1mount -t vfat $@

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.