mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[FAT] Fix that first 2 FAT entries are not considered part of the allocation ones, allocating two more.
This commit is contained in:
@@ -726,7 +726,8 @@ public sealed partial class FAT
|
||||
{
|
||||
if(clusters < 4089)
|
||||
{
|
||||
ushort[] fat12 = new ushort[clusters];
|
||||
// The first 2 FAT entries do not count as allocation clusters in FAT12 and FAT16
|
||||
ushort[] fat12 = new ushort[clusters + 2];
|
||||
|
||||
_reservedSectors = fakeBpb.rsectors;
|
||||
sectorsPerRealSector = fakeBpb.bps / imagePlugin.Info.SectorSize;
|
||||
@@ -751,14 +752,14 @@ public sealed partial class FAT
|
||||
|
||||
bool fat12Valid = fat12[0] >= FAT12_RESERVED && fat12[1] >= FAT12_RESERVED;
|
||||
|
||||
if(fat12.Any(entry => entry < FAT12_RESERVED && entry > clusters))
|
||||
if(fat12.Any(entry => entry < FAT12_RESERVED && entry > clusters + 2))
|
||||
fat12Valid = false;
|
||||
|
||||
ushort[] fat16 = MemoryMarshal.Cast<byte, ushort>(fatBytes).ToArray();
|
||||
|
||||
bool fat16Valid = fat16[0] >= FAT16_RESERVED && fat16[1] >= 0x3FF0;
|
||||
|
||||
if(fat16.Any(entry => entry < FAT16_RESERVED && entry > clusters))
|
||||
if(fat16.Any(entry => entry < FAT16_RESERVED && entry > clusters + 2))
|
||||
fat16Valid = false;
|
||||
|
||||
isFat12 = fat12Valid;
|
||||
|
||||
@@ -315,7 +315,7 @@ public sealed partial class FAT
|
||||
{
|
||||
if(clusters < 4089)
|
||||
{
|
||||
ushort[] fat12 = new ushort[clusters];
|
||||
ushort[] fat12 = new ushort[clusters + 1];
|
||||
|
||||
_reservedSectors = fakeBpb.rsectors;
|
||||
sectorsPerRealSector = fakeBpb.bps / imagePlugin.Info.SectorSize;
|
||||
@@ -782,8 +782,9 @@ public sealed partial class FAT
|
||||
|
||||
_bytesPerCluster = _sectorsPerCluster * imagePlugin.Info.SectorSize;
|
||||
|
||||
ushort[] firstFatEntries = new ushort[_statfs.Blocks];
|
||||
ushort[] secondFatEntries = new ushort[_statfs.Blocks];
|
||||
// The first 2 FAT entries do not count as allocation clusters in FAT12 and FAT16
|
||||
ushort[] firstFatEntries = new ushort[_statfs.Blocks + 2];
|
||||
ushort[] secondFatEntries = new ushort[_statfs.Blocks + 2];
|
||||
bool firstFatValid = true;
|
||||
bool secondFatValid = true;
|
||||
|
||||
@@ -813,7 +814,7 @@ public sealed partial class FAT
|
||||
if(errno != ErrorNumber.NoError)
|
||||
return errno;
|
||||
|
||||
_fatEntries = new ushort[_statfs.Blocks];
|
||||
_fatEntries = new ushort[_statfs.Blocks + 2];
|
||||
|
||||
pos = 0;
|
||||
|
||||
@@ -827,10 +828,10 @@ public sealed partial class FAT
|
||||
secondFatEntries[pos++] = (ushort)(((fatBytes[i + 1] & 0xF0) >> 4) + (fatBytes[i + 2] << 4));
|
||||
}
|
||||
|
||||
if(firstFatEntries.Any(entry => entry < FAT12_RESERVED && entry > _statfs.Blocks))
|
||||
if(firstFatEntries.Any(entry => entry < FAT12_RESERVED && entry > _statfs.Blocks + 2))
|
||||
firstFatValid = false;
|
||||
|
||||
if(secondFatEntries.Any(entry => entry < FAT12_RESERVED && entry > _statfs.Blocks))
|
||||
if(secondFatEntries.Any(entry => entry < FAT12_RESERVED && entry > _statfs.Blocks + 2))
|
||||
secondFatValid = false;
|
||||
|
||||
if(firstFatValid == secondFatValid)
|
||||
@@ -860,10 +861,10 @@ public sealed partial class FAT
|
||||
AaruConsole.DebugWriteLine("FAT plugin", Localization.Casting_FAT);
|
||||
secondFatEntries = MemoryMarshal.Cast<byte, ushort>(fatBytes).ToArray();
|
||||
|
||||
if(firstFatEntries.Any(entry => entry < FAT16_RESERVED && entry > _statfs.Blocks))
|
||||
if(firstFatEntries.Any(entry => entry < FAT16_RESERVED && entry > _statfs.Blocks + 2))
|
||||
firstFatValid = false;
|
||||
|
||||
if(secondFatEntries.Any(entry => entry < FAT16_RESERVED && entry > _statfs.Blocks))
|
||||
if(secondFatEntries.Any(entry => entry < FAT16_RESERVED && entry > _statfs.Blocks + 2))
|
||||
secondFatValid = false;
|
||||
|
||||
if(firstFatValid == secondFatValid)
|
||||
|
||||
Reference in New Issue
Block a user