home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
pcmag
/
v14n12
/
chkdrv.exe
/
CHKDRIVE.C
next >
Wrap
C/C++ Source or Header
|
1995-03-09
|
3KB
|
98 lines
#include <stdio.h>
#include <direct.h>
#include <ctype.h>
#include <dos.h>
void ScanDirectory (char *);
void ProcessFile (struct _find_t *);
unsigned long bytecount = 0;
unsigned long filecount = 0;
unsigned long dircount = 0;
unsigned long overhang[6] = { 0, 0, 0, 0, 0, 0 };
unsigned long fatspace[6] = { 0, 0, 0, 0, 0, 0 };
int main (int argc, char *argv[])
{
int drive, i;
char directory[80];
float efficiency;
// Save the current drive and directory
drive = _getdrive ();
_getcwd (directory, sizeof (directory));
// Change drives if a drive letter was entered on the command line
if (argc > 1) {
if (_chdrive (toupper ((int) argv[1][0]) - 0x40) == -1) {
printf ("Invalid drive specification\n");
return;
}
}
// Collect statistics for the drive
ScanDirectory ("\\");
// Display the results
printf ("Scanned %lu files in %lu directories on drive %c:\n",
filecount, dircount, _getdrive () + 0x40);
printf ("Cumulative length of all files is %lu bytes\n\n", bytecount);
printf ("Cluster Size Overhang (Bytes) FAT Space (Bytes)"\
" Efficiency\n");
printf ("============ ================ ================="\
" ==========\n");
for (i=0; i<6; i++) {
efficiency = ((float) (bytecount) / (float) (bytecount +
overhang[i] + fatspace[i])) * 100.0;
printf (" %2.0dK %13.0lu %17.0lu %6.1f%%\n",
2 << i, overhang[i], fatspace[i], efficiency);
}
// Restore the drive and directory, and then exit
_chdrive (drive);
_chdir (directory);
return 0;
}
void ScanDirectory (char *directory)
{
struct _find_t fileinfo;
dircount++;
_chdir (directory);
if (_dos_findfirst ("*.*", _A_HIDDEN | _A_SYSTEM | _A_RDONLY,
&fileinfo) == 0) {
ProcessFile (&fileinfo);
while (_dos_findnext (&fileinfo) == 0)
ProcessFile (&fileinfo);
}
if (_dos_findfirst ("*.*", _A_SUBDIR, &fileinfo) == 0) {
if ((fileinfo.attrib & _A_SUBDIR) && (fileinfo.name[0] != 0x2E))
ScanDirectory (fileinfo.name);
while (_dos_findnext (&fileinfo) == 0) {
if ((fileinfo.attrib & _A_SUBDIR) && (fileinfo.name[0] != 0x2E))
ScanDirectory (fileinfo.name);
}
}
_chdir ("..");
}
void ProcessFile (struct _find_t *fileinfo)
{
int i;
filecount++;
bytecount += fileinfo->size;
for (i=0; i<6; i++) {
overhang[i] += (fileinfo->size % ((unsigned long) 2048 << i));
fatspace[i] += (((fileinfo->size >> (11 + i)) + 1) << 1);
}
}