From owner-freebsd-questions@FreeBSD.ORG Sat May 24 16:10:46 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A6A4D1EC for ; Sat, 24 May 2014 16:10:46 +0000 (UTC) Received: from blue.qeng-ho.org (blue.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 34CF727CE for ; Sat, 24 May 2014 16:10:45 +0000 (UTC) Received: from fileserver.home.qeng-ho.org (localhost [127.0.0.1]) by fileserver.home.qeng-ho.org (8.14.7/8.14.5) with ESMTP id s4OGAcoP094625; Sat, 24 May 2014 17:10:38 +0100 (BST) (envelope-from freebsd@qeng-ho.org) Message-ID: <5380C47E.7020008@qeng-ho.org> Date: Sat, 24 May 2014 17:10:38 +0100 From: Arthur Chance User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Polytropon Subject: Re: write-protected usb flash drive References: <537FE744.3030002@dreamchaser.org> <20140524080127.f2e788d5.freebsd@edvax.de> <5380AB17.2070300@dreamchaser.org> <5380B953.5090700@qeng-ho.org> <20140524174102.66eff3da.freebsd@edvax.de> In-Reply-To: <20140524174102.66eff3da.freebsd@edvax.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: FreeBSD Mailing List X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2014 16:10:46 -0000 On 24/05/2014 16:41, Polytropon wrote: > On Sat, 24 May 2014 16:22:59 +0100, Arthur Chance wrote: >> OK, thought I'd better try my own advice rather than just handing it >> out. I put a microSD card out of an old phone into a SanDisk mSD -> SD >> adapter and plugged that into my SanDisk SD -> USB adapter, mounted it >> (FAT32 file system already on it) and wrote a file to it. Worked as >> you'd expect. I then unmounted and unplugged it, flipped the write >> protect switch and tried to remount. Result was >> >> mount_msdosfs: /dev/da5s1: Input/output error >> >> Mounting it read-only was fine. So, the write protect is honoured by at >> least some SD -> USB adapters. > > This is already on file system level. It _should_ work the same > at upper layers, for example when using dd to write NULs to the > device with the write protection on - an error should (correctly) > occur in that case. > > When a r/o mount is forced, the routines accessing that file > system cannot avoid the write protection. Still writes are > possible _aside of_ the file system which should be prevented > by the switch as well. It's probably a good idea to check that > too, e. g. put in the card with write protection on and then > try dd or newfs on it. Good point. I had presumed that the writable mount failed because it tries to update the superblock, but making sure at the disk driver level is sensible. With write protect enabled on the card: fileserver:1# tail /var/log/messages May 24 16:50:28 fileserver kernel: ugen3.7: at usbus3 May 24 16:50:28 fileserver kernel: umass2: on usbus3 May 24 16:50:28 fileserver kernel: umass2: SCSI over Bulk-Only; quirks = 0x4100 May 24 16:50:28 fileserver kernel: umass2:12:2:-1: Attached to scbus12 May 24 16:50:28 fileserver kernel: da5 at umass-sim2 bus 2 scbus12 target 0 lun 0 May 24 16:50:28 fileserver kernel: da5: Removable Direct Access SCSI-0 device May 24 16:50:28 fileserver kernel: da5: Serial Number 000000009412 May 24 16:50:28 fileserver kernel: da5: 40.000MB/s transfers May 24 16:50:28 fileserver kernel: da5: 3768MB (7716864 512 byte sectors: 255H 63S/T 480C) May 24 16:50:28 fileserver kernel: da5: quirks=0x2 fileserver:1# dd if=/dev/zero of=/dev/da5 bs=4k count=1 dd: /dev/da5: Input/output error 1+0 records in 0+0 records out 0 bytes transferred in 2.353360 secs (0 bytes/sec) Yes, it works at the disk driver level. Gary, if you want bigger/faster than my adapter, there's a USB3.0 version of my adapter available, look for the SanDisk Extreme PRO® SDHC™/SDXC™ UHS-II Card Reader/Writer, aka the SanDisk SDDR-329. You'll need to check it honours the write protect switch of course.