public void SetUsingSectors(IEnumerable <long> sectors) { foreach (var sector in sectors) { if (!_bitmapManager.Get(sector)) { _bitmapManager.Set(sector, true); _usingSectorCount++; } } _freeSectors.ExceptWith(sectors); }
public Task CheckBlocks(Action <CheckBlocksProgressReport> progress, CancellationToken token) { return(Task.Run(() => { // 重複するセクタを確保したブロックを検出しRemoveする。 lock (_lockObject) { using (var bitmapManager = new BitmapManager(_bufferManager)) { bitmapManager.SetLength(this.Size / SectorSize); var hashes = new List <Hash>(); foreach (var(hash, clusterInfo) in _clusterIndex) { foreach (var sector in clusterInfo.Indexes) { if (!bitmapManager.Get(sector)) { bitmapManager.Set(sector, true); } else { hashes.Add(hash); break; } } } foreach (var hash in hashes) { this.Remove(hash); } } } // 読めないブロックを検出しRemoveする。 { var list = this.ToArray(); int badCount = 0; int checkedCount = 0; int blockCount = list.Length; token.ThrowIfCancellationRequested(); progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); foreach (var hash in list) { token.ThrowIfCancellationRequested(); ArraySegment <byte>?block = null; try { lock (_lockObject) { if (this.Contains(hash)) { block = this.Get(hash); if (block == null) { badCount++; } } } } catch (Exception) { } finally { if (block != null) { _bufferManager.ReturnBuffer(block.Value.Array); } } checkedCount++; if (checkedCount % 32 == 0) { progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); } } progress.Invoke(new CheckBlocksProgressReport(badCount, checkedCount, blockCount)); } }, token)); }