From owner-freebsd-questions@freebsd.org Tue Sep 26 18:04:06 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 24C19E1269B for ; Tue, 26 Sep 2017 18:04:06 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay15.qsc.de (mailrelay15.qsc.de [212.99.187.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.antispameurope.com", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8C3806FAE0 for ; Tue, 26 Sep 2017 18:04:05 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay15.qsc.de; Tue, 26 Sep 2017 20:03:10 +0200 Received: from r56.edvax.de (port-92-195-63-92.dynamic.qsc.de [92.195.63.92]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 8F5453CBF9; Tue, 26 Sep 2017 20:03:09 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id v8QI38t4002034; Tue, 26 Sep 2017 20:03:09 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 26 Sep 2017 20:03:08 +0200 From: Polytropon To: Tomasz CEDRO Cc: FreeBSD Questions Mailing List , "freebsd-usb@FreeBSD.org" , freebsd-hardware@freebsd.org Subject: Re: USB Device self-umount Message-Id: <20170926200308.5a9fb785.freebsd@edvax.de> In-Reply-To: References: Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-cloud-security-sender: freebsd@edvax.de X-cloud-security-recipient: freebsd-questions@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay15.qsc.de with 17146683678 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1407 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2017 18:04:06 -0000 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, ...