mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
General cleanup and refactor.
This commit is contained in:
@@ -30,14 +30,14 @@
|
||||
// Copyright © 2011-2022 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
|
||||
namespace Aaru.Decoders.SCSI;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Aaru.CommonTypes.Structs.Devices.SCSI;
|
||||
|
||||
namespace Aaru.Decoders.SCSI;
|
||||
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
||||
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public static partial class Modes
|
||||
@@ -58,15 +58,15 @@ public static partial class Modes
|
||||
{
|
||||
header.BlockDescriptors = new BlockDescriptor[modeResponse[3] / 8];
|
||||
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
for(var i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
{
|
||||
header.BlockDescriptors[i].Density = (DensityType)modeResponse[0 + (i * 8) + 4];
|
||||
header.BlockDescriptors[i].Blocks += (ulong)(modeResponse[1 + (i * 8) + 4] << 16);
|
||||
header.BlockDescriptors[i].Blocks += (ulong)(modeResponse[2 + (i * 8) + 4] << 8);
|
||||
header.BlockDescriptors[i].Blocks += modeResponse[3 + (i * 8) + 4];
|
||||
header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[5 + (i * 8) + 4] << 16);
|
||||
header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[6 + (i * 8) + 4] << 8);
|
||||
header.BlockDescriptors[i].BlockLength += modeResponse[7 + (i * 8) + 4];
|
||||
header.BlockDescriptors[i].Density = (DensityType)modeResponse[0 + i * 8 + 4];
|
||||
header.BlockDescriptors[i].Blocks += (ulong)(modeResponse[1 + i * 8 + 4] << 16);
|
||||
header.BlockDescriptors[i].Blocks += (ulong)(modeResponse[2 + i * 8 + 4] << 8);
|
||||
header.BlockDescriptors[i].Blocks += modeResponse[3 + i * 8 + 4];
|
||||
header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[5 + i * 8 + 4] << 16);
|
||||
header.BlockDescriptors[i].BlockLength += (uint)(modeResponse[6 + i * 8 + 4] << 8);
|
||||
header.BlockDescriptors[i].BlockLength += modeResponse[7 + i * 8 + 4];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,24 +114,24 @@ public static partial class Modes
|
||||
Header = hdr.Value
|
||||
};
|
||||
|
||||
int blkDrLength = 0;
|
||||
var blkDrLength = 0;
|
||||
|
||||
if(decoded.Header.BlockDescriptors != null)
|
||||
blkDrLength = decoded.Header.BlockDescriptors.Length;
|
||||
|
||||
int offset = 4 + (blkDrLength * 8);
|
||||
int offset = 4 + blkDrLength * 8;
|
||||
int length = modeResponse[0] + 1;
|
||||
|
||||
if(length != modeResponse.Length)
|
||||
return decoded;
|
||||
|
||||
List<ModePage> listpages = new List<ModePage>();
|
||||
var listpages = new List<ModePage>();
|
||||
|
||||
while(offset < modeResponse.Length)
|
||||
{
|
||||
bool isSubpage = (modeResponse[offset] & 0x40) == 0x40;
|
||||
var pg = new ModePage();
|
||||
byte pageNo = (byte)(modeResponse[offset] & 0x3F);
|
||||
var pageNo = (byte)(modeResponse[offset] & 0x3F);
|
||||
|
||||
if(pageNo == 0)
|
||||
{
|
||||
@@ -187,8 +187,7 @@ public static partial class Modes
|
||||
|
||||
public static byte[] EncodeModeHeader6(ModeHeader header, PeripheralDeviceTypes deviceType)
|
||||
{
|
||||
byte[] hdr = header.BlockDescriptors != null ? new byte[4 + (header.BlockDescriptors.Length * 8)]
|
||||
: new byte[4];
|
||||
byte[] hdr = header.BlockDescriptors != null ? new byte[4 + header.BlockDescriptors.Length * 8] : new byte[4];
|
||||
|
||||
hdr[1] = (byte)header.MediumType;
|
||||
|
||||
@@ -233,15 +232,15 @@ public static partial class Modes
|
||||
|
||||
hdr[3] = (byte)(header.BlockDescriptors.Length * 8);
|
||||
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
for(var i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
{
|
||||
hdr[0 + (i * 8) + 4] = (byte)header.BlockDescriptors[i].Density;
|
||||
hdr[1 + (i * 8) + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16);
|
||||
hdr[2 + (i * 8) + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8);
|
||||
hdr[3 + (i * 8) + 4] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF);
|
||||
hdr[5 + (i * 8) + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16);
|
||||
hdr[6 + (i * 8) + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8);
|
||||
hdr[7 + (i * 8) + 4] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF);
|
||||
hdr[0 + i * 8 + 4] = (byte)header.BlockDescriptors[i].Density;
|
||||
hdr[1 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16);
|
||||
hdr[2 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8);
|
||||
hdr[3 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF);
|
||||
hdr[5 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF0000) >> 16);
|
||||
hdr[6 + i * 8 + 4] = (byte)((header.BlockDescriptors[i].BlockLength & 0xFF00) >> 8);
|
||||
hdr[7 + i * 8 + 4] = (byte)(header.BlockDescriptors[i].BlockLength & 0xFF);
|
||||
}
|
||||
|
||||
return hdr;
|
||||
@@ -249,14 +248,14 @@ public static partial class Modes
|
||||
|
||||
public static byte[] EncodeMode6(DecodedMode mode, PeripheralDeviceTypes deviceType)
|
||||
{
|
||||
int modeSize = 0;
|
||||
var modeSize = 0;
|
||||
|
||||
if(mode.Pages != null)
|
||||
modeSize += mode.Pages.Sum(page => page.PageResponse.Length);
|
||||
|
||||
byte[] hdr = EncodeModeHeader6(mode.Header, deviceType);
|
||||
modeSize += hdr.Length;
|
||||
byte[] md = new byte[modeSize];
|
||||
var md = new byte[modeSize];
|
||||
|
||||
Array.Copy(hdr, 0, md, 0, hdr.Length);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user