diff --git a/ATA/Identify.cs b/ATA/Identify.cs index 594972f67..e06b341c5 100644 --- a/ATA/Identify.cs +++ b/ATA/Identify.cs @@ -177,9 +177,7 @@ namespace Aaru.Decoders.ATA { sb.Append("ATA-1 "); maxatalevel = 1; - - if(minatalevel > 1) - minatalevel = 1; + minatalevel = 1; } if(ata2) @@ -751,11 +749,11 @@ namespace Aaru.Decoders.ATA else sb.AppendFormat("Device rotate at {0} rpm", ATAID.NominalRotationRate).AppendLine(); - uint logicalsectorsize = 0; + uint logicalSectorSize = 0; if(!atapi) { - uint physicalsectorsize; + uint physicalSectorSize; if((ATAID.PhysLogSectorSize & 0x8000) == 0x0000 && (ATAID.PhysLogSectorSize & 0x4000) == 0x4000) @@ -763,27 +761,27 @@ namespace Aaru.Decoders.ATA if((ATAID.PhysLogSectorSize & 0x1000) == 0x1000) if(ATAID.LogicalSectorWords <= 255 || ATAID.LogicalAlignment == 0xFFFF) - logicalsectorsize = 512; + logicalSectorSize = 512; else - logicalsectorsize = ATAID.LogicalSectorWords * 2; + logicalSectorSize = ATAID.LogicalSectorWords * 2; else - logicalsectorsize = 512; + logicalSectorSize = 512; if((ATAID.PhysLogSectorSize & 0x2000) == 0x2000) - physicalsectorsize = logicalsectorsize * (uint)Math.Pow(2, ATAID.PhysLogSectorSize & 0xF); + physicalSectorSize = logicalSectorSize * (uint)Math.Pow(2, ATAID.PhysLogSectorSize & 0xF); else - physicalsectorsize = logicalsectorsize; + physicalSectorSize = logicalSectorSize; } else { - logicalsectorsize = 512; - physicalsectorsize = 512; + logicalSectorSize = 512; + physicalSectorSize = 512; } - sb.AppendFormat("Physical sector size: {0} bytes", physicalsectorsize).AppendLine(); - sb.AppendFormat("Logical sector size: {0} bytes", logicalsectorsize).AppendLine(); + sb.AppendFormat("Physical sector size: {0} bytes", physicalSectorSize).AppendLine(); + sb.AppendFormat("Logical sector size: {0} bytes", logicalSectorSize).AppendLine(); - if(logicalsectorsize != physicalsectorsize && + if(logicalSectorSize != physicalSectorSize && (ATAID.LogicalAlignment & 0x8000) == 0x0000 && (ATAID.LogicalAlignment & 0x4000) == 0x4000) sb.AppendFormat("Logical sector starts at offset {0} from physical sector", @@ -825,73 +823,73 @@ namespace Aaru.Decoders.ATA if(minatalevel <= 5) if(ATAID.CurrentSectors > 0) sb.AppendFormat("Device size in CHS mode: {0} bytes, {1} Mb, {2} MiB", - (ulong)ATAID.CurrentSectors * logicalsectorsize, - ((ulong)ATAID.CurrentSectors * logicalsectorsize) / 1000 / 1000, + (ulong)ATAID.CurrentSectors * logicalSectorSize, + ((ulong)ATAID.CurrentSectors * logicalSectorSize) / 1000 / 1000, ((ulong)ATAID.CurrentSectors * 512) / 1024 / 1024).AppendLine(); else { ulong currentSectors = (ulong)(ATAID.Cylinders * ATAID.Heads * ATAID.SectorsPerTrack); sb.AppendFormat("Device size in CHS mode: {0} bytes, {1} Mb, {2} MiB", - currentSectors * logicalsectorsize, - (currentSectors * logicalsectorsize) / 1000 / 1000, + currentSectors * logicalSectorSize, + (currentSectors * logicalSectorSize) / 1000 / 1000, (currentSectors * 512) / 1024 / 1024).AppendLine(); } if(ATAID.Capabilities.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.LBASupport)) - if(((ulong)ATAID.LBASectors * logicalsectorsize) / 1024 / 1024 > 1000000) + if(((ulong)ATAID.LBASectors * logicalSectorSize) / 1024 / 1024 > 1000000) sb.AppendFormat("Device size in 28-bit LBA mode: {0} bytes, {1} Tb, {2} TiB", - (ulong)ATAID.LBASectors * logicalsectorsize, - ((ulong)ATAID.LBASectors * logicalsectorsize) / 1000 / 1000 / 1000 / 1000, + (ulong)ATAID.LBASectors * logicalSectorSize, + ((ulong)ATAID.LBASectors * logicalSectorSize) / 1000 / 1000 / 1000 / 1000, ((ulong)ATAID.LBASectors * 512) / 1024 / 1024 / 1024 / 1024).AppendLine(); - else if(((ulong)ATAID.LBASectors * logicalsectorsize) / 1024 / 1024 > 1000) + else if(((ulong)ATAID.LBASectors * logicalSectorSize) / 1024 / 1024 > 1000) sb.AppendFormat("Device size in 28-bit LBA mode: {0} bytes, {1} Gb, {2} GiB", - (ulong)ATAID.LBASectors * logicalsectorsize, - ((ulong)ATAID.LBASectors * logicalsectorsize) / 1000 / 1000 / 1000, + (ulong)ATAID.LBASectors * logicalSectorSize, + ((ulong)ATAID.LBASectors * logicalSectorSize) / 1000 / 1000 / 1000, ((ulong)ATAID.LBASectors * 512) / 1024 / 1024 / 1024).AppendLine(); else sb.AppendFormat("Device size in 28-bit LBA mode: {0} bytes, {1} Mb, {2} MiB", - (ulong)ATAID.LBASectors * logicalsectorsize, - ((ulong)ATAID.LBASectors * logicalsectorsize) / 1000 / 1000, + (ulong)ATAID.LBASectors * logicalSectorSize, + ((ulong)ATAID.LBASectors * logicalSectorSize) / 1000 / 1000, ((ulong)ATAID.LBASectors * 512) / 1024 / 1024).AppendLine(); if(ATAID.CommandSet2.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CommandSetBit2.LBA48)) if(ATAID.CommandSet5.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CommandSetBit5.ExtSectors)) - if((ATAID.ExtendedUserSectors * logicalsectorsize) / 1024 / 1024 > 1000000) + if((ATAID.ExtendedUserSectors * logicalSectorSize) / 1024 / 1024 > 1000000) sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Tb, {2} TiB", - ATAID.ExtendedUserSectors * logicalsectorsize, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1000 / 1000 / 1000 / 1000, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1024 / 1024 / 1024 / + ATAID.ExtendedUserSectors * logicalSectorSize, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1000 / 1000 / 1000 / 1000, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024).AppendLine(); - else if((ATAID.ExtendedUserSectors * logicalsectorsize) / 1024 / 1024 > 1000) + else if((ATAID.ExtendedUserSectors * logicalSectorSize) / 1024 / 1024 > 1000) sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Gb, {2} GiB", - ATAID.ExtendedUserSectors * logicalsectorsize, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1000 / 1000 / 1000, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1024 / 1024 / 1024). + ATAID.ExtendedUserSectors * logicalSectorSize, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1000 / 1000 / 1000, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1024 / 1024 / 1024). AppendLine(); else sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Mb, {2} MiB", - ATAID.ExtendedUserSectors * logicalsectorsize, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1000 / 1000, - (ATAID.ExtendedUserSectors * logicalsectorsize) / 1024 / 1024).AppendLine(); + ATAID.ExtendedUserSectors * logicalSectorSize, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1000 / 1000, + (ATAID.ExtendedUserSectors * logicalSectorSize) / 1024 / 1024).AppendLine(); else { - if((ATAID.LBA48Sectors * logicalsectorsize) / 1024 / 1024 > 1000000) + if((ATAID.LBA48Sectors * logicalSectorSize) / 1024 / 1024 > 1000000) sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Tb, {2} TiB", - ATAID.LBA48Sectors * logicalsectorsize, - (ATAID.LBA48Sectors * logicalsectorsize) / 1000 / 1000 / 1000 / 1000, - (ATAID.LBA48Sectors * logicalsectorsize) / 1024 / 1024 / 1024 / 1024). + ATAID.LBA48Sectors * logicalSectorSize, + (ATAID.LBA48Sectors * logicalSectorSize) / 1000 / 1000 / 1000 / 1000, + (ATAID.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024 / 1024). AppendLine(); - else if((ATAID.LBA48Sectors * logicalsectorsize) / 1024 / 1024 > 1000) + else if((ATAID.LBA48Sectors * logicalSectorSize) / 1024 / 1024 > 1000) sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Gb, {2} GiB", - ATAID.LBA48Sectors * logicalsectorsize, - (ATAID.LBA48Sectors * logicalsectorsize) / 1000 / 1000 / 1000, - (ATAID.LBA48Sectors * logicalsectorsize) / 1024 / 1024 / 1024).AppendLine(); + ATAID.LBA48Sectors * logicalSectorSize, + (ATAID.LBA48Sectors * logicalSectorSize) / 1000 / 1000 / 1000, + (ATAID.LBA48Sectors * logicalSectorSize) / 1024 / 1024 / 1024).AppendLine(); else sb.AppendFormat("Device size in 48-bit LBA mode: {0} bytes, {1} Mb, {2} MiB", - ATAID.LBA48Sectors * logicalsectorsize, - (ATAID.LBA48Sectors * logicalsectorsize) / 1000 / 1000, - (ATAID.LBA48Sectors * logicalsectorsize) / 1024 / 1024).AppendLine(); + ATAID.LBA48Sectors * logicalSectorSize, + (ATAID.LBA48Sectors * logicalSectorSize) / 1000 / 1000, + (ATAID.LBA48Sectors * logicalSectorSize) / 1024 / 1024).AppendLine(); } if(ata1 || cfa) @@ -974,7 +972,8 @@ namespace Aaru.Decoders.ATA sb.Append("Device capabilities:"); - if(ATAID.Capabilities.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.StandardStanbyTimer)) + if(ATAID.Capabilities.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.StandardStandbyTimer) + ) sb.AppendLine().Append("Standby time values are standard"); if(ATAID.Capabilities.HasFlag(CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.IORDY)) @@ -1378,7 +1377,7 @@ namespace Aaru.Decoders.ATA if(ATAID.InterseekDelay != 0x0000 && ATAID.InterseekDelay != 0xFFFF) - sb.AppendLine().AppendFormat("{0} microseconds of interseek delay for ISO-7779 accoustic testing", + sb.AppendLine().AppendFormat("{0} microseconds of interseek delay for ISO-7779 acoustic testing", ATAID.InterseekDelay); if((ushort)ATAID.DeviceFormFactor != 0x0000 && @@ -2080,7 +2079,7 @@ namespace Aaru.Decoders.ATA sb.AppendLine(ATAID.SecurityStatus.HasFlag(CommonTypes. Structs.Devices.ATA.Identify.SecurityStatusBit.Expired) - ? "Security count has expired" : "Security count has notexpired"); + ? "Security count has expired" : "Security count has not expired"); sb.AppendLine(ATAID.SecurityStatus.HasFlag(CommonTypes. Structs.Devices.ATA.Identify.SecurityStatusBit.Maximum) @@ -2156,7 +2155,7 @@ namespace Aaru.Decoders.ATA sb.AppendLine().AppendFormat("Version {0}", (ATAID.NVCacheCaps & 0x0F00) >> 8).AppendLine(); } - sb.AppendLine().AppendFormat("Non-Volatile Cache is {0} bytes", ATAID.NVCacheSize * logicalsectorsize). + sb.AppendLine().AppendFormat("Non-Volatile Cache is {0} bytes", ATAID.NVCacheSize * logicalSectorSize). AppendLine(); } diff --git a/MMC/ExtendedCSD.cs b/MMC/ExtendedCSD.cs index 84cb6a906..15bc67a6b 100644 --- a/MMC/ExtendedCSD.cs +++ b/MMC/ExtendedCSD.cs @@ -215,10 +215,7 @@ namespace Aaru.Decoders.MMC { public static ExtendedCSD DecodeExtendedCSD(byte[] response) { - if(response == null) - return null; - - if(response.Length != 512) + if(response?.Length != 512) return null; var handle = GCHandle.Alloc(response, GCHandleType.Pinned); diff --git a/SCSI/MMC/DiscInformation.cs b/SCSI/MMC/DiscInformation.cs index 741dd3063..2be3781a4 100644 --- a/SCSI/MMC/DiscInformation.cs +++ b/SCSI/MMC/DiscInformation.cs @@ -122,17 +122,12 @@ namespace Aaru.Decoders.SCSI.MMC public static string Prettify000b(StandardDiscInformation? information) { - if(!information.HasValue) - return null; - - StandardDiscInformation decoded = information.Value; - - if(decoded.DataType != 0) + if(information?.DataType != 0) return null; var sb = new StringBuilder(); - switch(decoded.DiscType) + switch(information.Value.DiscType) { case 0x00: sb.AppendLine("Disc type declared as CD-DA or CD-ROM"); @@ -151,12 +146,12 @@ namespace Aaru.Decoders.SCSI.MMC break; default: - sb.AppendFormat("Unknown disc type {0:X2}h", decoded.DiscType).AppendLine(); + sb.AppendFormat("Unknown disc type {0:X2}h", information.Value.DiscType).AppendLine(); break; } - switch(decoded.DiscStatus) + switch(information.Value.DiscStatus) { case 0: sb.AppendLine("Disc is empty"); @@ -172,10 +167,10 @@ namespace Aaru.Decoders.SCSI.MMC break; } - if(decoded.Erasable) + if(information.Value.Erasable) sb.AppendLine("Disc is erasable"); - switch(decoded.LastSessionStatus) + switch(information.Value.LastSessionStatus) { case 0: sb.AppendLine("Last session is empty"); @@ -195,7 +190,7 @@ namespace Aaru.Decoders.SCSI.MMC break; } - switch(decoded.BGFormatStatus) + switch(information.Value.BGFormatStatus) { case 1: sb.AppendLine("Media was being formatted in the background but it is stopped and incomplete"); @@ -211,39 +206,39 @@ namespace Aaru.Decoders.SCSI.MMC break; } - if(decoded.Dbit) + if(information.Value.Dbit) sb.AppendLine("MRW is dirty"); - sb.AppendFormat("First track on disc is track {0}", decoded.FirstTrackNumber).AppendLine(); - sb.AppendFormat("Disc has {0} sessions", decoded.Sessions).AppendLine(); - sb.AppendFormat("First track in last session is track {0}", decoded.FirstTrackLastSession).AppendLine(); - sb.AppendFormat("Last track in last session is track {0}", decoded.LastTrackLastSession).AppendLine(); + sb.AppendFormat("First track on disc is track {0}", information.Value.FirstTrackNumber).AppendLine(); + sb.AppendFormat("Disc has {0} sessions", information.Value.Sessions).AppendLine(); + sb.AppendFormat("First track in last session is track {0}", information.Value.FirstTrackLastSession).AppendLine(); + sb.AppendFormat("Last track in last session is track {0}", information.Value.LastTrackLastSession).AppendLine(); sb.AppendFormat("Last session Lead-In address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}", - decoded.LastSessionLeadInStartLBA, (decoded.LastSessionLeadInStartLBA & 0xFF0000) >> 16, - (decoded.LastSessionLeadInStartLBA & 0xFF00) >> 8, - decoded.LastSessionLeadInStartLBA & 0xFF).AppendLine(); + information.Value.LastSessionLeadInStartLBA, (information.Value.LastSessionLeadInStartLBA & 0xFF0000) >> 16, + (information.Value.LastSessionLeadInStartLBA & 0xFF00) >> 8, + information.Value.LastSessionLeadInStartLBA & 0xFF).AppendLine(); sb.AppendFormat("Last possible Lead-Out address is {0} (as LBA) or {1:X2}:{2:X2}:{3:X2}", - decoded.LastPossibleLeadOutStartLBA, (decoded.LastPossibleLeadOutStartLBA & 0xFF0000) >> 16, - (decoded.LastPossibleLeadOutStartLBA & 0xFF00) >> 8, - decoded.LastPossibleLeadOutStartLBA & 0xFF).AppendLine(); + information.Value.LastPossibleLeadOutStartLBA, (information.Value.LastPossibleLeadOutStartLBA & 0xFF0000) >> 16, + (information.Value.LastPossibleLeadOutStartLBA & 0xFF00) >> 8, + information.Value.LastPossibleLeadOutStartLBA & 0xFF).AppendLine(); - sb.AppendLine(decoded.URU ? "Disc is defined for unrestricted use" : "Disc is defined for restricted use"); + sb.AppendLine(information.Value.URU ? "Disc is defined for unrestricted use" : "Disc is defined for restricted use"); - if(decoded.DID_V) - sb.AppendFormat("Disc ID: {0:X6}", decoded.DiscIdentification & 0x00FFFFFF).AppendLine(); + if(information.Value.DID_V) + sb.AppendFormat("Disc ID: {0:X6}", information.Value.DiscIdentification & 0x00FFFFFF).AppendLine(); - if(decoded.DBC_V) - sb.AppendFormat("Disc barcode: {0:X16}", decoded.DiscBarcode).AppendLine(); + if(information.Value.DBC_V) + sb.AppendFormat("Disc barcode: {0:X16}", information.Value.DiscBarcode).AppendLine(); - if(decoded.DAC_V) - sb.AppendFormat("Disc application code: {0}", decoded.DiscApplicationCode).AppendLine(); + if(information.Value.DAC_V) + sb.AppendFormat("Disc application code: {0}", information.Value.DiscApplicationCode).AppendLine(); - if(decoded.OPCTables == null) + if(information.Value.OPCTables == null) return sb.ToString(); - foreach(OPCTable table in decoded.OPCTables) + foreach(OPCTable table in information.Value.OPCTables) sb.AppendFormat("OPC values for {0}Kbit/sec.: {1}, {2}, {3}, {4}, {5}, {6}", table.Speed, table.OPCValues[0], table.OPCValues[1], table.OPCValues[2], table.OPCValues[3], table.OPCValues[4], table.OPCValues[5]).AppendLine(); @@ -278,23 +273,18 @@ namespace Aaru.Decoders.SCSI.MMC public static string Prettify001b(TrackResourcesInformation? information) { - if(!information.HasValue) - return null; - - TrackResourcesInformation decoded = information.Value; - - if(decoded.DataType != 1) + if(information?.DataType != 1) return null; var sb = new StringBuilder(); - sb.AppendFormat("{0} maximum possible tracks on the disc", decoded.MaxTracks).AppendLine(); - sb.AppendFormat("{0} assigned tracks on the disc", decoded.AssignedTracks).AppendLine(); + sb.AppendFormat("{0} maximum possible tracks on the disc", information.Value.MaxTracks).AppendLine(); + sb.AppendFormat("{0} assigned tracks on the disc", information.Value.AssignedTracks).AppendLine(); - sb.AppendFormat("{0} maximum possible appendable tracks on the disc", decoded.AppendableTracks). + sb.AppendFormat("{0} maximum possible appendable tracks on the disc", information.Value.AppendableTracks). AppendLine(); - sb.AppendFormat("{0} current appendable tracks on the disc", decoded.MaxAppendableTracks).AppendLine(); + sb.AppendFormat("{0} current appendable tracks on the disc", information.Value.MaxAppendableTracks).AppendLine(); return sb.ToString(); } @@ -331,22 +321,17 @@ namespace Aaru.Decoders.SCSI.MMC public static string Prettify010b(POWResourcesInformation? information) { - if(!information.HasValue) - return null; - - POWResourcesInformation decoded = information.Value; - - if(decoded.DataType != 1) + if(information?.DataType != 1) return null; var sb = new StringBuilder(); - sb.AppendFormat("{0} remaining POW replacements", decoded.RemainingPOWReplacements).AppendLine(); + sb.AppendFormat("{0} remaining POW replacements", information.Value.RemainingPOWReplacements).AppendLine(); - sb.AppendFormat("{0} remaining POW reallocation map entries", decoded.RemainingPOWReallocation). + sb.AppendFormat("{0} remaining POW reallocation map entries", information.Value.RemainingPOWReallocation). AppendLine(); - sb.AppendFormat("{0} remaining POW updates", decoded.RemainingPOWUpdates).AppendLine(); + sb.AppendFormat("{0} remaining POW updates", information.Value.RemainingPOWUpdates).AppendLine(); return sb.ToString(); }