home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
DU_DF2.ZIP
/
DF.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-28
|
2KB
|
86 lines
/* df.c
* returns info on file system of specified drive
*/
#define INCL_DOS
#include <os2.h>
#include <stdlib.h>
#include <ctype.h>
main(int argc, char *argv[])
{
unsigned long map; /* map of all disk drives */
unsigned drive; /* drive number */
/* 0=default, 1=A, 2=B, etc. */
int i;
if ( argc > 1 ) {
for (i=1; i<argc; i++ ) {
if ( isalpha( *argv[i] ) ) drive = toupper( *argv[i] ) - 'A' + 1;
else drive = atoi( argv[i] );
print_info( drive );
}
}
else {
DosQCurDisk( &drive, &map );
map >>= 2;
i = 2;
while ( map ) {
drive = map - ( ( map >> 1 ) << 1);
if ( drive ) print_info( i+1 );
map >>= 1;
i++;
}
}
exit(0);
}
int print_info(int drive)
{
struct _FSALLOCATE buffer; /* defined in bsedos.h */
unsigned size; /* size of buffer */
unsigned rc; /* return code */
unsigned long bytes_free, bytes_total, cluster;
int a, b, c, d, p;
char aa[4], cc[4];
struct _FSINFO vol;
size = sizeof(struct _FSALLOCATE);
if (rc = DosQFSInfo(drive, 1, (unsigned char far *)&buffer, size)) {
printf("DosQFSInfo level 1 error=%u on drive %c:\n",
rc, 'A'+drive-1 );
return 1;
}
size = sizeof(struct _FSINFO);
if (rc = DosQFSInfo(drive, 2, (unsigned char far *)&vol, size)) {
printf("DosQFSInfo level 1 error=%u on drive %c:\n",
rc, 'A'+drive-1 );
return 1;
}
cluster = buffer.cbSector * buffer.cSectorUnit;
bytes_free = cluster * buffer.cUnitAvail ;
bytes_free /= 1024;
bytes_total = cluster * buffer.cUnit ;
bytes_total /= 1024;
p = (bytes_total - bytes_free) * 100 / bytes_total;
a = bytes_free / 1000 ;
b = bytes_free - (a * 1000);
c = bytes_total / 1000;
d = bytes_total - (c * 1000);
if ( a ) itoa( a, aa, 10 );
else strcpy( aa, " " );
if ( c ) itoa( c, cc, 10 );
else strcpy( cc, " " );
printf("%c:%3s%c%03uK free,%4s%c%03uK total, %d%% used,",
'A'+drive-1, aa, a?',':' ', b, cc, c?',':' ', d, p );
printf(" cluster = %ld, volume = %s\n",
cluster, vol.vol.szVolLabel );
return 0;
}