home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / df2-3211.zip / df.c next >
C/C++ Source or Header  |  1994-09-06  |  3KB  |  139 lines

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