private void add(long offset, long length, byte b) //called on different thread to IsScrubbed { //round to the nearest block start if (offset % 0x7c00L != 0) { length += offset % 0x7c00L; offset -= offset % 0x7c00L; } if (length % 0x7c00L != 0) { length += 0x7c00L - (length % 0x7c00L); //pad to block end } offset = (long)(offset / 0x7c00L) * 0x8000L; length = (long)(length / 0x7c00L) * 0x8000L; if (_last != null && _last.Byte == b && offset >= _last.Offset && offset <= _last.Offset + _last.Length) //extend { if (offset + length > _last.Offset + _last.Length) { _last.Length = (offset + length) - _last.Offset; } } else { _last = new ScrubRegion() { Offset = offset, Length = length, Byte = b }; lock (_scrub) _scrub.Enqueue(_last); _cache.Add(_last); } }
private bool isBlockScrubbed(ScrubRegion region, long offset, out byte scrubByte) { scrubByte = 0; if (region != null) { if ((offset >= region.Offset && offset < region.Offset + region.Length)) { scrubByte = region.Byte; return(true); } } return(false); }
public bool IsBlockScrubbedScanMode(long offset, out byte scrubByte) { if (_next == null || _next.Offset + _next.Length < offset) { lock (_scrub) { if (_scrub.Count != 0) { _next = _scrub.Dequeue(); } else { _next = null; } } } return(isBlockScrubbed(_next, offset, out scrubByte)); }