diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-05-01 19:29:18 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2005-05-01 19:29:18 +0000 |
commit | a97029e989ef5c35cea27b28af96ed95951c71ea (patch) | |
tree | 6195a18d1aaf4755e6a8fbec22e820ab52af8581 | |
parent | 49b98b86bd49f7af2d222da6891e9cba361dae86 (diff) |
Allow RAW_PART+S_IFCHR device opens to succeed even if media not
present. A successful open is required for ioctl's to work. Mostly
from NetBSD, partly correcting previous code cleanup error.
From deraadt@, treat MTIOCTOP+MTRETEN as CDIOCCLOSE for cd devices
(i.e. close the cd drawer).
ok deraadt@.
-rw-r--r-- | sys/scsi/cd.c | 11 | ||||
-rw-r--r-- | sys/scsi/sd.c | 17 |
2 files changed, 20 insertions, 8 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index d19864ef6e5..bf9c8925571 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd.c,v 1.78 2005/04/06 02:51:13 krw Exp $ */ +/* $OpenBSD: cd.c,v 1.79 2005/05/01 19:29:17 krw Exp $ */ /* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */ /* @@ -359,6 +359,7 @@ cdopen(dev, flag, fmt, p) * and don't ignore NOT_READY. */ error = scsi_test_unit_ready(sc_link, TEST_READY_RETRIES_CD, + (part == RAW_PART && fmt == S_IFCHR) ? SCSI_SILENT : 0 | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); /* Start the cd spinning if necessary. */ @@ -368,9 +369,10 @@ cdopen(dev, flag, fmt, p) SCSI_IGNORE_MEDIA_CHANGE | SCSI_SILENT); if (error) { - if (part == RAW_PART && fmt == S_IFCHR) + if (part == RAW_PART && fmt == S_IFCHR) { + error = 0; goto out; - else + } else goto bad; } @@ -1100,12 +1102,15 @@ cdioctl(dev, cmd, addr, flag, p) error = scsi_start(cd->sc_link, SSS_STOP, 0); break; + close_tray: case CDIOCCLOSE: error = scsi_start(cd->sc_link, SSS_START|SSS_LOEJ, SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE); break; case MTIOCTOP: + if (((struct mtop *)addr)->mt_op == MTRETEN) + goto close_tray; if (((struct mtop *)addr)->mt_op != MTOFFL) { error = EIO; break; diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 1e13885f423..33e41e1c884 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.75 2005/04/06 02:51:13 krw Exp $ */ +/* $OpenBSD: sd.c,v 1.76 2005/05/01 19:29:17 krw Exp $ */ /* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */ /*- @@ -383,9 +383,11 @@ sdopen(dev, flag, fmt, p) if (sd->sc_dk.dk_openmask != 0) { /* * If any partition is open, but the disk has been invalidated, - * disallow further opens. + * disallow further opens of non-raw partition. */ if ((sc_link->flags & SDEV_MEDIA_LOADED) == 0) { + if (part == RAW_PART && fmt == S_IFCHR) + goto out; error = EIO; goto bad; } @@ -405,8 +407,13 @@ sdopen(dev, flag, fmt, p) SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_MEDIA_CHANGE); - if (error) - goto bad; + if (error) { + if (part == RAW_PART && fmt == S_IFCHR) { + error = 0; + goto out; + } else + goto bad; + } /* Lock the pack in. */ if ((sc_link->flags & SDEV_REMOVABLE) != 0) { @@ -440,7 +447,7 @@ sdopen(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: sd->sc_dk.dk_copenmask |= (1 << part); |