home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / open / hdparker.lzh / PARKHARD.C next >
C/C++ Source or Header  |  1987-09-15  |  4KB  |  158 lines

  1. /* PARKHARD.C
  2.  
  3.    program to park hard disk drives
  4.  
  5.    portions Copyright (c) Thomas P. Keller 1987
  6.    portions Copyright (c) Borland International 1987
  7.    All Rights Reserved.
  8. */
  9.  
  10. /**********************************************************************
  11.  
  12. This program reads the hard disk parameters from the drive parameter
  13. table by invoking bios interupt 0x13 function 0x8 and then parks the
  14. drive heads on the cylinder 1 past the last one used by DOS
  15.  
  16. **********************************************************************/
  17.  
  18.  
  19. #include <stdio.h>
  20. #include <dos.h>
  21.  
  22. void main()
  23.     {
  24.     union REGS outregs;
  25.  
  26.     unsigned int drive_no, max_drives,error_flag,error_code;
  27.  
  28.     void get_drive_parms(unsigned int drive_no, union REGS *regs);
  29.     void park_drive(unsigned int drive_no, union REGS *regs);
  30.     void print_drive_error(unsigned char error_code);    
  31.  
  32.     printf("\nHard Disk Park Program\n");
  33.     printf("Copyright (c) Thomas P. Keller & Borland International 1987\n");
  34.     printf("All Rights Reserved\n");
  35.     drive_no = 0;    /* drive c: */
  36.  
  37.     get_drive_parms( drive_no, &outregs);
  38.  
  39.     max_drives = outregs.h.dl;
  40.     error_flag = outregs.x.cflag;
  41.     error_code = outregs.h.ah;
  42.  
  43.     if (error_flag != 0)
  44.         print_drive_error(error_code);
  45.     else {
  46.  
  47.         if (max_drives == 0)
  48.             printf("\nNo hard disks installed\n\n");
  49.         else
  50.         {
  51.             printf("\nNumber of hard disks = %2hu\n\n",max_drives);
  52.             do {
  53.                 get_drive_parms( drive_no, &outregs);
  54.                  park_drive( drive_no, &outregs);
  55.                 drive_no = drive_no + 1;
  56.             } while (drive_no < max_drives);
  57.         }
  58.     }
  59.     return;
  60. }
  61. /* end of main */
  62.  
  63. /* functions */
  64.  
  65. void get_drive_parms(unsigned int drive_no, union REGS *regs)
  66. {
  67.     #define DISK    0x13
  68.  
  69.     regs->h.ah = 0x08;    /* get drive parameters */
  70.     regs->h.al = 0x00;
  71.     regs->h.dh = 0x00;
  72.     regs->h.dl = 0x80+drive_no;    /* drive number +0x80 */
  73.     regs->h.cl = 0x00;
  74.     regs->h.ch = 0x00;
  75.     regs->x.cflag = 0x00;
  76.  
  77.     int86(DISK, regs, regs);
  78.  
  79.     return;
  80. }
  81.  
  82. void park_drive(unsigned int drive_no, union REGS *regs)
  83. {
  84.  
  85.     unsigned char error_code;
  86.  
  87.     unsigned int error_flag,max_heads,max_sectors,max_cylinders,max_tracks;
  88.  
  89.     void print_drive_error(unsigned char error_code);    
  90.  
  91.     #define DISK    0x13
  92.  
  93.     max_tracks = regs->h.ch + ((regs->h.cl & 0xc0)<<2) + 1;
  94.  
  95.     printf ("Parking hard disk number %2u at cylinder number %4u\n",drive_no+1,max_tracks);
  96.  
  97.     regs->h.ah = 0x0c;    /* seek cylinder */
  98.     regs->h.al = 0x00;
  99.     regs->h.dh = 0x00;
  100.     regs->h.dl = 0x80+drive_no;    /* drive number +0x80 */
  101.     regs->h.ch = max_tracks & 0xff; /* low bits of track */
  102.     regs->h.cl = ((max_tracks & 0x300) >> 2) + 1; /* high bits of track + sector 1 */
  103.     regs->x.cflag = 0x00;
  104.  
  105.     int86(DISK, regs, regs);
  106.  
  107.     error_flag = regs->x.cflag;
  108.     error_code = regs->h.ah;
  109.  
  110.     if (error_flag != 0) {
  111.         print_drive_error(error_code);
  112.         printf("\n");
  113.         }
  114.     else
  115.         printf("Drive parked successfully\n\n");
  116.  
  117.     return;
  118. }
  119.  
  120. /* end of  */
  121.  
  122.  
  123. void print_drive_error(unsigned char error_code)
  124. {
  125.  
  126.     printf("\nBios Interrupt 19 Error Code Recieved\n");
  127.  
  128.     if ((error_code & 0x01) == 0x01)
  129.         printf("Bad Command\n");
  130.     if ((error_code & 0x02) == 0x02) 
  131.         printf("Address Mark Not Found\n");
  132.     if ((error_code & 0x03) == 0x03) 
  133.         printf("Write Attempted on Write-Protected Disk\n");
  134.     if ((error_code & 0x04) == 0x04)
  135.         printf("Sector Not Found\n");
  136.     if ((error_code & 0x06) == 0x06) 
  137.         printf("Diskette Removed\n");
  138.     if ((error_code & 0x08) == 0x08) 
  139.         printf("DMA Overrun\n");
  140.     if ((error_code & 0x09) == 0x09) 
  141.         printf("DMA Across 64k Boundary\n");
  142.     if ((error_code & 0x10) == 0x10) 
  143.         printf("Bad CRC\n");
  144.     if ((error_code & 0x20) == 0x20) 
  145.         printf("Controller Failure\n");
  146.     if ((error_code & 0x40) == 0x40)
  147.         printf("Seek Failed\n");
  148.     if ((error_code & 0x80) == 0x80) 
  149.         printf("Time Out\n");
  150.     if ((error_code & 0xFF) == 0xFF) 
  151.         printf("Unknown Error\n");
  152.  
  153.     return ;
  154.  
  155. }
  156.  
  157. /* end of program */
  158.