Re: "Safely remove hardware" for USB

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 28 Sep 2009, Oliver Neukum wrote:

> Am Montag, 28. September 2009 20:16:44 schrieb Alan Stern:
> > On Mon, 28 Sep 2009, Oliver Neukum wrote:
> 
> > > Wouldn't it be better if the device were removed in a suspended state
> > > so buffers on storage devices could be flushed?
> >
> > That is a userspace detail.  The intended mode of operation is that a
> > program like "eject" will first unmount all filesystems on the device
> 
> Hm. The device may or may not have a filesystem on it.

Well, if it doesn't have a filesystem then there's nothing to unmount!  
:-)

In fact, the "remove" attribute works for any USB device, since all it
does is disable the upstream port.  But normally it's intended only for
mass-storage devices.  I was going to say that it's needed only for
mass-storage devices, but that's not correct -- it isn't _needed_ at
all.  Its main purpose is to make people who have been conditioned by
Windows feel more comfortable, by turning off an LED on the device to 
indicate that removal is now safe.

> > and unbind usb-storage (causing buffers to be flushed), and then write
> 
> How does unbinding usb-storage flush buffers?

Unbinding usb-storage causes the underlying SCSI host to be
unregistered, which unbinds the sd driver, which sends a SYNCHRONIZE
CACHE command from within its unbind method.

> > to the "remove" attribute.
> 
> If this is the only way to correctly use the attribute why not make the
> attribute do what needs to be done to be correct?

Because doing that requires a larger view of the whole system.  The USB 
layer doesn't know whether a device contains a mounted filesystem, or a 
filesystem at all, or even whether it has an underlying block device.

I suppose the attribute could switch the device to configuration 0 
before disabling the port.  That would cause the drivers to be unbound 
safely, while communication was still possible.  On the other hand, 
userspace can do the same thing just as easily by writing "-1" to the 
bConfigurationValue attribute -- which would remove the need to unbind 
usb-storage explicitly.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux