home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / driver / scsi / aspiscsi / scsilook.c < prev    next >
C/C++ Source or Header  |  1993-09-15  |  3KB  |  131 lines

  1. // ----------------------------------------------------------------------
  2. // Module SCSILOOK.C
  3. // Test program to illustrate ASPI routines.
  4. // Performs inquiry of attached SCSI devices, reporting device type,
  5. // model, and manufacturer.
  6. //
  7. // Copyright (C) 1993, Brian Sawert.
  8. // All rights reserved.
  9. //
  10. // ----------------------------------------------------------------------
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <mem.h>
  16.  
  17. #include "aspi.h"                        // ASPI definitions and constants
  18. #include "scsi.h"                        // SCSI definitions and constants
  19.  
  20.  
  21. // -------------------- defines and macros --------------------
  22.  
  23. #define asize(x)    sizeof((x)) / sizeof(*(x))
  24.  
  25.  
  26. // -------------------- global variables --------------------
  27.  
  28. char copyright[] = "SCSILOOK 1.0 SCSI inventory utility.\n"
  29.     "Copyright (C) 1993, Brian Sawert.\n";
  30.  
  31. char aspi_id[MAX_IDSTR + 1];
  32. char *devtype[] =
  33.     {                                    // SCSI device type descriptions
  34.     "Disk Drive",
  35.     "Tape Drive",
  36.     "Printer",
  37.     "Processor",
  38.     "WORM Drive",
  39.     "CD-ROM Drive",
  40.     "Scanner",
  41.     "Optical Drive",
  42.     "Autochanger",
  43.     "Communications Device"
  44.     };
  45.  
  46. group_0_t inq_cdb;                        // CDB for Device Inquiry command
  47. inquire_block_t    inq_data;                // buffer for inquiry data
  48.  
  49.  
  50. // -------------------- start of code --------------------
  51.  
  52. void print_dev_info(int id, inquire_block_t *ib)
  53.     {
  54.     int dtype;
  55.     char *dstr;
  56.  
  57.     dtype = (ib->devtype & 0x17);        // extract device type
  58.     dstr = (dtype < asize(devtype)) ? devtype[dtype] : "Unknown";
  59.  
  60.     printf("\nDevice ID:    %-d\n", id);
  61.     printf("Device Type:  %s\n", dstr);
  62.     printf("Vendor ID:    %.8s\n", ib->vendid);
  63.     printf("Product ID:   %.16s\n", ib->prodid);
  64.  
  65.     return;
  66.     }
  67.  
  68.  
  69. main(int argc, char *argv[])
  70.     {
  71.     int nhosts;
  72.     int devid;
  73.     int devtype;
  74.     int stat, ht_stat;
  75.  
  76.  
  77.     printf("%s\n", copyright);            // print startup message
  78.  
  79.     if (aspi_open() == 0)
  80.         {                                // ASPI access failed
  81.         printf("Error accessing ASPI driver - check installation.\n");
  82.         exit(1);
  83.         }
  84.  
  85.     if ((nhosts = aspi_host_inq(aspi_id, NULL)) <= 0)
  86.         {                                // no host adapters found
  87.         printf("Error - no host adapters found.\n");
  88.         exit(1);
  89.         }
  90.     else
  91.         {                                // print SCSI host information
  92.         printf("%d host adapter(s) installed.\n", nhosts); 
  93.         printf("ASPI manager ID:  %s.\n", aspi_id);
  94.         }
  95.  
  96.     for (devid = 0; devid <= MAX_TARG_ID; devid++)
  97.         {                                // query each device on SCSI bus
  98.         if ((devtype = aspi_devtype(devid)) != -1)
  99.             {                            // found a valid device
  100.             memset(&inq_cdb, 0, sizeof(group_0_t));    // clear CDB
  101.             inq_cdb.opcode = SC_INQUIRY;    // set inquire command code
  102.             inq_cdb.params[2] = sizeof(inquire_block_t);
  103.  
  104.             stat = aspi_io(&inq_cdb, &inq_data, sizeof(inquire_block_t),
  105.                 RF_DREAD, devid, &ht_stat);    // call ASPI I/O function
  106.  
  107.             if (stat == -1)
  108.                 {                        // ASPI request failed
  109.                 printf("ASPI request failure on SCSI ID %d.\n", devid);
  110.                 }
  111.             else if (stat != REQ_NOERR)
  112.                 {                        // ASPI returned error
  113.                 printf("ASPI error on SCSI ID %n.\n", devid);
  114.                 printf("ASPI status:    %x\n", stat);
  115.                 printf("Host status:    %x\n", (ht_stat >> 8));
  116.                 printf("Target status:  %x\n", (ht_stat & 0xf));
  117.                 }
  118.             else
  119.                 {                        // ASPI request succeeded
  120.                 print_dev_info(devid, &inq_data);    // print device info
  121.                 }
  122.             }
  123.         }
  124.  
  125.     exit(0);
  126.     }
  127.  
  128.  
  129.  
  130.  
  131.