private void ResizeFile(long startBlock, long endBlock) { if ((startBlock & _maskVersion) != 0 || (endBlock & _maskVersion) != 0) { throw new InvalidDataException(); } using (FileBlock block = new FileBlock(_blockSize, _useAlignedIo)) using (Stream io = _streamCache.Open(FileAccess.Write)) { _header.Flags |= BlockFlags.ResizingFile; _header.NextBlockId = startBlock; io.Position = 0; _header.Write(io, FileBlock.HeaderSize); try { block.Clear(); block.Flags = BlockFlags.BlockDeleted; _nextFree = 0; for (long ix = endBlock; ix >= startBlock; ix -= _blockSize) { block.BlockId = ix; block.NextBlockId = _nextFree; _nextFree = block.BlockId; io.Position = ix & _maskOffset; block.Write(io, FileBlock.HeaderSize); } } finally { _header.Flags &= ~BlockFlags.ResizingFile; _header.NextBlockId = long.MinValue; io.Position = 0; _header.Write(io, FileBlock.HeaderSize); } } }
private void ResizeFile(long startBlock, long endBlock) { if ((startBlock & _maskVersion) != 0 || (endBlock & _maskVersion) != 0) throw new InvalidDataException(); using (FileBlock block = new FileBlock(_blockSize, _useAlignedIo)) using (Stream io = _streamCache.Open(FileAccess.Write)) { _header.Flags |= BlockFlags.ResizingFile; _header.NextBlockId = startBlock; io.Position = 0; _header.Write(io, FileBlock.HeaderSize); try { block.Clear(); block.Flags = BlockFlags.BlockDeleted; _nextFree = 0; for (long ix = endBlock; ix >= startBlock; ix -= _blockSize) { block.BlockId = ix; block.NextBlockId = _nextFree; _nextFree = block.BlockId; io.Position = ix & _maskOffset; block.Write(io, FileBlock.HeaderSize); } } finally { _header.Flags &= ~BlockFlags.ResizingFile; _header.NextBlockId = long.MinValue; io.Position = 0; _header.Write(io, FileBlock.HeaderSize); } } }