home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / lockr.exe / LOGLOCK.C < prev    next >
Text File  |  1995-02-05  |  8KB  |  245 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:   loglock.c
  22. **
  23. **   Desc: Program that tests the logical record locks. 
  24. **
  25. **   Parameter descriptions:    > input
  26. **                              < output
  27. **
  28. **   API Calls:
  29. **         NWCallsInit
  30. **         NWGetConnectionHandle
  31. **         NWLogLogicalRecord
  32. **         NWLockLogicalRecord
  33. **         NWGetConnectionNumber
  34. **         NWScanLogicalLocksByConn
  35. **         NWClearLogicalRecord
  36. **        
  37. **   Programmers:
  38. **   Ini   Who         Firm
  39. **   ------------------------------------------------------------------
  40. **   ARM   A. Ray Maxwell     Novell Developer Support.
  41. **
  42. **   History:
  43. **       
  44. **   ------------------------------------------------------------------
  45. **   06-28-94   ARM   First code.
  46. */
  47.  
  48. /****************************************************************************
  49. ** Include Headers, Macros & function Prototypes.
  50. */
  51.    /*-------------------------------------------------------------------
  52.    ** Borland C.
  53.    */
  54.    #include <stdio.h>
  55.    #include <stdlib.h>
  56.    #include <string.h>
  57.    #include <conio.h>
  58.    #include <mem.h>
  59.  
  60.    #define RETURN '\r'
  61.  
  62.    /*-------------------------------------------------------------------
  63.    ** NetWare API's
  64.    */
  65.         #include <nwcalls.h>
  66.    /*-------------------------------------------------------------------
  67.    ** Defines
  68.    */
  69.    #define NWDOS
  70.  
  71. /****************************************************************************
  72. ** Program start.
  73. */
  74. void main(int argc, char *argv[ ])
  75. {
  76.    NWCONN_HANDLE        connHandle;
  77.    CONNECT_INFO         connInfo;
  78.    NWCCODE              ccode;
  79.    char                 server[50];
  80.    NWCONN_NUM           connNumber;
  81.    NWLAST_RECORD        lastRecord;
  82.    CONN_LOGICAL_LOCKS   logicalLocks;
  83.    CONN_LOGICAL_LOCK    logicalLock;
  84.  
  85.    setmem(&logicalLocks,sizeof(CONN_LOGICAL_LOCKS),'\0');
  86.    setmem(&logicalLock,sizeof(CONN_LOGICAL_LOCK),'\0');
  87.  
  88.    if(argc != 2) {
  89.       printf("Usage: LOGLOCK <servername> \n");
  90.       exit(1);
  91.    }
  92.  
  93.    strcpy(server,  strupr(argv[1]));
  94.  
  95.    ccode = NWCallsInit(NULL, NULL);
  96.  
  97.    if(ccode)
  98.       exit(1);
  99.  
  100.    ccode = NWGetConnectionHandle(
  101.            /* > servername        */ server,
  102.            /*   Novell Reserved1  */ 0,
  103.            /* < connection Handle */ &connHandle,
  104.            /*   Novell Reserved2  */ NULL);
  105.  
  106.    if(ccode){
  107.      printf("NWGetConnectionHandle failed error %X\n",ccode);
  108.       exit(1);
  109.   }
  110.  
  111.  
  112.   ccode = NWLogLogicalRecord(
  113.           /* > connection Handle         */ connHandle,
  114.           /* > Pointer to record Name    */ "test",
  115.           /* > Lock flags 0 logonly
  116.                0 Log Only
  117.                1 log and lock exclusive
  118.                3 log and lock sharable   */ 1,
  119.           /* >    timeOutLimit           */ 0);
  120.  
  121.    if(ccode){
  122.      printf("NWLogLogicalRecord failed error %X\n",ccode);
  123.       exit(1);
  124.   }
  125.   ccode = NWLogLogicalRecord(
  126.           /* > connection Handle         */ connHandle,
  127.           /* > Pointer to record Name    */ "test1",
  128.           /* > Lock flags 0 logonly
  129.                0 Log Only
  130.                1 log and lock exclusive
  131.                3 log and lock sharable   */ 3,
  132.           /* >    timeOutLimit    ``     */ 0);
  133.  
  134.    if(ccode){
  135.      printf("NWLogLogicalRecord failed error %X\n",ccode);
  136.       exit(1);
  137.   }
  138.  
  139.   ccode = NWLockLogicalRecordSet(
  140.           /* > lockflags 0 = shareable Lock
  141.                1 = exclusive Lock            */ 1,
  142.           /* > timeOutLimit                  */ 16);
  143.  
  144.    if(ccode){
  145.      printf("NWLockLogicalRecordSet failed error %X\n",ccode);
  146.       exit(1);
  147.   }
  148.  
  149.   ccode = NWGetConnectionNumber(
  150.           /* > connection Handle  */ connHandle,
  151.           /* < connection Number  */ &connNumber);
  152.  
  153.    if(ccode){
  154.      printf("NWGetConnectionNumber failed error %X\n",ccode);
  155.       exit(1);
  156.   }
  157.  
  158.   lastRecord=0;
  159.   do{
  160.      ccode = NWScanLogicalLocksByConn(
  161.              /* > connection Handle                   */ connHandle,
  162.              /* > connection Number                   */ connNumber,
  163.              /* <>Pointer to next record              */ &lastRecord,
  164.              /* < pointer to CONN_LOGICAL_LOCKS(opt)  */ &logicalLock,
  165.              /* < pointer to CONN_LOGICAL_LOCKS       */ &logicalLocks);
  166.  
  167.     switch(ccode){
  168.         case 0x8801 :
  169.            printf("ERROR: NWScanLogicalLocksByConn =%X INVALID_CONNECTION",
  170.                   ccode);
  171.            exit(0);
  172.            break;
  173.         case 0x88FF :
  174.            printf("ERROR: NWScanLogicalLocksByConn =%X Scan Completed",
  175.                   ccode);
  176.            exit(0);
  177.            break;
  178.         case 0x89C6 :
  179.            printf("ERROR: NWScanLogicalLocksByConn =%X NO_CONSOLE_PRIVILEGES",
  180.                   ccode);
  181.            exit(0);
  182.            break;
  183.         case 0x88FD :
  184.            printf("ERROR: NWScanLogicalLocksByConn =%X Bad Connection Number",
  185.                   ccode);
  186.            exit(0);
  187.            break;
  188.  
  189.         default : break;
  190.      }
  191.      if (ccode>0 && ccode<0x87FF){
  192.            printf("ERROR: NWScanLogicalLocksByConn =%X WorkStation Error",
  193.            ccode);
  194.            exit(0);
  195.      }
  196.      if (ccode>=0x8800 && ccode<0x88FE && ccode!=0x8801){
  197.            printf("ERROR: NWScanLogicalLocksByConn =%X Requester/Shell Error",
  198.            ccode);
  199.            exit(0);
  200.      }
  201.      if (ccode>=0x8900 && ccode<0x89FF && ccode!=0x89C6 & ccode!=0x89FD){
  202.            printf("ERROR: NWScanLogicalLocksByConn =%X NetWare Error",
  203.            ccode);
  204.            exit(0);
  205.      }
  206.  
  207.  
  208.  
  209.      /*--------------------------------------------------------------------
  210.      ** NOTE: lockStatus is a bit mask describing how the file is locked:
  211.      **       0x01 = Locked
  212.      **       0x02 = Open shareable
  213.      **       0x04 = Logged
  214.      **       0x08 = OpenNormal
  215.      **       0x40 = TTS holding
  216.      **       0x80 = Transaction flag set
  217.      */
  218.  
  219.      printf ("TaskNumber = %d\n LockStatus = %X\n logicalName = %s\n\n",
  220.               logicalLock.taskNumber,
  221.               logicalLock.lockStatus,
  222.               logicalLock.logicalName);
  223.  
  224.  
  225.   }while(lastRecord !=-1);
  226.   
  227.  
  228.    if(ccode && ccode !=0x88FF){
  229.      printf("NWScanLogicalLocksByConn failed error %X\n",ccode);
  230.      exit(1);
  231.   }
  232.   ccode = NWClearLogicalRecord(connHandle,"test1");
  233.   if (ccode){
  234.       printf("NWClearLogicalRecord failed %X\n",ccode);
  235.       exit(1);
  236.   }
  237.  
  238.   ccode = NWClearLogicalRecord(connHandle,"test");
  239.   if (ccode){
  240.       printf("NWClearLogicalRecord failed %X\n",ccode);
  241.       exit(1);
  242.   }
  243.  
  244. }
  245.