mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix bug in CachedStorage that would drop writes
If block 0 of the storage was written to before the cache was filled and then another block was accessed, any writes to block 0 would be lost.
This commit is contained in:
parent
b83fb6c7fc
commit
b9236b973a
1 changed files with 7 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace LibHac.IO
|
namespace LibHac.IO
|
||||||
|
@ -23,15 +22,14 @@ namespace LibHac.IO
|
||||||
|
|
||||||
for (int i = 0; i < cacheSize; i++)
|
for (int i = 0; i < cacheSize; i++)
|
||||||
{
|
{
|
||||||
// todo why is this rented?
|
var block = new CacheBlock { Buffer = new byte[blockSize], Index = -1 };
|
||||||
var block = new CacheBlock { Buffer = ArrayPool<byte>.Shared.Rent(blockSize) };
|
|
||||||
Blocks.AddLast(block);
|
Blocks.AddLast(block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CachedStorage(SectorStorage baseStorage, int cacheSize, bool leaveOpen)
|
public CachedStorage(SectorStorage baseStorage, int cacheSize, bool leaveOpen)
|
||||||
: this(baseStorage, baseStorage.SectorSize, cacheSize, leaveOpen) { }
|
: this(baseStorage, baseStorage.SectorSize, cacheSize, leaveOpen) { }
|
||||||
|
|
||||||
protected override void ReadImpl(Span<byte> destination, long offset)
|
protected override void ReadImpl(Span<byte> destination, long offset)
|
||||||
{
|
{
|
||||||
long remaining = destination.Length;
|
long remaining = destination.Length;
|
||||||
|
@ -124,7 +122,11 @@ namespace LibHac.IO
|
||||||
|
|
||||||
CacheBlock block = node.Value;
|
CacheBlock block = node.Value;
|
||||||
Blocks.RemoveLast();
|
Blocks.RemoveLast();
|
||||||
BlockDict.Remove(block.Index);
|
|
||||||
|
if (block.Index != -1)
|
||||||
|
{
|
||||||
|
BlockDict.Remove(block.Index);
|
||||||
|
}
|
||||||
|
|
||||||
FlushBlock(block);
|
FlushBlock(block);
|
||||||
ReadBlock(block, blockIndex);
|
ReadBlock(block, blockIndex);
|
||||||
|
|
Loading…
Reference in a new issue