WdfIoTargetSendWriteSynchronously function (wdfiotarget.h)

[Applies to KMDF and UMDF]

The WdfIoTargetSendWriteSynchronously method builds a write request and sends it synchronously to an I/O target.

Syntax

NTSTATUS WdfIoTargetSendWriteSynchronously(
  [in]            WDFIOTARGET               IoTarget,
  [in, optional]  WDFREQUEST                Request,
  [in, optional]  PWDF_MEMORY_DESCRIPTOR    InputBuffer,
  [in, optional]  PLONGLONG                 DeviceOffset,
  [in, optional]  PWDF_REQUEST_SEND_OPTIONS RequestOptions,
  [out, optional] PULONG_PTR                BytesWritten
);

Parameters

[in] IoTarget

A handle to a local or remote I/O target object that was obtained from a previous call to WdfDeviceGetIoTarget or WdfIoTargetCreate, or from a method that a specialized I/O target supplies.

[in, optional] Request

A handle to a framework request object. This parameter is optional and can be NULL. For more information about this parameter, see the following Remarks section.

[in, optional] InputBuffer

A pointer to a caller-allocated WDF_MEMORY_DESCRIPTOR structure that describes the buffer that contains data that will be written to the device. This parameter is optional and can be NULL. For more information about this parameter, see the following Remarks section.

[in, optional] DeviceOffset

A pointer to a location that specifies a starting offset for the transfer. The I/O target (that is, the next-lower driver) defines how to use this value. For example, the drivers in a disk's driver stack might specify an offset from the beginning of the disk. The I/O target obtains this information in the Parameters.Write.DeviceOffset member of the request's WDF_REQUEST_PARAMETERS structure. This pointer is optional. Most drivers set this pointer to NULL.

[in, optional] RequestOptions

A pointer to a caller-allocated WDF_REQUEST_SEND_OPTIONS structure that specifies options for the request. This pointer is optional and can be NULL. For more information about this parameter, see the following Remarks section.

[out, optional] BytesWritten

A pointer to a location that receives the number of bytes written, if the operation succeeds. This pointer is optional and can be NULL.

Return value

If the operation succeeds, WdfIoTargetSendWriteSynchronously returns after the I/O request completes, and the return value is the request's completion status value. Otherwise, this method might return one of the following values:

Return code Description
STATUS_INVALID_PARAMETER
An invalid parameter was detected.
STATUS_INFO_LENGTH_MISMATCH
The size of the WDF_REQUEST_SEND_OPTIONS structure that the RequestOptions parameter pointed to was incorrect.
STATUS_INVALID_DEVICE_REQUEST
The I/O request was already queued to an I/O target.
STATUS_INSUFFICIENT_RESOURCES
The framework could not allocate system resources (typically memory).
STATUS_IO_TIMEOUT
The driver supplied a time-out value and the request did not complete within the allotted time.
STATUS_REQUEST_NOT_ACCEPTED
The I/O request packet (IRP) that the Request parameter represents does not provide enough IO_STACK_LOCATION structures to allow the driver to forward the request.
 

This method also might return other NTSTATUS values.

A bug check occurs if the driver supplies an invalid object handle.

Remarks

Use the WdfIoTargetSendWriteSynchronously method to send write requests synchronously. To send write requests asynchronously, use the WdfIoTargetFormatRequestForWrite method, followed by the WdfRequestSend method.

WdfIoTargetSendWriteSynchronously does not return until the request has completed, unless the driver supplies a time-out value in the RequestOptions parameter's WDF_REQUEST_SEND_OPTIONS structure, or unless an error is detected.

You can forward an I/O request that your driver received in an I/O queue, or you can create and send a new request. In either case, the framework requires a request object and some buffer space.

To forward an I/O request that your driver received in an I/O queue:

  1. Specify the received request's handle for the WdfIoTargetSendWriteSynchronously method's Request parameter.
  2. Use the received request's input buffer for the WdfIoTargetSendWriteSynchronously method's InputBuffer parameter.

    The driver must call WdfRequestRetrieveInputMemory to obtain a handle to a framework memory object that represents the request's input buffer and then place that handle in the WDF_MEMORY_DESCRIPTOR structure that the driver supplies for the InputBuffer parameter.

For more information about forwarding an I/O request, see Forwarding I/O Requests.

Drivers often divide received I/O requests into smaller requests that they send to an I/O target, so your driver might create new requests.

