Update ReadSector and ReadSectors methods to include sector status output

This commit is contained in:
2025-10-22 14:28:58 +01:00
parent 1003088cc3
commit 0ac2a48fb6
238 changed files with 5881 additions and 5196 deletions

View File

@@ -56,19 +56,21 @@ public sealed partial class ProDOSPlugin
{
if(partition.Length < 3) return false;
uint multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
var multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
// Blocks 0 and 1 are boot code
ErrorNumber errno =
imagePlugin.ReadSectors(2 * multiplier + partition.Start, multiplier, out byte[] rootDirectoryKeyBlock);
ErrorNumber errno = imagePlugin.ReadSectors(2 * multiplier + partition.Start,
multiplier,
out byte[] rootDirectoryKeyBlock,
out _);
if(errno != ErrorNumber.NoError) return false;
bool apmFromHddOnCd = false;
var apmFromHddOnCd = false;
if(imagePlugin.Info.SectorSize is 2352 or 2448 or 2048)
{
errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] tmp);
errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] tmp, out _);
if(errno != ErrorNumber.NoError) return false;
@@ -88,12 +90,12 @@ public sealed partial class ProDOSPlugin
}
}
ushort prePointer = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0);
var prePointer = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0);
AaruLogging.Debug(MODULE_NAME, "prePointer = {0}", prePointer);
if(prePointer != 0) return false;
byte storageType = (byte)((rootDirectoryKeyBlock[0x04] & STORAGE_TYPE_MASK) >> 4);
var storageType = (byte)((rootDirectoryKeyBlock[0x04] & STORAGE_TYPE_MASK) >> 4);
AaruLogging.Debug(MODULE_NAME, "storage_type = {0}", storageType);
if(storageType != ROOT_DIRECTORY_TYPE) return false;
@@ -108,21 +110,21 @@ public sealed partial class ProDOSPlugin
if(entriesPerBlock != ENTRIES_PER_BLOCK) return false;
ushort bitMapPointer = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0x27);
var bitMapPointer = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0x27);
AaruLogging.Debug(MODULE_NAME, "bit_map_pointer = {0}", bitMapPointer);
if(bitMapPointer > partition.End) return false;
ushort totalBlocks = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0x29);
var totalBlocks = BitConverter.ToUInt16(rootDirectoryKeyBlock, 0x29);
if(apmFromHddOnCd) totalBlocks /= 4;
AaruLogging.Debug(MODULE_NAME,
"{0} <= ({1} - {2} + 1)? {3}",
totalBlocks,
partition.End,
partition.Start,
totalBlocks <= partition.End - partition.Start + 1);
"{0} <= ({1} - {2} + 1)? {3}",
totalBlocks,
partition.End,
partition.Start,
totalBlocks <= partition.End - partition.Start + 1);
return totalBlocks <= partition.End - partition.Start + 1;
}
@@ -134,21 +136,22 @@ public sealed partial class ProDOSPlugin
encoding ??= new Apple2c();
information = "";
metadata = new FileSystem();
var sbInformation = new StringBuilder();
uint multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
var sbInformation = new StringBuilder();
var multiplier = (uint)(imagePlugin.Info.SectorSize == 256 ? 2 : 1);
// Blocks 0 and 1 are boot code
ErrorNumber errno = imagePlugin.ReadSectors(2 * multiplier + partition.Start,
multiplier,
out byte[] rootDirectoryKeyBlockBytes);
out byte[] rootDirectoryKeyBlockBytes,
out _);
if(errno != ErrorNumber.NoError) return;
bool apmFromHddOnCd = false;
var apmFromHddOnCd = false;
if(imagePlugin.Info.SectorSize is 2352 or 2448 or 2048)
{
errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] tmp);
errno = imagePlugin.ReadSectors(partition.Start, 2, out byte[] tmp, out _);
if(errno != ErrorNumber.NoError) return;
@@ -177,24 +180,24 @@ public sealed partial class ProDOSPlugin
rootDirectoryKeyBlock.header.storage_type = (byte)((rootDirectoryKeyBlockBytes[0x04] & STORAGE_TYPE_MASK) >> 4);
rootDirectoryKeyBlock.header.name_length = (byte)(rootDirectoryKeyBlockBytes[0x04] & NAME_LENGTH_MASK);
byte[] temporal = new byte[rootDirectoryKeyBlock.header.name_length];
var temporal = new byte[rootDirectoryKeyBlock.header.name_length];
Array.Copy(rootDirectoryKeyBlockBytes, 0x05, temporal, 0, rootDirectoryKeyBlock.header.name_length);
rootDirectoryKeyBlock.header.volume_name = encoding.GetString(temporal);
rootDirectoryKeyBlock.header.reserved = BitConverter.ToUInt64(rootDirectoryKeyBlockBytes, 0x14);
ushort tempTimestampLeft = BitConverter.ToUInt16(rootDirectoryKeyBlockBytes, 0x1C);
ushort tempTimestampRight = BitConverter.ToUInt16(rootDirectoryKeyBlockBytes, 0x1E);
var tempTimestampLeft = BitConverter.ToUInt16(rootDirectoryKeyBlockBytes, 0x1C);
var tempTimestampRight = BitConverter.ToUInt16(rootDirectoryKeyBlockBytes, 0x1E);
bool dateCorrect;
try
{
uint tempTimestamp = (uint)((tempTimestampLeft << 16) + tempTimestampRight);
int year = (int)((tempTimestamp & YEAR_MASK) >> 25);
int month = (int)((tempTimestamp & MONTH_MASK) >> 21);
int day = (int)((tempTimestamp & DAY_MASK) >> 16);
int hour = (int)((tempTimestamp & HOUR_MASK) >> 8);
int minute = (int)(tempTimestamp & MINUTE_MASK);
var tempTimestamp = (uint)((tempTimestampLeft << 16) + tempTimestampRight);
var year = (int)((tempTimestamp & YEAR_MASK) >> 25);
var month = (int)((tempTimestamp & MONTH_MASK) >> 21);
var day = (int)((tempTimestamp & DAY_MASK) >> 16);
var hour = (int)((tempTimestamp & HOUR_MASK) >> 8);
var minute = (int)(tempTimestamp & MINUTE_MASK);
year += 1900;
if(year < 1940) year += 100;
@@ -204,12 +207,12 @@ public sealed partial class ProDOSPlugin
AaruLogging.Debug(MODULE_NAME, "temp_timestamp = 0x{0:X8}", tempTimestamp);
AaruLogging.Debug(MODULE_NAME,
Localization.Datetime_field_year_0_month_1_day_2_hour_3_minute_4,
year,
month,
day,
hour,
minute);
Localization.Datetime_field_year_0_month_1_day_2_hour_3_minute_4,
year,
month,
day,
hour,
minute);
rootDirectoryKeyBlock.header.creation_time = new DateTime(year, month, day, hour, minute, 0);
dateCorrect = true;
@@ -305,8 +308,8 @@ public sealed partial class ProDOSPlugin
if((rootDirectoryKeyBlock.header.access & RESERVED_ATTRIBUTE_MASK) != 0)
{
AaruLogging.Debug(MODULE_NAME,
Localization.Reserved_attributes_are_set_0,
rootDirectoryKeyBlock.header.access);
Localization.Reserved_attributes_are_set_0,
rootDirectoryKeyBlock.header.access);
}
information = sbInformation.ToString();