home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / pcmag / v14n12 / chkdrv.exe / CHKDRIVE.C next >
C/C++ Source or Header  |  1995-03-09  |  3KB  |  98 lines

  1. #include <stdio.h>
  2. #include <direct.h>
  3. #include <ctype.h>
  4. #include <dos.h>
  5.  
  6. void ScanDirectory (char *);
  7. void ProcessFile (struct _find_t *);
  8.  
  9. unsigned long bytecount = 0;
  10. unsigned long filecount = 0;
  11. unsigned long dircount = 0;
  12.  
  13. unsigned long overhang[6] = { 0, 0, 0, 0, 0, 0 };
  14. unsigned long fatspace[6] = { 0, 0, 0, 0, 0, 0 };
  15.  
  16. int main (int argc, char *argv[])
  17. {
  18.     int drive, i;
  19.     char directory[80];
  20.     float efficiency;
  21.  
  22.     // Save the current drive and directory
  23.     drive = _getdrive ();
  24.     _getcwd (directory, sizeof (directory));
  25.  
  26.     // Change drives if a drive letter was entered on the command line
  27.     if (argc > 1) {
  28.         if (_chdrive (toupper ((int) argv[1][0]) - 0x40) == -1) {
  29.             printf ("Invalid drive specification\n");
  30.             return;
  31.         }
  32.     }
  33.  
  34.     // Collect statistics for the drive
  35.     ScanDirectory ("\\");
  36.  
  37.     // Display the results
  38.     printf ("Scanned %lu files in %lu directories on drive %c:\n",
  39.         filecount, dircount, _getdrive () + 0x40);
  40.     printf ("Cumulative length of all files is %lu bytes\n\n", bytecount);
  41.  
  42.     printf ("Cluster Size    Overhang (Bytes)    FAT Space (Bytes)"\
  43.         "    Efficiency\n");
  44.     printf ("============    ================    ================="\
  45.         "    ==========\n");
  46.     
  47.     for (i=0; i<6; i++) {
  48.         efficiency = ((float) (bytecount) / (float) (bytecount +
  49.             overhang[i] + fatspace[i])) * 100.0;
  50.         printf ("    %2.0dK         %13.0lu    %17.0lu        %6.1f%%\n",
  51.             2 << i, overhang[i], fatspace[i], efficiency);
  52.     }
  53.  
  54.     // Restore the drive and directory, and then exit
  55.     _chdrive (drive);
  56.     _chdir (directory);
  57.     return 0;
  58. }
  59.  
  60. void ScanDirectory (char *directory)
  61. {
  62.     struct _find_t fileinfo;
  63.  
  64.     dircount++;
  65.     _chdir (directory);
  66.  
  67.     if (_dos_findfirst ("*.*", _A_HIDDEN | _A_SYSTEM | _A_RDONLY,
  68.         &fileinfo) == 0) {
  69.         ProcessFile (&fileinfo);
  70.         while (_dos_findnext (&fileinfo) == 0)
  71.             ProcessFile (&fileinfo);
  72.     }
  73.  
  74.     if (_dos_findfirst ("*.*", _A_SUBDIR, &fileinfo) == 0) {
  75.         if ((fileinfo.attrib & _A_SUBDIR) && (fileinfo.name[0] != 0x2E))
  76.             ScanDirectory (fileinfo.name);
  77.  
  78.         while (_dos_findnext (&fileinfo) == 0) {
  79.             if ((fileinfo.attrib & _A_SUBDIR) && (fileinfo.name[0] != 0x2E))
  80.                 ScanDirectory (fileinfo.name);
  81.         }
  82.     }
  83.     _chdir ("..");
  84. }
  85.  
  86. void ProcessFile (struct _find_t *fileinfo)
  87. {
  88.     int i;
  89.  
  90.     filecount++;
  91.     bytecount += fileinfo->size;
  92.  
  93.     for (i=0; i<6; i++) {
  94.         overhang[i] += (fileinfo->size % ((unsigned long) 2048 << i));
  95.         fatspace[i] += (((fileinfo->size >> (11 + i)) + 1) << 1);
  96.     }
  97. }
  98.