What is the use of do_device_initializing?

Source: Internet
Author: User

 

When the device driver callsIocreatedeviceWhen creating a device object, the I/O managerFlagsSet do_device_initializing in the field. The purpose of do_device_initializing is to prevent other components from sending I/O to the device before the driver completes device object initialization.

I/O manager checks do_device_initializing every time a device handle is opened and whenever the driver tries to append it to a device stack (check the identifier of the device object at the top of the stack. If do_device_initializing is set, the I/O manager will not allow another component to useCreatefile,OpenfileOrIogetdeviceobjectpointerAnd other functions. Do_device_initializing does not prevent the driver from receiving plug-and-play requests or requests from high-level drivers in the stack. It only prevents the component from opening the device.

For the driver program in itsDriverEntryThe I/O manager is responsible for clearing any device objects created in the routine. For DivisionDriverEntryThe driver is responsible for clearing do_device_initializing any device objects created in any other routine.

Traditional drivers (for example, non-plug-and-play drivers written for Windows NT 4)DriverEntryThe device objects that you create. Plug-and-play driversAdddeviceCreate their device objects, but the plug-and-play driver mayDriverEntryCreate Control Device objects (for example, publish your own device interfaces or devices in an exclusive stack that an application can open ). (Drivers do not report Control Device objects to plug-and-play or attach them to the device stack .)

The driver is responsible for receiving I/O requests before returning the routine (where the driver creates a device object. The steps involved in different types of drivers are different. For plug-and-play drivers, the steps typically include storing the device's PDO pointer to the device extension, defining the flag to track the device's plug-and-play status, setting the power management flag, and creating or initializing software resources (such as drivers) events and spin locks used to manage their devices ). Drivers can also register device interfaces or create one or more symbolic links to their devices.

ForDriverEntryThe device object created in, which is allowed by the I/O manager.DriverEntryTurn on the device as soon as it returns. For plug-and-play drivers, the driver stack must successfully complete a startup request (irp_mn_start_device) before the I/O Manager allows the device to be opened ). Although the plug-and-play driver may needAdddeviceAnd start requests to process requests from other drivers in the stack (for example, the storage port driver must process srb_function_claim_device at this interval ), however, the driver does not receive any CREATE request or file object-based I/O request before the device is started. From the time when the driver clears this sign to the time when the plug-and-play manager starts the device, the driver does not need to synchronize the irp_mj_create or I/O requests passed in based on the file handle.

The following code is simplified:AdddeviceExample of a routine (based on the toaster example in Windows DDK ). (The error check and device extension initialization code have been deleted from this example. For the complete code, see the toaster driver example on % winddk %/src/General/toaster/func/featured1 ).

NTSTATUS ToasterAddDevice( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject ) { NTSTATUS                status = STATUS_SUCCESS; PDEVICE_OBJECT          deviceObject = NULL; PFDO_DATA               fdoData; POWER_STATE             powerState;PAGED_CODE();// Create a function device object. status = IoCreateDevice (DriverObject, sizeof (FDO_DATA), NULL,  // No Name FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject);// Code to initialize the device extension.// Attach driver to the device stack. fdoData->NextLowerDriver = IoAttachDeviceToDeviceStack (deviceObject, PhysicalDeviceObject);// Clear the DO_DEVICE_INITIALIZING flag.// Note:Do not clear this flag until the driver has set the // device power state and the power DO flags. //deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;return status; }

What should you do?

Clear the driver inDriverEntryOther routines (such as plug-and-play driverAdddeviceRoutine) The do_device_initializing flag of any device object created in.

Clear do_device_initializing after device object initialization and before returning from the routine.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.