diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2001-10-25 12:59:22 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2001-10-25 12:59:22 +0000 |
commit | 74308e0816164ec82755a51004f622a445e74110 (patch) | |
tree | ffee61007922d96070d79dadd6547a2e637bb98d | |
parent | 12ed00c794adf60b1b3d3a1415bc8139d2e3551d (diff) |
Allow an empty cd to be opened (raw device/whole disk) primarily to
allow empty CD caddies to be ejected.
Original diff from Alexander Guy. "pretty much straight from NetBSD"
Addition to allow eject (mt) to eject an empty tray.
ok csapuntz@
-rw-r--r-- | sys/scsi/cd.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index 5b96b226336..a9046485b64 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.56 2001/06/22 14:35:42 deraadt Exp $ */ +/* $OpenBSD: cd.c,v 1.57 2001/10/25 12:59:21 drahn Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -340,12 +340,15 @@ cdopen(dev, flag, fmt, p) return error; } + part = CDPART(dev); + if (cd->sc_dk.dk_openmask != 0) { /* * If any partition is open, but the disk has been invalidated, * disallow further opens. */ - if ((sc_link->flags & SDEV_MEDIA_LOADED) == 0) { + if ((sc_link->flags & SDEV_MEDIA_LOADED) == 0 && + (part != RAW_PART || fmt != S_IFCHR)) { error = EIO; goto bad3; } @@ -354,15 +357,24 @@ cdopen(dev, flag, fmt, p) error = scsi_test_unit_ready(sc_link, SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE | SCSI_IGNORE_NOT_READY); - if (error) - goto bad3; - + if (error) { + if (part != RAW_PART || fmt != S_IFCHR) + goto bad3; + else + goto out; + } + /* Start the pack spinning if necessary. */ error = scsi_start(sc_link, SSS_START, SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE | SCSI_SILENT); - if (error) - goto bad3; + + if (error) { + if (part != RAW_PART || fmt != S_IFCHR) + goto bad3; + else + goto out; + } sc_link->flags |= SDEV_OPEN; @@ -389,8 +401,6 @@ cdopen(dev, flag, fmt, p) } } - part = CDPART(dev); - /* Check that the partition exists. */ if (part != RAW_PART && (part >= cd->sc_dk.dk_label->d_npartitions || @@ -399,7 +409,7 @@ cdopen(dev, flag, fmt, p) goto bad; } - /* Insure only one open at a time. */ +out: /* Insure only one open at a time. */ switch (fmt) { case S_IFCHR: cd->sc_dk.dk_copenmask |= (1 << part); @@ -834,6 +844,7 @@ cdioctl(dev, cmd, addr, flag, p) case CDIOCRESET: case DVD_AUTH: case DVD_READ_STRUCT: + case MTIOCTOP: if (part == RAW_PART) break; /* FALLTHROUGH */ |