diff --git a/Aaru.Filesystems/CBM/CBM.cs b/Aaru.Filesystems/CBM/CBM.cs index 7224ee55b..62ea60123 100644 --- a/Aaru.Filesystems/CBM/CBM.cs +++ b/Aaru.Filesystems/CBM/CBM.cs @@ -43,6 +43,7 @@ public sealed partial class CBM : IReadOnlyFilesystem Dictionary _cache; bool _debug; byte[] _diskHeader; + bool _is1581; bool _mounted; byte[] _root; FileSystemInfo _statfs; @@ -95,4 +96,15 @@ public sealed partial class CBM : IReadOnlyFilesystem "debug", false.ToString() } }; + + ulong CbmChsToLba(byte track, byte sector, bool is1581) + { + if(track == 0 || track > 40) + return 0; + + if(is1581) + return (ulong)((track - 1) * 40 + sector - 1); + + return trackStartingLbas[track - 1] + sector; + } } \ No newline at end of file diff --git a/Aaru.Filesystems/CBM/Consts.cs b/Aaru.Filesystems/CBM/Consts.cs index 14239a8c3..30bc86f0f 100644 --- a/Aaru.Filesystems/CBM/Consts.cs +++ b/Aaru.Filesystems/CBM/Consts.cs @@ -33,4 +33,10 @@ namespace Aaru.Filesystems; public sealed partial class CBM { const string FS_TYPE = "cbmfs"; + + readonly ulong[] trackStartingLbas = + [ + 0, 21, 42, 63, 84, 105, 126, 147, 168, 189, 210, 231, 252, 273, 294, 315, 336, 357, 376, 395, 414, 433, 452, + 471, 490, 508, 526, 544, 562, 580, 598, 615, 632, 649, 666, 683, 700, 717, 734, 751 + ]; } \ No newline at end of file diff --git a/Aaru.Filesystems/CBM/Super.cs b/Aaru.Filesystems/CBM/Super.cs index 674debd5f..352a7bb34 100644 --- a/Aaru.Filesystems/CBM/Super.cs +++ b/Aaru.Filesystems/CBM/Super.cs @@ -115,10 +115,11 @@ public sealed partial class CBM if(cbmHdr.directoryTrack == 0) return ErrorNumber.InvalidArgument; - rootLba = (ulong)((cbmHdr.directoryTrack - 1) * 40 + cbmHdr.directorySector - 1); + rootLba = CbmChsToLba(cbmHdr.directoryTrack, cbmHdr.directorySector, true); serial = cbmHdr.diskId; Metadata.VolumeName = StringHandlers.CToString(cbmHdr.name, encoding); Metadata.VolumeSerial = $"{cbmHdr.diskId}"; + _is1581 = true; } else { @@ -133,7 +134,7 @@ public sealed partial class CBM and { unused1 : 0x00, directoryTrack: 0x12 })) return ErrorNumber.InvalidArgument; - rootLba = (ulong)((cbmBam.directoryTrack - 1) * 40 + cbmBam.directorySector - 1); + rootLba = CbmChsToLba(cbmBam.directoryTrack, cbmBam.directorySector, false); serial = cbmBam.diskId; Metadata.VolumeName = StringHandlers.CToString(cbmBam.name, encoding); @@ -159,7 +160,7 @@ public sealed partial class CBM if(sector[0] == 0) break; - nextLba = (ulong)((sector[0] - 1) * 40 + sector[1] - 1); + nextLba = CbmChsToLba(sector[0], sector[1], _is1581); } while(nextLba > 0); _root = rootMs.ToArray(); @@ -254,7 +255,7 @@ public sealed partial class CBM var data = new MemoryStream(); - nextLba = (ulong)((dirEntry.firstFileBlockTrack - 1) * 40 + dirEntry.firstFileBlockSector - 1); + nextLba = CbmChsToLba(dirEntry.firstFileBlockTrack, dirEntry.firstFileBlockSector, _is1581); _statfs.FreeBlocks -= (ulong)dirEntry.blocks; @@ -272,7 +273,7 @@ public sealed partial class CBM if(sector[0] == 0) break; - nextLba = (ulong)((sector[0] - 1) * 40 + sector[1] - 1); + nextLba = CbmChsToLba(sector[0], sector[1], _is1581); } FileAttributes attributes = FileAttributes.File;