ShowRegisteredSCSIDevices.c

/*
    File:       ShowRegisteredSCSIDevices.c
 
    Contains:   This subroutine prints the bus ID and driver refNum for all drivers
                registered with SCSI Manager 4.3
 
    Written by: Martin Minow    
 
    Copyright:  Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/14/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#include <stdio.h>
#include <Files.h>
#include <Devices.h>
#include <Memory.h>
/*
 * Include the O.S. files in a specific order to make sure that we have
 * a definition for the _SCSIAtomic trap.
 */
#include <Traps.h>
#ifndef _SCSIAtomic
#define _SCSIAtomic 0xA089
#endif
/*
 * Note that this uses a later version of <Scsi.h> than is available in
 * the published headers.
 */
#include "Scsi.h"
 
Boolean                 AsyncSCSIPresent(void);
void                    ShowRegisteredSCSIDevices(void);
 
static void
ClearMemory(
        Ptr             ptr,
        Size            size
    )
{
        while (size > 0) {
            *ptr++ = 0;
            --size;
        }
}
 
 
void
ShowRegisteredSCSIDevices(void)
{
        SCSIDriverPB            pb;
        OSErr                   status;
        int                     foundCount;
        
        if (AsyncSCSIPresent()) {
            ClearMemory((Ptr) &pb, sizeof pb);
            pb.scsiPBLength = sizeof (SCSIDriverPB);
            pb.scsiCompletion = NULL;
            pb.scsiFlags = 0;
            pb.scsiFunctionCode = SCSILookupRefNumXref;
            * ((long *) &pb.scsiDevice) = 0xFFFFFFFFL;
            foundCount = 0;
            do {
                status = SCSIAction((SCSI_PB *) &pb);
                if (status == noErr) {
                    if (pb.scsiDevice.bus != 0xFF) {
                        printf("Device ID [%d.%d.%d], %3d refNum\n",
                            (int) pb.scsiDevice.bus,
                            (int) pb.scsiDevice.targetID,
                            (int) pb.scsiDevice.LUN,
                            (int) pb.scsiDriver
                        );
                        ++foundCount;
                    }
                    pb.scsiDevice = pb.scsiNextDevice;
                }
            }
            while (pb.scsiDevice.bus != 0xFF);
            switch (foundCount) {
            case 0:     printf("No devices were registered\n");             break;
            case 1:     printf("One device was registered\n");              break;
            default:    printf("%d devices were regisered\n", foundCount);  break;
            }
        }
        else {
            printf("SCSI Manager 4.3 is not present on this machine\n");
        }
}