Wait for drive to become ready if its in progress of loading..

Based on patch in PR-42659, but done somewhat differently.

PR: 42659
This commit is contained in:
Søren Schmidt 2002-09-12 13:55:24 +00:00
parent 9d54441f7f
commit 175f0ce5a4

View File

@ -509,6 +509,7 @@ static int
acdopen(dev_t dev, int flags, int fmt, struct thread *td)
{
struct acd_softc *cdp = dev->si_drv1;
int timeout = 60;
if (!cdp)
return ENXIO;
@ -517,6 +518,19 @@ acdopen(dev_t dev, int flags, int fmt, struct thread *td)
if (count_dev(dev) > 1)
return EBUSY;
}
/* wait if drive is not finished loading the medium */
while (timeout--) {
struct atapi_reqsense *sense = cdp->device->result;
if (!atapi_test_ready(cdp->device))
break;
if (sense->sense_key == 2 && sense->asc == 4 && sense->ascq == 1)
tsleep(&timeout, PRIBIO, "acdld", hz / 2);
else
break;
}
if (count_dev(dev) == 1) {
if (cdp->changer_info && cdp->slot != cdp->changer_info->current_slot) {
acd_select_slot(cdp);