home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 283.lha / Park / park.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-08  |  4.3 KB  |  170 lines

  1. /* park.c
  2.     This example code shows how to direct access a generic SCSI device driver
  3. that has been constructed in accordance with the specifications in the scsidisk.h
  4. file. This is the resultant format from the Amiga Working Group on SCSI
  5. interfacing standardization.
  6.  
  7.     It is used from the cli as
  8.   "park <board number><LUN><SCSI address> [<device name>]"
  9. with board number being a valid board for this driver in the range 0 through 7.
  10. The LUN is a valid SCSI LUN, which are in the range 0 through 7. The SCSI address
  11. is a valid SCSI device address. The device name defaults to HardFrame.device if
  12. you enter nothing. You can enter "StarDrive.device" and the newest StarDrive
  13. device driver will park the indicated unit. (This driver is as yet to be 
  14. released as of this date, though.) Other device drivers may work depending on
  15. the manufacturer's compliance with the specification. 
  16.  
  17.     As an added tweak to the code a unit number that is 1<board><LUN>SCSIId>
  18. will cause the drive to unpark if it is there.
  19.  
  20.     © Joanne Dow, Wizardess Designs, 16 Dec 1988 All rights reserved.
  21.  This may be freely copied as long as this notice remains here and the notice
  22. remains in the executable version.
  23. */
  24.  
  25. /*#define    D(f)    f*/
  26. /*#define    dprintf    printf*/
  27. #define    D(f)
  28.  
  29. #include    "Park.h"
  30.  
  31. char DefaultName[] = "HardFrame.device";
  32. char *DeviceName;
  33.  
  34. struct MsgPort IORP = {
  35.     {0L, 0L, NT_MSGPORT, 0, 0L}, 0, SIGB_SINGLE, 0,
  36.     {0, 0, 0, 0, 0}
  37. };
  38.  
  39. struct IOStdReq IOR = {
  40.     { {0L, 0L, NT_MESSAGE, 0, 0L}, /* Message Succ, Pred, Type, Pri, Name */
  41.     &IORP, 0 },            /* Message ReplyPort, Length */
  42.     0, 0, 0, 0, 0,        /* IO Device, Unit, Command, Flags, Error */
  43.     0L, 0L, 0L, 0L        /* IO Actual, Length, Data, Offset */
  44. };
  45.  
  46. struct SCSICmd SC;
  47.  
  48. UBYTE SCCmd[10];
  49.  
  50. extern struct ExecBase *SysBase;
  51.  
  52.  
  53. int
  54. PromptedNumber(query, result)
  55. char *query;
  56. int result;
  57. {
  58.     char Data[81];
  59.  
  60.     printf(query, result);
  61.     gets(Data);
  62.     sscanf(Data, "%d", &result);
  63.     return(result);
  64. }
  65.  
  66. void
  67. EndGame(code, format, arg1, arg2)
  68. int code;
  69. char *format, *arg1, *arg2;
  70. {
  71.     D(dprintf( "EndGame\n"));
  72.     if (code != 0) {
  73.         printf(format, arg1, arg2);
  74.     }
  75.     if (IOR.io_Device != 0) {
  76.         D(dprintf("CloseDevice\n"));
  77.         CloseDevice((struct IORequest *) &IOR);
  78.     }
  79.     exit(code);
  80. }
  81.  
  82.  
  83. int
  84. main(argc, argv)
  85. int argc;
  86. char *argv[];
  87. {
  88.     struct Library *mbhf;
  89.     int  unit, board, scsiID, scsiLUN;
  90.     BOOL unpark;
  91.     int result;
  92.  
  93.     printf( "    Microbotics HardFrame Park Utility Example\n");
  94.     printf( "               Version 1.0.\n" );
  95.     printf( "        Copyright © 1988 Wizardess Designs\n\n");
  96.  
  97.     unit = 0; /* For default. */
  98.     if (( argc == 2 ) && ( argv[1][0] == '?' )) {
  99.         printf( "usage: park UNIT [Device Name]\n" );
  100.         exit ( 0 ); /* No unit number given. */
  101.         }
  102.  
  103.     if ( argc < 2 ) {
  104.         unit = PromptedNumber("Enter unit to park [%ld]: ", unit);
  105.     }
  106.     else {
  107.         result = stcd_i( argv[1], &unit );
  108.     }
  109.  
  110.     if (unpark = (unit > 999 )) unit -= 1000;
  111.  
  112.     if ( argc > 2 )
  113.         DeviceName = argv[2];
  114.     else
  115.         DeviceName = DefaultName;
  116.     
  117.     /* Find the name in the device list if it is there. */
  118.     mbhf = (struct Library *)
  119.         FindName(&SysBase->DeviceList, DeviceName);
  120.     if (mbhf == 0) {
  121.         EndGame(20, "%s not found\n", DeviceName);
  122.     }
  123.     printf("%s release %ld.%ld\n", DeviceName,
  124.         mbhf->lib_Version, mbhf->lib_Revision);
  125.  
  126.     /* finish IORP initialization */
  127.     IORP.mp_SigTask = (struct Task *) FindTask(NULL);
  128.     NewList(&IORP.mp_MsgList);
  129.  
  130.     board = unit/100;
  131.     scsiLUN = (unit%100)/10;
  132.     scsiID = unit%10;
  133.  
  134.     result = OpenDevice(DeviceName, unit, (struct IORequest *) &IOR, 0);
  135.     if ( result ) {
  136.         EndGame( 20, "%s will not Open. Likely %d is an invalid unit.",
  137.                  DeviceName, unit );
  138.         }
  139.  
  140.     if (unpark) printf( "Unp" );
  141.     else printf( "P");
  142.     printf( "arking board %d, ID %d, LUN %d.\n", board,
  143.          scsiID, scsiLUN );
  144.     SC.scsi_Data = NULL;
  145.     SC.scsi_Length = 0;
  146.     SC.scsi_Command = SCCmd;
  147.     SC.scsi_CmdLength = 6;
  148.     SC.scsi_Flags = 0;
  149.     SCCmd[0] = 0x1b;    /* Park */
  150.     SCCmd[1] = scsiLUN<<5;
  151.     SCCmd[2] = 0;
  152.     SCCmd[3] = 0;
  153.     SCCmd[5] = 0;
  154.     if (unpark)
  155.         SCCmd[4] = 1;  /* Set to 1 to unpark... */
  156.     else
  157.         SCCmd[4] = 0;  /* Set to 0 to park... */
  158.     IOR.io_Command = HD_SCSICMD;
  159.     IOR.io_Length = sizeof(SC);
  160.     IOR.io_Data = (APTR) &SC;
  161.     if ((DoIO((struct IORequest *) &IOR) == 0) && (SC.scsi_Actual > 18)) {
  162.             D(dprintf("IOE: %ld, Actual: %ld, %08lx\n",
  163.               IOR.io_Error, SC.scsi_Actual));
  164.     }
  165.     CloseDevice((struct IORequest *) &IOR);
  166.     IOR.io_Device = 0;
  167.     EndGame(0);
  168. return(0); /* Stop compiler squawk. */
  169. }
  170.