home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
c_spec
/
execute
/
du.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-20
|
2KB
|
94 lines
#include <stdio.h>
#include "/include/mydos.h"
/* DU: Get Disk Usage. Returns the number of used
* and avaliable bytes on the indicated
* drive. Usage is: du [<drive> ... <drive>] where <drive> is
* one of a, b, etc.
*
* Copyright (C) 1986, Allen I. Holub. All rights reserved.
*/
#define E(x) fprintf(stderr, "%s\n", x )
main( argc, argv )
char **argv;
{
REGS regs;
register int verbose = 0 ;
ctlc();
if( argc > 1 && argv[1][0] == '-' )
{
if( !( verbose = (argv[1][1] == 'v')) )
usage();
argv++;
--argc;
}
if( argc == 1 )
{
gregs( ®s );
regs.h.ah = 0x19 ; /* Get current disk id */
mydos( ®s );
printf("%c: ", regs.h.al + 'A' );
dodrive( 0, verbose );
}
else
{
for( ++argv ; --argc > 0 ; ++argv )
{
printf("%c: ", toupper( **argv ) );
dodrive( (toupper(**argv) - 'A') + 1, verbose );
}
}
}
/*----------------------------------------------------------------------*/
usage()
{
E("du: Copyright (c) 1986, Allen I. Holub, All rights reserved.");
E("\nUsage: du [-v] [disk id]\n" );
E("Prints the disk capacity, amount of space used, and amount");
E("of space available. The optional disk id can be a: b: ,etc., or ");
E("a b c, etc. If no drive is specified, the current drive is used");
E("The percentage of space available is also given.");
E("The -v flag gives a more verbose output.\n");
exit(1);
}
/*----------------------------------------------------------------------*/
dodrive( id, verbose )
{
unsigned spc, bps, ac, tc;
double total, avail ;
if( !diskinfo( id, &spc, &bps, &ac, &tc ) )
printf("Can't access drive\n");
else
{
total = (double)( (double)spc * (double)bps * (double)tc );
avail = (double)( (double)spc * (double)bps * (double)ac );
printf("%7.1f K bytes total, ", total/1024.0 );
printf("%7.1f K used, ", (total-avail)/1024.0 );
printf("%7.1f K (%05.2f%% of disk) available\n",
avail/1024.0, 100.0 * (avail/total) );
if( verbose )
{
printf(" Sectors per Cluster . %-9d", spc );
printf(" Bytes per Sector .... %-9d\n", bps );
printf(" Available Clusters .. %-9d", ac );
printf(" Total Clusters ...... %-9d\n\n", tc );
}
}
}