IT tutorials
 
Windows
 

Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 8) - File Create and Close Requests

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
11/30/2013 8:27:11 PM

5. Sample Software-Only Driver

The Featured Toaster sample extends the Simple Toaster sample by adding support for the following features:

  • File create and close requests.

  • Additional device object attributes.

  • Plug and Play and power management events.

  • Windows management instrumentation (WMI).

This sample is supplied in Toaster\Func\Featured and supports the same features as the Featured2 Toaster sample for WDM, which is provided in the WDK.

5.1. File Create and Close Requests

File object events occur when applications and kernel-mode components that open a handle to the device issue create, close, and cleanup requests on the device. Drivers that handle such requests must configure the device object with the appropriate callbacks.

To handle create events, a driver can either receive the events from a queue or can supply an event callback that is invoked immediately. The driver’s options are the following:

  • To be called immediately, the driver supplies an EvtDeviceFileCreate callback and registers it from the EvtDriverDeviceAdd callback by calling WdfDeviceInitSetFileObjectConfig.

  • To configure a queue to receive the requests, the driver calls WdfDeviceConfigureRequestDispatching and specifies WdfRequestTypeCreate. If the queue is not manual, the driver must register an EvtIoDefault callback, which is called when a create request arrives.

Queuing takes precedence over the EvtDeviceFileCreate callback—that is, if the driver both registers for EvtDeviceFileCreate events and configures a queue to receive such requests, KMDF queues the requests and does not invoke the callback. KMDF does not queue requests to a default queue; the driver must explicitly configure a queue to receive them.

In a function or bus driver, if a create request arrives for which the driver has neither registered an EvtDeviceFileCreate callback function nor configured a queue to receive create request, KMDF opens a file object to represent the device and completes the request with STATUS_SUCCESS. Therefore, any function or bus driver that does not accept create or open requests from user-mode applications—and thus does not register a device interface—must register an EvtDeviceFileCreate callback that explicitly fails such requests. Supplying a callback to fail create requests ensures that a rogue user-mode application cannot gain access to the device.

If a filter driver does not handle create requests, KMDF by default forwards all create, cleanup, and close requests to the default I/O target (the next lower driver).

Filter drivers that handle create requests should perform whatever filtering tasks are required and then forward such requests to the default I/O target. If the filter driver completes a create request for a file object, it should set AutoForwardCleanupClose to WdfFalse in the file object configuration so that KMDF completes cleanup and close requests for the file object instead of forwarding them.

To handle file close and cleanup requests on a device handle, the driver supplies the EvtFileClose and EvtFileCleanup callbacks. It registers both of these callbacks in its EvtDriverDeviceAdd function.

5. 1.1. Register EvtDeviceFileCreate and EvtFileClose Callbacks

The following code is excerpted from the Featured Toaster’s ToasterEvtDeviceAdd function. It shows how the driver registers the EvtDeviceFileCreate and EvtFileClose callbacks.

WDF_FILEOBJECT_CONFIG_INIT(
&fileConfig,
ToasterEvtDeviceFileCreate,
ToasterEvtFileClose,
WDF_NO_EVENT_CALLBACK // not interested in Cleanup
);

WdfDeviceInitSetFileObjectConfig(DeviceInit,
&fileConfig,
WDF_NO_OBJECT_ATTRIBUTES);

As the example shows, the driver initializes a WDF_FILEOBJECT_CONFIG structure by calling the configuration function and supplying pointers to its EvtDeviceFileCreate and EvtFileClose callbacks. The driver does not implement the EvtFileCleanup callback, so it supplies WDF_NO_EVENT_CALLBACK instead of a third function pointer.

It then calls WdfDeviceInitSetFileObjectConfig to record these settings in the WDFDEVICE_INIT structure (DeviceInit), which the framework uses later when it creates the device object.

The EvtDeviceFileCreate and EvtFileClose functions are stubs in the Featured Toaster driver, so they are not shown here.

 
Others
 
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 7)
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 6) - Device Object and Device Context Area, Device Interface
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 5) - Creating the Device Object, Device Interface
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 4) - Creating a WDF Driver Object: DriverEntry
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 3) - KMDF Driver Structure and Concepts - Object Context Area
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 2) - KMDF Driver Structure and Concepts - Object Creation
- Windows 7 : Programming Drivers for the Kernel Mode Driver Framework (part 1)
- Windows Server 2008 : Creating and Running a PowerShell Script - Testing for the Existence of a File, Creating Output as HTML
- Windows Server 2008 : Creating and Running a PowerShell Script - Running PowerShell Scripts, Logging Processes with a get-process Script
- Windows Server 2008 : Creating and Running a PowerShell Script - Creating and Modifying the Global PowerShell Profile
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us