mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Code reformat.
This commit is contained in:
@@ -37,21 +37,26 @@ using System.Linq;
|
||||
|
||||
namespace DiscImageChef.Decoders.SCSI
|
||||
{
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBeInternal")]
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming"), SuppressMessage("ReSharper", "MemberCanBeInternal"),
|
||||
SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||
public static partial class Modes
|
||||
{
|
||||
public static ModeHeader? DecodeModeHeader10(byte[] modeResponse, PeripheralDeviceTypes deviceType)
|
||||
{
|
||||
if(modeResponse == null || modeResponse.Length < 8) return null;
|
||||
if(modeResponse == null ||
|
||||
modeResponse.Length < 8)
|
||||
return null;
|
||||
|
||||
ushort modeLength = (ushort)((modeResponse[0] << 8) + modeResponse[1]);
|
||||
ushort blockDescLength = (ushort)((modeResponse[6] << 8) + modeResponse[7]);
|
||||
|
||||
if(modeResponse.Length < modeLength) return null;
|
||||
if(modeResponse.Length < modeLength)
|
||||
return null;
|
||||
|
||||
ModeHeader header = new ModeHeader {MediumType = (MediumTypes)modeResponse[2]};
|
||||
var header = new ModeHeader
|
||||
{
|
||||
MediumType = (MediumTypes)modeResponse[2]
|
||||
};
|
||||
|
||||
bool longLBA = (modeResponse[4] & 0x01) == 0x01;
|
||||
|
||||
@@ -59,11 +64,17 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
if(longLBA)
|
||||
{
|
||||
header.BlockDescriptors = new BlockDescriptor[blockDescLength / 16];
|
||||
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
{
|
||||
if(12 + i * 16 + 8 >= modeResponse.Length) break;
|
||||
if(12 + i * 16 + 8 >= modeResponse.Length)
|
||||
break;
|
||||
|
||||
header.BlockDescriptors[i] = new BlockDescriptor
|
||||
{
|
||||
Density = DensityType.Default
|
||||
};
|
||||
|
||||
header.BlockDescriptors[i] = new BlockDescriptor {Density = DensityType.Default};
|
||||
byte[] temp = new byte[8];
|
||||
temp[0] = modeResponse[7 + i * 16 + 8];
|
||||
temp[1] = modeResponse[6 + i * 16 + 8];
|
||||
@@ -83,11 +94,14 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
else
|
||||
{
|
||||
header.BlockDescriptors = new BlockDescriptor[blockDescLength / 8];
|
||||
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
{
|
||||
if(7 + i * 8 + 8 >= modeResponse.Length) break;
|
||||
if(7 + i * 8 + 8 >= modeResponse.Length)
|
||||
break;
|
||||
|
||||
header.BlockDescriptors[i] = new BlockDescriptor();
|
||||
|
||||
if(deviceType != PeripheralDeviceTypes.DirectAccess)
|
||||
header.BlockDescriptors[i].Density = (DensityType)modeResponse[0 + i * 8 + 8];
|
||||
else
|
||||
@@ -111,19 +125,23 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
case PeripheralDeviceTypes.MultiMediaDevice:
|
||||
header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
|
||||
header.DPOFUA = (modeResponse[3] & 0x10) == 0x10;
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.SequentialAccess:
|
||||
header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
|
||||
header.Speed = (byte)(modeResponse[3] & 0x0F);
|
||||
header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4);
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.PrinterDevice:
|
||||
header.BufferedMode = (byte)((modeResponse[3] & 0x70) >> 4);
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.OpticalDevice:
|
||||
header.WriteProtected = (modeResponse[3] & 0x80) == 0x80;
|
||||
header.EBC = (modeResponse[3] & 0x01) == 0x01;
|
||||
header.DPOFUA = (modeResponse[3] & 0x10) == 0x10;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -136,29 +154,41 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
public static DecodedMode? DecodeMode10(byte[] modeResponse, PeripheralDeviceTypes deviceType)
|
||||
{
|
||||
ModeHeader? hdr = DecodeModeHeader10(modeResponse, deviceType);
|
||||
if(!hdr.HasValue) return null;
|
||||
|
||||
DecodedMode decoded = new DecodedMode {Header = hdr.Value};
|
||||
bool longlba = (modeResponse[4] & 0x01) == 0x01;
|
||||
int offset;
|
||||
int blkDrLength = 0;
|
||||
if(decoded.Header.BlockDescriptors != null) blkDrLength = decoded.Header.BlockDescriptors.Length;
|
||||
if(!hdr.HasValue)
|
||||
return null;
|
||||
|
||||
var decoded = new DecodedMode
|
||||
{
|
||||
Header = hdr.Value
|
||||
};
|
||||
|
||||
bool longlba = (modeResponse[4] & 0x01) == 0x01;
|
||||
int offset;
|
||||
int blkDrLength = 0;
|
||||
|
||||
if(decoded.Header.BlockDescriptors != null)
|
||||
blkDrLength = decoded.Header.BlockDescriptors.Length;
|
||||
|
||||
if(longlba)
|
||||
offset = 8 + blkDrLength * 16;
|
||||
else
|
||||
offset = 8 + blkDrLength * 8;
|
||||
|
||||
if(longlba) offset = 8 + blkDrLength * 16;
|
||||
else offset = 8 + blkDrLength * 8;
|
||||
int length = modeResponse[0] << 8;
|
||||
length += modeResponse[1];
|
||||
length += 2;
|
||||
|
||||
if(length != modeResponse.Length) return decoded;
|
||||
if(length != modeResponse.Length)
|
||||
return decoded;
|
||||
|
||||
List<ModePage> listpages = new List<ModePage>();
|
||||
|
||||
while(offset < modeResponse.Length)
|
||||
{
|
||||
bool isSubpage = (modeResponse[offset] & 0x40) == 0x40;
|
||||
ModePage pg = new ModePage();
|
||||
byte pageNo = (byte)(modeResponse[offset] & 0x3F);
|
||||
bool isSubpage = (modeResponse[offset] & 0x40) == 0x40;
|
||||
var pg = new ModePage();
|
||||
byte pageNo = (byte)(modeResponse[offset] & 0x3F);
|
||||
|
||||
if(pageNo == 0)
|
||||
{
|
||||
@@ -174,7 +204,8 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
{
|
||||
pg.PageResponse = new byte[(modeResponse[offset + 2] << 8) + modeResponse[offset + 3] + 4];
|
||||
|
||||
if(pg.PageResponse.Length + offset > modeResponse.Length) return decoded;
|
||||
if(pg.PageResponse.Length + offset > modeResponse.Length)
|
||||
return decoded;
|
||||
|
||||
Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
|
||||
pg.Page = (byte)(modeResponse[offset] & 0x3F);
|
||||
@@ -185,7 +216,8 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
{
|
||||
pg.PageResponse = new byte[modeResponse[offset + 1] + 2];
|
||||
|
||||
if(pg.PageResponse.Length + offset > modeResponse.Length) return decoded;
|
||||
if(pg.PageResponse.Length + offset > modeResponse.Length)
|
||||
return decoded;
|
||||
|
||||
Array.Copy(modeResponse, offset, pg.PageResponse, 0, pg.PageResponse.Length);
|
||||
pg.Page = (byte)(modeResponse[offset] & 0x3F);
|
||||
@@ -203,15 +235,15 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
}
|
||||
|
||||
public static byte[] EncodeModeHeader10(ModeHeader header, PeripheralDeviceTypes deviceType,
|
||||
bool longLBA = false)
|
||||
bool longLBA = false)
|
||||
{
|
||||
byte[] hdr;
|
||||
|
||||
if(header.BlockDescriptors != null)
|
||||
hdr = longLBA
|
||||
? new byte[8 + header.BlockDescriptors.Length * 16]
|
||||
: new byte[8 + header.BlockDescriptors.Length * 8];
|
||||
else hdr = new byte[8];
|
||||
hdr = longLBA ? new byte[8 + header.BlockDescriptors.Length * 16]
|
||||
: new byte[8 + header.BlockDescriptors.Length * 8];
|
||||
else
|
||||
hdr = new byte[8];
|
||||
|
||||
hdr[2] = (byte)header.MediumType;
|
||||
|
||||
@@ -219,27 +251,43 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
{
|
||||
case PeripheralDeviceTypes.DirectAccess:
|
||||
case PeripheralDeviceTypes.MultiMediaDevice:
|
||||
if(header.WriteProtected) hdr[3] += 0x80;
|
||||
if(header.DPOFUA) hdr[3] += 0x10;
|
||||
if(header.WriteProtected)
|
||||
hdr[3] += 0x80;
|
||||
|
||||
if(header.DPOFUA)
|
||||
hdr[3] += 0x10;
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.SequentialAccess:
|
||||
if(header.WriteProtected) hdr[3] += 0x80;
|
||||
if(header.WriteProtected)
|
||||
hdr[3] += 0x80;
|
||||
|
||||
hdr[3] += (byte)(header.Speed & 0x0F);
|
||||
hdr[3] += (byte)((header.BufferedMode << 4) & 0x70);
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.PrinterDevice:
|
||||
hdr[3] += (byte)((header.BufferedMode << 4) & 0x70);
|
||||
|
||||
break;
|
||||
case PeripheralDeviceTypes.OpticalDevice:
|
||||
if(header.WriteProtected) hdr[3] += 0x80;
|
||||
if(header.EBC) hdr[3] += 0x01;
|
||||
if(header.DPOFUA) hdr[3] += 0x10;
|
||||
if(header.WriteProtected)
|
||||
hdr[3] += 0x80;
|
||||
|
||||
if(header.EBC)
|
||||
hdr[3] += 0x01;
|
||||
|
||||
if(header.DPOFUA)
|
||||
hdr[3] += 0x10;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(longLBA) hdr[4] += 0x01;
|
||||
if(longLBA)
|
||||
hdr[4] += 0x01;
|
||||
|
||||
if(header.BlockDescriptors == null) return hdr;
|
||||
if(header.BlockDescriptors == null)
|
||||
return hdr;
|
||||
|
||||
if(longLBA)
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
@@ -262,8 +310,10 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
for(int i = 0; i < header.BlockDescriptors.Length; i++)
|
||||
{
|
||||
if(deviceType != PeripheralDeviceTypes.DirectAccess)
|
||||
hdr[0 + i * 8 + 8] = (byte)header.BlockDescriptors[i].Density;
|
||||
else hdr[0 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF000000) >> 24);
|
||||
hdr[0 + i * 8 + 8] = (byte)header.BlockDescriptors[i].Density;
|
||||
else
|
||||
hdr[0 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF000000) >> 24);
|
||||
|
||||
hdr[1 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF0000) >> 16);
|
||||
hdr[2 + i * 8 + 8] = (byte)((header.BlockDescriptors[i].Blocks & 0xFF00) >> 8);
|
||||
hdr[3 + i * 8 + 8] = (byte)(header.BlockDescriptors[i].Blocks & 0xFF);
|
||||
@@ -277,8 +327,10 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
|
||||
public static byte[] EncodeMode10(DecodedMode mode, PeripheralDeviceTypes deviceType)
|
||||
{
|
||||
int modeSize = 0;
|
||||
if(mode.Pages != null) modeSize += mode.Pages.Sum(page => page.PageResponse.Length);
|
||||
int modeSize = 0;
|
||||
|
||||
if(mode.Pages != null)
|
||||
modeSize += mode.Pages.Sum(page => page.PageResponse.Length);
|
||||
|
||||
byte[] hdr = EncodeModeHeader10(mode.Header, deviceType);
|
||||
modeSize += hdr.Length;
|
||||
@@ -286,10 +338,12 @@ namespace DiscImageChef.Decoders.SCSI
|
||||
|
||||
Array.Copy(hdr, 0, md, 0, hdr.Length);
|
||||
|
||||
if(mode.Pages == null) return md;
|
||||
if(mode.Pages == null)
|
||||
return md;
|
||||
|
||||
{
|
||||
int offset = hdr.Length;
|
||||
|
||||
foreach(ModePage page in mode.Pages)
|
||||
{
|
||||
Array.Copy(page.PageResponse, 0, md, offset, page.PageResponse.Length);
|
||||
|
||||
Reference in New Issue
Block a user