home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / xvol1.exe / XVOL1.C next >
Text File  |  1994-12-15  |  6KB  |  203 lines

  1. /****************************************************************************
  2. **    File: XVOL1.C
  3. **
  4. **    Description:
  5. **
  6. **        Sample code that shows how to determine the number of bytes free on a
  7. **        NetWare volume.
  8. **
  9. **    Disclaimer:
  10. **
  11. **        Novell, Inc. makes no representations or warranties with respect to
  12. **        any NetWare software, and specifically disclaims any express or
  13. **        implied warranties of merchantability, title, or fitness for a
  14. **        particular purpose.  
  15. **
  16. **        Distribution of any NetWare software is forbidden without the
  17. **        express written consent of Novell, Inc.  Further, Novell reserves
  18. **        the right to discontinue distribution of any NetWare software.
  19. **
  20. **        Novell is not responsible for lost profits or revenue, loss of use
  21. **        of the software, loss of data, costs of re-creating lost data, the
  22. **        cost of any substitute equipment or program, or claims by any party
  23. **        other than you.  Novell strongly recommends a backup be made before
  24. **        any software is installed.   Developer support for this software
  25. **        may be provided at the discretion of Novell.
  26. **
  27. **    QMK386 options used:
  28. **
  29. **        None
  30. **
  31. **    Programmers:
  32. **    
  33. **        Ini    Name                        Firm
  34. **        -----------------------------------------------------------------------
  35. **        ABJ    Adam B. Jerome            Novell Developer Support
  36. **
  37. **    History:
  38. **        
  39. **        When        Who    What
  40. **        -----------------------------------------------------------------------
  41. **        12-06-94    ABJ    First code.
  42. */
  43.  
  44. /****************************************************************************
  45. **    Compiler setup.
  46. */
  47.     /*------------------------------------------------------------------------
  48.     **    ANSI
  49.     */
  50.     #include <STDLIB.H>
  51.     #include <STDIO.H>
  52.     #include <ERRNO.H>
  53.  
  54.     /*------------------------------------------------------------------------
  55.     **    NetWare
  56.     */
  57.     #include <NWDIR.H>
  58.     #include <NITERROR.H>
  59.  
  60. /****************************************************************************
  61. **    Program start.
  62. */
  63. void main(int argC, char *argV[])
  64.     {
  65.     VOLUME_INFO volInfo;
  66.     int     rVal;
  67.     LONG    freeBlocks;
  68.     LONG    bytesPerSector;
  69.     LONG    bytesPerBlock;
  70.     LONG    freeBytes;
  71.     int    volumeNumber;
  72.     char *volumeName    = "SYS";
  73.     char  pathName[255+1];
  74.     LONG  availableSpace;
  75.  
  76.     /*------------------------------------------------------------------------
  77.     **    Parse command line.
  78.     */
  79.     if(argC > 2)
  80.         {
  81.         printf("Usage: LOAD %s <volumeName>\n", argV[0]);
  82.         printf("\n");
  83.         printf("     <volumeName>     Optional volume name.  (default = SYS)\n");
  84.         goto END_ERR;
  85.         }
  86.  
  87.     if(argC > 1)
  88.         volumeName=argV[1];
  89.  
  90.     /*------------------------------------------------------------------------
  91.     **    Convert volume name to volume number.
  92.     */
  93.      rVal=GetVolumeNumber(
  94.         /* I-    volumeName        */    volumeName,
  95.         /*    -O    volumeNumber    */    &volumeNumber
  96.         );
  97.     switch(rVal)
  98.         {
  99.         case ESUCCESS:
  100.             break;
  101.  
  102.         case ERR_INVALID_VOLUME:
  103.             printf("ERROR:  GetVolumeNumber() reports: Volume does not exist.\n");
  104.             goto END_ERR;
  105.  
  106.         default:
  107.             printf("ERROR:  GetVolumeNumber() reports error code: %d\n", rVal);
  108.             goto END_ERR;
  109.         }
  110.     
  111.     /*------------------------------------------------------------------------
  112.     **    Get volume stats.
  113.     */
  114.     rVal=GetVolumeStatistics(
  115.         /*    I-    fileServerID                    */    0,
  116.         /*    I-    volumeNumber                    */    volumeNumber,
  117.         /*    I-    structSize                        */ sizeof(volInfo),
  118.         /*    -O    returnedVolumeStatistics    */    &volInfo
  119.         );
  120.     switch(rVal)
  121.         {
  122.         case ESUCCESS:
  123.             break;
  124.  
  125.         case ERR_INVALID_VOLUME:
  126.             printf("ERROR:  GetVolumeStatistics() reports: Invalid volume number.\n");
  127.             goto END_ERR;
  128.  
  129.         default:
  130.             printf("ERROR:  GetVolumeStatistics() reports error code: %d\n", rVal);
  131.             goto END_ERR;
  132.  
  133.         }
  134.  
  135.     /*------------------------------------------------------------------------
  136.     **    Calculate values.
  137.     **
  138.     **    Note: An unsigned long can store a number between 0 and 4294967295.
  139.     **            Therefore, if the volume is greater than 4gb, some of the values
  140.     **            below may -wrap- and become invalid when multiplied to resolve
  141.     **            to a number of bytes.  In otherwords; the formula is correct, but
  142.     **            may be limited to a total volume size of 4gb or less.
  143.     */
  144.     freeBlocks         = volInfo.availableBlocks + volInfo.purgableBlocks;
  145.     bytesPerSector    = 512;    /* According to Rob Carlson - Novell CLIB team. */
  146.     bytesPerBlock    = bytesPerSector * volInfo.sectorsPerBlock;
  147.     freeBytes         = freeBlocks * bytesPerBlock;
  148.  
  149.     /*------------------------------------------------------------------------
  150.     **    Print report.
  151.     */
  152.     printf("Volume...........:  %s\n", volumeName);
  153.     printf("\n");
  154.     printf("Available Blocks.:  %10u\n", volInfo.availableBlocks);
  155.     printf("Purgable Blocks..:  %10u\n", volInfo.purgableBlocks);
  156.     printf("                    ----------\n");
  157.     printf("Free Blocks......:  %10u\n", freeBlocks);
  158.     printf("\n");
  159.     printf("\n");
  160.     printf("Bytes Per Sector.:  %10u  (Constant)\n", bytesPerSector);
  161.     printf("Sectors Per block:  %10hu\n", volInfo.sectorsPerBlock); 
  162.     printf("                    ----------\n");
  163.     printf("Bytes Per Block..:  %10u\n", bytesPerBlock);
  164.     printf("\n");
  165.     printf("\n");
  166.     printf("Free Blocks......:  %10u\n", freeBlocks);
  167.     printf("Bytes Per Block..:  %10u\n", bytesPerBlock);
  168.     printf("                    ----------\n");
  169.     printf("Free Bytes.......:  %10u\n", freeBytes);
  170.     printf("\n");
  171.     printf("\n");
  172.  
  173.     /*------------------------------------------------------------------------
  174.     **    Get this user's available disk space (I know, it's connection 0, which
  175.     **    has no user restrictions.  It's the formula that counts.)
  176.     **
  177.     **    GetAvailableUserDiskSpace() returns the same value as 'freeBlocks'
  178.     ** (detailed above) if there are no current user space restrictions.
  179.     */
  180.     sprintf(pathName, "%s:", volumeName);
  181.     rVal=GetAvailableUserDiskSpace(
  182.         /* I-    pathName            */    pathName,
  183.         /*    -O    availableSpace    */    &availableSpace
  184.         );
  185.     switch(rVal)
  186.         {
  187.         case ESUCCESS:
  188.             break;
  189.  
  190.         default:
  191.             printf("ERROR:  GetAvailableUserDiskSpace() reports error code: %d\n", rVal);
  192.             goto END_ERR;
  193.  
  194.         }
  195.     
  196.     printf("GetAvailableUserDiskSpace: %10u\n", availableSpace);    
  197.  
  198. END_ERR:
  199.  
  200.  
  201.     exit(0);
  202.     }
  203.