Exemple #1
0
            public BlockStreamWriter(FragmentedFile file, long ordinal)
                : this(file)
            {
                _current = _first = new FileBlock(file._blockSize, file._useAlignedIo);
                _file.ReadBlock(ordinal, _current, file._blockSize, BlockFlags.ExternalBlock);

                if ((_current.Flags & BlockFlags.ExternalBlock) != BlockFlags.ExternalBlock)
                {
                    throw new InvalidOperationException();
                }

                if ((_current.Flags & BlockFlags.Temporary) == BlockFlags.Temporary)
                {
                    _isNew          = true;
                    _restore        = null;
                    _current.Flags &= ~BlockFlags.Temporary;
                }
                else
                {
                    _isNew               = false;
                    _restore             = _current.Clone();
                    _current.NextBlockId = 0;
                }

                _current.Length = 0;
            }
Exemple #2
0
        private bool FreeBlock(long blockId, BlockFlags expected)
        {
            using (FileBlock first = new FileBlock(_blockSize, _useAlignedIo))
            {
                ReadBlock(blockId, first, FileBlock.HeaderSize, expected | BlockFlags.BlockDeleted);

                if ((first.Flags & expected) != expected)
                {
                    return(false);
                }

                using (FileBlock last = first.Clone())
                {
                    while (last.NextBlockId != 0)
                    {
                        last.Flags = BlockFlags.BlockDeleted;

                        WriteBlock(last.BlockId, last, FileBlock.HeaderSize);
                        ReadBlock(last.NextBlockId, last, FileBlock.HeaderSize, BlockFlags.InternalBlock);
                    }

                    using (new SafeLock(_syncFreeBlock))
                    {
                        last.Flags       = BlockFlags.BlockDeleted;
                        last.NextBlockId = _nextFree;
                        WriteBlock(last.BlockId, last, FileBlock.HeaderSize);
                        _nextFree = first.BlockId;
                    }
                    return(true);
                }
            }
        }
            public BlockStreamWriter(FragmentedFile file, long ordinal)
                : this(file)
            {
                _current = _first = new FileBlock(file._blockSize, file._useAlignedIo);
                _file.ReadBlock(ordinal, _current, file._blockSize, BlockFlags.ExternalBlock);

                if ((_current.Flags & BlockFlags.ExternalBlock) != BlockFlags.ExternalBlock)
                    throw new InvalidOperationException();

                if ((_current.Flags & BlockFlags.Temporary) == BlockFlags.Temporary)
                {
                    _isNew = true;
                    _restore = null;
                    _current.Flags &= ~BlockFlags.Temporary;
                }
                else
                {
                    _isNew = false;
                    _restore = _current.Clone();
                    _current.NextBlockId = 0;
                }

                _current.Length = 0;
            }
        private bool FreeBlock(long blockId, BlockFlags expected)
        {
            using (FileBlock first = new FileBlock(_blockSize, _useAlignedIo))
            {
                ReadBlock(blockId, first, FileBlock.HeaderSize, expected | BlockFlags.BlockDeleted);

                if ((first.Flags & expected) != expected)
                    return false;

                using (FileBlock last = first.Clone())
                {
                    while (last.NextBlockId != 0)
                    {
                        last.Flags = BlockFlags.BlockDeleted;

                        WriteBlock(last.BlockId, last, FileBlock.HeaderSize);
                        ReadBlock(last.NextBlockId, last, FileBlock.HeaderSize, BlockFlags.InternalBlock);
                    }

                    using (new SafeLock(_syncFreeBlock))
                    {
                        last.Flags = BlockFlags.BlockDeleted;
                        last.NextBlockId = _nextFree;
                        WriteBlock(last.BlockId, last, FileBlock.HeaderSize);
                        _nextFree = first.BlockId;
                    }
                    return true;
                }
            }
        }