mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Implement FAT12 reading.
This commit is contained in:
@@ -51,6 +51,7 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
bool fat12;
|
bool fat12;
|
||||||
bool fat16;
|
bool fat16;
|
||||||
bool fat32;
|
bool fat32;
|
||||||
|
ushort[] fatEntries;
|
||||||
ulong fatFirstSector;
|
ulong fatFirstSector;
|
||||||
ulong firstClusterSector;
|
ulong firstClusterSector;
|
||||||
bool mounted;
|
bool mounted;
|
||||||
|
|||||||
@@ -166,8 +166,6 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
|
|
||||||
uint nextCluster = startCluster;
|
uint nextCluster = startCluster;
|
||||||
|
|
||||||
if(fat12) return null;
|
|
||||||
|
|
||||||
ulong nextSector = nextCluster / fatEntriesPerSector + fatFirstSector + (useFirstFat ? 0 : sectorsPerFat);
|
ulong nextSector = nextCluster / fatEntriesPerSector + fatFirstSector + (useFirstFat ? 0 : sectorsPerFat);
|
||||||
int nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
int nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
||||||
|
|
||||||
@@ -175,7 +173,7 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
byte[] fatData = image.ReadSector(currentSector);
|
byte[] fatData = image.ReadSector(currentSector);
|
||||||
|
|
||||||
if(fat32)
|
if(fat32)
|
||||||
while((nextCluster & FAT32_MASK) > 0 && (nextCluster & FAT32_MASK) <= FAT32_BAD)
|
while((nextCluster & FAT32_MASK) > 0 && (nextCluster & FAT32_MASK) <= FAT32_FORMATTED)
|
||||||
{
|
{
|
||||||
clusters.Add(nextCluster);
|
clusters.Add(nextCluster);
|
||||||
|
|
||||||
@@ -191,7 +189,7 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
||||||
}
|
}
|
||||||
else if(fat16)
|
else if(fat16)
|
||||||
while(nextCluster > 0 && nextCluster <= FAT16_BAD)
|
while(nextCluster > 0 && nextCluster <= FAT16_FORMATTED)
|
||||||
{
|
{
|
||||||
clusters.Add(nextCluster);
|
clusters.Add(nextCluster);
|
||||||
|
|
||||||
@@ -206,6 +204,12 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
(useFirstFat ? 0 : sectorsPerFat);
|
(useFirstFat ? 0 : sectorsPerFat);
|
||||||
nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
nextEntry = (int)(nextCluster % fatEntriesPerSector);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
while(nextCluster > 0 && nextCluster <= FAT12_FORMATTED)
|
||||||
|
{
|
||||||
|
clusters.Add(nextCluster);
|
||||||
|
nextCluster = fatEntries[nextCluster];
|
||||||
|
}
|
||||||
|
|
||||||
return clusters.ToArray();
|
return clusters.ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -491,6 +491,21 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
|
|
||||||
bytesPerCluster = sectorsPerCluster * imagePlugin.Info.SectorSize;
|
bytesPerCluster = sectorsPerCluster * imagePlugin.Info.SectorSize;
|
||||||
|
|
||||||
|
if(fat12)
|
||||||
|
{
|
||||||
|
byte[] fatBytes =
|
||||||
|
imagePlugin.ReadSectors(fatFirstSector + (useFirstFat ? 0 : sectorsPerFat), sectorsPerFat);
|
||||||
|
|
||||||
|
fatEntries = new ushort[statfs.Blocks];
|
||||||
|
|
||||||
|
int pos = 0;
|
||||||
|
for(int i = 0; i + 3 < fatBytes.Length && pos < fatEntries.Length; i += 3)
|
||||||
|
{
|
||||||
|
fatEntries[pos++] = (ushort)(((fatBytes[i + 1] & 0xF) << 8) + fatBytes[i + 0]);
|
||||||
|
fatEntries[pos++] = (ushort)(((fatBytes[i + 1] & 0xF0) >> 4) + (fatBytes[i + 2] << 4));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Check how this affects international filenames
|
// TODO: Check how this affects international filenames
|
||||||
cultureInfo = new CultureInfo("en-US", false);
|
cultureInfo = new CultureInfo("en-US", false);
|
||||||
directoryCache = new Dictionary<string, Dictionary<string, DirectoryEntry>>();
|
directoryCache = new Dictionary<string, Dictionary<string, DirectoryEntry>>();
|
||||||
@@ -506,7 +521,8 @@ namespace DiscImageChef.Filesystems.FAT
|
|||||||
{
|
{
|
||||||
if(!mounted) return Errno.AccessDenied;
|
if(!mounted) return Errno.AccessDenied;
|
||||||
|
|
||||||
mounted = false;
|
mounted = false;
|
||||||
|
fatEntries = null;
|
||||||
return Errno.NoError;
|
return Errno.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user