home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / DISKSTAT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  2.4 KB  |  116 lines

  1. /*
  2.  * diskstat.c
  3.  * contains: diskstatus()
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "gfuncts.h"
  10.  
  11. /*
  12.  *  int
  13.  * diskstatus(drive,option)
  14.  *
  15.  * ARGUMENT
  16.  *  (int)    drive    -    0=A:, 1=B:, max = 1
  17.  *  (int)    option    -    0 = read only, 1=attempt re-write sector 1
  18.  *
  19.  * DESCRIPTION
  20.  *  This function determines the status of a diskette drive.  It works only
  21.  *  for drives A: and B:.  The operation is dependent upon the value used
  22.  *  for option.
  23.  *  If opt = 0, 
  24.  *    This function tries to verify track 0, side 0 sector 1.  The result
  25.  *    of this will be a status code which is used to derive the return.
  26.  *  If the second argument is a 1 then this sector is read and rewritten.
  27.  *    If it cannot be rewritten, then the write protect status may be
  28.  *    returned.
  29.  *
  30.  * RETURNS
  31.  *
  32.  *  0 = Drive OK
  33.  *  1 = Drive Door Open (timeout, drive failed to respond)
  34.  *  2 = Write Protected
  35.  *  3 = Bad Address Mark (i.e. wrong format)
  36.  *  4 = Sector Not Found
  37.  *  5 = Other Problem - data error or seek error.
  38.  *  6 = Argument error (drive > 1)
  39.  *  7 = Cannot allocate memory.
  40.  *
  41.  *  NOTE:  Function returns 0 if no problems, else > 0.
  42.  *
  43.  * AUTHOR
  44.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  45.  *
  46.  * MODIFICATIONS
  47.  *  "" Wed 09-Nov-1988 10:01:28
  48.  *    Modified (!opt) case to reset disk system (SAR #114)
  49.  */
  50. int GF_CONV diskstatus(drv,opt)
  51. int drv;
  52. int opt;
  53. {
  54.     unsigned stat;
  55.     struct GFREGS in,out;
  56.     int cyf;
  57.     char *buf;
  58.     
  59.  
  60.     if(drv>1) 
  61.         return 32;
  62.     if(!opt) {
  63.         in.ax=0x0;            /* Reset disk system */
  64.         in.dx=drv;
  65.         cyf=sysint(0x13,&in,&out);
  66.         in.ax=0x0401;            /* Attempt verify    */
  67.         in.dx=drv;
  68.         in.cx=1;
  69.         cyf=sysint(0x13,&in,&out);
  70.         if((cyf&1)==0) 
  71.             return 0;
  72.         else 
  73.             goto pt1;
  74.     } else {
  75.         buf=malloc(2049);
  76.         if(buf==NULL)
  77.             return(7);
  78.         in.bx=ofsspu(buf);
  79.         in.es=segspu(buf);
  80.         in.ax=0x0201;
  81.         in.dx=drv;
  82.         in.cx=1;
  83.         cyf=sysint(0x13,&in,&out);
  84.         if((cyf&1)==1) {
  85.             free(buf);
  86.             goto pt1;
  87.         }
  88.         in.bx=ofsspu(buf);
  89.         in.es=segspu(buf);
  90.         in.ax=0x0301;
  91.         in.dx=drv;
  92.         in.cx=1;
  93.         cyf=sysint(0x13,&in,&out);
  94.         free(buf);
  95.         if((cyf&1)==0) 
  96.             return 0;
  97. pt1:
  98.         stat=(unsigned)((out.ax&0xFF00)>>8); 
  99.         if(stat==0)
  100.             return 0;
  101.         if(stat==0x0003) 
  102.             return 2;
  103.         if(stat&0x0080) 
  104.             return 1;
  105.         if(stat&0x0004) 
  106.             return 4;
  107.         if(stat&0x0040) 
  108.             return 5;
  109.         if(stat&0x0010) 
  110.             return 5;
  111.         if(stat&0x0002) 
  112.             return 3;
  113.     }
  114.     return 6;
  115. }
  116.