Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a USB card reader with two SD card interfaces and two USB ports (so it can also act as a USB hub) all on the same device. I am running an embedded Linux device that is unsupervised in its use and intend to use 2 SD cards in the reader for storing data collected over several hours of operation. Each card is meant to hold specific data and the two data types cannot be mixed.

Using mdev's ability to fire off a script when a USB SCSI device (either an SD card or a USB flash disk) is mounted, I can note the physical location of the USB device so that I can identify which disk is which, but there is one exception to this. The card reader reports that both of the SD cards in the reader are physically located on port 1 of the reader. This means that I'm unable to (with my current knowledge) identify in my custom-written programs the physical card that data is being written to.

I can't bring the user into the loop to tell the system which card is which (the user simply plugs 2 fresh cards in, turns the device on, and walks away). How can I determine which filesystem belongs to which physical disk by using tools compatible with Busybox?

Thank you.

share|improve this question
    
I'd start looking through /sys—if the kernel knows, its probably there. –  derobert Nov 28 '11 at 14:30
    
Looks like /sys is giving me some leads. I'll keep posting with what i discover. Thanks. –  San Jacinto Nov 28 '11 at 15:04
add comment

1 Answer

up vote 1 down vote accepted

/sys/block is the place to look for this. When the card reader is plugged in, it lists two block devices in the style of sd*, where * is a letter. It's as though the system has added a physical scsi device without any way to access the media (unless of course there's a formatted partition on it, which the hotplug system mounts automatically through mdev's /etc/mdev.conf).

/sys/block/sda (for example) is a symbolic link to /sys/devices/platform/fsl-ehci.0/usb2/2-1/2-1.1/2-1.1:1.0/host0/target0:0:0/0:0:0:1/block/sda.

The section before /host/target0:0:0 is the physical device tree configuration of my USB devices. The card reader is in bus 2, port 1, port 1.

The section after /host/target0:0:0 is some more device mapping that I can't quite figure out, but the last digit (for devices in this reader) is always either a 0 or a 1, which corresponds to one port or the other.

So, I have what I need but it would be good for someone to come along and fill in the holes and offer a much better explanation for posterity.

share|improve this answer
    
I don't know what those numbers after the target are, but chances are that the numeric assignment is specific to that particular reader. What do you mean by “the system has added a physical scsi device without any way to access the media”? Most hard-disk-like devices use the SCSI driver, because they communicate with the computer using SCSI commands at the logical level, even if the electrical level isn't SCSI. –  Gilles Nov 28 '11 at 17:53
    
What I meant was that even if there is no media in the reader, these devices still appear. It's like connecting a real, unformatted SCSI disk with no partition table. It sees the disk and lists it in /sys, but there is no way to interact with the device through normal read/write calls, but I'm guessing the SCSI ioctl's would still work on it. –  San Jacinto Nov 28 '11 at 18:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.