24.2.2 ReadBlocks() and ReadBlocksEx() Implementation

Reading 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. The BlockSize field of the Media structure must have a nonzero value, even when no media is present.

    • If there is no media, return EFI_NO_MEDIA.

    • If the media is different, return EFI_MEDIA_CHANGED.

  3. Verify parameters

    • The Buffer, sized BufferSize, must be a whole number of blocks

    • The read does not start past the end of the media

    • The read does not extend past the end of the media

    • The Buffer is aligned as required

  4. Read the requested sectors from the media

    • If a non-blocking request is made through ReadBlocksEx(), 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 ReadBlocksEx() to inform the caller that the previous request has been completed.
  5. If needed, copy the appropriate portion of the read into Buffer.

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