home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / volnum.exe / VOLUME.C < prev    next >
Text File  |  1994-11-23  |  9KB  |  234 lines

  1. /****************************************************************************
  2. **      DISCLAIMER
  3. **
  4. **   Novell, Inc. makes no representations or warranties with respect to
  5. **   any NetWare software, and specifically disclaims any express or
  6. **   implied warranties of merchantability, title, or fitness for a
  7. **   particular purpose.
  8. **
  9. **   Distribution of any NetWare software is forbidden without the
  10. **   express written consent of Novell, Inc.  Further, Novell reserves
  11. **   the right to discontinue distribution of any NetWare software.
  12. **
  13. **   Novell is not responsible for lost profits or revenue, loss of use
  14. **   of the software, loss of data, costs of re-creating lost data, the
  15. **   cost of any substitute equipment or program, or claims by any party
  16. **   other than you.  Novell strongly recommends a backup be made before
  17. **   any software is installed.   Technical support for this software
  18. **   may be provided at the discretion of Novell.
  19. ****************************************************************************
  20. **
  21. **   File:   Volume.c
  22. **
  23. **   Desc: This program will find the volume information that is usually
  24. **         reported in chkvol.  Or if the path to a directory is added on the
  25. **         command line you can get back that directories information instead.
  26. **         You need to pass in the server name volume name and/or the name of
  27. **         a directory in the volume.
  28. **
  29. **
  30. */
  31.  
  32. /***************************************************************************
  33. **   Include headers, macros, function prototypes, etc.
  34. */
  35.  
  36.   /*------------------------------------------------------------------
  37.   **   ANSI
  38.   */
  39.   #define DEBUG   /* rem out this line for debug info to print */
  40.  
  41.   #include <stdio.h>         /* printf()          */
  42.   #include <stdlib.h>        /* exit()            */
  43.   #include <string.h>        /* strcpy() strupr() */
  44.   #include <conio.h>         /* clrscr()          */
  45.   #include <ctype.h>         /* toupper           */
  46.  
  47.   /*------------------------------------------------------------------
  48.   **   NetWare
  49.   */
  50.   #include <nwcalls.h>
  51.  
  52. /****************************************************************************
  53. **   Program Start  Complete program in main
  54. */
  55.  
  56. void main (int argc, char *argv[])
  57. {
  58.   int               ccode;
  59.   NWVOL_NUM         volNumber;
  60.   char              volName[48];
  61.   char              serverName[48];
  62.   char              directory[128];
  63.   DIR_SPACE_INFO    spaceInfo;
  64.   NWCONN_HANDLE     connID;
  65.   NWDIR_HANDLE      dirHandle;
  66.   NWACCESS_RIGHTS   rightsMask;
  67.   int               blocksize;
  68.   unsigned long     totalsize,
  69.                     availsize,
  70.                     purgesize,
  71.                     notyetpurgesize;
  72.  
  73.  
  74.   ccode=NWCallsInit(NULL,NULL);
  75.   if (ccode)
  76.      exit(1);
  77.  
  78.   strcpy(serverName,strupr(argv[1]));
  79.  
  80.   if (argc>=2){
  81.      ccode=NWGetConnectionHandle(serverName,NULL,&connID,NULL);
  82.      if (ccode){
  83.         printf("NWGetConnectionHandle failed with error code %x\n",ccode);
  84.         exit (ccode);
  85.      }
  86.   }
  87.   switch(argc){
  88.      case 3:
  89.         strcpy(volName,strupr(argv[2]));
  90.         /* get the volume number  */
  91.         ccode = NWGetVolumeNumber(connID, volName, &volNumber);
  92.         if (ccode){
  93.            printf("NWGetVolumeNumber fatal error= %X\n",ccode);
  94.            exit(1);
  95.         }
  96.  
  97.         dirHandle=0; /* volume info will be returned */
  98.         break;
  99.      case 4:
  100.         strcpy(volName,strupr(argv[2]));
  101.         strcpy(directory,strupr(argv[3]));
  102.         volNumber=0; /* directory info will be returned */
  103.  
  104.         /*----------------------------------------------------------------
  105.         **  The following code will allocate a temporary directory handle 
  106.         **  for use in the NWGetDirSpaceInfo() function
  107.         */
  108.  
  109.         ccode = NWAllocTemporaryDirectoryHandle(  connID,
  110.                                                   NULL,
  111.                                                   directory,
  112.                                                   &dirHandle,
  113.                                                   &rightsMask);
  114.         if (ccode){
  115.            printf("NWAllocTemproaryDirectoryHandle failed error code= %X\n",
  116.                     ccode);
  117.            exit(1);
  118.         }
  119.         volNumber = 0; /* because only dir info is being gotten. */
  120.         break;
  121.  
  122.      default:
  123.         clrscr();
  124.         printf("USAGE: volume <server name> <volume name> <directory>\n");
  125.         printf("\n       Directory information EXAMPLE:\n");
  126.         printf("            volume server1 sys sys:users\\jsmith\n");
  127.         printf("\n       Volume information EXAMPLE:\n");
  128.         printf("            volume server1 sys ");
  129.         exit(1);
  130.   }
  131.  
  132.   /*----------------------------------------------------------------------
  133.   ** The code dealing with NWGetDirSpaceInfo is dealing with block
  134.   ** information in 32bit mode on any NetWare Server. 
  135.   **     If dealing only in 16bit mode you can use the call 
  136.   ** NWGetVolumeInfoWithNumber() but it will not work properly on any 
  137.   ** drive that is greater than 1 gig this call was originally written to 
  138.   ** work only on 256 meg volumes (2.x)  and therefore shouldn't be used on
  139.   ** 3.x and 4.x any volume greater than 256 meg.
  140.   **
  141.   ** NOTE: if you take the sectors per Block say 8 and multiple by 512 (the
  142.   ** size of a sector you will get the block size on the server.
  143.   ** The best thing to do is 8/2=4k block size then you can multiply
  144.   ** 4XtotalBlocks to come up with the total bytes available etc.
  145.   **
  146.   ** NOTE: If the dirHandle is passed in as 0 then volume info is returned
  147.   **       but if the volNumber is 0 then directory info is returned.
  148.   */
  149.  
  150.  
  151.   ccode = NWGetDirSpaceInfo(connID,dirHandle,volNumber,&spaceInfo);
  152.  
  153.   blocksize=spaceInfo.sectorsPerBlock/2;
  154.  
  155.   totalsize=spaceInfo.totalBlocks * blocksize;
  156.   availsize=spaceInfo.availableBlocks * blocksize;
  157.   purgesize =spaceInfo.purgeableBlocks * blocksize;
  158.   notyetpurgesize = spaceInfo.notYetPurgeableBlocks * blocksize;
  159.  
  160.  
  161.  
  162.   if (ccode){
  163.      printf("NWGetDirSpaceInfo fatal error= %X\n",ccode);
  164.      exit(1);
  165.   }
  166.   /*------------------------------------------------------------------------
  167.   **  If purgeableBlocks is 0 then dirHandle is not 0 and directory info
  168.   **  will be returned if purgeable Blocks is non 0 then volume inforamtion
  169.   **  will be returned.
  170.   */
  171.   if (spaceInfo.purgeableBlocks==0){
  172.  
  173.      clrscr();
  174.      printf("             DIRECTORY INFORMATION\n\n");
  175. #ifndef DEBUG
  176.      printf("Directory Name %s\n",directory);
  177.      printf("totalBlocks %ld\n",spaceInfo.totalBlocks);
  178.      printf("availableBlocks %ld\n",spaceInfo.availableBlocks);
  179.  
  180.      printf("purgeable Blocks = %ld\nnot yet purgeable blocks = %ld\n",
  181.               spaceInfo.purgeableBlocks,
  182.               spaceInfo.notYetPurgeableBlocks);
  183.  
  184.      printf("total dir entries = %ld\navailable dir entries = %ld\n",
  185.               spaceInfo.totalDirEntries,
  186.               spaceInfo.availableDirEntries);
  187.  
  188.      printf("sectors per block = %d\n",spaceInfo.sectorsPerBlock);
  189. #endif
  190.  
  191.      printf("Total dir space:                    %ld\t K Bytes\n",totalsize);
  192.  
  193.      printf("Space used by files:                %ld\t K Bytes\n",totalsize-
  194.               (availsize+purgesize-notyetpurgesize));
  195.  
  196.      printf("Space remaining on dir:             %ld\t K Bytes\n",availsize+
  197.               purgesize-notyetpurgesize);
  198.  
  199.   }
  200.   else{
  201.      clrscr();
  202.      printf("             VOLUME INFORMATION\n\n");
  203.      printf("VolName = %s\n", volName);
  204.  
  205. #ifndef DEBUG
  206.      printf("totalBlocks %ld\n",spaceInfo.totalBlocks);
  207.      printf("availableBlocks %ld\n",spaceInfo.availableBlocks);
  208.  
  209.      printf("purgeable Blocks = %ld\nnot yet purgeable blocks = %ld\n",
  210.               spaceInfo.purgeableBlocks,
  211.               spaceInfo.notYetPurgeableBlocks);
  212.  
  213.      printf("total dir entries = %ld\navailable dir entries = %ld\n",
  214.               spaceInfo.totalDirEntries,
  215.               spaceInfo.availableDirEntries);
  216.  
  217.      printf("sectors per block = %d\n",spaceInfo.sectorsPerBlock);
  218. #endif
  219.      printf("Total volume space:                 %ld\t K Bytes\n",totalsize);
  220.      printf("Space used by files:                %ld\t K Bytes\n",totalsize-
  221.               (availsize+purgesize-notyetpurgesize));
  222.  
  223.      printf("Space in use by deleted files:      %ld\t K Bytes\n", purgesize+
  224.               notyetpurgesize);
  225.  
  226.      printf("Space available from deleted files: %ld\t K Bytes\n", purgesize-
  227.               notyetpurgesize);
  228.  
  229.      printf("Space remaining on volume:          %ld\t K Bytes\n",availsize+
  230.               purgesize-notyetpurgesize);
  231.  
  232.   }
  233. }
  234.