24.2.3 WriteBlocks() and WriteBlockEx() Implementation

Writing blocks from media typically uses the following order of operations:

  1. Verify media presence. This is critical for removable or swappable media.

  2. If a media change event is detected, then reinstall the Block I/O Protocols using the UEFI Boot Service ReinstallProtocolInterface(). A media change event can be a change from the media present state to the media not present state. A change from the media not present state to the media present state A change from the media present state to the media present state with different media in the device being managed.

  3. If there is no media return EFI_NO_MEDIA.

  4. If the media is different return EFI_MEDIA_CHANGED.

  5. Get the media's block size. The BlockSize field of the Media structure must have a non-zero value, even when no media is present.

  6. Verify parameters.

  7. The Buffer, sized BufferSize, is a whole number of blocks.

  8. The write does not start past the end of the media.

  9. The write does not extend past the end of the media.

  10. The Buffer is aligned as required.

  11. If needed, copy the appropriate portion of the buffer to a location visible to the mass storage device.

  12. Write the appropriate sectors to the media

  13. If a non-blocking request is made through WriteBlocksEx(), then start the request and if the request is expected to take some time to complete, set up a timer event to periodically check the completion status and return immediately. When the request is complete, signal the event passed into WriteBlocksEx() to inform the caller that the previous request has been completed.

  14. (Optional) Update the driver's cache for better performance.