⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c

📁 winddk src目录下的文件系统驱动源码压缩!
💻 C
📖 第 1 页 / 共 2 页
字号:
/*++

Copyright (c) 1989 - 1999 Microsoft Corporation

Module Name:

    Init.c

Abstract:

    This module implements the DRIVER_INITIALIZATION routine for 
    the null mini rdr.

--*/

#include "precomp.h"
#pragma  hdrstop

//
//  The local debug trace level
//

#define Dbg                              (DEBUG_TRACE_INIT)

#include "ntverp.h"
#include "nulmrx.h"


//
// Global data declarations.
//

NULMRX_STATE NulMRxState = NULMRX_STARTABLE;

//
//  Mini Redirector global variables.
//

//
//  LogRate
//
ULONG   LogRate = 0;

//
//  NULMRX version
//
ULONG   NulMRxVersion = VER_PRODUCTBUILD;

//
//  This is the minirdr dispatch table. It is initialized by 
//  NulMRxInitializeTables. This table will be used by the wrapper to call 
//  into this minirdr
//

struct _MINIRDR_DISPATCH  NulMRxDispatch;

//
// Pointer to the device Object for this minirdr. Since the device object is 
// created by the wrapper when this minirdr registers, this pointer is 
// initialized in the DriverEntry routine below (see RxRegisterMinirdr)
//

PRDBSS_DEVICE_OBJECT      NulMRxDeviceObject;

//
// declare the shadow debugtrace controlpoints
//

RXDT_DefineCategory(CREATE);
RXDT_DefineCategory(CLEANUP);
RXDT_DefineCategory(CLOSE);
RXDT_DefineCategory(READ);
RXDT_DefineCategory(WRITE);
RXDT_DefineCategory(LOCKCTRL);
RXDT_DefineCategory(FLUSH);
RXDT_DefineCategory(PREFIX);
RXDT_DefineCategory(FCBSTRUCTS);
RXDT_DefineCategory(DISPATCH);
RXDT_DefineCategory(EA);
RXDT_DefineCategory(DEVFCB);
RXDT_DefineCategory(INIT);

//
// The following enumerated values signify the current state of the minirdr
// initialization. With the aid of this state information, it is possible
// to determine which resources to deallocate, whether deallocation comes
// as a result of a normal stop/unload, or as the result of an exception
//

typedef enum _NULMRX_INIT_STATES {
    NULMRXINIT_ALL_INITIALIZATION_COMPLETED,
    NULMRXINIT_MINIRDR_REGISTERED,
    NULMRXINIT_START
} NULMRX_INIT_STATES;

//
// function prototypes
//

NTSTATUS
NulMRxInitializeTables(
          void
    );

VOID
NulMRxUnload(
    IN PDRIVER_OBJECT DriverObject
    );

VOID
NulMRxInitUnwind(
    IN PDRIVER_OBJECT DriverObject,
    IN NULMRX_INIT_STATES NulMRxInitState
    );


