(IntPtr buffer, ulong fileOffset, uint length)
| 752 | } |
| 753 | |
| 754 | public uint ReadBytes(IntPtr buffer, ulong fileOffset, uint length) |
| 755 | { |
| 756 | if (fileOffset >= Size) |
| 757 | return 0; |
| 758 | |
| 759 | if (fileOffset + length >= Size) |
| 760 | length = (uint)(Size - fileOffset); |
| 761 | |
| 762 | if (FakeData != null) |
| 763 | { |
| 764 | byte[] bytes2 = new byte[length]; |
| 765 | int read = 0; |
| 766 | lock (FakeData) |
| 767 | { |
| 768 | FakeData.Seek((long)fileOffset, SeekOrigin.Begin); |
| 769 | read = FakeData.Read(bytes2, 0, bytes2.Length); |
| 770 | } |
| 771 | Marshal.Copy(bytes2, 0, buffer, read); |
| 772 | return (uint)read; |
| 773 | } |
| 774 | |
| 775 | // Lock so that two threads can't try updating chain at once... |
| 776 | lock (this) |
| 777 | if (BlockChain == null) |
| 778 | BlockChain = FileSystem.StfsGetDataBlockChain(DirEntry.FirstBlockNumber); |
| 779 | |
| 780 | uint chainNum = (uint)(fileOffset / kSectorSize); |
| 781 | uint blockOffset = (uint)(fileOffset % kSectorSize); |
| 782 | |
| 783 | uint blockRemaining = kSectorSize - blockOffset; |
| 784 | uint lengthRemaining = length; |
| 785 | uint transferred = 0; |
| 786 | |
| 787 | byte[] bytes = new byte[kSectorSize]; |
| 788 | while (lengthRemaining > 0) |
| 789 | { |
| 790 | var blockNum = BlockChain[chainNum]; |
| 791 | |
| 792 | uint toRead = blockRemaining; |
| 793 | if (toRead > lengthRemaining) |
| 794 | toRead = lengthRemaining; |
| 795 | |
| 796 | int read = 0; |
| 797 | lock (FileSystem.StreamLock) |
| 798 | { |
| 799 | FileSystem.Stream.Seek((long)FileSystem.StfsDataBlockToOffset(blockNum) + blockOffset, SeekOrigin.Begin); |
| 800 | read = FileSystem.Stream.Read(bytes, 0, (int)toRead); |
| 801 | } |
| 802 | |
| 803 | Marshal.Copy(bytes, 0, buffer, read); |
| 804 | transferred += (uint)read; |
| 805 | |
| 806 | if (blockOffset + read >= kSectorSize) |
| 807 | chainNum++; |
| 808 | |
| 809 | buffer += read; |
| 810 | blockRemaining = kSectorSize; |
| 811 | blockOffset = 0; |
no test coverage detected