Opened 17 years ago

Closed 17 years ago

#2375 closed bug (fixed)

Unmounting card in usb card reader doesn't work

Reported by: monni Owned by: mmlr
Priority: normal Milestone: R1
Component: Drivers/Disk Version: R1/pre-alpha1
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

How to reproduce: connect card reader with card inserted to EHCI bus, mount the file system on the card, unmount the card, disconnect card reader Experienced behavior: Card reader says connection was prematurely disconnected Expected behavior: No error

From syslog: KERN: usb_disk: operation 0x35 failed at the SCSI level KERN: usb_disk: request_sense: key: 0x05; asc: 0x20; ascq: 0x00; KERN: usb_disk: request_sense: illegal request

Attachments (1)

start_stop_unit.diff (1.0 KB ) - added by mmlr 17 years ago.
Implement B_EJECT_DEVICE through the START_STOP_UNIT command

Download all attachments as: .zip

Change History (7)

comment:1 by mmlr, 17 years ago

Owner: changed from marcusoverhagen to mmlr
Status: newassigned

How do you mean "Card reader says connection was prematurely disconnected"? Does the cardreader itself say so or do you get an error message from Haiku? If it is the device, you can pretty much safely ignore it. The device would probably expect the system to turn off the power to the USB port first (as Windows does amongst other things when you do the "safely remove"). When the filesystem was unmounted though, all the caches have been flushed, so there should be no data corruption possible. The output from syslog simply tells you that the device does not implement the SYNCHRONIZE_CACHE_10 command. As most of these devices do not actually use a cache in the first place, this does not indicate an error. The usb_disk driver will try a few times and when it recognizes that non of the cache flush commands worked it will simply disable them assuming they are not implemented.

in reply to:  1 comment:2 by monni, 17 years ago

Replying to mmlr:

How do you mean "Card reader says connection was prematurely disconnected"? Does the cardreader itself say so or do you get an error message from Haiku? If it is the device, you can pretty much safely ignore it. The device would probably expect the system to turn off the power to the USB port first (as Windows does amongst other things when you do the "safely remove").

Card reader is connected through my cellular phone in pass-through mode. Well... I'm pretty sure it knows when something is unsafe. I guess if it wants Haiku to shutdown power from the port, then Haiku should.

comment:3 by mmlr, 17 years ago

Resolution: invalid
Status: assignedclosed

But Haiku cannot, as it has no provision to do so. Just unmounting all volumes does not really indicate you want to remove the device. It would be perfectly fine for you to remount the volume, or mount another partition/card provided by the same device. If the volume was properly unmounted though there is no reason for a surprise disconnect to be unsafe. If there is data corruption occuring then the device would be using a cache but doesn't implement the synchronize command. This is highly unlikely though as the benefit of a cache for memory cards is marginal at best. USB devices are made for hot-plugging and surprise removal and as long as there is no cache involved that doesn't get flushed there should be no issues.

What makes you think the device needs the actual power off from the port? It's probably just a reminder to use "safely remove hardware" under Windows, as there is no other way to unmount a volume under Windows (except for removing the drive letter through the device manager). This does not really apply to Haiku or other systems though that do provide means to explicitly mount/unmount. Interesting to see would be how Linux behaves in that situation. It might take unmounting all volumes as a device shutdown.

I am closing this as invalid. If data corruption actually happens, please reopen this, as then there is a bug somewhere. If you have reasons to believe not shutting down port power leads to problems, please open an enhancement ticket to implement a way to explicitly shut down USB ports, as there currently is none. This will probably require an API change though, so it won't happen too soon.

comment:4 by monni, 17 years ago

Actually Windows does have command to unmount USB removable drives. When I click the option my phone says "You can now remove USB cable". If I check USB devices after I unmount the disk, the device is still there until I actually remove the cable, so it hasn't shut down port power.

comment:5 by mmlr, 17 years ago

Resolution: invalid
Status: closedreopened

Implementing B_EJECT_DEVICE for "removable" media could do the trick here. Reopening and attaching a diff that might work.

by mmlr, 17 years ago

Attachment: start_stop_unit.diff added

Implement B_EJECT_DEVICE through the START_STOP_UNIT command

comment:6 by mmlr, 17 years ago

Resolution: fixed
Status: reopenedclosed

B_EJECT_DEVICE and B_LOAD_MEDIA implemented through SCSI START_STOP_UNIT in hrev25955.

Note: See TracTickets for help on using tickets.