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

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