AmendHub

Download:

akuker

/

scsi_test

/

amendments

/

2

Initial commit 2


akuker made amendment 2 over 2 years ago
--- SCSIFindDevices.h Tue Jun 16 01:55:46 2009 +++ SCSIFindDevices.h Tue Jun 16 01:55:46 2009 @@ -0,0 +1,119 @@ +/* + File: SCSIFindDevices.h + + Contains: Include the O.S. files in a specific order to make sure that we have + a definition for the _SCSIAtomic trap. + + Written by: + + 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 <Traps.h> +#ifndef _SCSIAtomic +#define _SCSIAtomic 0xA089 +#endif +/* + * This uses the new "common" SCSI.h which is not yet in the public + * header folders. + */ +#include "SCSI.h" + +/* + * This is a parameter block for SCSIFindNextDevice that contains the data shared + * with the calling program and the internal state that the function needs to + * sequence between each device. If SCSIFindNextDevice succeeds, the device + * inquiry data is stored in the record. + */ +struct SCSIFindDevicesRec { +/* Public variables */ + DeviceIdent deviceID; /* <-> Bus/target/LUN */ + short maxLUN; /* -> Maximum logical units */ + Boolean isAsyncSCSIPresent; /* <- TRUE if SCSI Manager 4.3 */ + long refNum; /* Reserved for the caller */ + long actualInquirySize; /* <- data length in inquiry */ + struct SCSI_Inquiry_Data { /* <- Inquiry returns this */ + unsigned char devType; /* 0 Device type, */ + unsigned char devTypeMod; /* 1 Device type modifier */ + unsigned char version; /* 2 ISO/ECMA/ANSI version */ + unsigned char format; /* 3 Response data format */ + unsigned char length; /* 4 Additional Length */ + unsigned char reserved5; /* 5 Reserved */ + unsigned char reserved6; /* 6 Reserved */ + unsigned char flags; /* 7 Capability flags */ + unsigned char vendor[8]; /* 8-15 Vendor-specific */ + unsigned char product[16]; /* 16-31 Product id */ + unsigned char revision[4]; /* 32-35 Product revision */ + unsigned char vendorSpecific[20]; /* 36-55 Vendor stuff */ + unsigned char moreReserved[40]; /* 56-95 Reserved */ + } inquiry; +/* Private variables */ + short state; /* Control overall operation */ + unsigned short lastHostBus; /* Host bus iteration limit */ + Boolean useAsynchSCSI; /* Is asynch ok on this bus? */ + unsigned short initiatorID; /* Host processor bus ID */ + unsigned short maxTargetID; /* Max target on this bus */ + short maxBusLUN; /* Max LUN on this bus */ + Boolean enableATN; /* Select with ATN on this bus? */ + unsigned long execIOPBSize; /* SCSIAction pb size */ + SCSIExecIOPB *scsiExecIOPB; /* Set on bus-by-bus basis */ +}; +typedef struct SCSIFindDevicesRec SCSIFindDevicesRec, *SCSIFindDevicesPtr; +/* + * Notes on the above: + * Public variables: + * deviceID This is the current SCSI device. If deviceID.bus == 0xFF + * SCSIFindNextDevice will initialize itself. + * maxLUN Set to zero to ignore logical units or seven to test + * all targets for multiple logical units. Beware: some + * devices fail miserably if a non-zero logical unit is + * selected. + * isAsyncSCSIPresent Set TRUE after the first call to SCSIFindNextDevice if + * the asynchronous SCSI Manager (SCSI Manager 4.3) is + * running. + * actualInquirySize If the function succeeds, it returns the Device Inquiry + * information in the inquiry field. actualInquirySize + * is the length of the data that was returned. + * inquiry This is the device information returned on success. + * Private variables: + * state This manages the overall code flow in the subroutine. + * lastHostBus The highest host bus on this system (if asynch present) + * useAsynchSCSI TRUE if the asynchronous SCSI Manager works on this bus + * initiatorID The bus ID of the Macintosh. Normally 7 + * maxTargetID The maximum target bus ID on this host bus. + * enableATN Enable "select with attention" if set. This works around + * a bug on un-patched Quadra 660-av and 840-av systems. + * execIOPBSize The size of the SCSI parameter block. + * scsiExecIOPB A pointer to the SCSI parameter block. + */ + +/* + * SCSIFindNextDevice: + * Scan the SCSI bus(es) for the next device. This will scan all buses, all + * targets, and all logical units in order. To initialize, set deviceID.bus to + * 0xFF and maxLUN to zero or seven as needed. + * SCSIFindNextDevice allocates memory. + * + * Return: + * noErr The deviceID field contains the next SCSI device and + * the inquiry structure contains device-specific information. + * eofErr The last device has been found. This is a normal status. + * other errors Something horrible happened, such as a memory error. + * (If your application calls SCSIFindNextDevice after any + * error status, it will start from the beginning.) + */ +OSErr SCSIFindNextDevice( + SCSIFindDevicesPtr scsiFindDevicesPtr + ); --- SCSIFindDevicesMain.c Tue Jun 16 01:55:46 2009 +++ SCSIFindDevicesMain.c Tue Jun 16 01:55:46 2009 @@ -0,0 +1,90 @@ +/* + File: SCSIFindDevicesMain.c + + Contains: This sample shows how to locate all attached SCSI devices. + + 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 <Folders.h> +#include <Errors.h> +#include <stdio.h> +#ifdef THINK_C +#include <console.h> +#endif +#include "SCSIFindDevices.h" + +SCSIFindDevicesRec gSCSIFindDevicesRec; + +void +main( +#ifdef THINK_C + int argc, + char **argv +#endif + ) +{ + OSErr status; + int devicesFound; + +#ifdef THINK_C + argc = ccommand(&argv); +#endif + /* + * Initialize the Find "global" area. If deviceID.bus is 0xFF, the + * find subroutine will initialize and return the first device. + * Set the maxLUN field to zero to prevent multiple LUN recognition + * or set it to seven to enable all LUNs. + */ + gSCSIFindDevicesRec.deviceID.bus = 0xFF; + gSCSIFindDevicesRec.maxLUN = 7; + devicesFound = 0; + while ((status = SCSIFindNextDevice(&gSCSIFindDevicesRec)) == noErr) { + ++devicesFound; + if (gSCSIFindDevicesRec.isAsyncSCSIPresent) { + printf("%d.%d.%d \"%.8s\" \"%.16s\"\n", + (int) gSCSIFindDevicesRec.deviceID.bus, + (int) gSCSIFindDevicesRec.deviceID.targetID, + (int) gSCSIFindDevicesRec.deviceID.LUN, + gSCSIFindDevicesRec.inquiry.vendor, + gSCSIFindDevicesRec.inquiry.product + ); + } + else { + printf("%d.%d \"%.8s\" \"%.16s\"\n", + (int) gSCSIFindDevicesRec.deviceID.targetID, + (int) gSCSIFindDevicesRec.deviceID.LUN, + gSCSIFindDevicesRec.inquiry.vendor, + gSCSIFindDevicesRec.inquiry.product + ); + } + } + if (status == eofErr) + printf("Normal completion, %d devices found\n", devicesFound); + else { + printf("Failure: system error %d after finding %d devices\n", + (int) status, + devicesFound + ); + } + if (gSCSIFindDevicesRec.isAsyncSCSIPresent) + printf("Using asynchronous SCSI Manager\n"); + else { + printf("Using original SCSI Manager only\n"); + } +} +