Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 May 2014 17:10:38 +0100
From:      Arthur Chance <freebsd@qeng-ho.org>
To:        Polytropon <freebsd@edvax.de>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: write-protected usb flash drive
Message-ID:  <5380C47E.7020008@qeng-ho.org>
In-Reply-To: <20140524174102.66eff3da.freebsd@edvax.de>
References:  <537FE744.3030002@dreamchaser.org> <20140524080127.f2e788d5.freebsd@edvax.de> <5380AB17.2070300@dreamchaser.org> <5380B953.5090700@qeng-ho.org> <20140524174102.66eff3da.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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: <SanDisk> at usbus3
May 24 16:50:28 fileserver kernel: umass2: <SanDisk SDDR-113, class 0/0, 
rev 2.00/94.12, addr 7> 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: <SanDisk SDDR-113 9412> 
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<NO_6_BYTE>

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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5380C47E.7020008>