home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / aspio02.zip / rewind.c < prev    next >
C/C++ Source or Header  |  1999-08-17  |  3KB  |  106 lines

  1. /*
  2.  * $Source: r:/source/aspi/RCS/rewind.c,v $
  3.  * $Revision: 1.4 $
  4.  * $Date: 1999/08/18 00:12:41 $
  5.  * $Locker:  $
  6.  *
  7.  *    ASPI Interface Library, REWIND
  8.  *
  9.  * $Log: rewind.c,v $
  10.  * Revision 1.4  1999/08/18 00:12:41  vitus
  11.  * - updated location of defines.h (moved)
  12.  * - changed function comments to new layout
  13.  *
  14.  * Revision 1.3  1997/09/22 02:24:49  vitus
  15.  * commented
  16.  *
  17.  * Revision 1.2  1997/09/18 02:01:21  vitus
  18.  * changed to new header file names
  19.  *
  20.  * Revision 1.1  1997/09/12 00:01:28  vitus
  21.  * Initial revision
  22.  * ----------------------------------------
  23.  * Sample code to demonstrate use of ASPI Interface.
  24.  */
  25. static char const id[]="$Id: rewind.c,v 1.4 1999/08/18 00:12:41 vitus Exp $";
  26.  
  27. #include <string.h>
  28. #include <stdlib.h>
  29.  
  30. #define INCL_DOS
  31. #define INCL_ERRORS
  32. #include <os2.h>
  33.  
  34. #include "../lib/defines.h"
  35. #include "scsi.h"
  36. #include "srb.h"
  37. #include "aspio.h"
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /*# ----------------------------------------------------------------------
  45.  * AspiRewind(ha,target,lun)
  46.  *
  47.  * PARAMETER
  48.  *    ha,target,lun    addresses device
  49.  *
  50.  * RETURNS    
  51.  *    APIRET
  52.  *
  53.  * GLOBAL
  54.  *    hsLastSense    updated
  55.  *
  56.  * DESPRIPTION
  57.  *    Rewinds medium in sequential devices.
  58.  *
  59.  * REMARKS
  60.  */
  61. PUBLIC APIRET _System
  62. AspiRewind(UCHAR ha,UCHAR target,UCHAR lun)
  63. {
  64.     APIRET        rc;
  65.     size_t const    srbsize = sizeof(ASPI_SRB_EXECUTE_IO)
  66.                 + 6 + sizeof(SCSI_REQSENSE_DATA);
  67.     PASPI_SRB_EXECUTE_IO srb = malloc(srbsize);
  68.  
  69.     if( srb == NULL )
  70.     return ERROR_NOT_ENOUGH_MEMORY;
  71.     memset(srb, 0, srbsize);
  72.  
  73.     srb->SRBHdr.CommandCode = ASPI_CMD_EXECUTE_IO;
  74.     srb->SRBHdr.AdapterIndex = ha;
  75.     srb->SRBHdr.ASPIReqFlags = ASPI_REQFLAG_DIR_NO_DATA_XFER | ASPI_REQFLAG_POST_ENABLE;
  76.  
  77.     srb->DeviceTargetID = target;
  78.     srb->DeviceTargetLUN = lun;
  79.     srb->DataXferLen = 0;
  80.     srb->pDataBuffer = NULL;
  81.     srb->SenseDataLen = sizeof(SCSI_REQSENSE_DATA);
  82.  
  83.     srb->CDBLen = 6;
  84.     srb->CDB[0] = SCSI_REWIND;
  85.     srb->CDB[1] = (lun << 5);
  86.     srb->CDB[2] = 0;
  87.     srb->CDB[3] = 0;
  88.     srb->CDB[4] = 0;
  89.     srb->CDB[5] = 0;
  90.  
  91.     rc = AspiSendSRB(&srb->SRBHdr, srbsize);
  92.  
  93.     if( rc == 0 )
  94.     {
  95.     if( srb->TargetStatus != ASPI_TSTATUS_NO_ERROR )
  96.         rc = 0xF2000000 | srb->TargetStatus;
  97.     else if( srb->HostStatus != ASPI_HSTATUS_NO_ERROR )
  98.         rc = 0xF1000000 | srb->HostStatus;
  99.     else if( srb->SRBHdr.ASPIStatus != ASPI_STATUS_NO_ERROR )
  100.         rc = 0xF0000000 | srb->SRBHdr.ASPIStatus;
  101.     memcpy(&strLastSense, &srb->CDB[6], sizeof(SCSI_REQSENSE_DATA));
  102.     }
  103.     free(srb);
  104.     return rc;
  105. }
  106.