Subject: sdclose should stop unit.
To: None <netbsd-bugs@NetBSD.ORG>
From: None <KLEIPOOL_REINIER/HPITCB_85@belgium.hp.com>
List: netbsd-bugs
Date: 01/18/1995 13:40:00
Subject: sdclose() should send STOP_UNIT command
Reply-To: reinier_kleipool@hpitcb.desk.hp.com
Status: R


>Submitter-Id:  net
>Originator:    Charlie &
>Organization:
" Reinier Kleipool private."
>Confidential:  no
>Synopsis:      sd driver prevents removable media to be removed from drive.
>Severity:      non-critical
>Priority:      low
>Category:      kern
>Class:         sw-bug
>Release:       1.0
>Environment:
System: NetBSD reinierux1.overschie.nl 1.0 NetBSD 1.0 (OVERSCHIE) #2: Wed Jan
18 00:06:38 MET 1995
root@reinierux1.overschie.nl:/usr/src/sys/arch/i386/compile/OVERSCHIE i386


>Description:
        I have attached a IoMega Bernoulli drive wich has a removable disc
        of 42Mb. The sd driver does not STOP the unit after use, preventing
        the operator from removing the disk. The motor of the drive stays
running,
        and the doorlock is NOT released.
>How-To-Repeat:
        mount /dev/sd1a /bernoulli
        umount /dev/sd1a
        ... The disk cannot be removed at this point ...
>Fix:
        /* Add the lines marked with /**/ to /sys/scsi/sd.c */

/*
 * close the device.. only called if we are the LAST occurence of an open
 * device.  Convenient now but usually a pain.
 */
int
sdclose(dev)
        dev_t dev;
{
        int unit, part;
        struct sd_data *sd;
/**/    struct scsi_link *sc_link;

        unit = SDUNIT(dev);
        part = SDPART(dev);

        sd = sdcd.cd_devs[unit];
        sd->partflags[part] &= ~SDOPEN;
        sd->openparts &= ~(1 << part);

/**/    sc_link = sd->sc_link;

        if (!sd->openparts) {
                scsi_prevent(sd->sc_link, PR_ALLOW, SCSI_ERR_OK | SCSI_SILENT);
/**/    /*
/**/     * In case it is a funny one, tell it to stop
/**/     * not needed for most hard drives (ignore failure)
/**/     */
/**/            scsi_start(sc_link, SSS_STOP, SCSI_ERR_OK | SCSI_SILENT);

                sd->sc_link->flags &= ~SDEV_OPEN;
        }
        return 0;
}/*sdclose*/