Skip to contentSkip to conversation

Removable USB device contents cached after removal?

DISCUSSION Matthew Mastracci 1 participant 1 message Jan 1, 2004

lore
Share & tools
lore
#0 lore raw

I've been working on getting my USB Atech 9-in-1 card reader working with Linux. Everything mounts, unmounts and reads fine, but I'm getting a strange situation where the contents of the card seem to be buffered after the media has been removed from the card reader.

The strange thing is that this only happens when the card itself has been mounted, but it does *not* happen if the card is inserted and removed without mounting.

I'm running kernel 2.6.0-1.107 from arjanv's RedHat builds.

Here are the steps I use to reproduce it:

Working case (never mounted)

1. Insert card into reader.
2. dd if=/dev/sdd1 count=1024 bs=1 | hexdump
- results in correct filesystem dump
3. Remove card from reader.
4. cat /dev/sdd1 results in "No medium found"

Non-working case:

1.  Insert card into reader.
2.  Mount card as directory somewhere in root filesystem, list contents of card
3.  dd if=/dev/sdd1 count=1024 bs=1024 | hexdump

- results in correct filesystem dump
4. Remove card from reader.
5. dd if=/dev/sdd1 count=1024 bs=1024 | hexdump
- same filesystem dump as before!
6. cd to mountpoint, contents are still available
7. dd if=/dev/sdd1 of=/dev/null
- approx 3MB of card data still available
8. umount the mountpoint from before
9. dd if=/dev/sdd1 of=/dev/null results in "No medium found"

I can provide more information as required. It appears as if the reader is correctly determining that no medium is present, but the mountpoint's existence somehow prevents userspace code from seeing this.

Any ideas?

Here's some dumps that might assist:

[root@matt root]# lsmod | grep "usb"

usb_storage            56384  1
scsi_mod              107320  2 sd_mod,usb_storage
usbcore                93148  7 usb_storage,hid,ohci_hcd,uhci_hcd,ehci_hcd

"dd" on non-existant card (note that 8976 was the amount of data read when the card was inserted):

[root@matt root]# dd if=/dev/sdd1 of=/dev/null
dd: reading `/dev/sdd1': Input/output error
8976+0 records in
8976+0 records out

dmesg output after "dd" on non-existant card:

Device sdd not ready.
end_request: I/O error, dev sdd, sector 9001 Buffer I/O error on device sdd1, logical block 8976 Buffer I/O error on device sdd1, logical block 8977 Buffer I/O error on device sdd1, logical block 8978 Buffer I/O error on device sdd1, logical block 8979 Buffer I/O error on device sdd1, logical block 8980 Buffer I/O error on device sdd1, logical block 8981 Buffer I/O error on device sdd1, logical block 8982 Buffer I/O error on device sdd1, logical block 8983

Matt.