Fix cluster numbering calculations in FAT12 and FAT16.

This commit is contained in:
2019-04-27 16:44:18 +01:00
parent 2a969452c9
commit 574e80cd6e
2 changed files with 10 additions and 6 deletions

View File

@@ -115,8 +115,9 @@ namespace DiscImageChef.Filesystems.FAT
for(int i = 0; i < clusters.Length; i++) for(int i = 0; i < clusters.Length; i++)
{ {
byte[] buffer = image.ReadSectors(firstClusterSector + (clusters[i] - 2) * sectorsPerCluster, byte[] buffer =
sectorsPerCluster); image.ReadSectors(firstClusterSector + (ulong)((clusters[i] - (fat32 ? 2 : 0)) * sectorsPerCluster),
sectorsPerCluster);
Array.Copy(buffer, 0, directoryBuffer, i * bytesPerCluster, bytesPerCluster); Array.Copy(buffer, 0, directoryBuffer, i * bytesPerCluster, bytesPerCluster);
} }

View File

@@ -56,7 +56,8 @@ namespace DiscImageChef.Filesystems.FAT
if(fileBlock >= clusters.Length) return Errno.InvalidArgument; if(fileBlock >= clusters.Length) return Errno.InvalidArgument;
deviceBlock = (long)(firstClusterSector + (clusters[fileBlock] - 2) * sectorsPerCluster); deviceBlock = (long)(firstClusterSector +
(ulong)((clusters[fileBlock] - (fat32 ? 2 : 0)) * sectorsPerCluster));
return Errno.NoError; return Errno.NoError;
} }
@@ -103,7 +104,7 @@ 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] - 2) * 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);
@@ -143,8 +144,10 @@ namespace DiscImageChef.Filesystems.FAT
if(entry.attributes.HasFlag(FatAttributes.Subdirectory)) if(entry.attributes.HasFlag(FatAttributes.Subdirectory))
{ {
stat.Attributes |= FileAttributes.Directory; stat.Attributes |= FileAttributes.Directory;
stat.Blocks = fat32 ? GetClusters((uint)((entry.ea_handle << 16) + entry.start_cluster)).Length : GetClusters(entry.start_cluster).Length; stat.Blocks = fat32
stat.Length = stat.Blocks * stat.BlockSize; ? GetClusters((uint)((entry.ea_handle << 16) + entry.start_cluster)).Length
: GetClusters(entry.start_cluster).Length;
stat.Length = stat.Blocks * stat.BlockSize;
} }
if(entry.attributes.HasFlag(FatAttributes.ReadOnly)) stat.Attributes |= FileAttributes.ReadOnly; if(entry.attributes.HasFlag(FatAttributes.ReadOnly)) stat.Attributes |= FileAttributes.ReadOnly;