Novell Home

CLIB's GetVolumeStatistics api

From Developer Community

This demonstrates how to call GetVolumeStatistics on a local server. Note that isRemovable will ALWAYS be true if you are running this on a 3.x or higher NetWare machine.

Sample Code

#include <stdlib.h>    
#include <stdio.h>   
#include <stddef.h>
#include <nit/nwdir.h>
#include <string.h>
#include <errno.h>
#include <nwerrno.h>
#include <time.h>  


int main(void)   
{   
   int            rcode;   
   VOLUME_INFO    volInfo;   
   char           svn[10];   
   int            vn;  


   printf("volume number: ");   
   gets(svn);   
   vn = atoi(svn);   
   
   printf("Calling GetVolumeStatistics...\r\n");
   //GetVolumeInformation
   rcode = GetVolumeStatistics(0,
                               vn,
                               sizeof (volInfo),
                               &volInfo);   
   if (rcode)
   {
      if (rcode == ERR_INVALID_VOLUME)
      {
         printf("Error: Invalid Volume Number\r\n");
      }
      else
      {
         
         printf("GetVolumeStatistics failed with: \r\n");
         printf("rc = %d\r\n",rcode);   
         printf("errno = %d\r\n",errno);   
         printf("%s\r\n",strerror(errno));
         printf("NetWareErrno = %x\r\n", NetWareErrno);
      }
   }
   else
   {
      printf("GetVolumeStatistics Success!\r\n");
      printf("Volume Number Requested:          #%d\r\n", vn);
      printf("Volume Number Returned:           #%d\r\n", volInfo.volumeNumber);
      printf("Volume Name:                      %s\r\n", volInfo.volumeName);
      printf("Volume LogicalNumber:             %d\r\n", volInfo.logicalDriveNumber);
      printf("System Elapsed Time:              %d\r\n", volInfo.systemElapsedTime);
      printf("Volume Starting Block:            %d\r\n", volInfo.startingBlock);
      printf("Volume Sectors per Block:         %d\r\n",volInfo.sectorsPerBlock);
      printf("Volume Total Blocks:              %d\r\n",volInfo.totalBlocks);
      printf("AvailableBlocks:                  %d\r\n", volInfo.availableBlocks);
      printf("Volume Total Dir Slots:           %d\r\n",volInfo.totalDirectorySlots);
      printf("Volume Available Dir Slots:       %d\r\n", volInfo.availableDirectorySlots);
      printf("Volume Purgable Blocks:           %d\r\n", volInfo.purgableBlocks);
      printf("Volume Not Yet Purgable Blocks:   %d\r\n",volInfo.notYetPurgableBlocks);
      printf("Volume IsHashing:                 %s\r\n", volInfo.isHashing ? "TRUE" : "FALSE");
      printf("Volume IsMounted:                 %s\r\n", volInfo.isMounted ? "TRUE" : "FALSE");
      //isRemovable is hard coded to return True from the NCP. 
      //so it really is not useful.
      printf("Volume IsRemovable:               %s\r\n",volInfo.isRemovable ? "TRUE (Always TRUE)" : 
             "NEVER FALSE, May just as well not have this case");
      
      // tricks from the NDK documentation
      //The following equations explain how to calculate available disk space in bytes:

      //Total usable blocks = availableBlocks + purgableBlocks . 
      printf("Total Usable Blocks:              %d\r\n", volInfo.availableBlocks + volInfo.purgableBlocks);
      //Block size in bytes = sectorsPerBlock * 512. 
      printf("Block size in Bytes:              %d\r\n", volInfo.sectorsPerBlock * 512);
      //TOTAL AVAILABLE DISK SPACE in bytes = total usable blocks * block size in bytes. 
      printf("Total Available Disk Space:       %u\r\n", (volInfo.availableBlocks + volInfo.purgableBlocks) 
                                                         * volInfo.sectorsPerBlock * 512);

   }   
}

--Benjamin Fjeldsted

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.