Novell Home

Code for a file system hook (CLIB)

From Developer Community

This code shows how to install a file system hook with NWAddFSMonitorHook(). Don't unload this program from the console with UNLOAD command, follow the directions on the application main screen instead.

Sample Code

#include <nwfshook.h>
#include <nwthread.h>
#include <stdio.h>
#include <stdlib.h>

static int main_thread_group_id;

static int callback_func( GenericOpenCreateCBStruct const* cbs) {
  int saved_thread_group_id = SetThreadGroupID( main_thread_group_id);
  printf( "connection            = %x\n", cbs -> connection);
  printf( "task                  = %x\n", cbs -> task);
  printf( "volume                = %x\n", cbs -> volume);
  printf( "openCreateFlags       = %x\n", cbs -> openCreateFlags);
  printf( "requestedAccessRights = %x\n", cbs -> requestedAccessRights);
  SetThreadGroupID( saved_thread_group_id);
  return 0;
}
int main( void) {
  LONG callback_handle;
  LONG ccode;
  main_thread_group_id = GetThreadGroupID();
  ccode = NWAddFSMonitorHook( FSHOOK_PRE_GEN_OPEN_CREATE, callback_func, &callback_handle);
  if ( ccode != 0) {
    printf( "NWAddFSMonitorHook failed, ccode = %u\n", ccode);
    return EXIT_FAILURE;
  }
  puts( "Press a key to remove the hook");
  getch();
  NWRemoveFSMonitorHook( FSHOOK_PRE_GEN_OPEN_CREATE, callback_handle);
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.