home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / phylck.exe / LOCK.C next >
C/C++ Source or Header  |  1995-06-06  |  4KB  |  141 lines

  1.  
  2. /****************************************************************************
  3. ** DISCLAIMER
  4. **
  5. ** Novell, Inc. makes no representations or warranties with respect to
  6. ** any NetWare software, and specifically disclaims any express or
  7. ** implied warranties of merchantability, title, or fitness for a
  8. ** particular purpose.
  9. **
  10. ** Distribution of any NetWare software is forbidden without the
  11. ** express written consent of Novell, Inc.  Further, Novell reserves
  12. ** the right to discontinue distribution of any NetWare software.
  13. **
  14. ** Novell is not responsible for lost profits or revenue, loss of use
  15. ** of the software, loss of data, costs of re-creating lost data, the
  16. ** cost of any substitute equipment or program, or claims by any party
  17. ** other than you.  Novell strongly recommends a backup be made before
  18. ** any software is installed.   Technical support for this software
  19. ** may be provided at the discretion of Novell.
  20. ****************************************************************************
  21. **
  22. ** File:  LOCK.C
  23. **
  24. ** Desc:  This program will take a file name on the command line in the
  25. **                format of VOLUME:PATH and the number of locks to create and
  26. **                create that number of physical record locks on the file.
  27. **                The program holds the locks until a key is pressed.
  28. **
  29. **
  30. ** Netware API Calls:   NWCallsInit()
  31. **                                            NWScanPhysicalLocksByFile()
  32. **
  33. ** Programmers:
  34. ** Ini  Who                 Firm
  35. ** ------------------------------------------------------------------
  36. ** CRG  Calvin R. Gaisford  Novell Developer Support.
  37. **
  38. ** History:
  39. **
  40. ** ------------------------------------------------------------------
  41. ** 06-06-95 CRG  First code. Taken from sample by Karl Bunnell.
  42. */
  43.  
  44. /****************************************************************************
  45. **   Include headers, macros, function prototypes, etc.
  46. */
  47.  
  48.  
  49.      /*------------------------------------------------------------------
  50.      **   ANSI
  51.      */
  52.      #include <conio.h>
  53.      #include <stdlib.h>
  54.      #include <stdio.h>
  55.      #include <string.h>
  56.      #include <fcntl.h>
  57.      #include <io.h>
  58.  
  59.      /*------------------------------------------------------------------
  60.      **   NetWare
  61.      */
  62.      #include <nwcalls.h>
  63.  
  64.      /*------------------------------------------------------------------
  65.      **   Defines
  66.      */
  67.      #define NWDOS
  68.  
  69.      /*------------------------------------------------------------------
  70.      **   Prototypes
  71.      */
  72.      /* Entire program contained in main() */
  73.  
  74.  
  75. /****************************************************************************
  76. **   Program Start
  77. */
  78. int main(int argc, char *argv[])
  79. {
  80.     FILE                    *fileStream;
  81.     int                   handle;
  82.     NWFILE_HANDLE fileHandle;
  83.     int                        lockCount;
  84.     NWCCODE            ccode;
  85.     NWOFFSET           recordStartOffset;
  86.     NWLEN                    recordLength;
  87.     NWFLAGS            lockFlag;
  88.     NWTICKS                timeOutLimit;
  89.  
  90.     if(argc < 3)
  91.     {
  92.         printf("Usage: Lock <filename (VOL:PATH)> <number of locks>\n");
  93.         return 1;
  94.     }
  95.  
  96.     ccode=NWCallsInit(NULL,NULL);
  97.     if(ccode)
  98.     {
  99.         printf("Unable to intialize Shell/Requester tables.  Status = %04X\n");
  100.         return 1;
  101.     }
  102.  
  103.     lockCount = atoi(argv[2]);
  104.     if ((handle = open(argv[1], O_CREAT | O_TEXT)) == -1)
  105.     {
  106.         printf("\nCannot open file");
  107.         return 1;
  108.     }
  109.     fileHandle = (unsigned int)handle;
  110.     fileStream = fdopen(fileHandle, "w");
  111.     if (fileStream == NULL)
  112.     {
  113.         printf("\nfdopen failed\n");
  114.         return 1;
  115.     }
  116.     recordLength = 1;
  117.     lockFlag = 0x01;
  118.     timeOutLimit = 0;
  119.     recordStartOffset = 0;
  120.     for(recordStartOffset = 0; recordStartOffset < lockCount; recordStartOffset++)
  121.     {
  122.         ccode = NWLogPhysicalRecord(
  123.                             /* File Handle */ fileHandle,
  124.                             /* rec. offset */ recordStartOffset,
  125.                             /* rec. Length */ recordLength,
  126.                             /* lock flags  */ lockFlag,
  127.                             /* num ticks   */ timeOutLimit);
  128.         if(ccode)
  129.         {
  130.             printf("\nNWLogPhysicalRecord Returned: %X\n", ccode);
  131.             break;
  132.         }
  133.     }
  134.     printf("%d locks set on file\n", recordStartOffset);
  135.     printf("\nPress any key to end and unlock records\n");
  136.     getch();
  137.  
  138.     fclose(fileStream);
  139.     return 0;
  140. }
  141.