[CBMFS] Fix LBA calculation in 154x images.

This commit is contained in:
2024-04-22 15:38:31 +01:00
parent 99b98bae3f
commit 2a89e1d96d
3 changed files with 24 additions and 5 deletions

View File

@@ -43,6 +43,7 @@ public sealed partial class CBM : IReadOnlyFilesystem
Dictionary<string, CachedFile> _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;
}
}

View File

@@ -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
];
}

View File

@@ -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;