summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2020-09-13 14:26:57 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2020-09-13 14:26:57 +0000
commit6815bfec67974834c99f92a06360e001689d5b21 (patch)
tree1062f4aeb0fe070709ffdd945160a536db4cdbd6 /sys
parent5e5c2e2bd92a4bf934d1f107d1f3048629f82bf5 (diff)
Always use READ(16)/WRITE(16) commands for disks large enough to require
READ(16)/WRITE(16) to access the last sectors Fixes (at least) large 512E (a.k.a. emulated 512-byte sector) devices plugged into overly helpful USB <-> ATA/ATAPI bridges. Which can tell you they are using 512-byte sector addresses but spontaneously/silently interpret READ(10)/WRITE(10) commands as using 4K sector addresses/sizes. Diagnosed and fix tested with James Cook. Thanks!
Diffstat (limited to 'sys')
-rw-r--r--sys/scsi/sd.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c
index f8667872a02..141f62fc250 100644
--- a/sys/scsi/sd.c
+++ b/sys/scsi/sd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sd.c,v 1.326 2020/09/01 12:17:53 krw Exp $ */
+/* $OpenBSD: sd.c,v 1.327 2020/09/13 14:26:56 krw Exp $ */
/* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */
/*-
@@ -695,14 +695,15 @@ sdstart(struct scsi_xfer *xs)
((secno & 0x1fffff) == secno) &&
((nsecs & 0xff) == nsecs))
xs->cmdlen = sd_cmd_rw6(xs->cmd, read, secno, nsecs);
- else if (((secno & 0xffffffff) == secno) &&
- ((nsecs & 0xffff) == nsecs))
+
+ else if (sc->params.disksize > UINT32_MAX)
+ xs->cmdlen = sd_cmd_rw16(xs->cmd, read, secno, nsecs);
+
+ else if (nsecs <= UINT16_MAX)
xs->cmdlen = sd_cmd_rw10(xs->cmd, read, secno, nsecs);
- else if (((secno & 0xffffffff) == secno) &&
- ((nsecs & 0xffffffff) == nsecs))
- xs->cmdlen = sd_cmd_rw12(xs->cmd, read, secno, nsecs);
+
else
- xs->cmdlen = sd_cmd_rw16(xs->cmd, read, secno, nsecs);
+ xs->cmdlen = sd_cmd_rw12(xs->cmd, read, secno, nsecs);
disk_busy(&sc->sc_dk);
if (!read)