Fix cluster start calculation for FAT32.

This commit is contained in:
2019-04-28 17:44:47 +01:00
parent 7b3d5d3f11
commit baf6f46eb2
4 changed files with 11 additions and 18 deletions

View File

@@ -115,16 +115,14 @@ namespace DiscImageChef.Filesystems.FAT
for(int i = 0; i < clusters.Length; i++) for(int i = 0; i < clusters.Length; i++)
{ {
byte[] buffer = byte[] buffer = image.ReadSectors(firstClusterSector + clusters[i] * sectorsPerCluster,
image.ReadSectors(firstClusterSector + (ulong)((clusters[i] - (fat32 ? 2 : 0)) * sectorsPerCluster), sectorsPerCluster);
sectorsPerCluster);
Array.Copy(buffer, 0, directoryBuffer, i * bytesPerCluster, bytesPerCluster); Array.Copy(buffer, 0, directoryBuffer, i * bytesPerCluster, bytesPerCluster);
} }
currentDirectory = new Dictionary<string, CompleteDirectoryEntry>(); currentDirectory = new Dictionary<string, CompleteDirectoryEntry>();
byte[] lastLfnName = null; byte[] lastLfnName = null;
byte lastLfnChecksum = 0; byte lastLfnChecksum = 0;
List<string> LFNs = new List<string>();
for(int pos = 0; pos < directoryBuffer.Length; pos += Marshal.SizeOf<DirectoryEntry>()) for(int pos = 0; pos < directoryBuffer.Length; pos += Marshal.SizeOf<DirectoryEntry>())
{ {

View File

@@ -56,8 +56,7 @@ namespace DiscImageChef.Filesystems.FAT
if(fileBlock >= clusters.Length) return Errno.InvalidArgument; if(fileBlock >= clusters.Length) return Errno.InvalidArgument;
deviceBlock = (long)(firstClusterSector + deviceBlock = (long)(firstClusterSector + clusters[fileBlock] * sectorsPerCluster);
(ulong)((clusters[fileBlock] - (fat32 ? 2 : 0)) * sectorsPerCluster));
return Errno.NoError; return Errno.NoError;
} }
@@ -103,9 +102,8 @@ namespace DiscImageChef.Filesystems.FAT
{ {
if(i + firstCluster >= clusters.Length) return Errno.InvalidArgument; if(i + firstCluster >= clusters.Length) return Errno.InvalidArgument;
byte[] buffer = byte[] buffer = image.ReadSectors(firstClusterSector + clusters[i + firstCluster] * sectorsPerCluster,
image.ReadSectors(firstClusterSector + (ulong)((clusters[i + firstCluster] - (fat32 ? 2 : 0)) * sectorsPerCluster), sectorsPerCluster);
sectorsPerCluster);
ms.Write(buffer, 0, buffer.Length); ms.Write(buffer, 0, buffer.Length);
} }

View File

@@ -192,9 +192,8 @@ namespace DiscImageChef.Filesystems.FAT
// First root directory sector // First root directory sector
firstClusterSector = firstClusterSector =
(ulong)((fat32Bpb.root_cluster - 2) * fat32Bpb.spc + fat32Bpb.big_spfat * fat32Bpb.fats_no + (ulong)(fat32Bpb.big_spfat * fat32Bpb.fats_no + fat32Bpb.rsectors) * sectorsPerRealSector -
fat32Bpb.rsectors) * sectorsPerRealSector; 2 * sectorsPerCluster;
sectorsForRootDirectory = 1;
if(fat32Bpb.fsinfo_sector + partition.Start <= partition.End) if(fat32Bpb.fsinfo_sector + partition.Start <= partition.End)
{ {
@@ -396,8 +395,7 @@ namespace DiscImageChef.Filesystems.FAT
foreach(uint cluster in rootDirectoryClusters) foreach(uint cluster in rootDirectoryClusters)
{ {
byte[] buffer = byte[] buffer =
imagePlugin.ReadSectors(firstClusterSector + (cluster - 2) * sectorsPerCluster, imagePlugin.ReadSectors(firstClusterSector + cluster * sectorsPerCluster, sectorsPerCluster);
sectorsPerCluster);
rootMs.Write(buffer, 0, buffer.Length); rootMs.Write(buffer, 0, buffer.Length);
} }

View File

@@ -129,8 +129,7 @@ namespace DiscImageChef.Filesystems.FAT
foreach(uint cluster in rootDirectoryClusters) foreach(uint cluster in rootDirectoryClusters)
{ {
byte[] buffer = image.ReadSectors(firstClusterSector + (cluster - 2) * sectorsPerCluster, byte[] buffer = image.ReadSectors(firstClusterSector + cluster * sectorsPerCluster, sectorsPerCluster);
sectorsPerCluster);
eaMs.Write(buffer, 0, buffer.Length); eaMs.Write(buffer, 0, buffer.Length);
} }