Ejemplo n.º 1
0
/*++

Routine Description:

    This routine updates the name of the target in the supplied stream handle context

Arguments:

    DirectoryName             - Supplies the directory name
    StreamHandleContext   - Returns the updated name in the stream context

Return Value:

    Status

Note:

    The caller must synchronize access to the context. This routine does no
    synchronization

--*/
NTSTATUS
CtxUpdateNameInStreamHandleContext (
    __in PUNICODE_STRING DirectoryName,
    __inout PCTX_STREAMHANDLE_CONTEXT StreamHandleContext
    )
{
    NTSTATUS status;

    PAGED_CODE();

    //
    //  Free any existing name
    //

    if (StreamHandleContext->FileName.Buffer != NULL) 
	{
        CtxFreeUnicodeString(&StreamHandleContext->FileName);
    }


    //
    //  Allocate and copy off the directory name
    //

    StreamHandleContext->FileName.MaximumLength = DirectoryName->Length;
    status = CtxAllocateUnicodeString(&StreamHandleContext->FileName);
    if (NT_SUCCESS(status))
	{
        RtlCopyUnicodeString(&StreamHandleContext->FileName, DirectoryName);
    }

    return status;
}
Ejemplo n.º 2
0
NTSTATUS
CtxUpdateNameInStreamHandleContext (
    __in PUNICODE_STRING DirectoryName,
    __inout PCTX_STREAMHANDLE_CONTEXT StreamHandleContext
    )
/*++

Routine Description:

    This routine updates the name of the target in the supplied stream handle context

Arguments:

    DirectoryName             - Supplies the directory name
    StreamHandleContext   - Returns the updated name in the stream context

Return Value:

    Status

Note:

    The caller must synchronize access to the context. This routine does no
    synchronization

--*/
{
    NTSTATUS status;

    PAGED_CODE();

    //
    //  Free any existing name
    //

    if (StreamHandleContext->FileName.Buffer != NULL) {

        CtxFreeUnicodeString(&StreamHandleContext->FileName);
    }


    //
    //  Allocate and copy off the directory name
    //

    StreamHandleContext->FileName.MaximumLength = DirectoryName->Length;
    status = CtxAllocateUnicodeString(&StreamHandleContext->FileName);
    if (NT_SUCCESS(status)) {

        RtlCopyUnicodeString(&StreamHandleContext->FileName, DirectoryName);
    }

    return status;
}
Ejemplo n.º 3
0
VOID
CtxContextCleanup (
    __in PFLT_CONTEXT Context,
    __in FLT_CONTEXT_TYPE ContextType
    )
{
    PCTX_INSTANCE_CONTEXT instanceContext;
    PCTX_FILE_CONTEXT fileContext;
    PCTX_STREAM_CONTEXT streamContext;
    PCTX_STREAMHANDLE_CONTEXT streamHandleContext;

    PAGED_CODE();

    switch(ContextType) {

    case FLT_INSTANCE_CONTEXT:

        instanceContext = (PCTX_INSTANCE_CONTEXT) Context;

        DebugTrace( DEBUG_TRACE_INSTANCE_CONTEXT_OPERATIONS,
                    ("[Ctx]: Cleaning up instance context for volume %wZ (Context = %p)\n",
                     &instanceContext->VolumeName,
                     Context) );

#if __NDAS_FS_MINI__
		if (instanceContext->DiskDeviceObject) {

			ObDereferenceObject( instanceContext->DiskDeviceObject );
		}

		if (instanceContext->DeviceObject) {

			ObDereferenceObject( instanceContext->DeviceObject );
		}

		if (instanceContext->VolumeProperties) {

			ExFreePoolWithTag( instanceContext->VolumeProperties, CTX_VOLUME_PROPERTY_TAG );
		}
#endif

        //
        //  Here the filter should free memory or synchronization objects allocated to
        //  objects within the instance context. The instance context itself should NOT
        //  be freed. It will be freed by Filter Manager when the ref count on the
        //  context falls to zero.
        //

        CtxFreeUnicodeString( &instanceContext->VolumeName );

        DebugTrace( DEBUG_TRACE_INSTANCE_CONTEXT_OPERATIONS,
                    ("[Ctx]: Instance context cleanup complete.\n") );

        break;


    case FLT_FILE_CONTEXT:

        fileContext = (PCTX_FILE_CONTEXT) Context;

        DebugTrace( DEBUG_TRACE_FILE_CONTEXT_OPERATIONS,
                    ("[Ctx]: Cleaning up file context for file %wZ (FileContext = %p)\n",
                     &fileContext->FileName,
                     fileContext) );


        //
        //  Free the file name
        //

        if (fileContext->FileName.Buffer != NULL) {

            CtxFreeUnicodeString(&fileContext->FileName);
        }

        DebugTrace( DEBUG_TRACE_FILE_CONTEXT_OPERATIONS,
                    ("[Ctx]: File context cleanup complete.\n") );

        break;

    case FLT_STREAM_CONTEXT:

        streamContext = (PCTX_STREAM_CONTEXT) Context;

        DebugTrace( DEBUG_TRACE_STREAM_CONTEXT_OPERATIONS,
                    ("[Ctx]: Cleaning up stream context for file %wZ (StreamContext = %p) \n\tCreateCount = %x \n\tCleanupCount = %x, \n\tCloseCount = %x\n",
                     &streamContext->FileName,
                     streamContext,
                     streamContext->CreateCount,
                     streamContext->CleanupCount,
                     streamContext->CloseCount) );

        //
        //  Delete the resource and memory the memory allocated for the resource
        //

        if (streamContext->Resource != NULL) {

            ExDeleteResourceLite( streamContext->Resource );
            CtxFreeResource( streamContext->Resource );
        }

        //
        //  Free the file name
        //

        if (streamContext->FileName.Buffer != NULL) {

            CtxFreeUnicodeString(&streamContext->FileName);
        }

        DebugTrace( DEBUG_TRACE_STREAM_CONTEXT_OPERATIONS,
                    ("[Ctx]: Stream context cleanup complete.\n") );

        break;

    case FLT_STREAMHANDLE_CONTEXT:

        streamHandleContext = (PCTX_STREAMHANDLE_CONTEXT) Context;

        DebugTrace( DEBUG_TRACE_STREAMHANDLE_CONTEXT_OPERATIONS,
                    ("[Ctx]: Cleaning up stream handle context for file %wZ (StreamContext = %p)\n",
                     &streamHandleContext->FileName,
                     streamHandleContext) );

        //
        //  Delete the resource and memory the memory allocated for the resource
        //

        if (streamHandleContext->Resource != NULL) {

            ExDeleteResourceLite( streamHandleContext->Resource );
            CtxFreeResource( streamHandleContext->Resource );
        }

        //
        //  Free the file name
        //

        if (streamHandleContext->FileName.Buffer != NULL) {

            CtxFreeUnicodeString(&streamHandleContext->FileName);
        }

        DebugTrace( DEBUG_TRACE_STREAMHANDLE_CONTEXT_OPERATIONS,
                    ("[Ctx]: Stream handle context cleanup complete.\n") );

        break;

    }

}