home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / dqdriver / old / ide-info.c < prev    next >
Text File  |  1995-02-08  |  16KB  |  264 lines

  1. #pragma module IDE_INFO "X-1"
  2.  
  3. /************************************************************************/
  4. /*                                    */
  5. /* Copyright ⌐ Digital Equipment Corporation, 1994 All Rights Reserved.    */
  6. /* Unpublished rights reserved under the copyright laws of the United    */
  7. /* States.                                */
  8. /*                                    */
  9. /* The software contained on this media is proprietary to and embodies    */
  10. /* the confidential technology of Digital Equipment Corporation.    */
  11. /* Possession, use, duplication or dissemination of the software and    */
  12. /* media is authorized only pursuant to a valid written license from    */
  13. /* Digital Equipment Corporation.                    */
  14. /*                                    */
  15. /* RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure by the    */
  16. /* U.S. Government is subject to restrictions as set forth in        */
  17. /* Subparagraph (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19,    */
  18. /* as applicable.                            */
  19. /*                                    */
  20. /************************************************************************/
  21.  
  22. /************************************************************************/
  23. /*                                    */
  24. /* Abstract:                                */
  25. /*    This program dumps the identify page information from an IDE    */
  26. /*    drive.  This information is obtained through the READRCT driver    */
  27. /*    function code.                            */
  28. /*                                    */
  29. /* Author:                                */
  30. /*    Benjamin J. Thomas III / November 1994                */
  31. /*                                    */
  32. /* Revision History:                            */
  33. /*                                    */
  34. /*    X-1        Benjamin J. Thomas III        November, 1994    */
  35. /*        Initial version.                    */
  36. /*                                    */
  37. /************************************************************************/
  38.  
  39. /************************************************************************/
  40. /*                                    */
  41. /*    $ CC IDE-INFO                            */
  42. /*    $ LINK IDE-INFO                            */
  43. /*                                    */
  44. /************************************************************************/
  45.  
  46. #include    descrip            /* Define string descriptors */
  47. #include    iodef            /* I/O function code */
  48. #include    lib$routines        /* Define LIB$ routines */
  49. #include    ssdef            /* Define SS$ status codes */
  50. #include    starlet            /* Get system service definitions */
  51. #include    stdio            /* Define standard I/O values */
  52. #include    stdlib            /* Get standard definitions */
  53. #include    string            /* String definitions */
  54. #include    stsdef            /* Status values */
  55.  
  56. /* Define the Identify Drive information buffer */
  57.  
  58. typedef unsigned short int WORD;        /* Define a WORD (16 bits) */
  59. typedef unsigned char BYTE;             /* Define a BYTE (8 bits) */
  60.  
  61. #define    MODEL_LENGTH 40
  62.  
  63. #pragma member_alignment save
  64. #pragma nomember_alignment
  65. typedef struct {
  66.     WORD    config;            /* 0 - Configuration information */
  67.     WORD    cyls;            /* 1 - Number of cylinders */
  68.     WORD    rsvd2;            /* 2 - Reserved word */
  69.     WORD    heads;            /* 3 - Number of heads */
  70.     WORD    ubytes_track;        /* 4 - Unformatted bytes/track */
  71.     WORD    ubytes_sector;        /* 5 - Unformatted bytes/sector */
  72.     WORD    sectors;        /* 6 - Number of sectors */
  73.     WORD    unique7[3];        /* 7-9 - Vendor unique */
  74.     char    serial_number[20];    /* 10-19 - ASCII serial number */
  75.     WORD    buffer_type;        /* 20 - Buffer type */
  76.     WORD    buffer_size_blocks;    /* 21 - Buffer size (in blocks) */
  77.     WORD    ecc_bytes;        /* 22 - Number of ECC bytes/sector */
  78.     char    firmware_revision[8];    /* 23-26- ASCII firmware revision */
  79.     char    model_number[MODEL_LENGTH];/* 27-46 - ASCII drive model */
  80.     BYTE    rw_multiple;        /* 47 - Number of sectors/interrupt */
  81.     BYTE    unique47;            /* 47 - Vendor unique */
  82.     WORD    dblword_io;        /* 48- Doubleword I/O flag */
  83.     WORD    capabilities;        /* 49 - Capabilities */
  84.     WORD    rsvd50;            /* 50 - Reserved */
  85.     WORD    pio_cycle;        /* 51 - Programmed I/O cycle times */
  86.     WORD    dma_cycle;        /* 52 - DMA I/O cycle times */
  87.     WORD    valid54_58;        /* 53 - Valid bit for next 4 fields */
  88.     WORD    curr_cyls;        /* 54 -     1) Current cylinder count */
  89.     WORD    curr_heads;        /* 55 -     2) Current head count */
  90.     WORD    curr_sectors;        /* 56 -     3) Current sector count */
  91.     unsigned int max_sectors;        /* 57-58 -  4) Maximum sector number */
  92.     WORD    multiple_sectors;    /* 59 - Current sectors/interrupt setting */
  93.     unsigned int lba_maxblock;        /* 60-61 - LBA mode maximum block number */
  94.     WORD    single_word_dma;    /* 62 - Single word DMA info */
  95.     WORD    multi_word_dma;        /* 63 - Multi word DMA info */
  96.     WORD    rsvd64[64];        /* 64-127 - Reserved */
  97.     WORD    unique128[32];        /* 128-159 - Vendor unique */
  98.     WORD    rsvd160[96];        /* 160-255 - Reserved */
  99.     } ID_PAGE;
  100.  
  101. ID_PAGE    buffer;                /* Data buffer */
  102.  
  103. #pragma member_alignment restore
  104.  
  105. /* Define what an IOSB looks like */
  106.  
  107. typedef struct {                /* Standard I/O status block */
  108.     short int   status;                /* Status word */
  109.     short int   byte_cnt;            /* Transferred byte count */
  110.     int     unused;                /* Unused */
  111.     } IOSB_T;
  112.  
  113. void copy(char *out, char *in,int nchar) {
  114.  
  115. /* This routine is used to copy a string with byte swapping        */
  116. /*                                    */
  117. /* Input:                                */
  118. /*    out    pointer to destination                    */
  119. /*    in    pointer to source                    */
  120. /*    nchar    number of characters to copy                */
  121. /*                                    */
  122. /* Output:                                */
  123. /*    none                                */
  124.  
  125. int    i;                /* Loop index */
  126.  
  127. /* Move all the characters two at a time and swap them */
  128.  
  129.     for (i=0; i<nchar; i+=2) {
  130.         out[i] = in[i+1];
  131.         out[i+1] = in[i];
  132.     }
  133.  
  134.     out[nchar] = 0;            /* Terminate the string */
  135. }
  136.  
  137. int main (int argc, char *argv[]) {
  138.  
  139. int    status;                /* Routine status */
  140. int    chan;                /* Device channel */
  141. int    efn;                /* Event flag */
  142. char    dev_name[31];            /* Device name string */
  143. char    string[128];            /* Buffer for ID strings */
  144. IOSB_T    iosb;                /* I/O status block for QIO call */
  145. int    debug_info[128];        /* Define debug information buffer */
  146. int    i;                /* Loop counter */
  147. int    tmo_time;            /* Timeout time */
  148.  
  149. struct dsc$descriptor_d            /* Define a string descriptor */
  150.         dev_dsc = {0, DSC$K_DTYPE_T, DSC$K_CLASS_S, 0};
  151.  
  152. /* Get device name */
  153.  
  154.     if (argc == 2) {            /* Is there one argument ? */
  155.         ++argv;                /* Move to second argument */
  156.         strcpy(dev_name,*argv);        /* Get the device name */
  157.     } else {
  158.         printf("\nUsage: ide-info <device-name>\n");
  159.         exit(SS$_INSFARG);        /* Exit */
  160.     }
  161. /* Assign a channel to the device */
  162.  
  163.     dev_dsc.dsc$w_length = strlen(dev_name);    /* Set string length */
  164.     dev_dsc.dsc$a_pointer= dev_name;    /* Point to the string */
  165.     status = sys$assign(&dev_dsc,&chan,0,0,0);    /* Assign the channel */
  166.     if (!$VMS_STATUS_SUCCESS(status)) {    /* Check for success */
  167.         printf("? Failed to assign channel, status is %X\n",status);
  168.         exit(status);            /* Exit with status */
  169.     }
  170.  
  171. /* Get an EFN to use */
  172.  
  173.     status = lib$get_ef(&efn);        /* Acquire an EFN */
  174.     if (!$VMS_STATUS_SUCCESS(status)) {    /* Check for success */
  175.         printf("? Failed to acquire EFN, status = %X\n",status);
  176.         exit(status);            /* Exit with status */
  177.     }
  178.  
  179. /* Ask for the ID page from the drive */
  180.  
  181.     status = sys$qiow(efn,chan,IO$_READRCT,&iosb,0,0,&buffer,512,0,0,0,0);
  182.     if (!$VMS_STATUS_SUCCESS(status)) {
  183.         printf("? QIO service call failed, status is %X\n",status);
  184.         exit(status);            /* Exit with failure status */
  185.     }
  186.     if (!$VMS_STATUS_SUCCESS(iosb.status)) {
  187.         printf("? QIO operation failed, IOSB status is %X\n",iosb.status);
  188.         exit(iosb.status);        /* Exit with status */
  189.     }
  190.  
  191. /* Print the information obtained from the page */
  192.  
  193.     printf("ID Page information for %s:\n\n",dev_name);
  194.     copy(string,buffer.model_number,MODEL_LENGTH);
  195.     printf("Drive Model: \"%s\"\n",string);
  196.     copy(string,buffer.serial_number,20);
  197.     printf("\tS/N: \"%s\"  ",string);
  198.     copy(string,buffer.firmware_revision,8);
  199.     printf("F/W rev: \"%s\"\n",string);
  200.     printf("Config: %x\n",buffer.config);
  201.     printf("Geometry: Cylinders: %d  ",buffer.cyls);
  202.     printf("Heads: %d  ",buffer.heads);
  203.     printf("Sectors: %d\n",buffer.sectors);
  204.     printf("Unformatted: bytes/track: %d  ",buffer.ubytes_track);
  205.     printf("bytes/sector: %d\n",buffer.ubytes_sector);
  206.     printf("Buffer type: %d  ",buffer.buffer_type);
  207.     printf("Buffer size (in blocks): %d\n",buffer.buffer_size_blocks);
  208.     printf("Number of ECC bytes/sector: %d\n",buffer.ecc_bytes);
  209.     printf("Number of sectors/interrupt: %d\n",buffer.rw_multiple);
  210.     printf("Vendor unique: %d\n",buffer.unique47);
  211.     printf("Doubleword I/O flag: %d\n",buffer.dblword_io);
  212.     printf("Capabilities: %x  (LBA - %d, DMA - %d)\n",buffer.capabilities,
  213.            ((buffer.capabilities&0x100)>>8),((buffer.capabilities&0x200)>>9));
  214.     printf("Reserved: %d\n",buffer.rsvd50);
  215.     printf("Cycle times: PIO %d  ",buffer.pio_cycle);
  216.     printf("DMA %d\n",buffer.dma_cycle);
  217.     printf("Valid bit for next 4 fields: %d\n",buffer.valid54_58);
  218.     printf("Current: Cylinders %d  ",buffer.curr_cyls);
  219.     printf("Heads %d  ",buffer.curr_heads);
  220.     printf("Sectors %d  ",buffer.curr_sectors);
  221.     printf("Maximum sector number %d\n",buffer.max_sectors);
  222.     printf("Current sectors/interrupt setting: %d valid: %d\n",buffer.multiple_sectors&0xFF,
  223.             ((buffer.multiple_sectors&0x100)>>8));
  224.     printf("LBA mode maximum block number: %d\n",buffer.lba_maxblock);
  225.     printf("Single word DMA info: %d\n",buffer.single_word_dma);
  226.     printf("Multi word DMA info: %d\n",buffer.multi_word_dma);
  227.  
  228. /* Ask for the debug information from the driver */
  229.  
  230.     printf("\n\nDebug Information:\n\n");
  231.     status = sys$qiow(efn,chan,IO$_RDSTATS,&iosb,0,0,&debug_info,
  232.                       sizeof(debug_info),0,0,0,0);
  233.     if (!$VMS_STATUS_SUCCESS(status)) {
  234.             printf("? QIO service call failed, status is %X\n",status);
  235.             exit(status);        /* Exit with failure status */
  236.     }
  237.     if (!$VMS_STATUS_SUCCESS(iosb.status)) {
  238.         if (iosb.status == SS$_NODATA) {
  239.             printf("\t%% DEBUG driver is not loaded\n");
  240.             exit(SS$_NORMAL);        /* Just exit at this point */
  241.         } else {
  242.             printf("? QIO operation failed, IOSB status is %X\n",iosb.status);
  243.             exit(iosb.status);        /* Exit with status */
  244.        }
  245.     }
  246.  
  247. /* Print out the debug information */
  248.  
  249.     printf("Total interrupts: %d",debug_info[0]);
  250.     printf("\tTotal unexpected interrupts: %d\n",debug_info[1]);
  251.     printf("Number of CRAMs - %d\n",debug_info[2]);
  252.     printf("Transfer buffer address - %x\n",debug_info[3]);
  253.     printf("Base SPTE address - %x",debug_info[4]);
  254.     printf("\tBase S0 address - %x\n",debug_info[5]);
  255.     tmo_time = debug_info[6]-2;
  256.     printf("Timeout time: %d seconds\n",tmo_time);
  257.     printf("\n\tSeconds\tCount\n");
  258.  
  259.         for (i=0; i<=tmo_time; i++) {
  260.             printf("\t%d\t%d\n",i,debug_info[7+i]);
  261.         }
  262.     printf("\t>%d\t%d\n",tmo_time,debug_info[7+tmo_time+1]);
  263. }