home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / dirutl / tools.arc / DF.C < prev    next >
Text File  |  1987-09-23  |  3KB  |  115 lines

  1. #include <stdio.h>              /* Standard I/O definitions */
  2. #include <ctype.h>              /* Character type macros */
  3. #include <dos.h>                /* Msdos definitions */
  4. #include <errno.h>              /* error codes */
  5. #include <string.h>
  6.  
  7. static char ID[]="## df.c 1.0 K.van Houten 230987 ##";
  8. union REGS r, o;
  9. char *getvol();
  10.  
  11. main (argc, argv)
  12. int     argc;
  13. char   *argv[];
  14. {
  15.     int i=3;
  16.  
  17.     printf("\
  18.        ------- b y t e s ------   - c l u s t e r s -\n\
  19. drive   total     used     free   total   used   free  usage\n");
  20.  
  21.     if (argc > 1) {
  22.         while (--argc > 0) {
  23.             ++argv;
  24.             if ((argv[0][1] == ':')&&(driveinfo(tolower(**argv) - 'a' + 1) != 0))
  25.                 exit(0);
  26.         }
  27.     }
  28.  
  29.     while (driveinfo(i) == 0)
  30.         i++;
  31. }
  32.  
  33. /* get info of drive i ( 1=A, 2=B, etc...) */
  34. driveinfo(i)
  35. int i;
  36. {
  37.     int tmp;
  38.     union REGS r;
  39.     unsigned long total, free;
  40.     float clsize;
  41.  
  42.     r.h.ah = 0x36;   /* get free space */
  43.     r.h.dl = i;
  44.     tmp = intdos(&r,&r);
  45.     if (r.x.ax == 0xffff)
  46.         return(1);
  47.     clsize =(float)((double)(r.x.ax * r.x.cx) / (double)1024);
  48.     total  = r.x.dx;
  49.     free   = r.x.bx;
  50.     printf("  %c:  ",i+64);
  51.     /*
  52.     printf(" %-10s",getvol(i));
  53.     */
  54.     printf("%5ld K  ",(long)(total * clsize));
  55.     printf("%5ld K  ",(long)((total - free) * clsize));
  56.     printf("%5ld K   ",(long)(free * clsize));
  57.  
  58.     printf("%5ld  ",total);
  59.     printf("%5ld  ",(total-free));
  60.     printf("%5ld   ",free);
  61.  
  62.     printf("%3d%%",(int)(100 * (float)((double)(total - free) / (double)total)));
  63.  
  64.     printf("\n");
  65.     return(0);
  66. }
  67.  
  68. char *
  69. getvol(d)
  70. int d;                          /* drive number */
  71. {
  72. #define A_VOLUME        0x08    /* Volume label */
  73.  
  74. struct date {
  75. unsigned    d_sec:      5;      /* Time, 2 second intervals */
  76. unsigned    d_min:      6;      /* Time, minutes */
  77. unsigned    d_hour:     5;      /* Time, hours */
  78. unsigned    d_day:      5;      /* Date, day of month */
  79. unsigned    d_month:    4;      /* Date, month of year */
  80. unsigned    d_year:     7;      /* Date, year since 1980 */
  81. };
  82. struct find {
  83.     char    fnd_dosinfo[21];    /* Reserved for dos */
  84.     char    fnd_attr;           /* File attribute */
  85.     struct date fnd_date;       /* Date structure */
  86.     long    fnd_size;           /* File size */
  87.     char    fnd_name[13];       /* File name less path */
  88. };
  89.     struct find f;              /* Used to return data from msdos */
  90.     union REGS r;               /* Contains register values for intcall() */
  91.     char file[20];
  92.     char *t;
  93.  
  94.  
  95.     r.h.ah = 0x1a;              /* SET DISK TRANSFER ADDRESS FUNCTION */
  96.     r.x.dx = (int) & f;
  97.     intdos (&r, &r);
  98.  
  99.     sprintf("%c:\\*.*",d+64);
  100.     r.h.ah = 0x4e;              /* FINDFIRST function */
  101.     r.x.cx = A_VOLUME;
  102.     r.x.dx = (int) file;
  103.     intdos (&r, &r);      /* Find first */
  104.     if (r.x.cflag) {
  105.         return(NULL);
  106.     }
  107.     t = (char *)malloc(13);
  108.     if (t == NULL) {
  109.         perror("volname");
  110.         exit(2);
  111.     }
  112.     strcpy(t,f.fnd_name);
  113.     return(t);
  114. }
  115.