Chapter 4 Driver From Start to Finish

Dispatch Routine

List of operations that the driver support

Create and Close MajorFunctions

These two functions esentially do the samething. Approve request.

WriteFile or DeviceIOControl? Which one is better when writing to Driver

Matter of taste. WriteFile for me.

DeviceIOControl

DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = PriorityBoosterControl;

When the client calls DeviceIoControl and pass in databuffer. The DeviceIOcontrol reaches the driver by invoking the IRP_MJ_DEVICE_CONTROL Major functionsroutine

Device Control Code

CTL_CODE

#define PRIORITY_BOOSTER_DEVICE 0x8000

#define IOCTL_PRIORITY_BOOSTER_SET_PRIORITY CTL_CODE(PRIORITY_BOOSTER_DEVICE, \\
	0x800, METHOD_NEITHER, FILE_ANY_ACCESS)

This I/O code is passed to the driver and makes it executes different routines based on the different IOCTLs that are passed to it through the DeviceIoControl API. Essentially, the dispatch routine at index IRP_MJ_DEVICE_CONTROL will, at some point in its code, act like this switch case:

switch(IOCTL)
{
    case 0xDEADBEEF:
        DoThis();
        break;
    case 0xC0FFEE;
        DoThat();
        break;
    case 0x600DBABE;
    DoElse();
    break;
}

IoCreateDevice

needed to create a UNICODE_STRING to hold the internal device name;