mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix some checks being ignored in savedata classes
- Return an error when an allocation table seek fails - Fix a copy/paste bug to properly error when resizing an AllocationTableStorage with not enough free space
This commit is contained in:
parent
8c61820e46
commit
49d42c5d1f
4 changed files with 16 additions and 4 deletions
|
@ -113,6 +113,7 @@ Module,DescriptionStart,DescriptionEnd,Name,Summary
|
||||||
2,4722,,SaveDataAllocationTableCorruptedInternal,
|
2,4722,,SaveDataAllocationTableCorruptedInternal,
|
||||||
2,4723,,SaveDataFileTableCorruptedInternal,
|
2,4723,,SaveDataFileTableCorruptedInternal,
|
||||||
2,4724,,AllocationTableIteratedRangeEntryInternal,
|
2,4724,,AllocationTableIteratedRangeEntryInternal,
|
||||||
|
2,4725,,InvalidAllocationTableOffset,
|
||||||
|
|
||||||
2,4741,4759,AesXtsFileSystemCorrupted,
|
2,4741,4759,AesXtsFileSystemCorrupted,
|
||||||
2,4742,,AesXtsFileHeaderTooShort,
|
2,4742,,AesXtsFileHeaderTooShort,
|
||||||
|
|
Can't render this file because it has a wrong number of fields in line 136.
|
|
@ -229,6 +229,8 @@ namespace LibHac.Fs
|
||||||
public static Result.Base SaveDataFileTableCorruptedInternal => new Result.Base(ModuleFs, 4723);
|
public static Result.Base SaveDataFileTableCorruptedInternal => new Result.Base(ModuleFs, 4723);
|
||||||
/// <summary>Error code: 2002-4724; Inner value: 0x24e802</summary>
|
/// <summary>Error code: 2002-4724; Inner value: 0x24e802</summary>
|
||||||
public static Result.Base AllocationTableIteratedRangeEntryInternal => new Result.Base(ModuleFs, 4724);
|
public static Result.Base AllocationTableIteratedRangeEntryInternal => new Result.Base(ModuleFs, 4724);
|
||||||
|
/// <summary>Error code: 2002-4725; Inner value: 0x24ea02</summary>
|
||||||
|
public static Result.Base InvalidAllocationTableOffset => new Result.Base(ModuleFs, 4725);
|
||||||
|
|
||||||
/// <summary>Error code: 2002-4741; Range: 4741-4759; Inner value: 0x250a02</summary>
|
/// <summary>Error code: 2002-4741; Range: 4741-4759; Inner value: 0x250a02</summary>
|
||||||
public static Result.Base AesXtsFileSystemCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ModuleFs, 4741, 4759); }
|
public static Result.Base AesXtsFileSystemCorrupted { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ModuleFs, 4741, 4759); }
|
||||||
|
|
|
@ -34,7 +34,11 @@ namespace LibHac.FsSystem.Save
|
||||||
while (remaining > 0)
|
while (remaining > 0)
|
||||||
{
|
{
|
||||||
int blockNum = (int)(inPos / BlockSize);
|
int blockNum = (int)(inPos / BlockSize);
|
||||||
iterator.Seek(blockNum);
|
|
||||||
|
if (!iterator.Seek(blockNum))
|
||||||
|
{
|
||||||
|
return ResultFs.InvalidAllocationTableOffset.Log();
|
||||||
|
}
|
||||||
|
|
||||||
int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
|
int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
|
||||||
long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;
|
long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;
|
||||||
|
@ -64,7 +68,11 @@ namespace LibHac.FsSystem.Save
|
||||||
while (remaining > 0)
|
while (remaining > 0)
|
||||||
{
|
{
|
||||||
int blockNum = (int)(inPos / BlockSize);
|
int blockNum = (int)(inPos / BlockSize);
|
||||||
iterator.Seek(blockNum);
|
|
||||||
|
if (!iterator.Seek(blockNum))
|
||||||
|
{
|
||||||
|
return ResultFs.InvalidAllocationTableOffset.Log();
|
||||||
|
}
|
||||||
|
|
||||||
int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
|
int segmentPos = (int)(inPos - (long)iterator.VirtualBlock * BlockSize);
|
||||||
long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;
|
long physicalOffset = iterator.PhysicalBlock * BlockSize + segmentPos;
|
||||||
|
@ -124,7 +132,7 @@ namespace LibHac.FsSystem.Save
|
||||||
if (newBlockCount > oldBlockCount)
|
if (newBlockCount > oldBlockCount)
|
||||||
{
|
{
|
||||||
int newBlocks = Fat.Allocate(newBlockCount - oldBlockCount);
|
int newBlocks = Fat.Allocate(newBlockCount - oldBlockCount);
|
||||||
if (InitialBlock == -1) throw new IOException("Not enough space to resize file.");
|
if (newBlocks == -1) throw new IOException("Not enough space to resize file.");
|
||||||
|
|
||||||
Fat.Join(InitialBlock, newBlocks);
|
Fat.Join(InitialBlock, newBlocks);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,8 @@ namespace LibHac.FsSystem.Save
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseStorage.Write(offset, source);
|
rc = BaseStorage.Write(offset, source);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
if ((options & WriteOption.Flush) != 0)
|
if ((options & WriteOption.Flush) != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue