From owner-freebsd-hardware@freebsd.org Tue Sep 26 14:31:10 2017 Return-Path: Delivered-To: freebsd-hardware@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 9DD57E0D3A6; Tue, 26 Sep 2017 14:31:10 +0000 (UTC) (envelope-from tomek.cedro@gmail.com) Received: from mail-vk0-x22e.google.com (mail-vk0-x22e.google.com [IPv6:2607:f8b0:400c:c05::22e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 582D267ED3; Tue, 26 Sep 2017 14:31:10 +0000 (UTC) (envelope-from tomek.cedro@gmail.com) Received: by mail-vk0-x22e.google.com with SMTP id q190so3770802vkd.13; Tue, 26 Sep 2017 07:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:from:date:message-id:subject:to; bh=xOyPwskdA6frPfhl6cBxoZKMMwQaEftRLifWMR8Ncno=; b=avVXNe5VWCBBkq7v1cxm2y0XSa3BkALeDIF3bxPVGCN5sI/58VoDC39VrrO4Tgyem3 li5J+jIzpB2xhXcdQMM0dkrf40Ox5FkpeOuRZjr+yDeufWE+G2vbmI8JeJBqkPt7T/XV G2zdhm4FJJARbTlDJ6JLjrJU4lx2WmY4CpwGK8ikSRFx3oOH4SouxZjSvwHjFeFki2Tk UjpVbBfzZVi79CPtfmZptb2MwoaGHDgx7dNDuRsUqxCFqOoD7cz3AYS0FwjT5M3AIvW3 uERop2rX4ISs1I1/XWn1nW+aWxEpETDwb0zlHK6CI2VV+g1kULIEThbdryHDRInNoofw DP7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:from:date:message-id:subject :to; bh=xOyPwskdA6frPfhl6cBxoZKMMwQaEftRLifWMR8Ncno=; b=LbaTKmG9krDkQf9EJQVYmMp2pojZ+no2+g0wl9xnR2il0meu7CrMJTZZvWjM2CCFY8 4foxl5BGt6qtFVdUtMKyVCTCuCRGsdY1coNzuQx33PVVbF3XocsFiQgDmCik+ietYFVM +LtEE1Ikor+6HNBya5d42qEMcY0EpJWvpjQkyJ0q5ix4Y9sRpPjGQouWowPSVPSVgIvm SsILTmjevvmmkbZHHi7iQZ8/tDoYWxNd2B0PQPX/f7NKSbnP5BEQIsSZAbmb/cLQLrmE 4p0IJW38UL+zGScH3ZGZIrq/huL/AVVtiPtCFf8UuUbO5r1E/KN1yKb4drvs6XmvHFRo 8HwQ== X-Gm-Message-State: AHPjjUg3s3FtsHqH6rSpCKzgY8qjfYx3Fy11aGuDE70/oCU0vI4RZ0x1 v5iqc5EUqPIpo/F4a+yy/ZBhAapc+z1Vw5/CfptPLviB X-Google-Smtp-Source: AOwi7QDgjFWC763/FKwkvDLLgh+6O5yYvf+DiUJHJtmWdtAwgwutANhwKCu0hpATCwLElhv5R9/WwIFp2h38KgsYrEE= X-Received: by 10.31.167.71 with SMTP id q68mr8547908vke.49.1506436268722; Tue, 26 Sep 2017 07:31:08 -0700 (PDT) MIME-Version: 1.0 Sender: tomek.cedro@gmail.com Received: by 10.176.20.35 with HTTP; Tue, 26 Sep 2017 07:30:48 -0700 (PDT) From: Tomasz CEDRO Date: Tue, 26 Sep 2017 16:30:48 +0200 X-Google-Sender-Auth: Tg_bzUrjNgVbqxK-3ZkuZSzZj94 Message-ID: Subject: USB Device self-umount To: FreeBSD Questions Mailing List , "freebsd-usb@FreeBSD.org" , freebsd-hardware@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2017 14:31:10 -0000 Hello world! :-) I am working on a device that implements USB MSC mass storage for firmware programming [1]. After receiving file, it flashes the firmware image to the target MCU, then reboots and starts the program or waits debug session.. 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.. Any hints appreciated :-) Tomek [1] https://github.com/mbedmicro/DAPLink -- CeDeROM, SQ7MHZ, http://www.tomek.cedro.info From owner-freebsd-hardware@freebsd.org Tue Sep 26 18:04:06 2017 Return-Path: Delivered-To: freebsd-hardware@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 27FF4E1269D 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 8C3BB6FAE1 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-hardware@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-hardware@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General discussion of FreeBSD hardware 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, ... From owner-freebsd-hardware@freebsd.org Tue Sep 26 20:52:50 2017 Return-Path: Delivered-To: freebsd-hardware@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 AB1E9E212F5; Tue, 26 Sep 2017 20:52:50 +0000 (UTC) (envelope-from tomek.cedro@gmail.com) Received: from mail-vk0-x242.google.com (mail-vk0-x242.google.com [IPv6:2607:f8b0:400c:c05::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 62B2E75CED; Tue, 26 Sep 2017 20:52:50 +0000 (UTC) (envelope-from tomek.cedro@gmail.com) Received: by mail-vk0-x242.google.com with SMTP id 78so3065338vkc.1; Tue, 26 Sep 2017 13:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=j5RaMmrS1C62CAfBnTI5StJl0NtGlHoWuc3meD3ozSg=; b=n0BTTweTOTWsXxnf2lx7lzhu2UwUyOzeUEkxFqAgW2hxXl+q3XQyzQP0UhQMy/eJmi z9sT2XN+yYfetC+NJX7+xuteikmXz0j4AhvTvD24DgJUsAuqPujYbMVjdWbWCu4kf+vR FBL2zn+udz2WprRKzyHtmcQIcLJRX7/C4/yW62YMsbPFdFqp7zjVUII7cMXrfafRuvNZ wI3Rm5FhQJghavJBXyTukktUmEqu6xdyH+hTN4WXkNLbQYi+yuE9OwRoiFNPp/uM1VI+ 3qHKq7rCgGRxsYOluazBNJ/CZanLzXOur1Cvrwcz5W4gx4wiRoQed8fwkwiFa2HSO0SX XGLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=j5RaMmrS1C62CAfBnTI5StJl0NtGlHoWuc3meD3ozSg=; b=FFEwEVlqerGXfg7njblljioa0xmvBUZaLycnWWqx27U04rnFjQkNwwR6EWvAUl58Tc yKmgL1F9erxEq7wWEKh0ZHuOztuasLCzcItotMviODbQygM7roVqpfAQdCMJbUEwmVZV 1+/q8/wRYAY7pd9YZlirDVqHCY4hoOWnaoZRtU7Cay/rOlSJWl3hUQIO8XbKEh+q6kUd jZSQC93adUX0kH5Fb7MAbGyV0c1EBzriVuwhCf4lmBedAnM1OuP4pOw5JT0AWmjsqwcC csO5MCYQFVHtk1OjVLdQ3gSm9UnA/AfAZoQLKeHV2AR0Hdr75sDZnhH9YdcDu+XZsrAK kM4A== X-Gm-Message-State: AHPjjUjZdkiZi7mc1y+pVCqvXYlkDNuL5XNL86l9Wl6JYA9pyuWXdYn9 h8WA53aQIJ++6d1NvLu9vybunQPibrggW7gNcVbmfuDo X-Google-Smtp-Source: AOwi7QCmV2VBO9GBCMTBGhBi+0bV1XN1Z5HDGtUbasrQNhrokf2oebMjrVCVp+tz6Uem5bXwt+xTJYU3ArQZ9WXB9WE= X-Received: by 10.31.82.3 with SMTP id g3mr9254182vkb.76.1506459169368; Tue, 26 Sep 2017 13:52:49 -0700 (PDT) MIME-Version: 1.0 Sender: tomek.cedro@gmail.com Received: by 10.176.20.35 with HTTP; Tue, 26 Sep 2017 13:52:28 -0700 (PDT) In-Reply-To: <20170926200308.5a9fb785.freebsd@edvax.de> References: <20170926200308.5a9fb785.freebsd@edvax.de> From: Tomasz CEDRO Date: Tue, 26 Sep 2017 22:52:28 +0200 X-Google-Sender-Auth: tXjEV8Ng_JoaHs2xKwNz8sHls8g Message-ID: Subject: Re: USB Device self-umount To: Polytropon Cc: FreeBSD Questions Mailing List , "freebsd-usb@FreeBSD.org" , freebsd-hardware@freebsd.org Content-Type: text/plain; charset="UTF-8" X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2017 20:52:50 -0000 Hey Polytropon! :-) Thanks for ideas! I am at the moment at point where I sniff out the USB traffic and analyze SCSI packets.. and also I got into SCSI specification to search for some possibilities.. :-) I will have to see how Windoze handles ATAPI EJECT, maybe that could bring some insight on how to umount ejectable media triggered by the device-eject-button-press.. As for now the device reports CHECK-CONDITION to mark media missing, then reboots and re-appeares, but that causes "device not cleanly unmounted" warnings on macOS for instance.. Will report back when I find anything interesting :-) Best regards! :-) Tomek -- CeDeROM, SQ7MHZ, http://www.tomek.cedro.info From owner-freebsd-hardware@freebsd.org Tue Sep 26 21:02:05 2017 Return-Path: Delivered-To: freebsd-hardware@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 8F7A6E2171D for ; Tue, 26 Sep 2017 21:02:05 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mailrelay12.qsc.de (mailrelay12.qsc.de [212.99.163.153]) (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 01D1C76171 for ; Tue, 26 Sep 2017 21:02:04 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de ([213.148.129.14]) by mailrelay12.qsc.de; Tue, 26 Sep 2017 23:01:31 +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 1F1AA3CC42; Tue, 26 Sep 2017 23:01:29 +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 v8QL1TBp002712; Tue, 26 Sep 2017 23:01:29 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Tue, 26 Sep 2017 23:01:29 +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: <20170926230129.7b00d9a7.freebsd@edvax.de> In-Reply-To: References: <20170926200308.5a9fb785.freebsd@edvax.de> 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-hardware@freebsd.org X-cloud-security-Virusscan: CLEAN X-cloud-security-disclaimer: This E-Mail was scanned by E-Mailservice on mailrelay12.qsc.de with 88B456A3827 X-cloud-security-connect: mx01.qsc.de[213.148.129.14], TLS=1, IP=213.148.129.14 X-cloud-security: scantime:.1473 X-BeenThere: freebsd-hardware@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General discussion of FreeBSD hardware List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Sep 2017 21:02:05 -0000 On Tue, 26 Sep 2017 22:52:28 +0200, Tomasz CEDRO wrote: > I will have to see how Windoze handles ATAPI EJECT, maybe that could > bring some insight on how to umount ejectable media triggered by the > device-eject-button-press.. Hmmm... I don't think this is what happens. ATAPI EJECT is issued by the OS (ATAPI device driver) and the device simply ejects. If this action is "prefixed" with an unmount() call and a certain delay, everything is well. This is how a typical GUI file manager on Linux or FreeBSD works. But pressing the device's eject button will simply eject the media. Subsequent TUR inquiries by the OS will result in "device not ready", and that may cause the umount() call, but _after_ the device has been removed. > As for now the device reports CHECK-CONDITION to mark media missing, > then reboots and re-appeares, but that causes "device not cleanly > unmounted" warnings on macOS for instance.. Of course it does. :-) With filesystems mounted read-only, this typically isn't a problem, but those with read-write access might be left in an inconsistent state, and depending on the OS, cannot be mounted again (or require a run of fsck, or in case of "Windows", a kind of "repair" that often leads to data loss and corrupted files). Examining the USB traffic and checking for the CAM packets exchanged between the device and the OS could help you find a way to implement the impossible. ;-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...