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

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