4.3 Serial I/O Requests

As both a lowest- and highest-level driver, the system-supplied serial device driver has much in common with all kernel-mode device drivers and some features in common with file system drivers. That is, the serial driver handles interrupts and controls its hardware directly like any device driver. The serial driver, like a file system driver, also must provide Dispatch routines that handle requests about the nature of the file objects that represent its ports to user-mode applications.

IRP_MJ_CREATE

Operation

Returns STATUS_SUCCESS if the serial port represented by the input device object is ready for I/O requests. If the driver is designed with pageable-image section(s), it maps in its code and sets up any resources it needs, such as internal buffers or queues, for handling subsequent I/O requests from the caller that is attempting to open the port. Then, it sets the I/O status block, completes the IRP, and returns. If the driver is resident, it simply sets the I/O status block, completes the IRP, and returns.

When Called

A user-mode application, protected subsystem, or another driver has made a request to open the serial port.

I/O Status Block

The Information field is set to zero. The Status field is set to STATUS_SUCCESS or possibly to an error status returned by a support routine that the driver called to allocate necessary resources.

IRP_MJ_CLEANUP

Operation

Cancels any IRPs currently queued to the serial port represented by the input device object. The next request for the device will be a close.

When Called

Any time following the successful completion of a create request and the receipt of additional requests for the target device object.

The current holder of the file object handle representing the serial port has canceled an I/O request, released its handle, or been terminated.

I/O Status Block

The Information field is set to zero. The Status field is set to STATUS_SUCCESS in the cleanup IRP, after the driver has completed all queued IRPs with their Status fields set to STATUS_CANCELLED.

IRP_MJ_CLOSE

Operation

Delays the close operation for an interval equal to ten send characters at the current line-control rate, disables interrupts from the device, lowers the hardware control lines, and resets the device. If the driver is designed with pageable-image section(s), it also releases any resources and mapped code it set up at the create request for the given device object.

When Called

Following a cleanup request for the same device object.

I/O Status Block

The Information field is set to zero and the Status field is set to STATUS_SUCCESS.

IRP_MJ_QUERY_INFORMATION

Operation

Returns end-of-file information (always set to zero) for the opened serial port to the buffer at Irp->AssociatedIrp.SystemBuffer.

When Called

Any time following the successful completion of a create request

The holder of a file handle, representing the opened serial port, has requested information about the length of the file.

I/O Status Block

The Information field is set to either sizeof(FILE_STANDARD_INFORMATION) or to sizeof(FILE_POSITION_INFORMATION) when the Status field is set to STATUS_SUCCESS. Otherwise, the Information field is set to zero, and the Status field is set to STATUS_INVALID_PARAMETER.

IRP_MJ_SET_INFORMATION

Operation

Sets the end-of-file information (always to zero) for the opened serial port.

When Called

Any time following the successful completion of a create request

The holder of a file handle, representing the opened serial port, has sent an EOF.

I/O Status Block

The Information field is set to zero. The Status field can be set to STATUS_SUCCESS or STATUS_INVALID_PARAMETER if the FileInformationClass value in the I/O stack location is not FileEndOfFileInformation.

IRP_MJ_READ

Operation

Transfers characters from the device, which can be already held in the driver’s internal buffers, to the buffer at Irp->AssociatedIrp.SystemBuffer.

When Called

Any time following the successful completion of a create request

The current holder of the handle for the serial port requested receive data.

I/O Status Block

The Information field is set to the number of characters read when the Status field is set to STATUS_SUCCESS. Otherwise, the Information field is set to zero if the Status field is set to STATUS_PENDING or STATUS_CANCELLED.

IRP_MJ_WRITE

Operation

Transfers characters from the buffer at Irp->AssociatedIrp.SystemBuffer to the device or, possibly, into the driver’s internal buffers first.

When Called

Any time following the successful completion of a create request

The current holder of the handle for the serial port sent a data-transmit request.

I/O Status Block

The Information field is set to the number of characters written when the Status field is set to STATUS_SUCCESS. Otherwise, the Information field is set to zero if the Status field is set to STATUS_PENDING or STATUS_CANCELLED.

IRP_MJ_DEVICE_CONTROL

Operation

Determined by the I/O control code set at Parameters.DeviceIoControl.IoControlCode in the driver’s I/O stack location of the IRP.

When Called

Any time following the successful completion of a create request

A Win32 application, VDM, or subsystem component has called DeviceIoControl to communicate a request to the serial driver.

I/O Status Block

The Status field value depends on the operation, either STATUS_SUCCESS or an appropriate STATUS_XXX value. For most operations, the set of possible STATUS_XXX values includes those propagated from a call to a support routine and/or those chosen by the driver designer. Usually, the Information field of the I/O status block is set to the number of bytes of returned or transferred data when the driver completes the IRP.