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

  1. /*
  2.  * $Source: r:/source/aspi/RCS/mount.c,v $
  3.  * $Revision: 1.4 $
  4.  * $Date: 1999/08/18 00:14:02 $
  5.  * $Locker:  $
  6.  *
  7.  *    ASPI Interface Library, MOUNT
  8.  *
  9.  * $Log: mount.c,v $
  10.  * Revision 1.4  1999/08/18 00:14:02  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:20  vitus
  15.  * documented
  16.  *
  17.  * Revision 1.2  1997/09/18 02:00:10  vitus
  18.  * changed to new header file names
  19.  *
  20.  * Revision 1.1  1997/09/12 00:19:09  vitus
  21.  * Initial revision
  22.  * ----------------------------------------
  23.  * Sample code to demonstrate use of ASPI Interface.
  24.  */
  25. static char const id[]="$Id: mount.c,v 1.4 1999/08/18 00:14:02 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.  * AspiMount(ha,target,lun,mount)
  46.  *
  47.  * PARAMETER
  48.  *    ha,target,lun    addresses device
  49.  *    mount        0: unmount
  50.  *            1: mount
  51.  *            2: unmount and eject (disks)
  52.  *            3: mount and retention (tapes)
  53.  *
  54.  * RETURNS
  55.  *    APIRET
  56.  *
  57.  * GLOBAL
  58.  *    hsLastSense    updated
  59.  *
  60.  * DESPRIPTION
  61.  *    Issues START STOP/LOAD UNLOAD command.  Usable for removable media in
  62.  *    direct or sequential access devices.
  63.  *
  64.  * REMARKS
  65.  *    Don't send this command to scanner devices: they will start to scan.
  66.  *    Don't send this command to printer devices: they will stop to print.
  67.  */
  68. PUBLIC APIRET _System
  69. AspiMount(UCHAR ha,UCHAR target,UCHAR lun,UCHAR mount)
  70. {
  71.     APIRET        rc;
  72.     size_t const    srbsize = sizeof(ASPI_SRB_EXECUTE_IO)
  73.                 + 6 + sizeof(SCSI_REQSENSE_DATA);
  74.     PASPI_SRB_EXECUTE_IO srb = malloc(srbsize);
  75.  
  76.     if( srb == NULL )
  77.     return ERROR_NOT_ENOUGH_MEMORY;
  78.     memset(srb, 0, srbsize);
  79.  
  80.     srb->SRBHdr.CommandCode = ASPI_CMD_EXECUTE_IO;
  81.     srb->SRBHdr.AdapterIndex = ha;
  82.     srb->SRBHdr.ASPIReqFlags = ASPI_REQFLAG_DIR_NO_DATA_XFER | ASPI_REQFLAG_POST_ENABLE;
  83.  
  84.     srb->DeviceTargetID = target;
  85.     srb->DeviceTargetLUN = lun;
  86.     srb->DataXferLen = 0;
  87.     srb->pDataBuffer = NULL;
  88.     srb->SenseDataLen = sizeof(SCSI_REQSENSE_DATA);
  89.  
  90.     srb->CDBLen = 6;
  91.     srb->CDB[0] = SCSI_LOAD_UNLOAD;
  92.     srb->CDB[1] = (lun << 5);
  93.     srb->CDB[2] = 0;
  94.     srb->CDB[3] = 0;
  95.     srb->CDB[4] = mount & 0x03;
  96.     srb->CDB[5] = 0;
  97.  
  98.     rc = AspiSendSRB(&srb->SRBHdr, srbsize);
  99.  
  100.     if( rc == 0 )
  101.     {
  102.     if( srb->TargetStatus != ASPI_TSTATUS_NO_ERROR )
  103.         rc = 0xF2000000 | srb->TargetStatus;
  104.     else if( srb->HostStatus != ASPI_HSTATUS_NO_ERROR )
  105.         rc = 0xF1000000 | srb->HostStatus;
  106.     else if( srb->SRBHdr.ASPIStatus != ASPI_STATUS_NO_ERROR )
  107.         rc = 0xF0000000 | srb->SRBHdr.ASPIStatus;
  108.     memcpy(&strLastSense, &srb->CDB[6], sizeof(SCSI_REQSENSE_DATA));
  109.     }
  110.     free(srb);
  111.     return rc;
  112. }
  113.