NTSTATUS
NulMRxFsdDispatch (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

VOID
NulMRxReadRegistryParameters();

NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT  DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
/*++

Routine Description:

    This is the initialization routine for the mini redirector

Arguments:

    DriverObject - Pointer to driver object created by the system.

Return Value:

    RXSTATUS - The function value is the final status from the initialization
        operation.

--*/
{
    NTSTATUS        	Status;
    PRX_CONTEXT     	RxContext = NULL;
    ULONG           	Controls = 0;
    NULMRX_INIT_STATES	NulMRxInitState = 0;
    UNICODE_STRING		NulMRxName;
    UNICODE_STRING		UserModeDeviceName;
    PNULMRX_DEVICE_EXTENSION pDeviceExtension;
    ULONG i;

    DbgPrint("+++ NULMRX Driver %08lx Loaded +++\n", DriverObject);
    Status =  RxDriverEntry(DriverObject, RegistryPath);
    if (Status != STATUS_SUCCESS) {
        DbgPrint("Wrapper failed to initialize. Status = %08lx\n",Status);
        return(Status);
    }

    try {
        NulMRxInitState = NULMRXINIT_START;

        //
        //  Register this minirdr with the connection engine. Registration makes the connection
        //  engine aware of the device name, driver object, and other characteristics.
        //  If registration is successful, a new device object is returned
        //
        //


        RtlInitUnicodeString(&NulMRxName, DD_NULMRX_FS_DEVICE_NAME_U);
        SetFlag(Controls,RX_REGISTERMINI_FLAG_DONT_PROVIDE_UNCS);
        SetFlag(Controls,RX_REGISTERMINI_FLAG_DONT_PROVIDE_MAILSLOTS);
        
        Status = RxRegisterMinirdr(
                     &NulMRxDeviceObject,				// where the new device object goes
                     DriverObject,						// the Driver Object to register
                     &NulMRxDispatch,					// the dispatch table for this driver
                     Controls,							// dont register with unc and for mailslots
                     &NulMRxName,						// the device name for this minirdr
                     sizeof(NULMRX_DEVICE_EXTENSION),	// IN ULONG DeviceExtensionSize,
                     FILE_DEVICE_NETWORK_FILE_SYSTEM,	// IN ULONG DeviceType - disk ?
                     FILE_REMOTE_DEVICE					// IN  ULONG DeviceCharacteristics
                     );

        if (Status!=STATUS_SUCCESS) {
            DbgPrint("NulMRxDriverEntry failed: %08lx\n", Status );
            try_return(Status);
        }

        //
        //  Init the device extension data
        //  NOTE: the device extension actually points to fields
        //  in the RDBSS_DEVICE_OBJECT. Our space is past the end
        //  of this struct !!
        //

        pDeviceExtension = (PNULMRX_DEVICE_EXTENSION)
            ((PBYTE)(NulMRxDeviceObject) + sizeof(RDBSS_DEVICE_OBJECT));

        RxDefineNode(pDeviceExtension,NULMRX_DEVICE_EXTENSION);
        pDeviceExtension->DeviceObject = NulMRxDeviceObject;

		// initialize local connection list
        for (i = 0; i < 26; i++)
		{
			pDeviceExtension->LocalConnections[i] = FALSE;
		}
		// Mutex for synchronizining our connection list
		ExInitializeFastMutex( &pDeviceExtension->LCMutex );

        // The device object has been created. Need to setup a symbolic
        // link so that the device may be accessed from a Win32 user mode
        // application.

        RtlInitUnicodeString(&UserModeDeviceName, DD_NULMRX_USERMODE_SHADOW_DEV_NAME_U);
        Status = IoCreateSymbolicLink( &UserModeDeviceName, &NulMRxName);
        if (Status!=STATUS_SUCCESS) {
            DbgPrint("NulMRxDriverEntry failed: %08lx\n", Status );
            try_return(Status);
        }

        NulMRxInitState = NULMRXINIT_MINIRDR_REGISTERED;

        //
        // Build the dispatch tables for the minirdr
        //

        Status = NulMRxInitializeTables();

        if (!NT_SUCCESS( Status )) {
            try_return(Status);
        }

        //
        // Get information from the registry
        //
        NulMRxReadRegistryParameters();

  try_exit: NOTHING;
    } finally {
        if (Status != STATUS_SUCCESS) {

            NulMRxInitUnwind(DriverObject,NulMRxInitState);
        }
    }

    if (Status != STATUS_SUCCESS) {

        DbgPrint("NulMRx failed to start with %08lx %08lx\n",Status,NulMRxInitState);
        return(Status);
    }


    //
    //  Setup Unload Routine
    //

    DriverObject->DriverUnload = NulMRxUnload;

    //
    //setup the driver dispatch for people who come in here directly....like the browser
    //

    for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
    {
        DriverObject->MajorFunction[i] = (PDRIVER_DISPATCH)NulMRxFsdDispatch;
    }
  
    //
    //  Start the mini-rdr (used to be a START IOCTL)
    //
    RxContext = RxCreateRxContext(
                    NULL,
                    NulMRxDeviceObject,
                    RX_CONTEXT_FLAG_IN_FSP);

    if (RxContext != NULL) {
        Status = RxStartMinirdr(
                             RxContext,
                             &RxContext->PostRequest);

        if (Status == STATUS_SUCCESS) {
            NULMRX_STATE State;

            State = (NULMRX_STATE)InterlockedCompareExchange(
                                                 (LONG *)&NulMRxState,
                                                 NULMRX_STARTED,
                                                 NULMRX_STARTABLE);
                    
            if (State != NULMRX_STARTABLE) {
                Status = STATUS_REDIRECTOR_STARTED;
                DbgPrint("Status is STATUS_REDIR_STARTED\n");
            }

            //
            //  Chance to get resources in context
            //  of system process.....!!!
            //
  
        } else if(Status == STATUS_PENDING ) {
    
        }
        
        RxDereferenceAndDeleteRxContext(RxContext);
    } else {
        Status = STATUS_INSUFFICIENT_RESOURCES;
    }
              
    return  STATUS_SUCCESS;
}

VOID
NulMRxInitUnwind(
    IN PDRIVER_OBJECT DriverObject,
    IN NULMRX_INIT_STATES NulMRxInitState
    )
/*++

Routine Description:

     This routine does the common uninit work for unwinding from a bad driver entry or for unloading.

Arguments:

     NulMRxInitState - tells how far we got into the intialization

Return Value:

     None

--*/

{
    PAGED_CODE();

    switch (NulMRxInitState) {
    case NULMRXINIT_ALL_INITIALIZATION_COMPLETED:

        //Nothing extra to do...this is just so that the constant in RxUnload doesn't change.......
        //lack of break intentional

    case NULMRXINIT_MINIRDR_REGISTERED:
        RxUnregisterMinirdr(NulMRxDeviceObject);

        //lack of break intentional

    case NULMRXINIT_START:
        break;
    }

}

VOID
NulMRxUnload(
    IN PDRIVER_OBJECT DriverObject
    )
/*++

Routine Description:

     This is the unload routine for the Exchange mini redirector.

Arguments:

     DriverObject - pointer to the driver object for the NulMRx

Return Value:

     None

--*/

{
    PRX_CONTEXT RxContext;
    NTSTATUS    Status;
    UNICODE_STRING  UserModeDeviceName;

    PAGED_CODE();

    NulMRxInitUnwind(DriverObject,NULMRXINIT_ALL_INITIALIZATION_COMPLETED);
    RxContext = RxCreateRxContext(
                    NULL,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -