Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

2.1.5.2 Server Requests a Read

The server provides:

  • Open: The Open of the DataFile to read from.

  • ByteOffset: The absolute byte offset in the stream from which to read data.

  • ByteCount: The requested number of bytes to read.

  • Unbuffered: A Boolean value. TRUE indicates that the read should be unbuffered (read directly from disk after writing and removing any cached data for this range), otherwise the value of Open.Mode.FILE_NO_INTERMEDIATE_BUFFERING should determine whether the read is unbuffered.

  • Key: A 32-bit unsigned integer containing an identifier for the open by a specific process.

On completion, the object store MUST return:

  • Status: An NTSTATUS code that specifies the result.

  • OutputBuffer: An array of bytes that were read.

  • BytesRead: The number of bytes that were read.

This operation uses the following local variables:

  • Boolean values (initialized to FALSE): IsUnbuffered

Pseudocode for the operation is as follows:

  • If Unbuffered is TRUE or Open.Mode.FILE_NO_INTERMEDIATE_BUFFERING is TRUE, then set IsUnbuffered to TRUE.

  • If IsUnbuffered is TRUE & (ByteOffset >= 0), the operation MUST be failed with STATUS_INVALID_PARAMETER under any of the following conditions:

    • (ByteOffset % Open.File.Volume.LogicalBytesPerSector) is not zero.

    • (ByteCount % Open.File.Volume.LogicalBytesPerSector) is not zero.

  • If ByteOffset is negative, then the operation MUST be failed with STATUS_INVALID_PARAMETER.

  • If (ByteOffset + ByteCount) is larger than MAXLONGLONG (0x7fffffffffffffff), the operation MUST be failed with STATUS_INVALID_PARAMETER.

  • If ByteCount is zero, the object store MUST return:

    • BytesRead set to zero.

    • Status set to STATUS_SUCCESS.

  • Set RequestedByteCount to ByteCount.

  • If Open.Stream.Oplock is not empty, the object store MUST check for an oplock break according to the algorithm in section 2.1.4.12, with input values as follows:

    • Open equal to this operation's Open

    • Oplock equal to Open.Stream.Oplock

    • Operation equal to "READ"

    • OpParams empty

  • Determine if the read is in conflict with an existing byte range lock on Open.Stream using the algorithm described in section 2.1.4.10 (with ByteOffset set to ByteOffset, Length set to ByteCount, IsExclusive set to FALSE, LockIntent set to FALSE, server provided Key and Open set to Open). If the algorithm returns TRUE, the operation MUST be failed with STATUS_FILE_LOCK_CONFLICT.

  • If ByteOffset >= Open.Stream.Size, the operation MUST be failed with STATUS_END_OF_FILE.

  • If (ByteOffset + ByteCount) >= Open.Stream.Size, truncate ByteCount to (Open.Stream.Size - ByteOffset) and then set RequestedByteCount to ByteCount.

  • If IsUnbuffered is TRUE:

    • The object store MUST write any unwritten cached data for this range of the stream to disk.

    • The object store MUST remove from the cache any cached data for this range of the stream.

    • If (ByteOffset >= Open.Stream.ValidDataLength):

      • If Open.Mode.FILE_SYNCHRONOUS_IO_ALERT is TRUE or Open.Mode.FILE_SYNCHRONOUS_IO_NONALERT is TRUE, the object store MUST set Open.CurrentByteOffset to (ByteOffset + ByteCount).

      • If Open.File.UserSetAccessTime is FALSE, the object store MUST update Open.File.LastAccessTime to the current system time.

      • The object store MUST return:

        • BytesRead set to ByteCount.

        • OutputBuffer filled with ByteCount zero(s).

        • Status set to STATUS_SUCCESS.

    • EndIf

    • If ((ByteOffset + ByteCount) >= Open.Stream.ValidDataLength), truncate ByteCount to (Open.Stream.ValidDataLength - ByteOffset).

    • Set BytesToRead to BlockAlign(ByteCount, Open.File.Volume.LogicalBytesPerSector).

    • Read BytesToRead bytes from the disk at offset ByteOffset for this stream into OutputBuffer. If the read from the disk failed, the operation MUST be failed with the same error status.

    • If RequestedByteCount > ByteCount, zero out OutputBuffer between ByteCount and RequestedByteCount.

    • If Open.Mode.FILE_SYNCHRONOUS_IO_ALERT is TRUE or Open.Mode.FILE_SYNCHRONOUS_IO_NONALERT is TRUE, the object store MUST set Open.CurrentByteOffset to (ByteOffset + RequestedByteCount).

    • If Open.File.UserSetAccessTime is FALSE, the object store MUST update Open.File.LastAccessTime to the current system time.

    • Upon successful completion of the operation, the object store MUST return:

      • BytesRead set to RequestedByteCount.

      • Status set to STATUS_SUCCESS.

  • Else

    • Read ByteCount bytes at offset ByteOffset from the cache for this stream into OutputBuffer.

    • If Open.Mode.FILE_SYNCHRONOUS_IO_ALERT is TRUE or Open.Mode.FILE_SYNCHRONOUS_IO_NONALERT is TRUE, the object store MUST set Open.CurrentByteOffset to (ByteOffset + ByteCount).

    • If Open.File.UserSetAccessTime is FALSE, the object store MUST update Open.File.LastAccessTime to the current system time.

    • Upon successful completion of the operation, the object store MUST return:

      • BytesRead set to ByteCount.

      • Status set to STATUS_SUCCESS.

  • EndIf

Show:
© 2016 Microsoft