summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2008-06-21 18:50:25 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2008-06-21 18:50:25 +0000
commitad9cbfe6ecb56a2e6038fc1d8747fd71ec1123fd (patch)
treef5e0a60f57bf97e927c18a36ec39250a88a88374
parentc580f097f14fce63bc6d06d1d07c188f50dd88b6 (diff)
Eliminate cd_size() and use scsi_size() + tweaked cd_get_params()
instead. We do not make use of the PMI and RELADDR bits in the READ CAPACITY command, and thus there is no difference between cd and sd capacity handling. Brings cd and sd more into line, shrinks code and makes things easier to understand. Make types for blocksize and disksize consistant and MI. Make cdopen() as silent as sdopen(). ok marco@
-rw-r--r--sys/scsi/cd.c78
-rw-r--r--sys/scsi/cd.h6
2 files changed, 22 insertions, 62 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c
index 58c2facee6c..4ce9a53f37d 100644
--- a/sys/scsi/cd.c
+++ b/sys/scsi/cd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd.c,v 1.139 2008/06/17 01:32:49 krw Exp $ */
+/* $OpenBSD: cd.c,v 1.140 2008/06/21 18:50:24 krw Exp $ */
/* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */
/*
@@ -98,7 +98,6 @@ void cdrestart(void *);
void cdminphys(struct buf *);
void cdgetdisklabel(dev_t, struct cd_softc *, struct disklabel *, int);
void cddone(struct scsi_xfer *);
-u_long cd_size(struct cd_softc *, int);
void cd_kill_buffers(struct cd_softc *);
int cd_setchan(struct cd_softc *, int, int, int, int, int);
int cd_getvol(struct cd_softc *cd, struct ioc_vol *, int);
@@ -343,7 +342,8 @@ cdopen(dev_t dev, int flag, int fmt, struct proc *p)
/* Load the physical device parameters. */
sc_link->flags |= SDEV_MEDIA_LOADED;
- if (cd_get_parms(cd, 0) != 0) {
+ if (cd_get_parms(cd, (rawopen ? SCSI_SILENT : 0) |
+ SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE)) {
sc_link->flags &= ~SDEV_MEDIA_LOADED;
error = ENXIO;
goto bad;
@@ -1174,56 +1174,6 @@ done:
}
}
-/*
- * Find out from the device what its capacity is
- */
-u_long
-cd_size(struct cd_softc *cd, int flags)
-{
- struct scsi_read_cap_data rdcap;
- struct scsi_read_capacity scsi_cmd;
- u_long size;
- int blksize;
-
- /* Reasonable defaults for drives that don't support READ_CAPACITY */
- cd->params.blksize = 2048;
- cd->params.disksize = 400000;
-
- if (cd->sc_link->quirks & ADEV_NOCAPACITY)
- goto exit;
-
- /*
- * make up a scsi command and ask the scsi driver to do
- * it for you.
- */
- bzero(&scsi_cmd, sizeof(scsi_cmd));
- scsi_cmd.opcode = READ_CAPACITY;
-
- /*
- * If the command works, interpret the result as a 4 byte
- * number of blocks and a blocksize
- */
- if (scsi_scsi_cmd(cd->sc_link,
- (struct scsi_generic *)&scsi_cmd, sizeof(scsi_cmd),
- (u_char *)&rdcap, sizeof(rdcap), CDRETRIES, 20000, NULL,
- flags | SCSI_DATA_IN) != 0)
- goto exit;
-
- blksize = _4btol(rdcap.length);
- if ((blksize < 512) || ((blksize & 511) != 0))
- blksize = 2048; /* some drives lie ! */
- cd->params.blksize = blksize;
-
- size = _4btol(rdcap.addr) + 1;
- if (size < 100)
- size = 400000; /* ditto */
- cd->params.disksize = size;
-
- exit:
- SC_DEBUG(cd->sc_link, SDEV_DB2, ("cd_size: %d %ld\n", blksize, size));
- return (cd->params.disksize);
-}
-
int
cd_setchan(struct cd_softc *cd, int p0, int p1, int p2, int p3, int flags)
{
@@ -1585,12 +1535,22 @@ cd_load_toc(struct cd_softc *cd, struct cd_toc *toc, int fmt)
int
cd_get_parms(struct cd_softc *cd, int flags)
{
- /*
- * give a number of sectors so that sec * trks * cyls
- * is <= disk_size
- */
- if (cd_size(cd, flags) == 0)
- return (ENXIO);
+ /* Reasonable defaults for drives that don't support READ_CAPACITY */
+ cd->params.blksize = 2048;
+ cd->params.disksize = 400000;
+
+ if (cd->sc_link->quirks & ADEV_NOCAPACITY)
+ return (0);
+
+ cd->params.disksize = scsi_size(cd->sc_link, flags,
+ &cd->params.blksize);
+
+ if ((cd->params.blksize < 512) || ((cd->params.blksize & 511) != 0))
+ cd->params.blksize = 2048; /* some drives lie ! */
+
+ if (cd->params.disksize < 100)
+ cd->params.disksize = 400000;
+
return (0);
}
diff --git a/sys/scsi/cd.h b/sys/scsi/cd.h
index 5965b6a7153..4ec7db3ec81 100644
--- a/sys/scsi/cd.h
+++ b/sys/scsi/cd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd.h,v 1.16 2008/06/17 01:32:49 krw Exp $ */
+/* $OpenBSD: cd.h,v 1.17 2008/06/21 18:50:24 krw Exp $ */
/* $NetBSD: scsi_cd.h,v 1.6 1996/03/19 03:06:39 mycroft Exp $ */
/*
@@ -289,8 +289,8 @@ struct cd_softc {
#endif
struct scsi_link *sc_link; /* contains our targ, lun, etc. */
struct cd_parms {
- int blksize;
- u_long disksize; /* total number sectors */
+ u_int32_t blksize;
+ daddr64_t disksize; /* total number sectors */
} params;
#ifdef CDDA
struct cd_parms orig_params; /* filled in when CD-DA mode starts */