Freigeben über


2.1.5.10.39.1 Algorithm to Zero Data Beyond ValidDataLength

This algorithm returns no value.

The inputs for the algorithm are:

  • ThisOpen: The Open for the stream being zeroed.

  • StartingZero: A 64-bit signed integer. The offset into the stream to begin zeroing.

  • ByteCount: The number of bytes to zero.

The algorithm uses the following local variables:

  • 64-bit signed integers: ZeroStart, BeyondZeroEnd, LastCompressionUnit, ClustersToDeallocate

Pseudocode for the algorithm is as follows:

  • Set ZeroStart to BlockAlign(StartingZero, ThisOpen.File.Volume.LogicalBytesPerSector).

  • Set BeyondZeroEnd to BlockAlign(StartingZero + ByteCount, ThisOpen.File.Volume.LogicalBytesPerSector).

  • If (ThisOpen.Stream.IsCompressed is FALSE) and (ThisOpen.Stream.IsSparse is FALSE) and (ZeroStart != StartingZero):

    • The object store MUST write zeroes into the stream from StartingZero to ZeroStart.

  • EndIf

  • If ((ThisOpen.Stream.IsCompressed is TRUE) or

    (ThisOpen.Stream.IsSparse is TRUE)) and

    (ByteCount > ThisOpen.File.Volume.CompressionUnitSize * 2):

    • If BlockAlign(ZeroStart, ThisOpen.File.Volume.CompressionUnitSize) != ZeroStart:

      • The object store MUST write zeroes into the stream from ZeroStart to BlockAlign(ZeroStart, ThisOpen.File.Volume.CompressionUnitSize).

      • The object store MUST set ThisOpen.Stream.ValidDataLength to BlockAlign(ZeroStart, ThisOpen.File.Volume.CompressionUnitSize).

      • Set ZeroStart equal to BlockAlign(ZeroStart, ThisOpen.File.Volume.CompressionUnitSize).

    • EndIf

    • Set LastCompressionUnit equal to BlockAlignTruncate(BeyondZeroEnd, ThisOpen.File.Volume.CompressionUnitSize).

    • Set ClustersToDeallocate equal to ClustersFromBytes(ThisOpen.File.Volume, LastCompressionUnit - ZeroStart).

    • The object store MUST delete ClusterToDeallocate clusters of allocation from the stream starting with the cluster at ClustersFromBytes(ThisOpen.File.Volume, ZeroStart).

    • If LastCompressionUnit != BeyondZeroEnd:

      • The object store MUST write zeroes into the stream from LastCompressionUnit to BeyondZeroEnd.

      • The object store MUST set ThisOpen.Stream.ValidDataLength equal to StartingZero + ByteCount.

    • EndIf

    • The algorithm returns at this point.

  • EndIf

  • If ZeroStart = BeyondZeroEnd

    • The algorithm returns at this point.

  • EndIf

  • The object store MUST write zeroes into the stream from ZeroStart to BeyondZeroEnd.

  • The object store MUST set ThisOpen.Stream.ValidDataLength equal to StartingZero + ByteCount.