mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix bugs when running out of save data space
This commit is contained in:
parent
47ba61db45
commit
26ac0ed975
2 changed files with 11 additions and 6 deletions
|
@ -154,27 +154,27 @@ namespace LibHac.IO.Save
|
|||
public int Trim(int listHeadBlockIndex, int newListLength)
|
||||
{
|
||||
int blocksRemaining = newListLength;
|
||||
int next = BlockToEntryIndex(listHeadBlockIndex);
|
||||
int nextEntry = BlockToEntryIndex(listHeadBlockIndex);
|
||||
int listAIndex = -1;
|
||||
int listBIndex = -1;
|
||||
|
||||
while (blocksRemaining > 0)
|
||||
{
|
||||
if (next < 0)
|
||||
if (nextEntry == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int currentEntryIndex = next;
|
||||
int currentEntryIndex = nextEntry;
|
||||
|
||||
ReadEntry(EntryIndexToBlock(currentEntryIndex), out next, out int _, out int segmentLength);
|
||||
ReadEntry(EntryIndexToBlock(currentEntryIndex), out int nextBlock, out int _, out int segmentLength);
|
||||
|
||||
next = BlockToEntryIndex(next);
|
||||
nextEntry = BlockToEntryIndex(nextBlock);
|
||||
|
||||
if (segmentLength == blocksRemaining)
|
||||
{
|
||||
listAIndex = currentEntryIndex;
|
||||
listBIndex = next;
|
||||
listBIndex = nextEntry;
|
||||
}
|
||||
else if (segmentLength > blocksRemaining)
|
||||
{
|
||||
|
|
|
@ -39,6 +39,11 @@ namespace LibHac.IO.Save
|
|||
int blockCount = (int)Util.DivideByRoundUp(size, AllocationTable.Header.BlockSize);
|
||||
int startBlock = AllocationTable.Allocate(blockCount);
|
||||
|
||||
if (startBlock == -1)
|
||||
{
|
||||
throw new IOException("Not enough available space to create file.");
|
||||
}
|
||||
|
||||
var fileEntry = new SaveFileInfo { StartBlock = startBlock, Length = size };
|
||||
|
||||
FileTable.AddFile(path, ref fileEntry);
|
||||
|
|
Loading…
Reference in a new issue