Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Sep 2017 20:03:08 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Tomasz CEDRO <tomek@cedro.info>
Cc:        FreeBSD Questions Mailing List <freebsd-questions@freebsd.org>, "freebsd-usb@FreeBSD.org" <freebsd-usb@freebsd.org>, freebsd-hardware@freebsd.org
Subject:   Re: USB Device self-umount
Message-ID:  <20170926200308.5a9fb785.freebsd@edvax.de>
In-Reply-To: <CAFYkXjnP7Ha_uZxc1zF0pz_7C3OdsJ3h-H8uyZQE_ViX5=YzBQ@mail.gmail.com>
References:  <CAFYkXjnP7Ha_uZxc1zF0pz_7C3OdsJ3h-H8uyZQE_ViX5=YzBQ@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 26 Sep 2017 16:30:48 +0200, Tomasz CEDRO wrote:
> The question is how to gracefully self-umount from a device point of
> view in a way not to confuse automounter and/or usb / mass storage
> drivers? Is there any way of doing that in SCSI+USB? Something like
> CD-ROM eject, then device removal..

This is a _very_ good question of high relevance which hasn't been
solved across many operating systems. :-)

Basically, a normal (clean) unmount can only be initiated by the OS.
You can program the controller (on the USB device) to disconnect on
its own, but that doesn't cause the OS to call unmount(), it just
makes the device disappear.

One thing I could imagine is the use of SCSI status messages and
a modified (!) storage access driver in the OS which could act upon
a specific status code with a call to unmount(), but that is, as far
as I know, not implemented yet anywhere.

The primary problem with disconnecting is that it happens _before_
the unmount() call, and keep in mind that unmounting also requires
some time. The OS can issue a certain direct access action, but it's
up to the device to perform that action. Until it has successfully
been performed, the device may not be deconnected.

Timing is hard. :-)

For CD-ROM, or optical media in general, it's not a problem because
it's read-only. The CAM EJECT command - again issued by the OS, not
by the device -, when performed _before_ unmount, leaves the OS in
a problematic state: Something is still mounted, but it doesn't
exist anymore. Okay, umount -f, no damage done. But with read-write
media such as USB direct access storage... well... that looks much
more complicated.

That's why you alway unmount first, then wait, then disconnect.
Sorry I couldn't provide more helpful suggestions... ;-)





-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170926200308.5a9fb785.freebsd>