Exemple #1
0
        protected override void WriteImpl(ReadOnlySpan <byte> source, long offset)
        {
            var iterator = new AllocationTableIterator(Fat, InitialBlock);

            long inPos     = offset;
            int  outPos    = 0;
            int  remaining = source.Length;

            while (remaining > 0)
            {
                int blockNum = (int)(inPos / BlockSize);
                iterator.Seek(blockNum);

                int  segmentPos     = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
                long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;

                int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos;
                int bytesToWrite       = Math.Min(remaining, remainingInSegment);

                BaseStorage.Write(source.Slice(outPos, bytesToWrite), physicalOffset);

                outPos    += bytesToWrite;
                inPos     += bytesToWrite;
                remaining -= bytesToWrite;
            }
        }
Exemple #2
0
        protected override void ReadImpl(Span <byte> destination, long offset)
        {
            var iterator = new AllocationTableIterator(Fat, InitialBlock);

            long inPos     = offset;
            int  outPos    = 0;
            int  remaining = destination.Length;

            while (remaining > 0)
            {
                int blockNum = (int)(inPos / BlockSize);
                iterator.Seek(blockNum);

                int  segmentPos     = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
                long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;

                int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos;
                int bytesToRead        = Math.Min(remaining, remainingInSegment);

                BaseStorage.Read(destination.Slice(outPos, bytesToRead), physicalOffset);

                outPos    += bytesToRead;
                inPos     += bytesToRead;
                remaining -= bytesToRead;
            }
        }
Exemple #3
0
        public static IEnumerable <(int block, int length)> DumpChain(this AllocationTable table, int startBlock)
        {
            var iterator = new AllocationTableIterator(table, startBlock);

            do
            {
                yield return(iterator.PhysicalBlock, iterator.CurrentSegmentSize);
            } while (iterator.MoveNext());
        }