Table of contents
TOC
Collapse the table of content
Expand the table of content

Managing Contexts

Last Updated: 7/30/2016

The filter manager enables minifilter drivers to associate contexts with objects to preserve state across I/O operations. Objects that can have contexts include volumes, instances, streams, and stream handles.

Third-party file systems must use the FSRTL_ADVANCED_FCB_HEADER structure (instead of the FSRTL_COMMON_FCB_HEADER structure) to work properly with stream and stream handle contexts.

Contexts can be allocated from paged or nonpaged pool except for volume contexts, which must be allocated from nonpaged pool.

Contexts are freed automatically when all outstanding references have been released. If the minifilter driver defines a context cleanup callback routine, the filter manager calls the routine before the context is freed.

The filter manager takes care of deleting contexts when the associated object is deleted, when an instance is detached, and when the minifilter driver is unloaded.

If a minifilter driver supports only one instance per volume, use instance contexts rather than volume contexts for better performance. You can also improve performance by storing a pointer to the minifilter driver instance context inside stream or stream handle contexts.

Contexts are not supported for paging files or during the following operations:

  • Preoperation processing for create requests

  • Postoperation processing for close requests

  • Processing of IRP_MJ_NETWORK_QUERY_OPEN requests

See the CTX sample for an example of a minifilter driver that uses contexts.

Filter Manager Routines for Context Management

The filter manager provides the following support routines for creating, registering, and setting contexts:

FltAllocateContext

FltRegisterFilter

FltSetInstanceContext

FltSetStreamContext

FltSetStreamHandleContext

FltSetVolumeContext

The following routines are provided for querying context support:

FltSupportsStreamContexts

FltSupportsStreamHandleContexts

The following routines are provided for getting and referencing contexts:

FltGetContexts

FltGetInstanceContext

FltGetStreamContext

FltGetStreamHandleContext

FltGetVolumeContext

FltReferenceContext

The following routines are provided for releasing and deleting contexts:

FltDeleteContext

FltDeleteInstanceContext

FltDeleteStreamContext

FltDeleteStreamHandleContext

FltDeleteVolumeContext

FltReleaseContext

FltReleaseContexts

Minifilter Driver Callback Routines for Context Management

The following callback routines are stored in the FLT_REGISTRATION structure that is passed as a parameter to FltRegisterFilter for minifilter drivers that manage contexts:

Callback Routine NameCallback Routine Type

ContextAllocateCallback

PFLT_CONTEXT_ALLOCATE_CALLBACK

ContextCleanupCallback

PFLT_CONTEXT_CLEANUP_CALLBACK

ContextFreeCallback

PFLT_CONTEXT_FREE_CALLBACK


© 2016 Microsoft