home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / c_spec / sources / diskinfo.c < prev    next >
C/C++ Source or Header  |  1986-02-20  |  1KB  |  65 lines

  1. #include  <stdio.h>
  2. #include  "mydos.h"
  3.  
  4. /*
  5.  *    Copyright (C) 1986, Allen I. Holub. All rights reserved.
  6.  */
  7.  
  8. extern void    mydos( REGS *);        /* In mydos.asm    */
  9.  
  10.  
  11.  
  12. diskinfo( disk, sec_per_cluster, bytes_per_sec, avail_clusters, tot_clusters)
  13.  
  14. int     disk;            /* 0=current, 1=a:, 2=b: etc.        */
  15. unsigned *sec_per_cluster,    /* # sectors in a cluster        */
  16.      *bytes_per_sec,    /* # bytes in a sector            */
  17.      *avail_clusters,    /* # cluster available for writting    */
  18.      *tot_clusters;        /* Total # clusters on the disk        */
  19. {
  20.     /*    Return 0 on failure (bad disk code, etc.) 1 on success
  21.      *    (and fill the last 4 parameters with the correct info).
  22.      */
  23.  
  24.     REGS    reg;
  25.  
  26.     gregs( ® );
  27.  
  28.     reg.h.ah = 0x36;    /* Get Disk Free Space    */
  29.     reg.h.dl = disk;
  30.  
  31.     mydos( ® );
  32.  
  33.     if( reg.x.ax == -1 )
  34.         return 0;
  35.     else
  36.     {
  37.         *sec_per_cluster = reg.x.ax ;
  38.         *avail_clusters  = reg.x.bx ;
  39.         *bytes_per_sec   = reg.x.cx ;
  40.         *tot_clusters    = reg.x.dx ;
  41.     }
  42.  
  43.     return 1;
  44. }
  45.  
  46. /*----------------------------------------------------------------------*/
  47. #ifdef DEBUG
  48.  
  49. main()
  50. {
  51.     unsigned    spc, ac, bps, tc;
  52.  
  53.     if( !diskinfo( 0, &spc, &bps, &ac, &tc ) )
  54.         printf("*** ERROR ***\n");
  55.     else
  56.     {
  57.         printf("%6d sec/cluster\n",        spc    );
  58.         printf("%6d available clusters\n",    ac    );
  59.         printf("%6d bytes per sector\n",    bps    );
  60.         printf("%6d total clusters\n",        tc    );
  61.     }
  62. }
  63.  
  64. #endif
  65.