Windows Driver Kit: Installable File System Drivers
IRP_MJ_DEVICE_CONTROL
When Sent
The IRP_MJ_DEVICE_CONTROL request is sent by the I/O Manager and other operating system components, as well as other kernel-mode drivers. Normally this IRP is sent on behalf of a user-mode application that has called the Microsoft Win32 DeviceIoControl function or on behalf of a kernel-mode component that has called ZwDeviceIoControlFile.
Operation: File System Drivers
The file system driver should extract and decode the file object to determine whether the request has been issued on a handle that is a volume open. If this is the case, the file system driver should pass the IRP to the device driver for the storage device on which the volume is mounted. If not, the driver should fail the IRP.
Operation: File System Filter Drivers
The filter driver should perform any needed processing and, depending on the nature of the filter, either complete the IRP or pass it down to the next-lower driver on the stack.
Parameters
A file system or filter driver calls IoGetCurrentIrpStackLocation for the given IRP to get a pointer to its own stack location in the IRP, shown in the following list as IrpSp. (The IRP is shown as Irp.) The driver can use the information that is set in the following members of the IRP and the IRP stack location in processing a device control request:
- DeviceObject
- Pointer to the target device object.
- Irp->AssociatedIrp.SystemBuffer
- Pointer to a system-supplied input buffer to be passed to the device driver for the target device. Used for METHOD_BUFFERED or METHOD_DIRECT I/O. Whether this parameter is required depends on the specific I/O control code.
- Irp->IoStatus
- Pointer to an IO_STATUS_BLOCK structure that receives the final completion status and information about the requested operation. For more information, see the description of the IoStatusBlock parameter to ZwDeviceIoControlFile.
- Irp->MdlAddress
- Address of a memory descriptor list (MDL) describing an output buffer to be passed to the device driver for the target device. Used for METHOD_DIRECT I/O. Whether this parameter is required depends on the specific I/O control code.
- Irp->RequestorMode
- Indicates the execution mode of the process that requested the operation, either KernelMode or UserMode.
- Irp->UserBuffer
- Pointer to a caller-supplied output buffer to be passed to the device driver for the target device. Used for METHOD_BUFFERED or METHOD_NEITHER I/O. Whether this parameter is optional or required depends on the specific I/O control code.
- IrpSp->FileObject
- Pointer to the file object that is associated with DeviceObject.
The IrpSp->FileObject parameter contains a pointer to the RelatedFileObject field, which is also a FILE_OBECT structure. The RelatedFileObject field of the FILE_OBJECT structure is not valid during the processing of IRP_MJ_DEVICE_CONTROL and should not be used.
- IrpSp->MajorFunction
- Specifies IRP_MJ_DEVICE_CONTROL.
- IrpSp->Parameters.DeviceIoControl.InputBufferLength
- Size in bytes of the buffer pointed to by Irp->AssociatedIrp.SystemBuffer.
- IrpSp->Parameters.DeviceIoControl.IoControlCode
- IOCTL function code to be passed to the device driver for the target device.
For detailed information about IOCTL requests, see Using I/O Control Codes in the Kernel Mode Architecture Guide and "Device Input and Output Control Codes" in the Microsoft Windows SDK documentation.
- IrpSp->Parameters.DeviceIoControl.OutputBufferLength
- Size in bytes of the buffer pointed to by Irp->UserBuffer.
- IrpSp->Parameters.DeviceIoControl.Type3InputBuffer
- Input buffer for kernel-mode requests that use METHOD_NEITHER.
See Also
IO_STACK_LOCATION, IO_STATUS_BLOCK, IoBuildDeviceIoControlRequest, IoGetCurrentIrpStackLocation, IoGetFunctionCodeFromCtlCode, IRP, IRP_MJ_DEVICE_CONTROL (WDK Kernel Reference), Using I/O Control Codes, ZwDeviceIoControlFile