summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2005-08-17 02:17:52 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2005-08-17 02:17:52 +0000
commitb914c2b9ed1199887db0c177b74de3844be13254 (patch)
tree7af52e031ef8246d2a954f3802227bf6f2d6c12f /sys
parent0d2bc6888a3a998ae2188f95f98335eb08982957 (diff)
Use defines for disk mode page codes. Check returned mode pages to
ensure they are the ones requested. No functional change unless garbage was being returned. ok marco@
Diffstat (limited to 'sys')
-rw-r--r--sys/scsi/scsi_disk.h9
-rw-r--r--sys/scsi/sd.c28
2 files changed, 20 insertions, 17 deletions
diff --git a/sys/scsi/scsi_disk.h b/sys/scsi/scsi_disk.h
index 74484649c1b..8e46dc5958b 100644
--- a/sys/scsi/scsi_disk.h
+++ b/sys/scsi/scsi_disk.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: scsi_disk.h,v 1.17 2005/08/12 01:49:08 krw Exp $ */
+/* $OpenBSD: scsi_disk.h,v 1.18 2005/08/17 02:17:51 krw Exp $ */
/* $NetBSD: scsi_disk.h,v 1.10 1996/07/05 16:19:05 christos Exp $ */
/*
@@ -236,7 +236,12 @@ struct scsi_reassign_blocks_data {
} defect_descriptor[1];
};
-#define DISK_PGCODE 0x3F /* Only 6 bits of pg_code are valid. */
+/* Only the lower 6 bits of the pg_code field are used for page #. */
+#define DISK_PGCODE(pg, n) ((pg) != NULL) && (((pg)->pg_code & 0x3f) == n)
+#define PAGE_DISK_FORMAT 3
+#define PAGE_RIGID_GEOMETRY 4
+#define PAGE_FLEX_GEOMETRY 5
+#define PAGE_REDUCED_GEOMETRY 6
struct page_disk_format {
u_int8_t pg_code; /* page code (should be 3) */
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c
index d5d39dba48f..5451603a849 100644
--- a/sys/scsi/sd.c
+++ b/sys/scsi/sd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sd.c,v 1.83 2005/08/12 01:49:08 krw Exp $ */
+/* $OpenBSD: sd.c,v 1.84 2005/08/17 02:17:51 krw Exp $ */
/* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */
/*-
@@ -1345,11 +1345,11 @@ sd_get_parms(sd, dp, flags)
break;
case T_RDIRECT:
- /* T_RDIRECT only supports RBC Device Parameter Page (6). */
- scsi_do_mode_sense(sd->sc_link, 6, &buf, (void **)&reduced,
- NULL, NULL, &blksize, sizeof(*reduced), flags | SCSI_SILENT,
- NULL);
- if (reduced) {
+ /* T_RDIRECT supports only PAGE_REDUCED_GEOMETRY (6). */
+ scsi_do_mode_sense(sd->sc_link, PAGE_REDUCED_GEOMETRY, &buf,
+ (void **)&reduced, NULL, NULL, &blksize, sizeof(*reduced),
+ flags | SCSI_SILENT, NULL);
+ if (DISK_PGCODE(reduced, PAGE_REDUCED_GEOMETRY)) {
if (dp->disksize == 0)
dp->disksize = _5btol(reduced->sectors);
if (blksize == 0)
@@ -1361,22 +1361,20 @@ sd_get_parms(sd, dp, flags)
rigid = NULL;
if (((sd->sc_link->flags & SDEV_ATAPI) == 0) ||
((sd->sc_link->flags & SDEV_REMOVABLE) == 0))
- /* Try mode sense page 4 (RIGID GEOMETRY). */
- scsi_do_mode_sense(sd->sc_link, 4, &buf,
- (void **)&rigid, NULL, NULL, &blksize,
+ scsi_do_mode_sense(sd->sc_link, PAGE_RIGID_GEOMETRY,
+ &buf, (void **)&rigid, NULL, NULL, &blksize,
sizeof(*rigid), flags | SCSI_SILENT, NULL);
- if (rigid) {
+ if (DISK_PGCODE(rigid, PAGE_RIGID_GEOMETRY)) {
heads = rigid->nheads;
cyls = _3btol(rigid->ncyl);
rpm = _2btol(rigid->rpm);
if (heads * cyls > 0)
sectors = dp->disksize / (heads * cyls);
} else {
- /* * Try page 5 (FLEX GEOMETRY). */
- scsi_do_mode_sense(sd->sc_link, 5, &buf, (void **)&flex,
- NULL, NULL, &blksize, sizeof(*flex),
- flags | SCSI_SILENT, NULL);
- if (flex) {
+ scsi_do_mode_sense(sd->sc_link, PAGE_FLEX_GEOMETRY,
+ &buf, (void **)&flex, NULL, NULL, &blksize,
+ sizeof(*flex), flags | SCSI_SILENT, NULL);
+ if (DISK_PGCODE(flex, PAGE_FLEX_GEOMETRY)) {
sectors = flex->ph_sec_tr;
heads = flex->nheads;
cyls = _2btol(flex->ncyl);