home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / df2_32.zip / DF.C next >
C/C++ Source or Header  |  1994-08-19  |  3KB  |  129 lines

  1. /* * Last edited: Aug 19 14:51 1994 (david) */
  2.  
  3. #define INCL_DOSFILEMGR
  4. #include <os2.h>
  5. #include <stdio.h>
  6.  
  7. void process_drive(int drive) ;
  8. void read_drive_info(ULONG *drivemap) ;
  9. void display_header() ;
  10.  
  11. typedef struct _tagFSInfo1 {
  12.     ULONG fs_ID ;
  13.     ULONG fs_SN ;
  14.     ULONG fs_UN ;
  15.     ULONG fs_UA ;
  16.     ULONG fs_BN ;
  17. } FSInfo1 ;
  18.  
  19. typedef struct _tagFSInfo2 {
  20.     ULONG fs_SERIAL ;
  21.     BYTE  fs_cbVol ;
  22.     CHAR  fs_Vol[30] ;
  23. } FSInfo2 ;
  24.  
  25. typedef struct _tagDriveBuffer {
  26.     FSQBUFFER2 qbuffer ;
  27.     UCHAR  padding[100] ;
  28. } DriveBuffer ;
  29.  
  30. void display_drive_info(DriveBuffer *pdata, FSInfo1 *pfsinfo1, FSInfo2 *pfsinfo2 ) ;
  31.  
  32. ULONG totalsize ;
  33. ULONG totalfree ;
  34.  
  35. void
  36. read_drive_info(ULONG *drivemap) {
  37.     ULONG drive ;
  38.     APIRET rc ;
  39.  
  40.     rc = DosQueryCurrentDisk(&drive, drivemap) ;
  41.     (*drivemap) >>= 2 ;
  42. }
  43.  
  44. void
  45. display_header()
  46. {
  47.     printf("Disk             Free      Used     Total  Capacity   Cluster    File System\n");
  48. }
  49.  
  50. main()
  51. {
  52.     ULONG drivemap ;
  53.     int index ;
  54.  
  55.     totalsize = 0;
  56.     totalfree = 0;
  57.  
  58.     read_drive_info(&drivemap);
  59.     display_header() ;
  60.  
  61.     for (index = 2 ; index < 25; index ++) {
  62.     if (drivemap & 0x01)
  63.         process_drive(index);
  64.     drivemap >>= 1 ;
  65.     }
  66.  
  67.     printf("\nTotal:       %8luk %8luk %8luk  %4u%%\n",
  68.        totalfree/1024, (totalsize-totalfree)/1024, totalsize/1024,
  69.        (totalsize-totalfree)/(totalsize/100)) ;
  70. }
  71.  
  72. void
  73. display_drive_info(DriveBuffer *pdata,
  74.                    FSInfo1 *pfsinfo1,
  75.            FSInfo2 *pfsinfo2 )
  76. {
  77.  
  78.     ULONG sector = (pfsinfo1->fs_BN * pfsinfo1->fs_SN) ;
  79.     ULONG size = pfsinfo1->fs_UN * sector ;
  80.     ULONG free = pfsinfo1->fs_UA * sector ;
  81.     char meg ;
  82.     ULONG limit = 99*1024*1024 ;
  83.     ULONG fact ;
  84.     
  85.     
  86.     if (pfsinfo1->fs_UA == -1)
  87.         free = 0 ;
  88.  
  89. #define key(x) meg = (x) > limit?'M':'k'; fact = (meg == 'M')?1024*1024:1024
  90.  
  91.     key(free);
  92.     
  93.     printf(pdata->qbuffer.szName);
  94.     printf("%-11s",pfsinfo2->fs_Vol) ;
  95.     printf("%8lu%c",free/fact,meg) ;
  96.  
  97.     key(size-free) ;
  98.     printf(" %8lu%c",(size-free)/fact,meg);
  99.  
  100.     key(size) ;
  101.     printf(" %8lu%c",size/fact,meg);
  102.     printf("  %4lu%%",(size-free)/(size/100));
  103.     printf("   %5lu bytes.",pfsinfo1->fs_BN * pfsinfo1->fs_SN) ;
  104.     printf("     %s\n", pdata->qbuffer.szFSDName+pdata->qbuffer.cbName);
  105.  
  106.     totalsize += size ;
  107.     totalfree += free ;
  108. }
  109.  
  110. void process_drive(int drive)
  111. {
  112.     APIRET rc ;
  113.     DriveBuffer data ;
  114.     char szName[3] ;
  115.     
  116.     static FSInfo1 fsinfo1;
  117.     FSInfo2 fsinfo2;
  118.  
  119.     ULONG  ndatabuffer ;
  120.  
  121.     sprintf(szName,"%c:",'A'+drive);
  122.  
  123.     ndatabuffer = sizeof(DriveBuffer) ;
  124.     rc = DosQueryFSAttach(szName,0,1,&(data.qbuffer),&ndatabuffer ) ;
  125.     rc = DosQueryFSInfo(drive+1,FSIL_ALLOC,&fsinfo1,sizeof(FSInfo1)) ;
  126.     rc = DosQueryFSInfo(drive+1,FSIL_VOLSER,&fsinfo2,sizeof(FSInfo2)) ;
  127.     display_drive_info(&data,&fsinfo1,&fsinfo2);
  128. }
  129.