To create a new I/O request:

  1. Supply a NULL request handle for the WdfIoTargetSendWriteSynchronously method's Request parameter, or create a new request object and supply its handle:
    • If you supply a NULL request handle, the framework uses an internal request object. This technique is simple to use, but the driver cannot cancel the request.
    • If you call WdfRequestCreate to create one or more request objects, you can reuse these request objects by calling WdfRequestReuse. This technique enables your driver's EvtDriverDeviceAdd callback function to preallocate request objects for a device. Additionally, another driver thread can call WdfRequestCancelSentRequest to cancel the request, if necessary.

    Your driver can specify a non-NULL RequestOptions parameter, whether the driver provides a non-NULL or a NULL Request parameter. You can, for example, use the RequestOptions parameter to specify a time-out value.

  2. Provide buffer space for the WdfIoTargetSendWriteSynchronously method's InputBuffer parameter.

    Your driver can specify this buffer space as a locally allocated buffer, as a WDFMEMORY handle, or as a memory descriptor list (MDL). You can use whichever method is most convenient.

    If necessary, the framework converts the buffer description to one that is correct for the I/O target's method for accessing data buffers.

    The following techniques to specify buffer space are available:

    • Supply a local buffer.

      Because WdfIoTargetSendWriteSynchronously handles I/O requests synchronously, the driver can create request buffers that are local to the calling routine, as the following code example shows.

      WDF_MEMORY_DESCRIPTOR  MemoryDescriptor;
      MY_BUFFER_TYPE  MyBuffer;
      WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&MemoryDescriptor,
                                        (PVOID) &MyBuffer,
                                        sizeof(MyBuffer));
      
    • Supply a WDFMEMORY handle.

      Call WdfMemoryCreate or WdfMemoryCreatePreallocated to obtain a handle to framework-managed memory, as the following code example shows.

      WDF_MEMORY_DESCRIPTOR  MemoryDescriptor;
      WDFMEMORY  MemoryHandle = NULL;
      status = WdfMemoryCreate(NULL,
                               NonPagedPool,
                               POOL_TAG,
                               MY_BUFFER_SIZE,
                               &MemoryHandle,
                               NULL);
      WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&MemoryDescriptor,
                                        MemoryHandle,
                                        NULL);
      

      Alternatively, the driver can call WdfRequestRetrieveInputMemory to obtain a handle to a framework memory object that represents a received I/O request's input buffer, if you want the driver to pass that buffer's contents to the I/O target. The driver must not complete the received I/O request until the new request that WdfIoTargetSendWriteSynchronously sends to the I/O target has been deleted, reused, or reformatted. (WdfIoTargetSendWriteSynchronously increments the memory object's reference count. Deleting, reusing, or reformatting a request object decrements the memory object's reference count.)

    • Supply an MDL.

      Drivers can obtain the MDL that is associated with a received I/O request by calling WdfRequestRetrieveInputWdmMdl.

Some I/O targets accept write requests that have a zero-length buffer. For such I/O targets, your driver can specify NULL for the InputBuffer parameter.

For information about obtaining status information after an I/O request completes, see Obtaining Completion Information.

For more information about WdfIoTargetSendWriteSynchronously, see Sending I/O Requests to General I/O Targets.

For more information about I/O targets, see Using I/O Targets.

Examples

The following code example creates a framework memory object, initializes a WDF_MEMORY_DESCRIPTOR structure, and passes the structure to WdfIoTargetSendWriteSynchronously. This example specifies NULL for the request object handle, so the framework will create a new request object for the I/O target.

WDF_MEMORY_DESCRIPTOR  MemoryDescriptor;
WDFMEMORY  MemoryHandle = NULL;
ULONG_PTR  bytesWritten = NULL;

status = WdfMemoryCreate(
                         NULL,
                         NonPagedPool,
                         POOL_TAG,
                         MY_BUFFER_SIZE,
                         &MemoryHandle,
                         NULL
                         );
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(
                                  &MemoryDescriptor,
                                  MemoryHandle,
                                  NULL
                                  );
status = WdfIoTargetSendWriteSynchronously(
                                          ioTarget,
                                          NULL,
                                          &MemoryDescriptor,
                                          NULL,
                                          NULL,
                                          &bytesWritten
                                          );
 

Requirements

Requirement Value
Target Platform Universal
Minimum KMDF version 1.0
Minimum UMDF version 2.0
Header wdfiotarget.h (include Wdf.h)
Library Wdf01000.sys (KMDF); WUDFx02000.dll (UMDF)
IRQL <=PASSIVE_LEVEL
DDI compliance rules DeferredRequestCompleted(kmdf), DriverCreate(kmdf), InternalIoctlReqs(kmdf), IoctlReqs(kmdf), KmdfIrql(kmdf), KmdfIrql2(kmdf), KmdfIrqlExplicit(kmdf), ReadReqs(kmdf), RequestCompleted(kmdf), RequestCompletedLocal(kmdf), SyncReqSend(kmdf)

See also

EvtDriverDeviceAdd

WDF_MEMORY_DESCRIPTOR

WDF_MEMORY_DESCRIPTOR_INIT_HANDLE

WDF_REQUEST_PARAMETERS

WDF_REQUEST_SEND_OPTIONS

WdfDeviceGetIoTarget

WdfIoTargetCreate

WdfIoTargetFormatRequestForWrite

WdfMemoryCreate

WdfMemoryCreatePreallocated

WdfRequestCancelSentRequest

WdfRequestCreate

WdfRequestRetrieveInputMemory

WdfRequestRetrieveInputWdmMdl

WdfRequestReuse

WdfRequestSend