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

  1. /*
  2.  * $Source: r:/source/aspi/RCS/dispg.c,v $
  3.  * $Revision $
  4.  * $Date: 1999/08/18 00:17:37 $
  5.  * $Locker:  $
  6.  *
  7.  *    Display mode sense page <x>
  8.  *
  9.  * $Log: dispg.c,v $
  10.  * Revision 1.3  1999/08/18 00:17:37  vitus
  11.  * - updated location of defines.h (moved)
  12.  *
  13.  * Revision 1.2  1997/09/22 02:27:07  vitus
  14.  * uses AH*() routines from library
  15.  *
  16.  * Revision 1.1  1997/09/18 01:34:24  vitus
  17.  * Initial revision
  18.  * ----------------------------------------
  19.  * Sample code to demonstrate use of ASPI Interface.
  20.  */
  21. static char const id[]="$Id: dispg.c,v 1.3 1999/08/18 00:17:37 vitus Exp $";
  22.  
  23. #include <stdio.h>
  24.  
  25. #define INCL_DOS
  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. UCHAR    data[5000];
  36.  
  37.  
  38.  
  39.  
  40.  
  41. PRIVATE void
  42. DumpBuffer(PVOID const arg1,ULONG const len)
  43. {
  44.     ULONG i;
  45.     PUCHAR p = arg1;
  46.  
  47.     for( i = 0; i < len; ++i, ++p )
  48.     {
  49.     printf("%02X", *p);
  50.     if( ((i + 1) % 16) == 0 )
  51.         printf("\n");
  52.     else if( ((i + 1) % 8) == 0 )
  53.         printf("-");
  54.     else
  55.         printf(" ");
  56.     }
  57.     putchar('\n');
  58. }
  59.  
  60.  
  61.  
  62.  
  63. PUBLIC int
  64. main(int argc,char *argv[])
  65. {
  66.     APIRET    rc;
  67.     unsigned    ha = -1, target = -1, lun = -1;
  68.     unsigned    pgno = -1;
  69.     UCHAR    type;                /* see SCSI spec */
  70.  
  71.     if( argc == 5 )
  72.     {
  73.     sscanf(argv[1], " %u", &ha);
  74.     sscanf(argv[2], " %u", &target);
  75.     sscanf(argv[3], " %u", &lun);
  76.     sscanf(argv[4], " %u", &pgno);
  77.     }
  78.     if( ha > 7  ||  target > 7  ||  lun > 7  ||  pgno > 0x3F )
  79.     {
  80.     fprintf(stderr,
  81.         "Invalid parameter\n"
  82.         "usage: dispg <ha> <target> <lun> <pgno>\n");
  83.     return 1;
  84.     }
  85.  
  86.     printf("Parameter: %u %u %u\n", ha, target, lun);
  87.     rc = AspiOpen(0);
  88.     if( rc != 0 )
  89.     {
  90.     fprintf(stderr, "AspiOpen - rc %lu\n", rc);
  91.     return rc;
  92.     }
  93.  
  94.     do
  95.     {
  96.     rc = AspiGetType(ha, target, lun, &type);
  97.     if( rc != 0 )
  98.     {
  99.         fprintf(stderr, "AspiGetType - rc %lu (%#lx)\n", rc, rc);
  100.         break;
  101.     }
  102.  
  103.     printf("HA %u  Target %u  LUN %u\t\"%s\" (%s)\n",
  104.            ha, target, lun,
  105.            AHInquiryType(type), AHInquiryQual(type));
  106.  
  107.     rc = AspiModeSense(ha, target, lun, pgno, 0, data, 250);
  108.     if( rc != 0 )
  109.     {
  110.         fprintf(stderr, "AspiModeSense - rc %lu (%#lx)\n", rc, rc);
  111.         DumpBuffer(&strLastSense, sizeof(strLastSense));
  112.         AHSense(data, &strLastSense),    printf(data);
  113.         break;
  114.     }
  115.  
  116.     printf("Dumping mode sense buffer\n");
  117.     DumpBuffer(data, data[0]);
  118.     }
  119.     while( 0 );
  120.  
  121.     rc = AspiClose();
  122.     if( rc != 0 )
  123.     {
  124.     fprintf(stderr, "AspiClose - rc %lu (%#lx)\n", rc, rc);
  125.     return rc;
  126.     }
  127.  
  128.     return 0;
  129. }
  130.