Novell Home

How to use NWScanPhysicalLocksByFile()

From Developer Community

This sample scans and displays all physical locks on a given file.

Sample Code

#if !defined( N_PLAT_NLM)
#define N_PLAT_WNT
#endif

#ifdef __MWERKS__
#pragma ANSI_strict off
#endif
#include <nwcalls.h>
#include <nwclxcon.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __MWERKS__
#pragma ANSI_strict reset
#endif

#if defined( __MWERKS__) && !defined( N_PLAT_NLM)
#define strupr(s) (_strupr(s),s) /* CW Pro 5.3 has a bug in _strupr */
#endif

int main( int argc, char* argv[]) {
   char const*    server_name;
#ifdef N_PLAT_NLM
   char const*    user_name;
   char const*    password;
#endif
   char const*    filename;
   NWRCODE        rcode;
   NWCCODE        ccode;
   NWCONN_HANDLE  conn_handle;
   nint16         iter_handle = 0;
   PHYSICAL_LOCKS locks;
#ifdef N_PLAT_NLM
   if ( argc != 5) {
      printf( "Usage: %s <servername> <username> <password> <filename>\n", *argv);
#else
   if ( argc != 3) {
      printf( "Usage: %s <servername> <filename>\n", *argv);
#endif
      return EXIT_FAILURE;
   }
   server_name = strupr( *++argv);
#ifdef N_PLAT_NLM
   user_name   = strupr( *++argv);
   password    = strupr( *++argv);
#endif
   filename    = strupr( *++argv);
   rcode = NWCCOpenConnByName( 0,
                               server_name,
                               NWCC_NAME_FORMAT_BIND,
                               NWCC_OPEN_LICENSED,
                               NWCC_TRAN_TYPE_WILD,
                               &conn_handle);
   if ( rcode != 0) {
      printf( "NWCCOpenConnByName failed, rcode = %x", rcode);
      return EXIT_FAILURE;
   }
#ifdef N_PLAT_NLM
   ccode = NWLoginToFileServer( conn_handle, user_name, OT_USER, password);
   if ( ccode != 0) {
      printf( "NWLoginToFileServer failed, ccode = %x", ccode);
      NWCCCloseConn( conn_handle);
      return EXIT_FAILURE;
   }
#endif
   ccode = NWScanPhysicalLocksByFile( conn_handle, 0, filename, 0, &iter_handle, NULL, &locks);
   if ( ccode != 0) {
      printf( "NWScanPhysicalLocksByFile failed, ccode = %x", ccode);
      NWCCCloseConn( conn_handle);
      return EXIT_FAILURE;
   }
   while ( iter_handle != -1) {
      printf( "numRecords = %u\n", locks.numRecords);
      ccode = NWScanPhysicalLocksByFile( conn_handle, 0, filename, 0, &iter_handle, NULL, &locks);
      if ( ccode != 0) {
         printf( "NWScanPhysicalLocksByFile failed, ccode = %x", ccode);
         NWCCCloseConn( conn_handle);
         return EXIT_FAILURE;
      }
   }
   puts( "No more locks");
   NWCCCloseConn( conn_handle);
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.