NWAddFSMonitorHook

Allows the application to monitor ("hook") various OS file system routines

Local Servers:blocking
Remote Servers:N/A
NetWare Server:4.x, 5.x, 6.x
Platform:NLM
Service:File System Monitoring

Syntax

   #include <nwfshook.h> 
     
   LONG NWAddFSMonitorHook  (  
      LONG    callBackNumber,   
      void   *callBackFunc,   
      LONG   *callBackHandle); 
   

Parameters

callBackNumber

(IN) Specifies which type of OS file system routine you want to hook.

callBackFunc

(IN) Points to the function that you want the OS to call (pass control to) when the hooked file system routine is going to be or has been called by a client or any NLM application on the local server.

callBackHandle

(OUT) Points to a handle that identifies the file system monitor hook. This handle is passed to NWRemoveFSMonitorHook when removing the hook.

Return Values

If NWAddFSMonitorHook succeeds, it returns 0 if the OS routine corresponding to callBackNumber was successfully "hooked." Otherwise, it returns errors.

Remarks

The callBackNumber parameter specifies the OS file system routine that you want to hook, and whether the callBackFunc is called before (a "pre OS call hook") or after (a "post OS call hook") the OS routine executes. The last eight sets of hooks (FSHOOK_PRE/POST_RENAME_NS_ENTRY and all generics) are used for tracking routines called from other than DOS clients (note that non-DOS hooks are available for use only with NetWare versions 3.12 and higher.) Hooks cannot be ORed, so you must call NWAddFSMonitorHook once for each routine you want to be monitored. Values for callBackNumber and the OS routines that they hook are defined in nwfshook.h and listed below:

Table 14-1 File System Hooks

Functionality

Constant

Valid Versions

file erasing

FSHOOK_PRE_ERASEFILE

FSHOOK_POST_ERASEFILE

3.11 and higher

file opening

FSHOOK_PRE_OPENFILE

FSHOOK_POST_OPENFILE

3.11 and higher

file creating

FSHOOK_PRE_CREATEFILE

FSHOOK_POST_CREATEFILE

3.11 and higher

file creating/opening

FSHOOK_PRE_CREATE_OPENFILE

FSHOOK_POST_CREATE_OPENFILE

3.11 and higher

file renaming/moving

FSHOOK_PRE_RENAME_OR_MOVE

FSHOOK_POST_RENAME_OR_MOVE

3.11 and higher

file closing

FSHOOK_PRE_CLOSEFILE

FSHOOK_POST_CLOSEFILE

3.11 and higher

directory creating

FSHOOK_PRE_CREATEDIR

FSHOOK_POST_CREATEDIR

3.11 and higher

directory deleting

FSHOOK_PRE_DELETEDIR

FSHOOK_POST_DELETEDIR

3.11 and higher

directory entry modification

FSHOOK_PRE_MODIFY_DIRENTRY

FSHOOK_POST_MODIFY_DIRENTRY

3.11 and higher

salvaging

FSHOOK_PRE_SALVAGE_DELETED

FSHOOK_POST_SALVAGE_DELETED

3.11 and higher

purging

FSHOOK_PRE_PURGE_DELETED

FSHOOK_POST_PURGE_DELETED

3.11 and higher

name space entry renaming

FSHOOK_PRE_RENAME_NS_ENTRY

FSHOOK_POST_RENAME_NS_ENTRY

3.12, 4.x, 5.x, 6.x

generic salvaging

FSHOOK_PRE_GEN_SALVAGE_DELETED

FSHOOK_POST_GEN_SALVAGE_DELETED

3.12, 4.x, 5.x, 6.x

generic purging

FSHOOK_PRE_GEN_PURGE_DELETED

FSHOOK_POST_GEN_PURGE_DELETED

3.12, 4.x, 5.x, 6.x

generic opening/creating

FSHOOK_PRE_GEN_OPEN_CREATE

FSHOOK_POST_GEN_OPEN_CREATE

3.12, 4.x, 5.x, 6.x

generic renaming

FSHOOK_PRE_GEN_RENAME

FSHOOK_POST_GEN_RENAME

3.12, 4.x, 5.x, 6.x

generic file erasing

FSHOOK_PRE_GEN_ERASEFILE

FSHOOK_POST_GEN_ERASEFILE

3.12, 4.x, 5.x, 6.x

generic DOS information modification

FSHOOK_PRE_GEN_MODIFY_DOS_INFO

FSHOOK_POST_GEN_MODIFY_DOS_INFO

3.12, 4.x, 5.x, 6.x

generic name space information modification

FSHOOK_PRE_GEN_MODIFY_NS_INFO

FSHOOK_POST_GEN_MODIFY_NS_INFO

3.12, 4.x, 5.x, 6.x

The callBackFunc parameter points to the callback function you have created. The number of parameters you should declare in callBackFunc varies depending on when the OS calls back the function.

The first parameter for both types of callback function is a pointer to the structure returned by the OS for the OS file system routine that is being monitored (for example, if you are monitoring file opens, the OS would return an OpenFileCallBackStruct). These callback structures are defined in nwfshook.h.

If you have specified a pre OS call back hook, this is the only parameter for the callBackFunc. If you have specified a post OS call back hook, the callBackFunc receives a second parameter, a pointer to a LONG value which is the completion code of the OS routine that you have hooked. The following illustrates what these functions would look like if you are monitoring file opens:

   int PreCallBackFunc (OpenFileCallBackStruct const *structure); 
   
   void PostCallBackFunc (OpenFileCallBackStruct const *structure, LONG ccode);
   

Definitions of the structures returned by the callback function are described in File System Monitoring Structures.

NOTE:If you specify a post OS call back hook, your callback function must not go to sleep, because the values in the callback structure can change before your thread wakes up again.

See Also

NWRemoveFSMonitorHook