I/O control codes are contained in IRP_MJ_DEVICE_CONTROL and IRP_MJ_INTERNAL_DEVICE_CONTROL requests. The I/O manager creates these requests as a result of calls to DeviceIoControl and IoBuildDeviceIoControlRequest.
Because DeviceIoControl and IoBuildDeviceIoControlRequest accept both an input buffer and an output buffer as arguments, all IRP_MJ_DEVICE_CONTROL and IRP_MJ_INTERNAL_DEVICE_CONTROL requests supply both an input buffer and an output buffer. システムがこれらのバッファーを記述する方法は、データ転送の種類によって異なります。 The transfer type is specified by the TransferType value in the CTL_CODE macro that creates IOCTL code values.
The system describes buffers for each TransferType value as follows.
METHOD_BUFFERED
For this transfer type, IRPs supply a pointer to a buffer at Irp->AssociatedIrp.SystemBuffer. This buffer represents both the input buffer and the output buffer that are specified in calls to DeviceIoControl and IoBuildDeviceIoControlRequest. ドライバーは、このバッファーからデータを転送し、その後、このバッファーにデータを転送します。
For input data, the buffer size is specified by Parameters.DeviceIoControl.InputBufferLength in the driver's IO_STACK_LOCATION structure. For output data, the buffer size is specified by Parameters.DeviceIoControl.OutputBufferLength in the driver's IO_STACK_LOCATION structure.
システムが単一の入出力バッファーに割り当てるスペースのサイズは、2 つの長さの値の中で大きくなります。
METHOD_IN_DIRECT または METHOD_OUT_DIRECT
For these transfer types, IRPs supply a pointer to a buffer at Irp->AssociatedIrp.SystemBuffer. This represents the first buffer that is specified in calls to DeviceIoControl and IoBuildDeviceIoControlRequest. The buffer size is specified by Parameters.DeviceIoControl.InputBufferLength in the driver's IO_STACK_LOCATION structure.
For these transfer types, IRPs also supply a pointer to an MDL at Irp->MdlAddress. This represents the second buffer that is specified in calls to DeviceIoControl and IoBuildDeviceIoControlRequest. このバッファーは、次のように入力バッファーまたは出力バッファーとして使用できます。
METHOD_IN_DIRECTは、IRP を処理するドライバーが呼び出されたときにバッファー内のデータを受信する場合に指定されます。 MDL は入力バッファーを記述し、METHOD_IN_DIRECTを指定すると、実行中のスレッドがバッファーへの読み取りアクセス権を持っていることを保証します。
METHOD_OUT_DIRECTは、IRP を処理するドライバーが IRP を完了する前にバッファーにデータを書き込む場合に指定されます。 MDL は出力バッファーを記述し、METHOD_OUT_DIRECTを指定することで、実行中のスレッドがバッファーへの書き込みアクセス権を持っていることを確認します。
For both of these transfer types, Parameters.DeviceIoControl.OutputBufferLength specifies the size of the buffer that is described by the MDL.
METHOD_NEITHER
I/O マネージャーは、システム バッファーまたは MDL を提供しません。 The IRP supplies the user-mode virtual addresses of the input and output buffers that were specified to DeviceIoControl or IoBuildDeviceIoControlRequest, without validating or mapping them.
The input buffer's address is supplied by Parameters.DeviceIoControl.Type3InputBuffer in the driver's IO_STACK_LOCATION structure, and the output buffer's address is specified by Irp->UserBuffer.
Buffer sizes are supplied by Parameters.DeviceIoControl.InputBufferLength and Parameters.DeviceIoControl.OutputBufferLength in the driver's IO_STACK_LOCATION structure.
For more information about the CTL_CODE macro and the transfer types listed above, see Defining I/O Control Codes.